Merge pull request #100262 from chaitanyabandi/daemon-ns-patch

use Patch API to add namespace annotations
This commit is contained in:
Kubernetes Prow Robot 2021-04-29 11:36:11 -07:00 committed by GitHub
commit eb326fdc07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,7 @@ package apps
import (
"bytes"
"context"
"encoding/json"
"fmt"
"math/rand"
"reflect"
@ -137,7 +138,7 @@ var _ = SIGDescribe("Daemon set [Serial]", func() {
c = f.ClientSet
updatedNS, err := updateNamespaceAnnotations(c, ns)
updatedNS, err := patchNamespaceAnnotations(c, ns)
framework.ExpectNoError(err)
ns = updatedNS.Name
@ -884,24 +885,24 @@ func clearDaemonSetNodeLabels(c clientset.Interface) error {
return nil
}
// updateNamespaceAnnotations sets node selectors related annotations on tests namespaces to empty
func updateNamespaceAnnotations(c clientset.Interface, nsName string) (*v1.Namespace, error) {
// patchNamespaceAnnotations sets node selectors related annotations on tests namespaces to empty
func patchNamespaceAnnotations(c clientset.Interface, nsName string) (*v1.Namespace, error) {
nsClient := c.CoreV1().Namespaces()
ns, err := nsClient.Get(context.TODO(), nsName, metav1.GetOptions{})
annotations := make(map[string]string)
for _, n := range NamespaceNodeSelectors {
annotations[n] = ""
}
nsPatch, err := json.Marshal(map[string]interface{}{
"metadata": map[string]interface{}{
"annotations": annotations,
},
})
if err != nil {
return nil, err
}
if ns.Annotations == nil {
ns.Annotations = make(map[string]string)
}
for _, n := range NamespaceNodeSelectors {
ns.Annotations[n] = ""
}
return nsClient.Update(context.TODO(), ns, metav1.UpdateOptions{})
return nsClient.Patch(context.TODO(), nsName, types.StrategicMergePatchType, nsPatch, metav1.PatchOptions{})
}
func setDaemonSetNodeLabels(c clientset.Interface, nodeName string, labels map[string]string) (*v1.Node, error) {