3535 helmRegistryConfigPath = env .String (helmRegistryConfigPathEnvVar , helmclient .DefaultRegistryConfigPath )
3636 krateoNamespace = env .String (krateoNamespaceEnvVar , krateoNamespaceDefault )
3737 helmRegistryConfigFile = filepath .Join (helmRegistryConfigPath , registry .CredentialsFileBasename )
38- helmMaxHistory = env .Int (helmMaxHistoryEnvvar , 10 )
38+ helmMaxHistory = env .Int (helmMaxHistoryEnvvar , 3 )
3939)
4040
4141const (
@@ -150,7 +150,7 @@ func (h *handler) Observe(ctx context.Context, mg *unstructured.Unstructured) (c
150150 return controller.ExternalObservation {}, fmt .Errorf ("updating cr with values: %w" , err )
151151 }
152152
153- hc , err := h .helmClientForResource (mg , pkg .RegistryAuth )
153+ hc , _ , err := h .helmClientForResource (mg , pkg .RegistryAuth )
154154 if err != nil {
155155 log .Error (err , "Getting helm client" )
156156 return controller.ExternalObservation {}, err
@@ -217,7 +217,7 @@ func (h *handler) Observe(ctx context.Context, mg *unstructured.Unstructured) (c
217217 }
218218
219219 tracer := & tracer.Tracer {}
220- hc , err = h .helmClientForResourceWithTransportWrapper (mg , pkg .RegistryAuth , func (rt http.RoundTripper ) http.RoundTripper {
220+ hc , _ , err = h .helmClientForResourceWithTransportWrapper (mg , pkg .RegistryAuth , func (rt http.RoundTripper ) http.RoundTripper {
221221 return tracer .WithRoundTripper (rt )
222222 })
223223 if err != nil {
@@ -365,7 +365,7 @@ func (h *handler) Create(ctx context.Context, mg *unstructured.Unstructured) err
365365 }
366366
367367 // Install the helm chart
368- hc , err := h .helmClientForResource (mg , pkg .RegistryAuth )
368+ hc , clientset , err := h .helmClientForResource (mg , pkg .RegistryAuth )
369369 if err != nil {
370370 log .Error (err , "Getting helm client" )
371371 return err
@@ -398,7 +398,7 @@ func (h *handler) Create(ctx context.Context, mg *unstructured.Unstructured) err
398398 }
399399 log .Debug ("Installing composition package" , "package" , pkg .URL )
400400
401- all , err := helmchart .GetResourcesRefFromRelease (rel , mg .GetNamespace ())
401+ all , err := helmchart .GetResourcesRefFromRelease (rel , mg .GetNamespace (), clientset )
402402 if err != nil {
403403 log .Error (err , "Getting resources from release" )
404404 return fmt .Errorf ("getting resources from release: %w" , err )
@@ -473,7 +473,7 @@ func (h *handler) Update(ctx context.Context, mg *unstructured.Unstructured) err
473473 }
474474
475475 // Update the helm chart
476- hc , err := h .helmClientForResource (mg , pkg .RegistryAuth )
476+ hc , clientset , err := h .helmClientForResource (mg , pkg .RegistryAuth )
477477 if err != nil {
478478 log .Error (err , "Getting helm client" )
479479 return err
@@ -484,7 +484,7 @@ func (h *handler) Update(ctx context.Context, mg *unstructured.Unstructured) err
484484 return err
485485 }
486486
487- all , err := helmchart .GetResourcesRefFromRelease (rel , mg .GetNamespace ())
487+ all , err := helmchart .GetResourcesRefFromRelease (rel , mg .GetNamespace (), clientset )
488488 if err != nil {
489489 log .Error (err , "Getting resources from release" )
490490 return fmt .Errorf ("getting resources from release: %w" , err )
@@ -576,7 +576,7 @@ func (h *handler) Delete(ctx context.Context, mg *unstructured.Unstructured) err
576576 return fmt .Errorf ("helm chart package info getter must be specified" )
577577 }
578578
579- hc , err := h .helmClientForResource (mg , nil )
579+ hc , _ , err := h .helmClientForResource (mg , nil )
580580 if err != nil {
581581 log .Error (err , "Getting helm client" )
582582 return err
@@ -667,7 +667,7 @@ func (h *handler) Delete(ctx context.Context, mg *unstructured.Unstructured) err
667667 return nil
668668}
669669
670- func (h * handler ) helmClientForResource (mg * unstructured.Unstructured , registryAuth * helmclient.RegistryAuth ) (helmclient.Client , error ) {
670+ func (h * handler ) helmClientForResource (mg * unstructured.Unstructured , registryAuth * helmclient.RegistryAuth ) (helmclient.Client , helmclient. CachedClientsInterface , error ) {
671671 log := h .logger .WithValues ("apiVersion" , mg .GetAPIVersion ()).
672672 WithValues ("kind" , mg .GetKind ()).
673673 WithValues ("name" , mg .GetName ()).
@@ -676,7 +676,7 @@ func (h *handler) helmClientForResource(mg *unstructured.Unstructured, registryA
676676 clientSet , err := helmclient .NewCachedClients (h .kubeconfig )
677677 if err != nil {
678678 log .Error (err , "Creating cached helm client set." )
679- return nil , err
679+ return nil , nil , err
680680 }
681681
682682 opts := & helmclient.Options {
@@ -700,16 +700,17 @@ func (h *handler) helmClientForResource(mg *unstructured.Unstructured, registryA
700700 RegistryAuth : (registryAuth ),
701701 }
702702
703- return helmclient .NewCachedClientFromRestConf (
703+ hc , err := helmclient .NewCachedClientFromRestConf (
704704 & helmclient.RestConfClientOptions {
705705 Options : opts ,
706706 RestConfig : h .kubeconfig ,
707707 },
708- & clientSet ,
708+ clientSet ,
709709 )
710+ return hc , clientSet , err
710711}
711712
712- func (h * handler ) helmClientForResourceWithTransportWrapper (mg * unstructured.Unstructured , registryAuth * helmclient.RegistryAuth , transportWrapper func (http.RoundTripper ) http.RoundTripper ) (helmclient.Client , error ) {
713+ func (h * handler ) helmClientForResourceWithTransportWrapper (mg * unstructured.Unstructured , registryAuth * helmclient.RegistryAuth , transportWrapper func (http.RoundTripper ) http.RoundTripper ) (helmclient.Client , helmclient. CachedClientsInterface , error ) {
713714 opts := & helmclient.Options {
714715 Namespace : mg .GetNamespace (),
715716 RepositoryCache : "/tmp/.helmcache" ,
@@ -723,17 +724,18 @@ func (h *handler) helmClientForResourceWithTransportWrapper(mg *unstructured.Uns
723724
724725 clientSet , err := helmclient .NewCachedClients (h .kubeconfig )
725726 if err != nil {
726- return nil , err
727+ return nil , nil , err
727728 }
728729
729730 cfg := rest .CopyConfig (h .kubeconfig )
730731 cfg .WrapTransport = transportWrapper
731732
732- return helmclient .NewCachedClientFromRestConf (
733+ hc , err := helmclient .NewCachedClientFromRestConf (
733734 & helmclient.RestConfClientOptions {
734735 Options : opts ,
735736 RestConfig : cfg ,
736737 },
737- & clientSet ,
738+ clientSet ,
738739 )
740+ return hc , clientSet , err
739741}
0 commit comments