Skip to content

Commit

Permalink
Add options to create namespace and use non-strict engine for helm ad…
Browse files Browse the repository at this point in the history
…dons

Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Nov 28, 2023
1 parent 29052bd commit 4648a00
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
26 changes: 21 additions & 5 deletions pkg/addonfactory/addonfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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...)
Expand Down
41 changes: 26 additions & 15 deletions pkg/addonfactory/helm_agentaddon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -104,7 +108,7 @@ func (a *HelmAgentAddon) renderManifests(
}

helmEngine := engine.Engine{
Strict: true,
Strict: a.helmEngineStrict,
LintMode: false,
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4648a00

Please sign in to comment.