@@ -28,13 +28,14 @@ const (
2828 // Default Configuration for Pod ENI resource type
2929 PodENIDefaultWorker = 30
3030
31- // Default Configuration for IPv4 resource type
32- IPv4DefaultWorker = 2
33- IPv4DefaultWPSize = 3
34- IPv4DefaultMaxDev = 1
35- IPv4DefaultResSize = 0
36-
37- // Default Configuration for IPv4 prefix resource type
31+ // Default Windows Configuration for IPv4 resource type
32+ IPv4DefaultWinWorkerCount = 2
33+ IPv4DefaultWinWarmIPTarget = 1
34+ IPv4DefaultWinMinIPTarget = 3
35+ IPv4DefaultWinMaxDev = 0
36+ IPv4DefaultWinResSize = 0
37+
38+ // Default Windows Configuration for IPv4 prefix resource type
3839 IPv4PDDefaultWorker = 2
3940 IPv4PDDefaultWPSize = 1
4041 IPv4PDDefaultMaxDev = 0
@@ -70,26 +71,43 @@ func LoadResourceConfig() map[string]ResourceConfig {
7071func LoadResourceConfigFromConfigMap (log logr.Logger , vpcCniConfigMap * v1.ConfigMap ) map [string ]ResourceConfig {
7172 resourceConfig := getDefaultResourceConfig ()
7273
73- warmIPTarget , minIPTarget , warmPrefixTarget := ParseWinPDTargets (log , vpcCniConfigMap )
74+ warmIPTarget , minIPTarget , warmPrefixTarget , isPDEnabled := ParseWinIPTargetConfigs (log , vpcCniConfigMap )
7475
7576 // If no PD configuration is set in configMap or none is valid, return default resource config
7677 if warmIPTarget == 0 && minIPTarget == 0 && warmPrefixTarget == 0 {
7778 return resourceConfig
7879 }
7980
80- resourceConfig [ResourceNameIPAddressFromPrefix ].WarmPoolConfig .WarmIPTarget = warmIPTarget
81- resourceConfig [ResourceNameIPAddressFromPrefix ].WarmPoolConfig .MinIPTarget = minIPTarget
82- resourceConfig [ResourceNameIPAddressFromPrefix ].WarmPoolConfig .WarmPrefixTarget = warmPrefixTarget
81+ if isPDEnabled {
82+ resourceConfig [ResourceNameIPAddressFromPrefix ].WarmPoolConfig .WarmIPTarget = warmIPTarget
83+ resourceConfig [ResourceNameIPAddressFromPrefix ].WarmPoolConfig .MinIPTarget = minIPTarget
84+ resourceConfig [ResourceNameIPAddressFromPrefix ].WarmPoolConfig .WarmPrefixTarget = warmPrefixTarget
85+ } else {
86+ resourceConfig [ResourceNameIPAddress ].WarmPoolConfig .WarmIPTarget = warmIPTarget
87+ resourceConfig [ResourceNameIPAddress ].WarmPoolConfig .MinIPTarget = minIPTarget
88+ resourceConfig [ResourceNameIPAddress ].WarmPoolConfig .WarmPrefixTarget = warmPrefixTarget // ignore warm prefix in secondary IP mode
89+ }
8390
8491 return resourceConfig
8592}
8693
87- // ParseWinPDTargets parses config map for Windows prefix delegation configurations set by users
88- func ParseWinPDTargets (log logr.Logger , vpcCniConfigMap * v1.ConfigMap ) (warmIPTarget int , minIPTarget int , warmPrefixTarget int ) {
94+ // ParseWinIPTargetConfigs parses Windows IP target configuration parameters in the amazon-vpc-cni ConfigMap
95+ func ParseWinIPTargetConfigs (log logr.Logger , vpcCniConfigMap * v1.ConfigMap ) (warmIPTarget int , minIPTarget int , warmPrefixTarget int , isPDEnabled bool ) {
8996 warmIPTarget , minIPTarget , warmPrefixTarget = 0 , 0 , 0
9097
9198 if vpcCniConfigMap .Data == nil {
92- return warmIPTarget , minIPTarget , warmPrefixTarget
99+ log .V (1 ).Info ("No configuration found in ConfigMap, falling back to using secondary IP mode with default values" )
100+ isPDEnabled = false
101+ minIPTarget = IPv4DefaultWinMinIPTarget
102+ warmIPTarget = IPv4DefaultWinWarmIPTarget
103+ warmPrefixTarget = 0
104+ return warmIPTarget , minIPTarget , warmPrefixTarget , isPDEnabled
105+ }
106+
107+ isPDEnabled , err := strconv .ParseBool (vpcCniConfigMap .Data [EnableWindowsPrefixDelegationKey ])
108+ if err != nil {
109+ log .V (1 ).Info ("Failed to parse prefix delegation flag from ConfigMap, falling back to using secondary IP mode" )
110+ isPDEnabled = false
93111 }
94112
95113 warmIPTargetStr , foundWarmIP := vpcCniConfigMap .Data [WarmIPTarget ]
@@ -105,36 +123,69 @@ func ParseWinPDTargets(log logr.Logger, vpcCniConfigMap *v1.ConfigMap) (warmIPTa
105123 warmPrefixTargetStr , foundWarmPrefix = vpcCniConfigMap .Data [WinWarmPrefixTarget ]
106124 }
107125
108- // If no configuration is found, return 0
109- if ! foundWarmIP && ! foundMinIP && ! foundWarmPrefix {
110- return warmIPTarget , minIPTarget , warmPrefixTarget
111- }
112-
126+ // If warm IP target config value is not found, or there is an error parsing it, the value will be set to zero
113127 if foundWarmIP {
114128 warmIPTargetInt , err := strconv .Atoi (warmIPTargetStr )
115129 if err != nil {
116- log .Error (err , "failed to parse warm ip target" , "warm ip target" , warmIPTargetStr )
130+ log .V (1 ).Info ("could not parse warm ip target, defaulting to zero" , "warm ip target" , warmIPTargetStr )
131+ warmIPTarget = 0
117132 } else {
118133 warmIPTarget = warmIPTargetInt
119134 }
135+ } else {
136+ log .V (1 ).Info ("could not find warm ip target in ConfigMap, defaulting to zero" )
137+ warmIPTarget = 0
120138 }
139+
140+ // If min IP target config value is not found, or there is an error parsing it, the value will be set to zero
121141 if foundMinIP {
122142 minIPTargetInt , err := strconv .Atoi (minIPTargetStr )
123143 if err != nil {
124- log .Error (err , "failed to parse minimum ip target" , "minimum ip target" , minIPTargetStr )
144+ log .V (1 ).Info ("could not parse minimum ip target, defaulting to zero" , "minimum ip target" , minIPTargetStr )
145+ minIPTarget = 0
125146 } else {
126147 minIPTarget = minIPTargetInt
127148 }
149+ } else {
150+ log .V (1 ).Info ("could not find minimum ip target in ConfigMap, defaulting to zero" )
151+ minIPTarget = 0
128152 }
129- if foundWarmPrefix {
153+
154+ // If PD is enabled and warm prefix target config value is not found, or there is an error parsing it, the value will be set to zero
155+ if ! isPDEnabled && foundWarmPrefix {
156+ log .V (1 ).Info ("warm prefix configuration not supported in secondary IP mode, will ignore warm prefix configuration" )
157+ } else if isPDEnabled && foundWarmPrefix {
130158 warmPrefixTargetInt , err := strconv .Atoi (warmPrefixTargetStr )
131159 if err != nil {
132- log .Error (err , "failed to parse warm prefix target" , "warm prefix target" , warmPrefixTargetStr )
160+ log .Error (err , "failed to parse warm prefix target, defaulting to zero" , "warm prefix target" , warmPrefixTargetStr )
161+ warmPrefixTarget = 0
133162 } else {
134163 warmPrefixTarget = warmPrefixTargetInt
135164 }
165+ } else if isPDEnabled && ! foundWarmPrefix {
166+ log .V (1 ).Info ("could not find warm prefix target in ConfigMap, defaulting to zero" )
167+ warmPrefixTarget = 0
136168 }
137- return warmIPTarget , minIPTarget , warmPrefixTarget
169+
170+ // If all three config parameter values (warm-ip-target, min-ip-target, warm-prefix-target) are 0,
171+ // Then default values for warm-ip-target and min-ip-target will be set
172+ // This ensures that when in PD mode and warm-prefix-target is set, then it can take precedence when other configs are unspecified
173+ if warmIPTarget == 0 && minIPTarget == 0 && warmPrefixTarget == 0 {
174+ if isPDEnabled {
175+ minIPTarget = IPv4PDDefaultMinIPTargetSize
176+ warmIPTarget = IPv4PDDefaultWarmIPTargetSize
177+ } else {
178+ minIPTarget = IPv4DefaultWinMinIPTarget
179+ warmIPTarget = IPv4DefaultWinWarmIPTarget
180+ }
181+ log .V (1 ).Info (
182+ "No valid configuration values for warm-ip-target, min-ip-target and warm-prefix-target found in ConfigMap, falling back to using default values" ,
183+ "minIPTarget" , minIPTarget ,
184+ "warmIPTarget" , warmIPTarget ,
185+ )
186+ }
187+
188+ return warmIPTarget , minIPTarget , warmPrefixTarget , isPDEnabled
138189}
139190
140191// getDefaultResourceConfig returns the default Resource Configuration.
@@ -153,13 +204,15 @@ func getDefaultResourceConfig() map[string]ResourceConfig {
153204
154205 // Create default configuration for IPv4 Resource
155206 ipV4WarmPoolConfig := WarmPoolConfig {
156- DesiredSize : IPv4DefaultWPSize ,
157- MaxDeviation : IPv4DefaultMaxDev ,
158- ReservedSize : IPv4DefaultResSize ,
207+ DesiredSize : IPv4DefaultWinWarmIPTarget ,
208+ WarmIPTarget : IPv4DefaultWinWarmIPTarget ,
209+ MinIPTarget : IPv4DefaultWinMinIPTarget ,
210+ MaxDeviation : IPv4DefaultWinMaxDev ,
211+ ReservedSize : IPv4DefaultWinResSize ,
159212 }
160213 ipV4Config := ResourceConfig {
161214 Name : ResourceNameIPAddress ,
162- WorkerCount : IPv4DefaultWorker ,
215+ WorkerCount : IPv4DefaultWinWorkerCount ,
163216 SupportedOS : map [string ]bool {OSWindows : true , OSLinux : false },
164217 WarmPoolConfig : & ipV4WarmPoolConfig ,
165218 }
0 commit comments