Skip to content

Commit 6325924

Browse files
add EnableAZR flag to make home az goroutine as an opt-in feature (#2067)
add EnabledAZR flag to make home az goroutine as an opt-in feature change PopulateHomeAzCacheRetryIntervalSecs default to 60 Co-authored-by: rjdenney <[email protected]>
1 parent 63548ed commit 6325924

File tree

5 files changed

+73
-41
lines changed

5 files changed

+73
-41
lines changed

cns/configuration/cns_config.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
"MSISettings": {
3030
"ResourceID": ""
3131
},
32-
"PopulateHomeAzCacheRetryIntervalSecs": 15,
33-
"MellanoxMonitorIntervalSecs": 30
32+
"MellanoxMonitorIntervalSecs": 30,
33+
"AZRSettings": {
34+
"EnableAZR": false,
35+
"PopulateHomeAzCacheRetryIntervalSecs": 60
36+
}
3437
}

cns/configuration/configuration.go

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,30 @@ const (
2020
)
2121

2222
type CNSConfig struct {
23-
ChannelMode string
24-
EnablePprof bool
25-
EnableSubnetScarcity bool
26-
InitializeFromCNI bool
27-
ManagedSettings ManagedSettings
28-
MetricsBindAddress string
29-
SyncHostNCTimeoutMs int
30-
SyncHostNCVersionIntervalMs int
31-
TLSCertificatePath string
32-
TLSEndpoint string
33-
TLSPort string
34-
TLSSubjectName string
35-
TelemetrySettings TelemetrySettings
36-
UseHTTPS bool
37-
WireserverIP string
38-
KeyVaultSettings KeyVaultSettings
39-
MSISettings MSISettings
40-
ProgramSNATIPTables bool
41-
ManageEndpointState bool
42-
CNIConflistScenario string
43-
EnableCNIConflistGeneration bool
44-
CNIConflistFilepath string
45-
PopulateHomeAzCacheRetryIntervalSecs int
46-
MellanoxMonitorIntervalSecs int
23+
ChannelMode string
24+
EnablePprof bool
25+
EnableSubnetScarcity bool
26+
InitializeFromCNI bool
27+
ManagedSettings ManagedSettings
28+
MetricsBindAddress string
29+
SyncHostNCTimeoutMs int
30+
SyncHostNCVersionIntervalMs int
31+
TLSCertificatePath string
32+
TLSEndpoint string
33+
TLSPort string
34+
TLSSubjectName string
35+
TelemetrySettings TelemetrySettings
36+
UseHTTPS bool
37+
WireserverIP string
38+
KeyVaultSettings KeyVaultSettings
39+
MSISettings MSISettings
40+
ProgramSNATIPTables bool
41+
ManageEndpointState bool
42+
CNIConflistScenario string
43+
EnableCNIConflistGeneration bool
44+
CNIConflistFilepath string
45+
MellanoxMonitorIntervalSecs int
46+
AZRSettings AZRSettings
4747
}
4848

4949
type TelemetrySettings struct {
@@ -80,6 +80,11 @@ type ManagedSettings struct {
8080
NodeSyncIntervalInSeconds int
8181
}
8282

83+
type AZRSettings struct {
84+
EnableAZR bool
85+
PopulateHomeAzCacheRetryIntervalSecs int
86+
}
87+
8388
type MSISettings struct {
8489
ResourceID string
8590
}
@@ -165,6 +170,13 @@ func setManagedSettingDefaults(managedSettings *ManagedSettings) {
165170
}
166171
}
167172

