@@ -18,6 +18,7 @@ package reconfigure
1818
1919import (
2020 "context"
21+ "encoding/json"
2122 "fmt"
2223 "os"
2324 "os/exec"
@@ -27,6 +28,7 @@ import (
2728
2829 log "github.com/sirupsen/logrus"
2930 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31+ "k8s.io/apimachinery/pkg/types"
3032 "k8s.io/apimachinery/pkg/util/wait"
3133 "k8s.io/client-go/kubernetes"
3234
@@ -573,20 +575,16 @@ func (r *Reconfigure) setNodeLabel(key, value string) error {
573575}
574576
575577func (r * Reconfigure ) setNodeLabels (labels map [string ]string ) error {
576- node , err := r .clientset .CoreV1 ().Nodes ().Get (r .ctx , r .opts .NodeName , metav1.GetOptions {})
578+ patchData , err := json .Marshal (map [string ]interface {}{
579+ "metadata" : map [string ]interface {}{
580+ "labels" : labels ,
581+ },
582+ })
577583 if err != nil {
578- return fmt .Errorf ("failed to get node: %w" , err )
579- }
580-
581- if node .Labels == nil {
582- node .Labels = make (map [string ]string )
583- }
584-
585- for key , value := range labels {
586- node .Labels [key ] = value
584+ return fmt .Errorf ("failed to marshal patch data: %w" , err )
587585 }
588586
589- _ , err = r .clientset .CoreV1 ().Nodes ().Update (r .ctx , node , metav1.UpdateOptions {})
587+ _ , err = r .clientset .CoreV1 ().Nodes ().Patch (r .ctx , r . opts . NodeName , types . MergePatchType , patchData , metav1.PatchOptions {})
590588 return err
591589}
592590
0 commit comments