Skip to content

Commit 732b6fa

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 in the validation section of the cluster class. Signed-off-by: Jan Klippel <[email protected]>
1 parent a896a6b commit 732b6fa

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

internal/controller/clusterstackrelease_controller.go

+5-1
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

+7-4
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ func (r *Release) Validate() error {
207207
if err := r.ClusterStack.Version.Validate(); err != nil {
208208
return fmt.Errorf("failed to validate cluster stack object: %w", err)
209209
}
210+
if _, err := r.ClusterClassChartPath(); err != nil {
211+
return fmt.Errorf("failed to validate cluster stack object: %w", err)
212+
}
210213
if err := r.Meta.Validate(); err != nil {
211214
return fmt.Errorf("failed to validate metadata: %w", err)
212215
}
@@ -238,11 +241,11 @@ func (r *Release) clusterClassChartName() string {
238241
}
239242

240243
// ClusterClassChartPath returns the absolute helm chart path for cluster class.
241-
func (r *Release) ClusterClassChartPath() string {
244+
func (r *Release) ClusterClassChartPath() (string, error) {
242245
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
246+
247+
path, err := r.helmChartNamePath(nameFilter)
248+
return path, err
246249
}
247250

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

0 commit comments

Comments
 (0)