Skip to content

Commit

Permalink
check for nil artifact before loading chart
Browse files Browse the repository at this point in the history
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
  • Loading branch information
somtochiama committed Sep 11, 2023
1 parent 9fa5cf7 commit 6efb5b6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/controller/helmrelease_controller_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,19 @@ func (r *HelmReleaseReconciler) getHelmChart(ctx context.Context, hr *v2.HelmRel
// loads it into a chart.Chart, and removes the downloaded artifact.
// It returns the loaded chart.Chart on success, or an error.
func (r *HelmReleaseReconciler) loadHelmChart(source *sourcev1b2.HelmChart) (*chart.Chart, error) {
artifact := source.GetArtifact()
if artifact == nil {
return nil, fmt.Errorf("cannot load Helm chart: HelmChart '%s/%s' has no artifact", source.GetNamespace(), source.GetName())
}

f, err := os.CreateTemp("", fmt.Sprintf("%s-%s-*.tgz", source.GetNamespace(), source.GetName()))
if err != nil {
return nil, err
}
defer f.Close()
defer os.Remove(f.Name())

artifactURL := source.GetArtifact().URL
artifactURL := artifact.URL
if hostname := os.Getenv("SOURCE_CONTROLLER_LOCALHOST"); hostname != "" {
u, err := url.Parse(artifactURL)
if err != nil {
Expand Down

0 comments on commit 6efb5b6

Please sign in to comment.