Skip to content

Commit 81d0b0d

Browse files
committed
[addon-operator] add virtual chart support for nelm
Signed-off-by: kerimov <brileyforbusiness@gmail.com>
1 parent e9ea3d8 commit 81d0b0d

File tree

4 files changed

+62
-11
lines changed

4 files changed

+62
-11
lines changed

pkg/helm/client/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ type HelmClient interface {
1919
WithLogLabels(map[string]string)
2020
WithExtraLabels(map[string]string)
2121
WithExtraAnnotations(map[string]string)
22+
WithVirtualChart(bool)
23+
WithModulePath(string)
2224
}

pkg/helm/helm3lib/helm3lib.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ func (h *LibClient) WithExtraAnnotations(_ map[string]string) {
9090
// helm3lib doesn't support annotations, no-op implementation
9191
}
9292

93+
func (h *LibClient) WithVirtualChart(_ bool) {
94+
// helm3lib doesn't need virtual chart flag, no-op implementation
95+
}
96+
97+
func (h *LibClient) WithModulePath(_ string) {
98+
// helm3lib doesn't need module path, no-op implementation
99+
}
100+
93101
// buildConfigFlagsFromEnv builds a ConfigFlags object from the environment and
94102
// returns it. It uses a persistent config, meaning that underlying clients will
95103
// be cached and reused.

pkg/helm/nelm/nelm.go

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ type NelmClient struct {
106106
labels map[string]string
107107
annotations map[string]string
108108

109-
opts *CommonOptions
110-
actions NelmActions
109+
opts *CommonOptions
110+
actions NelmActions
111+
virtualChart bool
112+
modulePath string
111113
}
112114

113115
// GetReleaseLabels returns a specific label value from the release.
@@ -159,6 +161,14 @@ func (c *NelmClient) WithExtraAnnotations(annotations map[string]string) {
159161
}
160162
}
161163

164+
func (c *NelmClient) WithVirtualChart(virtual bool) {
165+
c.virtualChart = virtual
166+
}
167+
168+
func (c *NelmClient) WithModulePath(path string) {
169+
c.modulePath = path
170+
}
171+
162172
// GetAnnotations returns the annotations for testing purposes
163173
func (c *NelmClient) GetAnnotations() map[string]string {
164174
return c.annotations
@@ -220,8 +230,8 @@ func (c *NelmClient) UpgradeRelease(releaseName string, chart *chart.Chart, valu
220230
}
221231
}
222232

223-
if err := c.actions.ReleaseInstall(context.TODO(), releaseName, namespace, action.ReleaseInstallOptions{
224-
Chart: chart.Metadata.Name, // TODO: This is a temporary fix - nelm needs chart path, not name
233+
// Prepare chart options based on whether this is a virtual chart
234+
opts := action.ReleaseInstallOptions{
225235
ExtraLabels: c.labels,
226236
ExtraAnnotations: extraAnnotations,
227237
KubeContext: c.opts.KubeContext,
@@ -234,7 +244,20 @@ func (c *NelmClient) UpgradeRelease(releaseName string, chart *chart.Chart, valu
234244
ValuesSets: setValues,
235245
ForceAdoption: true,
236246
NoPodLogs: true,
237-
}); err != nil {
247+
}
248+
249+
if c.virtualChart {
250+
// For virtual charts, use default chart fields and empty chart path
251+
opts.Chart = ""
252+
opts.DefaultChartAPIVersion = chart.Metadata.APIVersion
253+
opts.DefaultChartName = chart.Metadata.Name
254+
opts.DefaultChartVersion = chart.Metadata.Version
255+
} else {
256+
// For regular charts, use the module path
257+
opts.Chart = c.modulePath
258+
}
259+
260+
if err := c.actions.ReleaseInstall(context.TODO(), releaseName, namespace, opts); err != nil {
238261
return fmt.Errorf("install nelm release %q: %w", releaseName, err)
239262
}
240263

@@ -378,9 +401,9 @@ func (c *NelmClient) Render(releaseName string, chart *chart.Chart, valuesPaths,
378401
extraAnnotations["maintenance.deckhouse.io/no-resource-reconciliation"] = ""
379402
}
380403

381-
chartRenderResult, err := c.actions.ChartRender(context.TODO(), action.ChartRenderOptions{
382-
OutputFilePath: "/dev/null", // No output file, we want to return the manifest as a string
383-
Chart: chart.Metadata.Name, // TODO: This is a temporary fix - nelm needs chart path, not name
404+
// Prepare chart render options based on whether this is a virtual chart
405+
renderOpts := action.ChartRenderOptions{
406+
OutputFilePath: "/dev/null", // No output file, we want to return the manifest as a string
384407
ExtraLabels: c.labels,
385408
ExtraAnnotations: extraAnnotations,
386409
KubeContext: c.opts.KubeContext,
@@ -391,7 +414,20 @@ func (c *NelmClient) Render(releaseName string, chart *chart.Chart, valuesPaths,
391414
ValuesFilesPaths: valuesPaths,
392415
ValuesSets: setValues,
393416
ForceAdoption: true,
394-
})
417+
}
418+
419+
if c.virtualChart {
420+
// For virtual charts, use default chart fields and empty chart path
421+
renderOpts.Chart = ""
422+
renderOpts.DefaultChartAPIVersion = chart.Metadata.APIVersion
423+
renderOpts.DefaultChartName = chart.Metadata.Name
424+
renderOpts.DefaultChartVersion = chart.Metadata.Version
425+
} else {
426+
// For regular charts, use the module path
427+
renderOpts.Chart = c.modulePath
428+
}
429+
430+
chartRenderResult, err := c.actions.ChartRender(context.TODO(), renderOpts)
395431
if err != nil {
396432
if !debug {
397433
return "", fmt.Errorf("render nelm chart %q: %w\n\nUse --debug flag to render out invalid YAML", chart.Metadata.Name, err)

pkg/module_manager/models/modules/helm.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ func (hm *HelmModule) RunHelmInstall(ctx context.Context, logLabels map[string]s
276276
}
277277

278278
helmClient := hm.dependencies.HelmClientFactory.NewClient(hm.logger.Named("helm-client"), helmClientOptions...)
279+
helmClient.WithVirtualChart(!hm.hasChartFile)
280+
helmClient.WithModulePath(hm.path)
279281

280282
if state == Unmanaged {
281283
isUnmanaged, err := helmClient.GetReleaseLabels(helmReleaseName, LabelMaintenanceNoResourceReconciliation)
@@ -521,6 +523,9 @@ func (hm *HelmModule) Render(namespace string, debug bool, state MaintenanceStat
521523
return "", fmt.Errorf("load module chart: %v", err)
522524
}
523525

524-
return hm.dependencies.HelmClientFactory.NewClient(hm.logger.Named("helm-client"), helmClientOptions...).
525-
Render(hm.name, moduleChart, []string{valuesPath}, nil, releaseLabels, namespace, debug)
526+
helmClient := hm.dependencies.HelmClientFactory.NewClient(hm.logger.Named("helm-client"), helmClientOptions...)
527+
helmClient.WithVirtualChart(!hm.hasChartFile)
528+
helmClient.WithModulePath(hm.path)
529+
530+
return helmClient.Render(hm.name, moduleChart, []string{valuesPath}, nil, releaseLabels, namespace, debug)
526531
}

0 commit comments

Comments
 (0)