@@ -238,12 +238,12 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
238238 }
239239
240240 // Return early if the revision is still the same as the current artifact
241- artifact := r .Storage .NewArtifactFor (chart .Kind , chart .GetObjectMeta (), cv .Version ,
241+ newArtifact := r .Storage .NewArtifactFor (chart .Kind , chart .GetObjectMeta (), cv .Version ,
242242 fmt .Sprintf ("%s-%s.tgz" , cv .Name , cv .Version ))
243- if ! force && repository .GetArtifact () != nil && repository . GetArtifact () .Revision == cv . Version {
244- if artifact .URL != repository .GetArtifact ().URL {
243+ if ! force && repository .GetArtifact (). HasRevision ( newArtifact .Revision ) {
244+ if newArtifact .URL != repository .GetArtifact ().URL {
245245 r .Storage .SetArtifactURL (chart .GetArtifact ())
246- repository .Status .URL = r .Storage .SetHostname (chart .Status .URL )
246+ chart .Status .URL = r .Storage .SetHostname (chart .Status .URL )
247247 }
248248 return chart , nil
249249 }
@@ -296,21 +296,19 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
296296 err = fmt .Errorf ("auth options error: %w" , err )
297297 return sourcev1 .HelmChartNotReady (chart , sourcev1 .AuthenticationFailedReason , err .Error ()), err
298298 }
299- if cleanup != nil {
300- defer cleanup ()
301- }
299+ defer cleanup ()
302300 clientOpts = opts
303301 }
304302
305303 // Ensure artifact directory exists
306- err = r .Storage .MkdirAll (artifact )
304+ err = r .Storage .MkdirAll (newArtifact )
307305 if err != nil {
308306 err = fmt .Errorf ("unable to create chart directory: %w" , err )
309307 return sourcev1 .HelmChartNotReady (chart , sourcev1 .StorageOperationFailedReason , err .Error ()), err
310308 }
311309
312310 // Acquire a lock for the artifact
313- unlock , err := r .Storage .Lock (artifact )
311+ unlock , err := r .Storage .Lock (newArtifact )
314312 if err != nil {
315313 err = fmt .Errorf ("unable to acquire lock: %w" , err )
316314 return sourcev1 .HelmChartNotReady (chart , sourcev1 .StorageOperationFailedReason , err .Error ()), err
@@ -328,7 +326,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
328326 // or write the chart directly to storage.
329327 var (
330328 readyReason = sourcev1 .ChartPullSucceededReason
331- readyMessage = fmt .Sprintf ("Fetched revision: %s" , artifact .Revision )
329+ readyMessage = fmt .Sprintf ("Fetched revision: %s" , newArtifact .Revision )
332330 )
333331 switch {
334332 case chart .Spec .ValuesFile != "" && chart .Spec .ValuesFile != chartutil .ValuesfileName :
@@ -362,36 +360,29 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
362360 }
363361
364362 // Copy the packaged chart to the artifact path
365- cf , err := os .Open (pkgPath )
366- if err != nil {
367- err = fmt .Errorf ("failed to open chart package: %w" , err )
363+ if err := r .Storage .CopyFromPath (& newArtifact , pkgPath ); err != nil {
364+ err = fmt .Errorf ("failed to write chart package to storage: %w" , err )
368365 return sourcev1 .HelmChartNotReady (chart , sourcev1 .StorageOperationFailedReason , err .Error ()), err
369366 }
370- if err := r .Storage .Copy (& artifact , cf ); err != nil {
371- cf .Close ()
372- err = fmt .Errorf ("failed to copy chart package to storage: %w" , err )
373- return sourcev1 .HelmChartNotReady (chart , sourcev1 .StorageOperationFailedReason , err .Error ()), err
374- }
375- cf .Close ()
376367
377- readyMessage = fmt .Sprintf ("Fetched and packaged revision: %s" , artifact .Revision )
368+ readyMessage = fmt .Sprintf ("Fetched and packaged revision: %s" , newArtifact .Revision )
378369 readyReason = sourcev1 .ChartPackageSucceededReason
379370 default :
380371 // Write artifact to storage
381- if err := r .Storage .AtomicWriteFile (& artifact , res , 0644 ); err != nil {
372+ if err := r .Storage .AtomicWriteFile (& newArtifact , res , 0644 ); err != nil {
382373 err = fmt .Errorf ("unable to write chart file: %w" , err )
383374 return sourcev1 .HelmChartNotReady (chart , sourcev1 .StorageOperationFailedReason , err .Error ()), err
384375 }
385376 }
386377
387378 // Update symlink
388- chartUrl , err := r .Storage .Symlink (artifact , fmt .Sprintf ("%s-latest.tgz" , cv .Name ))
379+ chartUrl , err := r .Storage .Symlink (newArtifact , fmt .Sprintf ("%s-latest.tgz" , cv .Name ))
389380 if err != nil {
390381 err = fmt .Errorf ("storage error: %w" , err )
391382 return sourcev1 .HelmChartNotReady (chart , sourcev1 .StorageOperationFailedReason , err .Error ()), err
392383 }
393384
394- return sourcev1 .HelmChartReady (chart , artifact , chartUrl , readyReason , readyMessage ), nil
385+ return sourcev1 .HelmChartReady (chart , newArtifact , chartUrl , readyReason , readyMessage ), nil
395386}
396387
397388func (r * HelmChartReconciler ) reconcileFromTarballArtifact (ctx context.Context ,
@@ -432,32 +423,30 @@ func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
432423 }
433424
434425 // Return early if the revision is still the same as the current chart artifact
435- chartArtifact := r .Storage .NewArtifactFor (chart .Kind , chart .ObjectMeta .GetObjectMeta (), chartMetadata .Version ,
426+ newArtifact := r .Storage .NewArtifactFor (chart .Kind , chart .ObjectMeta .GetObjectMeta (), chartMetadata .Version ,
436427 fmt .Sprintf ("%s-%s.tgz" , chartMetadata .Name , chartMetadata .Version ))
437- if ! force && chart .GetArtifact () != nil && chart . GetArtifact () .Revision == chartMetadata . Version {
438- if chartArtifact .URL != artifact .URL {
439- r .Storage .SetArtifactURL (& chartArtifact )
428+ if ! force && chart .GetArtifact (). HasRevision ( newArtifact .Revision ) {
429+ if newArtifact .URL != artifact .URL {
430+ r .Storage .SetArtifactURL (& newArtifact )
440431 chart .Status .URL = r .Storage .SetHostname (chart .Status .URL )
441432 }
442433 return chart , nil
443434 }
444435
445- // Overwrite default values if instructed to
446- if chart .Spec .ValuesFile != "" {
447- if err := helm .OverwriteChartDefaultValues (chartPath , chart .Spec .ValuesFile ); err != nil {
448- return sourcev1 .HelmChartNotReady (chart , sourcev1 .ChartPackageFailedReason , err .Error ()), err
449- }
436+ // Overwrite default values if configured
437+ if err := helm .OverwriteChartDefaultValues (chartPath , chart .Spec .ValuesFile ); err != nil {
438+ return sourcev1 .HelmChartNotReady (chart , sourcev1 .ChartPackageFailedReason , err .Error ()), err
450439 }
451440
452441 // Ensure artifact directory exists
453- err = r .Storage .MkdirAll (chartArtifact )
442+ err = r .Storage .MkdirAll (newArtifact )
454443 if err != nil {
455444 err = fmt .Errorf ("unable to create artifact directory: %w" , err )
456445 return sourcev1 .HelmChartNotReady (chart , sourcev1 .StorageOperationFailedReason , err .Error ()), err
457446 }
458447
459448 // Acquire a lock for the artifact
460- unlock , err := r .Storage .Lock (chartArtifact )
449+ unlock , err := r .Storage .Lock (newArtifact )
461450 if err != nil {
462451 err = fmt .Errorf ("unable to acquire lock: %w" , err )
463452 return sourcev1 .HelmChartNotReady (chart , sourcev1 .StorageOperationFailedReason , err .Error ()), err
@@ -475,27 +464,20 @@ func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
475464 }
476465
477466 // Copy the packaged chart to the artifact path
478- cf , err := os .Open (pkgPath )
479- if err != nil {
480- err = fmt .Errorf ("failed to open chart package: %w" , err )
481- return sourcev1 .HelmChartNotReady (chart , sourcev1 .StorageOperationFailedReason , err .Error ()), err
482- }
483- if err := r .Storage .Copy (& chartArtifact , cf ); err != nil {
484- cf .Close ()
485- err = fmt .Errorf ("failed to copy chart package to storage: %w" , err )
467+ if err := r .Storage .CopyFromPath (& newArtifact , pkgPath ); err != nil {
468+ err = fmt .Errorf ("failed to write chart package to storage: %w" , err )
486469 return sourcev1 .HelmChartNotReady (chart , sourcev1 .StorageOperationFailedReason , err .Error ()), err
487470 }
488- cf .Close ()
489471
490472 // Update symlink
491- cUrl , err := r .Storage .Symlink (chartArtifact , fmt .Sprintf ("%s-latest.tgz" , chartMetadata .Name ))
473+ cUrl , err := r .Storage .Symlink (newArtifact , fmt .Sprintf ("%s-latest.tgz" , chartMetadata .Name ))
492474 if err != nil {
493475 err = fmt .Errorf ("storage error: %w" , err )
494476 return sourcev1 .HelmChartNotReady (chart , sourcev1 .StorageOperationFailedReason , err .Error ()), err
495477 }
496478
497- message := fmt .Sprintf ("Fetched and packaged revision: %s" , chartArtifact .Revision )
498- return sourcev1 .HelmChartReady (chart , chartArtifact , cUrl , sourcev1 .ChartPackageSucceededReason , message ), nil
479+ message := fmt .Sprintf ("Fetched and packaged revision: %s" , newArtifact .Revision )
480+ return sourcev1 .HelmChartReady (chart , newArtifact , cUrl , sourcev1 .ChartPackageSucceededReason , message ), nil
499481}
500482
501483// resetStatus returns a modified v1alpha1.HelmChart and a boolean indicating
0 commit comments