diff --git a/pkg/addonfactory/addonfactory.go b/pkg/addonfactory/addonfactory.go index 23923be4e..c4a9a8745 100644 --- a/pkg/addonfactory/addonfactory.go +++ b/pkg/addonfactory/addonfactory.go @@ -34,9 +34,11 @@ type AgentAddonFactory struct { getValuesFuncs []GetValuesFunc agentAddonOptions agent.AgentAddonOptions // trimCRDDescription flag is used to trim the description of CRDs in manifestWork. disabled by default. - trimCRDDescription bool - hostingCluster *clusterv1.ManagedCluster - agentInstallNamespace func(addon *addonapiv1alpha1.ManagedClusterAddOn) string + trimCRDDescription bool + hostingCluster *clusterv1.ManagedCluster + agentInstallNamespace func(addon *addonapiv1alpha1.ManagedClusterAddOn) string + createAgentInstallNamespace bool + helmEngineStrict bool } // NewAgentAddonFactory builds an addonAgentFactory instance with addon name and fs. @@ -57,8 +59,10 @@ func NewAgentAddonFactory(addonName string, fs embed.FS, dir string) *AgentAddon HealthProber: nil, SupportedConfigGVRs: []schema.GroupVersionResource{}, }, - trimCRDDescription: false, - scheme: s, + trimCRDDescription: false, + scheme: s, + createAgentInstallNamespace: false, + helmEngineStrict: false, } } @@ -114,6 +118,18 @@ func (f *AgentAddonFactory) WithTrimCRDDescription() *AgentAddonFactory { return f } +// WithCreateAgentInstallNamespace is to create the agent install namespace object in manifestWork. +func (f *AgentAddonFactory) WithCreateAgentInstallNamespace() *AgentAddonFactory { + f.createAgentInstallNamespace = true + return f +} + +// WithHelmEngineStrict is to enable script go template rendering for Helm charts to generate manifestWork. +func (f *AgentAddonFactory) WithHelmEngineStrict() *AgentAddonFactory { + f.helmEngineStrict = true + return f +} + // WithConfigGVRs defines the addon supported configuration GroupVersionResource func (f *AgentAddonFactory) WithConfigGVRs(gvrs ...schema.GroupVersionResource) *AgentAddonFactory { f.agentAddonOptions.SupportedConfigGVRs = append(f.agentAddonOptions.SupportedConfigGVRs, gvrs...) diff --git a/pkg/addonfactory/helm_agentaddon.go b/pkg/addonfactory/helm_agentaddon.go index 0da7eae0a..25b9d4390 100644 --- a/pkg/addonfactory/helm_agentaddon.go +++ b/pkg/addonfactory/helm_agentaddon.go @@ -45,24 +45,28 @@ type helmDefaultValues struct { } type HelmAgentAddon struct { - decoder runtime.Decoder - chart *chart.Chart - getValuesFuncs []GetValuesFunc - agentAddonOptions agent.AgentAddonOptions - trimCRDDescription bool - hostingCluster *clusterv1.ManagedCluster - agentInstallNamespace func(addon *addonapiv1alpha1.ManagedClusterAddOn) string + decoder runtime.Decoder + chart *chart.Chart + getValuesFuncs []GetValuesFunc + agentAddonOptions agent.AgentAddonOptions + trimCRDDescription bool + hostingCluster *clusterv1.ManagedCluster + agentInstallNamespace func(addon *addonapiv1alpha1.ManagedClusterAddOn) string + createAgentInstallNamespace bool + helmEngineStrict bool } func newHelmAgentAddon(factory *AgentAddonFactory, chart *chart.Chart) *HelmAgentAddon { return &HelmAgentAddon{ - decoder: serializer.NewCodecFactory(factory.scheme).UniversalDeserializer(), - chart: chart, - getValuesFuncs: factory.getValuesFuncs, - agentAddonOptions: factory.agentAddonOptions, - trimCRDDescription: factory.trimCRDDescription, - hostingCluster: factory.hostingCluster, - agentInstallNamespace: factory.agentInstallNamespace, + decoder: serializer.NewCodecFactory(factory.scheme).UniversalDeserializer(), + chart: chart, + getValuesFuncs: factory.getValuesFuncs, + agentAddonOptions: factory.agentAddonOptions, + trimCRDDescription: factory.trimCRDDescription, + hostingCluster: factory.hostingCluster, + agentInstallNamespace: factory.agentInstallNamespace, + createAgentInstallNamespace: factory.createAgentInstallNamespace, + helmEngineStrict: factory.helmEngineStrict, } } @@ -104,7 +108,7 @@ func (a *HelmAgentAddon) renderManifests( } helmEngine := engine.Engine{ - Strict: true, + Strict: a.helmEngineStrict, LintMode: false, } @@ -170,6 +174,13 @@ func (a *HelmAgentAddon) renderManifests( } } + if agentInstallNamespace != "" && a.createAgentInstallNamespace { + var ns unstructured.Unstructured + ns.SetAPIVersion("v1") + ns.SetKind("Namespace") + ns.SetName(agentInstallNamespace) + objects = append(objects, &ns) + } } if a.trimCRDDescription {