From 88d51743b32e6858ad3cd54a2e5f0ed79c164d89 Mon Sep 17 00:00:00 2001 From: l1b0k Date: Tue, 21 Jan 2025 19:53:09 +0800 Subject: [PATCH] daemon: add flag to control patch podIP annotations Signed-off-by: l1b0k --- daemon/daemon.go | 12 +++++++++--- types/daemon/config.go | 6 ++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index a17b8f98..1bda0691 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -88,6 +88,8 @@ type networkService struct { gcRulesOnce sync.Once rpc.UnimplementedTerwayBackendServer + + EnablePatchPodIPs bool } var serviceLog = logf.Log.WithName("server") @@ -277,9 +279,11 @@ func (n *networkService) AllocIP(ctx context.Context, r *rpc.AllocIPRequest) (*r } } - ips := getPodIPs(netConf) - if len(ips) > 0 { - _ = n.k8s.PatchPodIPInfo(pod, strings.Join(ips, ",")) + if n.EnablePatchPodIPs { + ips := getPodIPs(netConf) + if len(ips) > 0 { + _ = n.k8s.PatchPodIPInfo(pod, strings.Join(ips, ",")) + } } // 4. Record resource info @@ -859,6 +863,8 @@ func newNetworkService(ctx context.Context, configFilePath, daemonMode string) ( return nil, err } + netSrv.EnablePatchPodIPs = *config.EnablePatchPodIPs + serviceLog.Info("got config", "config", fmt.Sprintf("%+v", config)) backoff.OverrideBackoff(config.BackoffOverride) diff --git a/types/daemon/config.go b/types/daemon/config.go index 6f2b2f1e..27ac3527 100644 --- a/types/daemon/config.go +++ b/types/daemon/config.go @@ -63,6 +63,7 @@ type Config struct { KubeClientQPS float32 `json:"kube_client_qps"` KubeClientBurst int `json:"kube_client_burst"` ResourceGroupID string `json:"resource_group_id"` + EnablePatchPodIPs *bool `json:"enable_patch_pod_ips,omitempty" mod:"default=true"` } func (c *Config) GetSecurityGroups() []string { @@ -102,6 +103,11 @@ func (c *Config) Populate() { if c.IPStack == "" { c.IPStack = string(types.IPStackIPv4) } + + if c.EnablePatchPodIPs == nil { + enable := true + c.EnablePatchPodIPs = &enable + } } func (c *Config) Validate() error {