Skip to content

Commit

Permalink
fix: send context over add/remove functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamir David authored and Tamir David committed Nov 10, 2024
1 parent 81d525c commit 2c0abd3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions k8sutils/pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (
"k8s.io/client-go/kubernetes"
)

func AddLabelToNode(clientset *kubernetes.Clientset, nodeName string, labelKey string, labelValue string) error {
func AddLabelToNode(ctx context.Context, clientset *kubernetes.Clientset, nodeName string, labelKey string, labelValue string) error {
patch := []byte(`{"metadata": {"labels": {"` + labelKey + `": "` + labelValue + `"}}}`)
_, err := clientset.CoreV1().Nodes().Patch(context.TODO(), nodeName, types.StrategicMergePatchType, patch, metav1.PatchOptions{})
_, err := clientset.CoreV1().Nodes().Patch(ctx, nodeName, types.StrategicMergePatchType, patch, metav1.PatchOptions{})
if err != nil {
return err
}
return nil
}

func RemoveLabelFromNode(clientset *kubernetes.Clientset, nodeName string, labelKey string) error {
func RemoveLabelFromNode(ctx context.Context, clientset *kubernetes.Clientset, nodeName string, labelKey string) error {
patch := []byte(`{"metadata": {"labels": {"` + labelKey + `": null}}}`)
_, err := clientset.CoreV1().Nodes().Patch(context.TODO(), nodeName, types.StrategicMergePatchType, patch, metav1.PatchOptions{})
_, err := clientset.CoreV1().Nodes().Patch(ctx, nodeName, types.StrategicMergePatchType, patch, metav1.PatchOptions{})
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions odiglet/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func main() {
}

// add label of Odiglet Installed so the k8s-scheduler can schedule instrumented pods on this nodes
if err := k8snode.AddLabelToNode(clientset, env.Current.NodeName, consts.OdigletInstalledLabel, "true"); err != nil {
if err := k8snode.AddLabelToNode(ctx, clientset, env.Current.NodeName, consts.OdigletInstalledLabel, "true"); err != nil {
log.Logger.Error(err, "Failed to add label to the node")
os.Exit(-1)
}
Expand All @@ -127,7 +127,7 @@ func main() {
os.Exit(-1)
}
// Remove the label before exiting
if err := k8snode.RemoveLabelFromNode(clientset, env.Current.NodeName, consts.OdigletInstalledLabel); err != nil {
if err := k8snode.RemoveLabelFromNode(ctx, clientset, env.Current.NodeName, consts.OdigletInstalledLabel); err != nil {
log.Logger.Error(err, "Failed to remove label from the node")
}
log.Logger.V(0).Info("odiglet exiting")
Expand Down

0 comments on commit 2c0abd3

Please sign in to comment.