@@ -37,6 +37,7 @@ import (
37
37
"go.uber.org/zap/zapcore"
38
38
v1 "k8s.io/api/core/v1"
39
39
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
40
+ "k8s.io/apimachinery/pkg/types"
40
41
"k8s.io/client-go/kubernetes"
41
42
"k8s.io/client-go/rest"
42
43
ctrl "sigs.k8s.io/controller-runtime"
@@ -297,7 +298,13 @@ func (w *Watcher) deleteNodesASNs() error {
297
298
if as >= w .data .asnStart && as <= w .data .asnEnd {
298
299
delete (anns , "projectcalico.org/ASNumber" )
299
300
node .SetAnnotations (anns )
300
- _ , err := w .clientset .CoreV1 ().Nodes ().Update (ctx , node .DeepCopy (), metav1.UpdateOptions {})
301
+ payload := []patchStringValue {{
302
+ Op : "remove" ,
303
+ Path : "/metadata/annotations/projectcalico.org~1ASNumber" ,
304
+ Value : asn ,
305
+ }}
306
+ payloadBytes , _ := json .Marshal (payload )
307
+ _ , err := w .clientset .CoreV1 ().Nodes ().Patch (ctx , node .Name , types .JSONPatchType , payloadBytes , metav1.PatchOptions {})
301
308
if err != nil {
302
309
return err
303
310
}
@@ -627,14 +634,21 @@ func (w *Watcher) fillNodesASNs() error {
627
634
if ! asnMap [asn ] {
628
635
anns ["projectcalico.org/ASNumber" ] = asn
629
636
node .SetAnnotations (anns )
637
+ payload := []patchStringValue {{
638
+ Op : "replace" ,
639
+ Path : "/metadata/annotations/projectcalico.org~1ASNumber" ,
640
+ Value : asn ,
641
+ }}
642
+ payloadBytes , _ := json .Marshal (payload )
630
643
ctx , cancel := context .WithTimeout (cntxt , contextTimeout )
631
- _ , err := w .clientset .CoreV1 ().Nodes ().Update (ctx , node .DeepCopy (), metav1.UpdateOptions {})
644
+ _ , err := w .clientset .CoreV1 ().Nodes ().Patch (ctx , node .Name , types . JSONPatchType , payloadBytes , metav1.PatchOptions {})
632
645
if err != nil {
633
646
cancel ()
634
647
return err
635
648
}
636
- cancel ()
637
649
asnMap [asn ] = true
650
+ cancel ()
651
+ break
638
652
}
639
653
}
640
654
} else {
@@ -773,3 +787,10 @@ func (w *Watcher) validateASNRange(asns string) (int, int, error) {
773
787
774
788
return a , b , nil
775
789
}
790
+
791
+ // patchStringValue specifies a patch operation for a string.
792
+ type patchStringValue struct {
793
+ Op string `json:"op"`
794
+ Path string `json:"path"`
795
+ Value string `json:"value"`
796
+ }
0 commit comments