diff --git a/addons/main.go b/addons/main.go index 3c9b88a686b..12c9cbf2e3b 100644 --- a/addons/main.go +++ b/addons/main.go @@ -120,6 +120,7 @@ type addonFlags struct { pprofBindAddress string tlsMinVersion string tlsCipherSuites string + configFile string } func parseAddonFlags(addonFlags *addonFlags) { @@ -164,6 +165,7 @@ func parseAddonFlags(addonFlags *addonFlags) { flag.StringVar(&addonFlags.pprofBindAddress, "pprof-bind-addr", ":18318", "Bind address of pprof web server if enabled") flag.StringVar(&addonFlags.tlsMinVersion, "tls-min-version", "1.2", "minimum TLS version in use by the webhook server. Recommended values are \"1.2\" and \"1.3\".") flag.StringVar(&addonFlags.tlsCipherSuites, "tls-cipher-suites", "", "Comma-separated list of cipher suites for the server. If omitted, the default Go cipher suites will be used.\n"+fmt.Sprintf("Possible values are %s.", strings.Join(cliflag.TLSCipherPossibleValues(), ", "))) + flag.StringVar(&addonFlags.configFile, "config-file", "", "The path to set configuration file for addon manager") flag.Parse() } @@ -237,6 +239,9 @@ func main() { os.Exit(1) } + opt := addonconfig.NewOptions(ctrl.Log.WithName("controllers").WithName("Addon")) + opt.Complete(flags.configFile) + addonReconciler := &controllers.AddonReconciler{ Client: mgr.GetClient(), Log: ctrl.Log.WithName("controllers").WithName("Addon"), @@ -251,6 +256,7 @@ func main() { AddonImagePullPolicy: flags.addonImagePullPolicy, CorePackageRepoName: flags.corePackageRepoName, FeatureGateClusterBootstrap: flags.featureGateClusterBootstrap, + AntreaNsxEnabled: opt.Config.AntreaNsxEnabled, }, } if err = addonReconciler.SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: flags.clusterConcurrency}); err != nil { diff --git a/addons/pkg/config/config.go b/addons/pkg/config/config.go index 4f17829dcf1..f569ddd642d 100644 --- a/addons/pkg/config/config.go +++ b/addons/pkg/config/config.go @@ -19,6 +19,7 @@ type AddonControllerConfig struct { AddonImagePullPolicy string CorePackageRepoName string FeatureGateClusterBootstrap bool + AntreaNsxEnabled bool } // ClusterBootstrapControllerConfig contains configuration information related to ClusterBootstrap diff --git a/addons/pkg/config/options.go b/addons/pkg/config/options.go new file mode 100644 index 00000000000..f9c819a1c2e --- /dev/null +++ b/addons/pkg/config/options.go @@ -0,0 +1,68 @@ +package config + +import ( + "os" + + "github.com/go-logr/logr" + "gopkg.in/yaml.v2" +) + +const ( + defaultConfigurationFile = "/etc/addons-manager/addons-manager.conf" +) + +type Options struct { + // The path of configuration file + ConfigFile string + Config *ControllerConfig + Log logr.Logger +} + +type ControllerConfig struct { + AntreaNsxEnabled bool `yaml:"antreaNsxEnabled,omitempty"` +} + +func NewOptions(Log logr.Logger) *Options { + return &Options{ + Config: new(ControllerConfig), + Log: Log, + } +} + +func (o *Options) Complete(configFile string) error { + o.setDefaults() + if configFile != "" { + _, err := os.Stat(configFile) + if err != nil { + o.Log.Info("configFile does not exist, will use default settings") + return nil + } + o.ConfigFile = configFile + } + if len(o.ConfigFile) > 0 { + err := o.loadConfigFromFile(o.ConfigFile) + if err != nil { + return err + } + } + return nil +} + +func (o *Options) setDefaults() { + if o.ConfigFile == "" { + o.ConfigFile = defaultConfigurationFile + } +} + +func (o *Options) loadConfigFromFile(file string) error { + data, err := os.ReadFile(file) + if err != nil { + return err + } + + err = yaml.UnmarshalStrict(data, o.Config) + if err != nil { + return err + } + return nil +} diff --git a/packages/addons-manager/bundle/config/upstream/addons-manager.yaml b/packages/addons-manager/bundle/config/upstream/addons-manager.yaml index 2e143aadfc3..6f94fc27d83 100644 --- a/packages/addons-manager/bundle/config/upstream/addons-manager.yaml +++ b/packages/addons-manager/bundle/config/upstream/addons-manager.yaml @@ -362,6 +362,7 @@ spec: - --feature-gate-cluster-bootstrap=true #@ if/end data.values.tanzuAddonsManager.featureGates.packageInstallStatus: - --feature-gate-package-install-status=true + - --config-file /etc/addons-manager/addons-manager.conf image: addons-controller:latest imagePullPolicy: IfNotPresent name: tanzu-addons-controller @@ -402,6 +403,20 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + volumeMounts: + - mountPath: /etc/addons-manager + name: addons-manager-config + readOnly: true + volumes: + - name: addons-manager-config + projected: + - configMap: + name: vmware-system-tkg-addons-manager-config + items: + - key: addons-manager.conf + path: addons-manager.conf + optional: true + configMap: serviceAccount: tanzu-addons-manager-sa terminationGracePeriodSeconds: 10 #@ if/end data.values.tanzuAddonsManager.deployment.hostNetwork: diff --git a/tkg/manifest/telemetry/zz_generated.bindata.go b/tkg/manifest/telemetry/zz_generated.bindata.go index a29b3163fab..7d27eb6a8d1 100644 --- a/tkg/manifest/telemetry/zz_generated.bindata.go +++ b/tkg/manifest/telemetry/zz_generated.bindata.go @@ -220,11 +220,9 @@ func bindataTkgManifestTelemetryZzgeneratedBindataGo() (*asset, error) { return a, nil } -// // Asset loads and returns the asset for the given name. // It returns an error if the asset could not be found or // could not be loaded. -// func Asset(name string) ([]byte, error) { cannonicalName := strings.Replace(name, "\\", "/", -1) if f, ok := _bindata[cannonicalName]; ok { @@ -237,11 +235,9 @@ func Asset(name string) ([]byte, error) { return nil, &os.PathError{Op: "open", Path: name, Err: os.ErrNotExist} } -// // MustAsset is like Asset but panics when Asset would return an error. // It simplifies safe initialization of global variables. // nolint: deadcode -// func MustAsset(name string) []byte { a, err := Asset(name) if err != nil { @@ -251,10 +247,8 @@ func MustAsset(name string) []byte { return a } -// // AssetInfo loads and returns the asset info for the given name. // It returns an error if the asset could not be found or could not be loaded. -// func AssetInfo(name string) (os.FileInfo, error) { cannonicalName := strings.Replace(name, "\\", "/", -1) if f, ok := _bindata[cannonicalName]; ok { @@ -267,10 +261,8 @@ func AssetInfo(name string) (os.FileInfo, error) { return nil, &os.PathError{Op: "open", Path: name, Err: os.ErrNotExist} } -// // AssetNames returns the names of the assets. // nolint: deadcode -// func AssetNames() []string { names := make([]string, 0, len(_bindata)) for name := range _bindata { @@ -279,9 +271,7 @@ func AssetNames() []string { return names } -// // _bindata is a table, holding each asset generator, mapped to its name. -// var _bindata = map[string]func() (*asset, error){ "tkg/manifest/telemetry/config-aws.yaml": bindataTkgManifestTelemetryConfigawsYaml, "tkg/manifest/telemetry/config-azure.yaml": bindataTkgManifestTelemetryConfigazureYaml, @@ -290,21 +280,21 @@ var _bindata = map[string]func() (*asset, error){ "tkg/manifest/telemetry/zz_generated.bindata.go": bindataTkgManifestTelemetryZzgeneratedBindataGo, } -// // AssetDir returns the file names below a certain // directory embedded in the file by go-bindata. // For example if you run go-bindata on data/... and data contains the // following hierarchy: -// data/ -// foo.txt -// img/ -// a.png -// b.png +// +// data/ +// foo.txt +// img/ +// a.png +// b.png +// // then AssetDir("data") would return []string{"foo.txt", "img"} // AssetDir("data/img") would return []string{"a.png", "b.png"} // AssetDir("foo.txt") and AssetDir("notexist") would return an error // AssetDir("") will return []string{"data"}. -// func AssetDir(name string) ([]string, error) { node := _bintree if len(name) != 0 {