Skip to content

Commit cc51781

Browse files
authored
Merge pull request #289 from jklippel/fix/cs-apply-fails-with-no-error
🐛 Fix: Handle empty chart directory correctly
2 parents ebe7565 + c12de9b commit cc51781

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-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

+5-10
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ 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+
162163
clusterClassChartPath, err := r.helmChartNamePath(clusterClassChartName)
163164
if err != nil {
164165
return fmt.Errorf("failed to get cluster class chart path: %w", err)
@@ -172,12 +173,6 @@ func (r *Release) CheckHelmCharts() error {
172173
if !os.IsNotExist(err) {
173174
return fmt.Errorf("failed to verify the clusteraddon.yaml path %s with error: %w", clusterAddonPath, err)
174175
}
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-
}
181176
}
182177

183178
// check if the cluster addon chart is present.
@@ -238,11 +233,11 @@ func (r *Release) clusterClassChartName() string {
238233
}
239234

240235
// ClusterClassChartPath returns the absolute helm chart path for cluster class.
241-
func (r *Release) ClusterClassChartPath() string {
236+
func (r *Release) ClusterClassChartPath() (string, error) {
242237
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
238+
239+
path, err := r.helmChartNamePath(nameFilter)
240+
return path, err
246241
}
247242

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

0 commit comments

Comments
 (0)