diff --git a/charts/spiderpool/templates/pod.yaml b/charts/spiderpool/templates/pod.yaml index 806a534f20..01aced2bab 100644 --- a/charts/spiderpool/templates/pod.yaml +++ b/charts/spiderpool/templates/pod.yaml @@ -133,6 +133,8 @@ spec: {{- end }} - name: SPIDERPOOL_INIT_ENABLE_MULTUS_CONFIG value: {{ .Values.multus.enableMultusConfig | quote }} + - name: SPIDERPOOL_INIT_INSTALL_MULTUS + value: {{ .Values.multus.multusCNI.install | quote }} - name: SPIDERPOOL_INIT_DEFAULT_CNI_NAME value: {{ .Values.multus.multusCNI.defaultCniCRName | quote }} - name: SPIDERPOOL_INIT_DEFAULT_CNI_NAMESPACE diff --git a/cmd/spiderpool-init/cmd/config.go b/cmd/spiderpool-init/cmd/config.go index 4d8ebb6c92..089250a03b 100644 --- a/cmd/spiderpool-init/cmd/config.go +++ b/cmd/spiderpool-init/cmd/config.go @@ -47,6 +47,7 @@ const ( ENVDefaultIPv6Gateway = "SPIDERPOOL_INIT_DEFAULT_IPV6_IPPOOL_GATEWAY" ENVEnableMultusConfig = "SPIDERPOOL_INIT_ENABLE_MULTUS_CONFIG" + ENVInstallMultusCNI = "SPIDERPOOL_INIT_INSTALL_MULTUS" ENVDefaultCNIDir = "SPIDERPOOL_INIT_DEFAULT_CNI_DIR" ENVDefaultCNIName = "SPIDERPOOL_INIT_DEFAULT_CNI_NAME" ENVDefaultCNINamespace = "SPIDERPOOL_INIT_DEFAULT_CNI_NAMESPACE" @@ -89,6 +90,7 @@ type InitDefaultConfig struct { // multuscniconfig enableMultusConfig bool + installMultusCNI bool DefaultCNIDir string DefaultCNIName string DefaultCNINamespace string @@ -276,6 +278,12 @@ func parseENVAsDefault() InitDefaultConfig { logger.Sugar().Fatalf("ENV %s: %s invalid: %v", ENVEnableMultusConfig, enableMultusConfig, err) } + installMultusCNI := strings.ReplaceAll(os.Getenv(ENVInstallMultusCNI), "\"", "") + config.installMultusCNI, err = strconv.ParseBool(installMultusCNI) + if err != nil { + logger.Sugar().Fatalf("ENV %s: %s invalid: %v", ENVInstallMultusCNI, installMultusCNI, err) + } + config.DefaultCNIDir = strings.ReplaceAll(os.Getenv(ENVDefaultCNIDir), "\"", "") if config.DefaultCNIDir != "" { _, err = os.ReadDir(config.DefaultCNIDir) diff --git a/cmd/spiderpool-init/cmd/multus.go b/cmd/spiderpool-init/cmd/multus.go index 29425d83a3..f3d996769e 100644 --- a/cmd/spiderpool-init/cmd/multus.go +++ b/cmd/spiderpool-init/cmd/multus.go @@ -49,6 +49,11 @@ func InitMultusDefaultCR(ctx context.Context, config *InitDefaultConfig, client return err } + if !config.installMultusCNI { + logger.Sugar().Infof("No install MultusCNI, Ignore update clusterNetwork for multus configMap") + return nil + } + // get multus configMap cm, err := getConfigMap(ctx, client, config.DefaultCNINamespace, config.MultusConfigMap) if err != nil {