Skip to content

Commit 394ab5a

Browse files
authored
Merge pull request #768 from somtochiama/nil-artifac
Check source for nil artifact before loading chart
2 parents 9fa5cf7 + c1d77ad commit 394ab5a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

internal/controller/helmrelease_controller_chart.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,19 @@ func (r *HelmReleaseReconciler) getHelmChart(ctx context.Context, hr *v2.HelmRel
111111
// loads it into a chart.Chart, and removes the downloaded artifact.
112112
// It returns the loaded chart.Chart on success, or an error.
113113
func (r *HelmReleaseReconciler) loadHelmChart(source *sourcev1b2.HelmChart) (*chart.Chart, error) {
114+
artifact := source.GetArtifact()
115+
if artifact == nil {
116+
return nil, fmt.Errorf("cannot load chart: HelmChart '%s/%s' has no artifact", source.GetNamespace(), source.GetName())
117+
}
118+
114119
f, err := os.CreateTemp("", fmt.Sprintf("%s-%s-*.tgz", source.GetNamespace(), source.GetName()))
115120
if err != nil {
116121
return nil, err
117122
}
118123
defer f.Close()
119124
defer os.Remove(f.Name())
120125

121-
artifactURL := source.GetArtifact().URL
126+
artifactURL := artifact.URL
122127
if hostname := os.Getenv("SOURCE_CONTROLLER_LOCALHOST"); hostname != "" {
123128
u, err := url.Parse(artifactURL)
124129
if err != nil {

0 commit comments

Comments
 (0)