Skip to content

Commit 65a4f6d

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 8ad85fa commit 65a4f6d

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

cs-dev/cs-ci.yaml

Whitespace-only changes.

internal/controller/clusterstackrelease_controller.go

+18-1
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)

pkg/release/release.go

+9-10
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)
@@ -172,12 +177,6 @@ func (r *Release) CheckHelmCharts() error {
172177
if !os.IsNotExist(err) {
173178
return fmt.Errorf("failed to verify the clusteraddon.yaml path %s with error: %w", clusterAddonPath, err)
174179
}
175-
176-
// check if the cluster addon values file is present.
177-
valuesPath := filepath.Join(r.LocalDownloadPath, ClusterAddonValuesName)
178-
if _, err := os.Stat(valuesPath); err != nil {
179-
return fmt.Errorf("failed to verify the cluster addon values path %s with error: %w", valuesPath, err)
180-
}
181180
}
182181

183182
// check if the cluster addon chart is present.
@@ -238,11 +237,11 @@ func (r *Release) clusterClassChartName() string {
238237
}
239238

240239
// ClusterClassChartPath returns the absolute helm chart path for cluster class.
241-
func (r *Release) ClusterClassChartPath() string {
240+
func (r *Release) ClusterClassChartPath() (string, error) {
242241
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
242+
243+
path, err := r.helmChartNamePath(nameFilter)
244+
return path, err
246245
}
247246

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

0 commit comments

Comments
 (0)