Skip to content

Commit

Permalink
fix dynamic flags (#295)
Browse files Browse the repository at this point in the history
fix dynamic flags (#293)
  • Loading branch information
MegaByte875 authored Sep 22, 2023
1 parent fbf5623 commit 6a77568
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/component/graphd_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,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)
}
}
Expand Down
21 changes: 4 additions & 17 deletions pkg/controller/component/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package component
import (
"encoding/json"
"fmt"
"reflect"
"strings"
"time"

Expand Down Expand Up @@ -218,31 +217,19 @@ 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 {
if err := json.Unmarshal([]byte(newFlagsVal), &newFlags); err != nil {
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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/component/metad_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/component/storaged_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,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)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/util/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"

Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 6a77568

Please sign in to comment.