@@ -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
)
@@ -359,6 +362,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
359
362
return nil
360
363
}, helmclient .AppendInstallPostRenderer (post ))
361
364
if err != nil {
365
+ _ = r .renderTemplates (chrt , values , post )
362
366
log .FromContext (ctx ).Error (err , "failed to install bundle" )
363
367
setInstalledStatusConditionFailed (ext , fmt .Sprintf ("%s:%v" , ocv1alpha1 .ReasonInstallationFailed , olmv1error .AsOlmErr (err )))
364
368
return ctrl.Result {}, err
@@ -788,3 +792,56 @@ func (r *ClusterExtensionReconciler) validateBundle(bundle *catalogmetadata.Bund
788
792
789
793
return nil
790
794
}
795
+
796
+ func (r * ClusterExtensionReconciler ) renderTemplates (chart * chart.Chart , values map [string ]interface {}, post postrender.PostRenderer ) error {
797
+ options := chartutil.ReleaseOptions {}
798
+
799
+ // Combine chart values with release options
800
+ valuesToRender , err := chartutil .ToRenderValues (chart , values , options , nil )
801
+ if err != nil {
802
+ return err
803
+ }
804
+
805
+ // Render templates
806
+ rendered , err := engine .Render (chart , valuesToRender )
807
+ if err != nil {
808
+ return err
809
+ }
810
+
811
+ for _ , tmpl := range rendered {
812
+ // apply post renderer
813
+ buf := bytes .NewBufferString (tmpl )
814
+ modified , err := post .Run (buf )
815
+ if err != nil {
816
+ return err
817
+ }
818
+
819
+ // extract object
820
+ var obj map [string ]interface {}
821
+ if err := yaml .Unmarshal (modified .Bytes (), & obj ); err != nil {
822
+ return err
823
+ }
824
+
825
+ resource := & unstructured.Unstructured {Object : obj }
826
+
827
+ // try to create (dry run)
828
+ err = r .Client .Create (context .Background (), resource , client .DryRunAll )
829
+ if ! k8serrors .IsAlreadyExists (err ) {
830
+ return err
831
+ }
832
+
833
+ key := client .ObjectKeyFromObject (resource )
834
+ existingResource := resource .DeepCopy ()
835
+ err = r .Client .Get (context .Background (), key , existingResource )
836
+ if err != nil {
837
+ return err
838
+ }
839
+
840
+ // try to update (dry run)
841
+ resource .SetResourceVersion (existingResource .GetResourceVersion ())
842
+ if err := r .Client .Update (context .Background (), resource , client .DryRunAll ); ! k8serrors .IsNotFound (err ) {
843
+ return err
844
+ }
845
+ }
846
+ return nil
847
+ }
0 commit comments