Skip to content

Commit 36757fe

Browse files
authored
feat: allow the CNI conflist generation settings to be configured via… (#1765)
* feat: allow the CNI conflist generation settings to be configured via cmd line args * make env var opt-in
1 parent 2418eaf commit 36757fe

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

cns/service/main.go

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ const (
7878
// 720 * acn.FiveSeconds sec sleeps = 1Hr
7979
maxRetryNodeRegister = 720
8080
initCNSInitalDelay = 10 * time.Second
81+
82+
// envVarEnableCNIConflistGeneration enables cni conflist generation if set (value doesn't matter)
83+
envVarEnableCNIConflistGeneration = "CNS_ENABLE_CNI_CONFLIST_GENERATION"
8184
)
8285

8386
type cniConflistScenario string
@@ -287,6 +290,20 @@ var args = acn.ArgumentList{
287290
Type: "bool",
288291
DefaultValue: false,
289292
},
293+
{
294+
Name: acn.OptCNIConflistFilepath,
295+
Shorthand: acn.OptCNIConflistFilepathAlias,
296+
Description: "Filepath to write CNI conflist when CNI conflist generation is enabled",
297+
Type: "string",
298+
DefaultValue: "",
299+
},
300+
{
301+
Name: acn.OptCNIConflistScenario,
302+
Shorthand: acn.OptCNIConflistScenarioAlias,
303+
Description: "Scenario to generate CNI conflist for",
304+
Type: "string",
305+
DefaultValue: "",
306+
},
290307
}
291308

292309
// init() is executed before main() whenever this package is imported
@@ -446,6 +463,8 @@ func main() {
446463
clientDebugArg := acn.GetArg(acn.OptDebugArg).(string)
447464
cmdLineConfigPath := acn.GetArg(acn.OptCNSConfigPath).(string)
448465
telemetryDaemonEnabled := acn.GetArg(acn.OptTelemetryService).(bool)
466+
cniConflistFilepathArg := acn.GetArg(acn.OptCNIConflistFilepath).(string)
467+
cniConflistScenarioArg := acn.GetArg(acn.OptCNIConflistScenario).(string)
449468

450469
if vers {
451470
printVersion()
@@ -489,15 +508,28 @@ func main() {
489508
configuration.SetCNSConfigDefaults(cnsconfig)
490509
logger.Printf("[Azure CNS] Read config :%+v", cnsconfig)
491510

511+
_, envEnableConflistGeneration := os.LookupEnv(envVarEnableCNIConflistGeneration)
512+
492513
var conflistGenerator restserver.CNIConflistGenerator
493-
if cnsconfig.EnableCNIConflistGeneration {
494-
writer, newWriterErr := fs.NewAtomicWriter(cnsconfig.CNIConflistFilepath)
514+
if cnsconfig.EnableCNIConflistGeneration || envEnableConflistGeneration {
515+
conflistFilepath := cnsconfig.CNIConflistFilepath
516+
if cniConflistFilepathArg != "" {
517+
// allow the filepath to get overidden by command line arg
518+
conflistFilepath = cniConflistFilepathArg
519+
}
520+
writer, newWriterErr := fs.NewAtomicWriter(conflistFilepath)
495521
if newWriterErr != nil {
496522
logger.Errorf("unable to create atomic writer to generate cni conflist: %v", newWriterErr)
497523
os.Exit(1)
498524
}
499525

500-
switch scenario := cniConflistScenario(cnsconfig.CNIConflistScenario); scenario {
526+
// allow the scenario to get overridden by command line arg
527+
scenarioString := cnsconfig.CNIConflistScenario
528+
if cniConflistScenarioArg != "" {
529+
scenarioString = cniConflistScenarioArg
530+
}
531+
532+
switch scenario := cniConflistScenario(scenarioString); scenario {
501533
case scenarioV4Overlay:
502534
conflistGenerator = &cniconflist.V4OverlayGenerator{Writer: writer}
503535
default:

common/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,14 @@ const (
136136
// CNS config path
137137
OptCNSConfigPath = "config-path"
138138
OptCNSConfigPathAlias = "cp"
139+
140+
// OptCNIConflistFilepath
141+
OptCNIConflistFilepath = "cni-conflist-filepath"
142+
// OptCNIConflistFilepathAlias TODO: a "shorthand" is required for the acn args package but this isn't helpful
143+
OptCNIConflistFilepathAlias = "cniconflist"
144+
145+
// OptCNIConflistFilepath
146+
OptCNIConflistScenario = "cni-conflist-scenario"
147+
// OptCNIConflistScenarioAlias "shorthand" for the cni conflist scenairo, see above
148+
OptCNIConflistScenarioAlias = "cniconflistscenario"
139149
)

0 commit comments

Comments
 (0)