Skip to content

Commit a5cd643

Browse files
committed
Fix: Handle empty chart directory correctly
Currently the return of helmChartNamePath is not checked on errors. This means that the CSO tries to helm template the container which leads to cryptic error messages from helm. This commit adds a check to the helm chart validation. Signed-off-by: Jan Klippel <[email protected]>
1 parent a896a6b commit a5cd643

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

internal/controller/clusterstackrelease_controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,10 @@ func (r *ClusterStackReleaseReconciler) templateAndApply(ctx context.Context, re
304304

305305
// templateClusterClassHelmChart templates the clusterClass helm chart.
306306
func (*ClusterStackReleaseReconciler) templateClusterClassHelmChart(releaseAssets *release.Release, name, namespace string) ([]byte, error) {
307-
clusterClassChart := releaseAssets.ClusterClassChartPath()
307+
clusterClassChart, e := releaseAssets.ClusterClassChartPath()
308+
if e != nil {
309+
return nil, fmt.Errorf("failed to template clusterClass helm chart: %w", e)
310+
}
308311

309312
splittedName := strings.Split(name, clusterstack.Separator)
310313
releaseName := strings.Join(splittedName[0:4], clusterstack.Separator)
@@ -315,6 +318,7 @@ func (*ClusterStackReleaseReconciler) templateClusterClassHelmChart(releaseAsset
315318
}
316319

317320
return template, nil
321+
318322
}
319323

320324
func helmTemplate(chartPath, releaseName, namespace string) ([]byte, error) {

pkg/release/release.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ func ensureMetadata(downloadPath, metadataFileName string) (Metadata, error) {
159159
func (r *Release) CheckHelmCharts() error {
160160
// check if the cluster class chart is present.
161161
clusterClassChartName := r.clusterClassChartName()
162+
163+
if _, err := r.ClusterClassChartPath(); err != nil {
164+
return fmt.Errorf("failed to validate cluster stack: %w", err)
165+
}
166+
162167
clusterClassChartPath, err := r.helmChartNamePath(clusterClassChartName)
163168
if err != nil {
164169
return fmt.Errorf("failed to get cluster class chart path: %w", err)
@@ -207,6 +212,9 @@ func (r *Release) Validate() error {
207212
if err := r.ClusterStack.Version.Validate(); err != nil {
208213
return fmt.Errorf("failed to validate cluster stack object: %w", err)
209214
}
215+
if err := r.CheckHelmCharts(); err != nil {
216+
return fmt.Errorf("failed to validate cluster stack object: %w", err)
217+
}
210218
if err := r.Meta.Validate(); err != nil {
211219
return fmt.Errorf("failed to validate metadata: %w", err)
212220
}
@@ -238,11 +246,11 @@ func (r *Release) clusterClassChartName() string {
238246
}
239247

240248
// ClusterClassChartPath returns the absolute helm chart path for cluster class.
241-
func (r *Release) ClusterClassChartPath() string {
249+
func (r *Release) ClusterClassChartPath() (string, error) {
242250
nameFilter := r.clusterClassChartName()
243-
// we ignore the error here, since we already checked for the presence of the chart.
244-
path, _ := r.helmChartNamePath(nameFilter)
245-
return path
251+
252+
path, err := r.helmChartNamePath(nameFilter)
253+
return path, err
246254
}
247255

248256
// helmChartNamePath returns the helm chart name from the given path.

0 commit comments

Comments
 (0)