173+
func setAZRSettingsDefaults(azrSettings *AZRSettings) {
174+
if azrSettings.PopulateHomeAzCacheRetryIntervalSecs == 0 {
175+
// set the default PopulateHomeAzCache retry interval to 60 seconds
176+
azrSettings.PopulateHomeAzCacheRetryIntervalSecs = 60
177+
}
178+
}
179+
168180
func setKeyVaultSettingsDefaults(kvs *KeyVaultSettings) {
169181
if kvs.RefreshIntervalInHrs == 0 {
170182
kvs.RefreshIntervalInHrs = 12 //nolint:gomnd // default times
@@ -176,6 +188,7 @@ func SetCNSConfigDefaults(config *CNSConfig) {
176188
setTelemetrySettingDefaults(&config.TelemetrySettings)
177189
setManagedSettingDefaults(&config.ManagedSettings)
178190
setKeyVaultSettingsDefaults(&config.KeyVaultSettings)
191+
setAZRSettingsDefaults(&config.AZRSettings)
179192

180193
if config.ChannelMode == "" {
181194
config.ChannelMode = cns.Direct
@@ -189,10 +202,6 @@ func SetCNSConfigDefaults(config *CNSConfig) {
189202
if config.SyncHostNCTimeoutMs == 0 {
190203
config.SyncHostNCTimeoutMs = 500 //nolint:gomnd // default times
191204
}
192-
if config.PopulateHomeAzCacheRetryIntervalSecs == 0 {
193-
// set the default PopulateHomeAzCache retry interval to 30 seconds
194-
config.PopulateHomeAzCacheRetryIntervalSecs = 30
195-
}
196205
if config.WireserverIP == "" {
197206
config.WireserverIP = "168.63.129.16"
198207
}

cns/configuration/configuration_test.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ func TestReadConfigFromFile(t *testing.T) {
8383
TelemetryBatchIntervalInSecs: 15,
8484
TelemetryBatchSizeBytes: 16384,
8585
},
86+
AZRSettings: AZRSettings{
87+
EnableAZR: true,
88+
PopulateHomeAzCacheRetryIntervalSecs: 60,
89+
},
8690
UseHTTPS: true,
8791
WireserverIP: "168.63.129.16",
8892
},
@@ -206,8 +210,10 @@ func TestSetCNSConfigDefaults(t *testing.T) {
206210
KeyVaultSettings: KeyVaultSettings{
207211
RefreshIntervalInHrs: 12,
208212
},
209-
PopulateHomeAzCacheRetryIntervalSecs: 30,
210-
WireserverIP: "168.63.129.16",
213+
AZRSettings: AZRSettings{
214+
PopulateHomeAzCacheRetryIntervalSecs: 60,
215+
},
216+
WireserverIP: "168.63.129.16",
211217
},
212218
},
213219
{
@@ -230,7 +236,10 @@ func TestSetCNSConfigDefaults(t *testing.T) {
230236
KeyVaultSettings: KeyVaultSettings{
231237
RefreshIntervalInHrs: 3,
232238
},
233-
PopulateHomeAzCacheRetryIntervalSecs: 10,
239+
AZRSettings: AZRSettings{
240+
EnableAZR: true,
241+
PopulateHomeAzCacheRetryIntervalSecs: 10,
242+
},
234243
},
235244
want: CNSConfig{
236245
ChannelMode: "Other",
@@ -250,8 +259,11 @@ func TestSetCNSConfigDefaults(t *testing.T) {
250259
KeyVaultSettings: KeyVaultSettings{
251260
RefreshIntervalInHrs: 3,
252261
},
253-
PopulateHomeAzCacheRetryIntervalSecs: 10,
254-
WireserverIP: "168.63.129.16",
262+
AZRSettings: AZRSettings{
263+
EnableAZR: true,
264+
PopulateHomeAzCacheRetryIntervalSecs: 10,
265+
},
266+
WireserverIP: "168.63.129.16",
255267
},
256268
},
257269
}

cns/configuration/testdata/good.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,9 @@
3030
"TelemetryBatchSizeBytes": 16384
3131
},
3232
"UseHTTPS": true,
33-
"WireserverIP": "168.63.129.16"
33+
"WireserverIP": "168.63.129.16",
34+
"AZRSettings": {
35+
"EnableAZR": true,
36+
"PopulateHomeAzCacheRetryIntervalSecs": 60
37+
}
3438
}

cns/service/main.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,11 @@ func main() {
567567
return
568568
}
569569

570-
homeAzMonitor := restserver.NewHomeAzMonitor(nmaClient, time.Duration(cnsconfig.PopulateHomeAzCacheRetryIntervalSecs)*time.Second)
571-
logger.Printf("start the goroutine for refreshing homeAz")
572-
homeAzMonitor.Start()
570+
homeAzMonitor := restserver.NewHomeAzMonitor(nmaClient, time.Duration(cnsconfig.AZRSettings.PopulateHomeAzCacheRetryIntervalSecs)*time.Second)
571+
if cnsconfig.AZRSettings.EnableAZR {
572+
logger.Printf("start the goroutine for refreshing homeAz")
573+
homeAzMonitor.Start()
574+
}
573575

574576
if cnsconfig.ChannelMode == cns.Managed {
575577
config.ChannelMode = cns.Managed
@@ -903,8 +905,10 @@ func main() {
903905
}
904906
}
905907

906-
logger.Printf("end the goroutine for refreshing homeAz")
907-
homeAzMonitor.Stop()
908+
if cnsconfig.AZRSettings.EnableAZR {
909+
logger.Printf("end the goroutine for refreshing homeAz")
910+
homeAzMonitor.Stop()
911+
}
908912

909913
logger.Printf("stop cns service")
910914
// Cleanup.

0 commit comments

Comments
 (0)