From ce5c6760f7f8fa2b15da9400cf32243b9f43e69b Mon Sep 17 00:00:00 2001 From: l1b0k Date: Tue, 7 Jan 2025 09:48:42 +0800 Subject: [PATCH] daemon: add flag to control patch podIP annotations Signed-off-by: l1b0k --- daemon/builder.go | 6 +++++- daemon/daemon.go | 10 +++++++--- types/daemon/config.go | 6 ++++++ types/daemon/config_test.go | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/daemon/builder.go b/daemon/builder.go index 81f99c55..e7e95743 100644 --- a/daemon/builder.go +++ b/daemon/builder.go @@ -83,6 +83,8 @@ func (b *NetworkServiceBuilder) LoadGlobalConfig() *NetworkServiceBuilder { b.err = err return b } + globalConfig.Populate() + switch globalConfig.IPStack { case "ipv4": b.service.enableIPv4 = true @@ -99,7 +101,7 @@ func (b *NetworkServiceBuilder) LoadGlobalConfig() *NetworkServiceBuilder { } b.service.ipamType = globalConfig.IPAMType - + b.service.enablePatchPodIPs = *globalConfig.EnablePatchPodIPs return b } @@ -147,6 +149,8 @@ func (b *NetworkServiceBuilder) LoadDynamicConfig() *NetworkServiceBuilder { b.config = config + b.service.enablePatchPodIPs = *config.EnablePatchPodIPs + return b } diff --git a/daemon/daemon.go b/daemon/daemon.go index 964497bf..70e07ab4 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -78,6 +78,8 @@ type networkService struct { gcRulesOnce sync.Once + enablePatchPodIPs bool + rpc.UnimplementedTerwayBackendServer } @@ -267,9 +269,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 diff --git a/types/daemon/config.go b/types/daemon/config.go index 959ef3b6..cfcc4e87 100644 --- a/types/daemon/config.go +++ b/types/daemon/config.go @@ -58,6 +58,7 @@ type Config struct { KubeClientBurst int `json:"kube_client_burst"` ResourceGroupID string `json:"resource_group_id"` RateLimit map[string]int `json:"rate_limit"` + EnablePatchPodIPs *bool `json:"enable_patch_pod_ips,omitempty" mod:"default=true"` } func (c *Config) GetSecurityGroups() []string { @@ -97,6 +98,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 { diff --git a/types/daemon/config_test.go b/types/daemon/config_test.go index 58818472..407588d6 100644 --- a/types/daemon/config_test.go +++ b/types/daemon/config_test.go @@ -152,6 +152,7 @@ func TestPopulateSetsDefaultValues(t *testing.T) { assert.Equal(t, 1.0, cfg.EniCapRatio) assert.Equal(t, VSwitchSelectionPolicyRandom, cfg.VSwitchSelectionPolicy) assert.Equal(t, string(types.IPStackIPv4), cfg.IPStack) + assert.True(t, *cfg.EnablePatchPodIPs) } func TestPopulateDoesNotOverrideExistingValues(t *testing.T) {