@@ -21,7 +21,11 @@ import (
21
21
"context"
22
22
"errors"
23
23
"fmt"
24
+ olmv1error "github.com/operator-framework/operator-controller/internal/action/error"
25
+ "gopkg.in/yaml.v3"
26
+ "helm.sh/helm/v3/pkg/engine"
24
27
"io"
28
+ k8serrors "k8s.io/apimachinery/pkg/api/errors"
25
29
"sort"
26
30
"strings"
27
31
"sync"
@@ -64,7 +68,7 @@ import (
64
68
"github.com/operator-framework/operator-registry/alpha/property"
65
69
rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2"
66
70
registryv1handler "github.com/operator-framework/rukpak/pkg/handler"
67
- crdupgradesafety "github.com/operator-framework/rukpak/pkg/preflights/crdupgradesafety"
71
+ "github.com/operator-framework/rukpak/pkg/preflights/crdupgradesafety"
68
72
rukpaksource "github.com/operator-framework/rukpak/pkg/source"
69
73
"github.com/operator-framework/rukpak/pkg/storage"
70
74
"github.com/operator-framework/rukpak/pkg/util"
@@ -74,7 +78,6 @@ import (
74
78
catalogfilter "github.com/operator-framework/operator-controller/internal/catalogmetadata/filter"
75
79
catalogsort "github.com/operator-framework/operator-controller/internal/catalogmetadata/sort"
76
80
"github.com/operator-framework/operator-controller/internal/conditionsets"
77
- olmv1error "github.com/operator-framework/operator-controller/internal/error"
78
81
"github.com/operator-framework/operator-controller/internal/httputil"
79
82
"github.com/operator-framework/operator-controller/internal/labels"
80
83
)
@@ -363,6 +366,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
363
366
return nil
364
367
}, helmclient .AppendInstallPostRenderer (post ))
365
368
if err != nil {
369
+ _ = r .renderTemplates (chrt , values , post )
366
370
log .FromContext (ctx ).Error (err , "failed to install bundle" )
367
371
setInstalledStatusConditionFailed (ext , fmt .Sprintf ("%s:%v" , ocv1alpha1 .ReasonInstallationFailed , olmv1error .AsOlmErr (err )))
368
372
return ctrl.Result {}, err
@@ -799,3 +803,56 @@ func (r *ClusterExtensionReconciler) validateBundle(bundle *catalogmetadata.Bund
799
803
800
804
return nil
801
805
}
806
+
807
+ func (r * ClusterExtensionReconciler ) renderTemplates (chart * chart.Chart , values map [string ]interface {}, post postrender.PostRenderer ) error {
808
+ options := chartutil.ReleaseOptions {}
809
+
810
+ // Combine chart values with release options
811
+ valuesToRender , err := chartutil .ToRenderValues (chart , values , options , nil )
812
+ if err != nil {
813
+ return err
814
+ }
815
+
816
+ // Render templates
817
+ rendered , err := engine .Render (chart , valuesToRender )
818
+ if err != nil {
819
+ return err
820
+ }
821
+
822
+ for _ , tmpl := range rendered {
823
+ // apply post renderer
824
+ buf := bytes .NewBufferString (tmpl )
825
+ modified , err := post .Run (buf )
826
+ if err != nil {
827
+ return err
828
+ }
829
+
830
+ // extract object
831
+ var obj map [string ]interface {}
832
+ if err := yaml .Unmarshal (modified .Bytes (), & obj ); err != nil {
833
+ return err
834
+ }
835
+
836
+ resource := & unstructured.Unstructured {Object : obj }
837
+
838
+ // try to create (dry run)
839
+ err = r .Client .Create (context .Background (), resource , client .DryRunAll )
840
+ if ! k8serrors .IsAlreadyExists (err ) {
841
+ return err
842
+ }
843
+
844
+ key := client .ObjectKeyFromObject (resource )
845
+ existingResource := resource .DeepCopy ()
846
+ err = r .Client .Get (context .Background (), key , existingResource )
847
+ if err != nil {
848
+ return err
849
+ }
850
+
851
+ // try to update (dry run)
852
+ resource .SetResourceVersion (existingResource .GetResourceVersion ())
853
+ if err := r .Client .Update (context .Background (), resource , client .DryRunAll ); ! k8serrors .IsNotFound (err ) {
854
+ return err
855
+ }
856
+ }
857
+ return nil
858
+ }
0 commit comments