From 25d663931d7087579ff36fad173fb0390f83ae79 Mon Sep 17 00:00:00 2001 From: "kevin.qiao" Date: Fri, 22 Sep 2023 16:47:33 +0800 Subject: [PATCH] fix dynamic flags (#293) --- pkg/controller/component/graphd_cluster.go | 2 +- pkg/controller/component/helper.go | 21 ++++---------------- pkg/controller/component/metad_cluster.go | 2 +- pkg/controller/component/storaged_cluster.go | 2 +- pkg/util/http/http.go | 4 ++-- 5 files changed, 9 insertions(+), 22 deletions(-) diff --git a/pkg/controller/component/graphd_cluster.go b/pkg/controller/component/graphd_cluster.go index b9b45ab3..3c2eaef9 100644 --- a/pkg/controller/component/graphd_cluster.go +++ b/pkg/controller/component/graphd_cluster.go @@ -136,7 +136,7 @@ func (c *graphdCluster) syncGraphdWorkload(nc *v1alpha1.NebulaCluster) error { if nc.GraphdComponent().IsReady() { endpoints := nc.GetGraphdEndpoints(v1alpha1.GraphdPortNameHTTP) - if err := updateDynamicFlags(endpoints, newWorkload.GetAnnotations(), oldWorkload.GetAnnotations()); err != nil { + if err := updateDynamicFlags(endpoints, newWorkload.GetAnnotations()); err != nil { return fmt.Errorf("update graphd cluster %s dynamic flags failed: %v", newWorkload.GetName(), err) } } diff --git a/pkg/controller/component/helper.go b/pkg/controller/component/helper.go index 55d8b26e..9664509f 100644 --- a/pkg/controller/component/helper.go +++ b/pkg/controller/component/helper.go @@ -19,7 +19,6 @@ package component import ( "encoding/json" "fmt" - "reflect" "strings" "time" @@ -218,7 +217,7 @@ func staticFlags(config map[string]string) map[string]string { return static } -func updateDynamicFlags(endpoints []string, newAnnotations, oldAnnotations map[string]string) error { +func updateDynamicFlags(endpoints []string, newAnnotations map[string]string) error { newFlags := make(map[string]string) newFlagsVal, ok := newAnnotations[annotation.AnnLastAppliedDynamicFlagsKey] if ok { @@ -226,23 +225,11 @@ func updateDynamicFlags(endpoints []string, newAnnotations, oldAnnotations map[s return err } } - oldFlags := make(map[string]string) - oldFlagsVal, ok := oldAnnotations[annotation.AnnLastAppliedDynamicFlagsKey] - if ok { - if err := json.Unmarshal([]byte(oldFlagsVal), &oldFlags); err != nil { - return err - } - } - if reflect.DeepEqual(newFlags, oldFlags) { + if len(newFlags) == 0 { return nil } - - updated, removed := maputil.IntersectionDifference(oldFlags, newFlags) - _, added := maputil.IntersectionDifference(newFlags, oldFlags) - maputil.ResetMap(removed, v1alpha1.DynamicFlags) - merged := maputil.MergeStringMaps(true, updated, added, removed) - klog.Infof("merged dynamic flags: %v", merged) - str, err := codec.Encode(merged) + klog.Infof("dynamic flags: %v", newFlags) + str, err := codec.Encode(newFlags) if err != nil { return err } diff --git a/pkg/controller/component/metad_cluster.go b/pkg/controller/component/metad_cluster.go index ed114c4d..343dc892 100644 --- a/pkg/controller/component/metad_cluster.go +++ b/pkg/controller/component/metad_cluster.go @@ -137,7 +137,7 @@ func (c *metadCluster) syncMetadWorkload(nc *v1alpha1.NebulaCluster) error { } endpoints := nc.GetMetadEndpoints(v1alpha1.MetadPortNameHTTP) - if err := updateDynamicFlags(endpoints, newWorkload.GetAnnotations(), oldWorkload.GetAnnotations()); err != nil { + if err := updateDynamicFlags(endpoints, newWorkload.GetAnnotations()); err != nil { return fmt.Errorf("update metad cluster %s dynamic flags failed: %v", newWorkload.GetName(), err) } } diff --git a/pkg/controller/component/storaged_cluster.go b/pkg/controller/component/storaged_cluster.go index 8bc499eb..ae9e8ace 100644 --- a/pkg/controller/component/storaged_cluster.go +++ b/pkg/controller/component/storaged_cluster.go @@ -180,7 +180,7 @@ func (c *storagedCluster) syncStoragedWorkload(nc *v1alpha1.NebulaCluster) error if nc.StoragedComponent().IsReady() { endpoints := nc.GetStoragedEndpoints(v1alpha1.StoragedPortNameHTTP) - if err := updateDynamicFlags(endpoints, newWorkload.GetAnnotations(), oldWorkload.GetAnnotations()); err != nil { + if err := updateDynamicFlags(endpoints, newWorkload.GetAnnotations()); err != nil { return fmt.Errorf("update storaged cluster %s dynamic flags failed: %v", newWorkload.GetName(), err) } diff --git a/pkg/util/http/http.go b/pkg/util/http/http.go index 1b2bf65a..08993abf 100644 --- a/pkg/util/http/http.go +++ b/pkg/util/http/http.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "net/http" "time" @@ -44,7 +44,7 @@ func request(url, method string, jsonData []byte) ([]byte, error) { } }() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("io read error: %v", err) }