@@ -26,6 +26,7 @@ import (
26
26
"github.com/zapier/kubechecks/pkg/git"
27
27
"github.com/zapier/kubechecks/pkg/kustomize"
28
28
"github.com/zapier/kubechecks/pkg/vcs"
29
+ "gopkg.in/yaml.v3"
29
30
"sigs.k8s.io/kustomize/kyaml/filesys"
30
31
)
31
32
@@ -358,6 +359,61 @@ func copyFile(srcpath, dstpath string) error {
358
359
return err
359
360
}
360
361
362
+ // processLocalHelmDependency handles copying local helm dependencies to the temp directory
363
+ func processLocalHelmDependency (
364
+ srcAppPath string ,
365
+ destAppDir string ,
366
+ dependencyPath string ,
367
+ ) error {
368
+ // Remove the file:// prefix if present
369
+ cleanPath := strings .TrimPrefix (dependencyPath , "file://" )
370
+
371
+ // Resolve the absolute path of the dependency
372
+ absDepPath := filepath .Join (srcAppPath , cleanPath )
373
+
374
+ // Create the destination path in the temp directory
375
+ destDepPath := filepath .Join (destAppDir , cleanPath )
376
+
377
+ // Create the charts directory if it doesn't exist
378
+ if err := os .MkdirAll (destDepPath , os .ModePerm ); err != nil {
379
+ return errors .Wrapf (err , "failed to create charts directory %s" , destDepPath )
380
+ }
381
+
382
+ // Copy the entire dependency directory
383
+ log .Debug ().Msgf ("copying helm dependency from %s to %s" , absDepPath , destDepPath )
384
+ if err := copyDir (filesys .MakeFsOnDisk (), absDepPath , destDepPath ); err != nil {
385
+ return errors .Wrapf (err , "failed to copy helm dependency from %s to %s" , absDepPath , destDepPath )
386
+ }
387
+
388
+ return nil
389
+ }
390
+
391
+ // parseChartYAML reads and parses a Chart.yaml file to extract dependencies
392
+ func parseChartYAML (chartPath string ) ([]struct {
393
+ Name string `yaml:"name"`
394
+ Version string `yaml:"version"`
395
+ Repository string `yaml:"repository"`
396
+ }, error ) {
397
+ content , err := os .ReadFile (chartPath )
398
+ if err != nil {
399
+ return nil , errors .Wrap (err , "failed to read Chart.yaml" )
400
+ }
401
+
402
+ var chart struct {
403
+ Dependencies []struct {
404
+ Name string `yaml:"name"`
405
+ Version string `yaml:"version"`
406
+ Repository string `yaml:"repository"`
407
+ } `yaml:"dependencies"`
408
+ }
409
+
410
+ if err := yaml .Unmarshal (content , & chart ); err != nil {
411
+ return nil , errors .Wrap (err , "failed to parse Chart.yaml" )
412
+ }
413
+
414
+ return chart .Dependencies , nil
415
+ }
416
+
361
417
func packageApp (
362
418
ctx context.Context ,
363
419
source v1alpha1.ApplicationSource ,
@@ -385,7 +441,6 @@ func packageApp(
385
441
relKustPath := filepath .Join (source .Path , "kustomization.yaml" )
386
442
absKustPath := filepath .Join (destDir , relKustPath )
387
443
if fsIface .Exists (absKustPath ) {
388
-
389
444
files , _ , err := kustomize .ProcessKustomizationFile (sourceFS , relKustPath )
390
445
if err != nil {
391
446
return "" , errors .Wrap (err , "failed to process kustomization dependencies" )
@@ -398,7 +453,27 @@ func packageApp(
398
453
}
399
454
}
400
455
456
+ // Process helm dependencies
401
457
if source .Helm != nil {
458
+ // Handle local helm dependencies from Chart.yaml
459
+ chartPath := filepath .Join (srcAppPath , "Chart.yaml" )
460
+ if _ , err := os .Stat (chartPath ); err == nil {
461
+ log .Debug ().Msg ("processing helm dependencies" )
462
+ deps , err := parseChartYAML (chartPath )
463
+ if err != nil {
464
+ return "" , errors .Wrap (err , "failed to parse Chart.yaml" )
465
+ }
466
+
467
+ for _ , dep := range deps {
468
+ if strings .HasPrefix (dep .Repository , "file://" ) {
469
+ log .Debug ().Msgf ("processing local helm dependency %s" , dep .Repository )
470
+ if err := processLocalHelmDependency (srcAppPath , destAppDir , dep .Repository ); err != nil {
471
+ return "" , errors .Wrapf (err , "failed to process local helm dependency %s" , dep .Name )
472
+ }
473
+ }
474
+ }
475
+ }
476
+
402
477
refsByName := make (map [string ]v1alpha1.ApplicationSource )
403
478
for _ , ref := range refs {
404
479
refsByName [ref .Ref ] = ref
0 commit comments