Skip to content

Commit e80d1a3

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 on errors on the call to helmChartNamePath and results in more helpful error messages by helm. Signed-off-by: Jan Klippel <[email protected]>
1 parent a896a6b commit e80d1a3

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ func (r *Release) clusterClassChartName() string {
238238
}
239239

240240
// ClusterClassChartPath returns the absolute helm chart path for cluster class.
241-
func (r *Release) ClusterClassChartPath() string {
241+
func (r *Release) ClusterClassChartPath() (string, error) {
242242
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
243+
244+
path, err := r.helmChartNamePath(nameFilter)
245+
return path, err
246246
}
247247

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

0 commit comments

Comments
 (0)