mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #97078 from srm09/add-context-to-cordon-update
Passes a context to the drain helper object
This commit is contained in:
commit
2efd293658
@ -73,6 +73,12 @@ func (c *CordonHelper) UpdateIfRequired(desired bool) bool {
|
|||||||
// JSON, or if either patch or update calls fail; it will also return a second error
|
// JSON, or if either patch or update calls fail; it will also return a second error
|
||||||
// whenever creating a patch has failed
|
// whenever creating a patch has failed
|
||||||
func (c *CordonHelper) PatchOrReplace(clientset kubernetes.Interface, serverDryRun bool) (error, error) {
|
func (c *CordonHelper) PatchOrReplace(clientset kubernetes.Interface, serverDryRun bool) (error, error) {
|
||||||
|
return c.PatchOrReplaceWithContext(context.TODO(), clientset, serverDryRun)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PatchOrReplaceWithContext provides the option to pass a custom context while updating
|
||||||
|
// the node status
|
||||||
|
func (c *CordonHelper) PatchOrReplaceWithContext(clientCtx context.Context, clientset kubernetes.Interface, serverDryRun bool) (error, error) {
|
||||||
client := clientset.CoreV1().Nodes()
|
client := clientset.CoreV1().Nodes()
|
||||||
|
|
||||||
oldData, err := json.Marshal(c.node)
|
oldData, err := json.Marshal(c.node)
|
||||||
@ -93,13 +99,13 @@ func (c *CordonHelper) PatchOrReplace(clientset kubernetes.Interface, serverDryR
|
|||||||
if serverDryRun {
|
if serverDryRun {
|
||||||
patchOptions.DryRun = []string{metav1.DryRunAll}
|
patchOptions.DryRun = []string{metav1.DryRunAll}
|
||||||
}
|
}
|
||||||
_, err = client.Patch(context.TODO(), c.node.Name, types.StrategicMergePatchType, patchBytes, patchOptions)
|
_, err = client.Patch(clientCtx, c.node.Name, types.StrategicMergePatchType, patchBytes, patchOptions)
|
||||||
} else {
|
} else {
|
||||||
updateOptions := metav1.UpdateOptions{}
|
updateOptions := metav1.UpdateOptions{}
|
||||||
if serverDryRun {
|
if serverDryRun {
|
||||||
updateOptions.DryRun = []string{metav1.DryRunAll}
|
updateOptions.DryRun = []string{metav1.DryRunAll}
|
||||||
}
|
}
|
||||||
_, err = client.Update(context.TODO(), c.node, updateOptions)
|
_, err = client.Update(clientCtx, c.node, updateOptions)
|
||||||
}
|
}
|
||||||
return err, patchErr
|
return err, patchErr
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ func RunCordonOrUncordon(drainer *Helper, node *corev1.Node, desired bool) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err, patchErr := c.PatchOrReplace(drainer.Client, false)
|
err, patchErr := c.PatchOrReplaceWithContext(drainer.Ctx, drainer.Client, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if patchErr != nil {
|
if patchErr != nil {
|
||||||
return fmt.Errorf("cordon error: %s; merge patch error: %s", err.Error(), patchErr.Error())
|
return fmt.Errorf("cordon error: %s; merge patch error: %s", err.Error(), patchErr.Error())
|
||||||
|
Loading…
Reference in New Issue
Block a user