Skip to content

Commit 092eb1c

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 clusterstackrelease_controller. Signed-off-by: Jan Klippel <[email protected]>
1 parent a896a6b commit 092eb1c

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

internal/controller/clusterstackrelease_controller.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ func (r *ClusterStackReleaseReconciler) Reconcile(ctx context.Context, req recon
151151
return reconcile.Result{Requeue: true}, nil
152152
}
153153

154+
// Check for helm charts in the release assets. If they are not present, then something went wrong.
155+
if err := releaseAssets.CheckHelmCharts(); err != nil {
156+
msg := fmt.Sprintf("failed to validate helm charts: %s", err.Error())
157+
conditions.MarkFalse(
158+
clusterStackRelease,
159+
csov1alpha1.ClusterStackReleaseAssetsReadyCondition,
160+
csov1alpha1.IssueWithReleaseAssetsReason,
161+
clusterv1.ConditionSeverityError,
162+
"%s", msg,
163+
)
164+
record.Warn(clusterStackRelease, "ValidateHelmChartFailed", msg)
165+
return reconcile.Result{}, nil
166+
}
167+
154168
conditions.MarkTrue(clusterStackRelease, csov1alpha1.ClusterStackReleaseAssetsReadyCondition)
155169

156170
kubeClient := r.KubeClientFactory.NewClient(req.Namespace, r.RESTConfig)
@@ -304,7 +318,10 @@ func (r *ClusterStackReleaseReconciler) templateAndApply(ctx context.Context, re
304318

305319
// templateClusterClassHelmChart templates the clusterClass helm chart.
306320
func (*ClusterStackReleaseReconciler) templateClusterClassHelmChart(releaseAssets *release.Release, name, namespace string) ([]byte, error) {
307-
clusterClassChart := releaseAssets.ClusterClassChartPath()
321+
clusterClassChart, e := releaseAssets.ClusterClassChartPath()
322+
if e != nil {
323+
return nil, fmt.Errorf("failed to template clusterClass helm chart: %w", e)
324+
}
308325

309326
splittedName := strings.Split(name, clusterstack.Separator)
310327
releaseName := strings.Join(splittedName[0:4], clusterstack.Separator)
@@ -315,6 +332,7 @@ func (*ClusterStackReleaseReconciler) templateClusterClassHelmChart(releaseAsset
315332
}
316333

317334
return template, nil
335+
318336
}
319337

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

pkg/release/release.go

Lines changed: 9 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)
@@ -238,11 +243,11 @@ func (r *Release) clusterClassChartName() string {
238243
}
239244

240245
// ClusterClassChartPath returns the absolute helm chart path for cluster class.
241-
func (r *Release) ClusterClassChartPath() string {
246+
func (r *Release) ClusterClassChartPath() (string, error) {
242247
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
248+
249+
path, err := r.helmChartNamePath(nameFilter)
250+
return path, err
246251
}
247252

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

0 commit comments

Comments
 (0)