@@ -25,12 +25,15 @@ import (
2525 "gomodules.xyz/jsonpatch/v2"
2626 "helm.sh/helm/v3/pkg/action"
2727 "helm.sh/helm/v3/pkg/chart"
28+ "helm.sh/helm/v3/pkg/kube"
2829 helmkube "helm.sh/helm/v3/pkg/kube"
30+ "helm.sh/helm/v3/pkg/postrender"
2931 "helm.sh/helm/v3/pkg/release"
3032 "helm.sh/helm/v3/pkg/storage/driver"
3133 apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
3234 apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
3335 apierrors "k8s.io/apimachinery/pkg/api/errors"
36+ "k8s.io/apimachinery/pkg/api/meta"
3437 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3538 "k8s.io/apimachinery/pkg/runtime"
3639 apitypes "k8s.io/apimachinery/pkg/types"
@@ -100,13 +103,23 @@ func AppendInstallFailureUninstallOptions(opts ...UninstallOption) ActionClientG
100103 return nil
101104 }
102105}
106+
103107func AppendUpgradeFailureRollbackOptions (opts ... RollbackOption ) ActionClientGetterOption {
104108 return func (getter * actionClientGetter ) error {
105109 getter .upgradeFailureRollbackOpts = append (getter .upgradeFailureRollbackOpts , opts ... )
106110 return nil
107111 }
108112}
109113
114+ type PostRendererGetter func (rm meta.RESTMapper , kubeClient kube.Interface , obj client.Object ) postrender.PostRenderer
115+
116+ func AppendPostRenderers (postRendererGetters ... PostRendererGetter ) ActionClientGetterOption {
117+ return func (getter * actionClientGetter ) error {
118+ getter .postRendererGetters = append (getter .postRendererGetters , postRendererGetters ... )
119+ return nil
120+ }
121+ }
122+
110123func NewActionClientGetter (acg ActionConfigGetter , opts ... ActionClientGetterOption ) (ActionClientGetter , error ) {
111124 actionClientGetter := & actionClientGetter {acg : acg }
112125 for _ , opt := range opts {
@@ -127,6 +140,8 @@ type actionClientGetter struct {
127140
128141 installFailureUninstallOpts []UninstallOption
129142 upgradeFailureRollbackOpts []RollbackOption
143+
144+ postRendererGetters []PostRendererGetter
130145}
131146
132147var _ ActionClientGetter = & actionClientGetter {}
@@ -140,16 +155,22 @@ func (hcg *actionClientGetter) ActionClientFor(obj client.Object) (ActionInterfa
140155 if err != nil {
141156 return nil , err
142157 }
143- postRenderer := DefaultPostRendererFunc (rm , actionConfig .KubeClient , obj )
158+ var chainedPostRenderer = chainedPostRenderer {
159+ DefaultPostRendererFunc (rm , actionConfig .KubeClient , obj ),
160+ }
161+ for _ , postRendererGetter := range hcg .postRendererGetters {
162+ chainedPostRenderer = append (chainedPostRenderer , postRendererGetter (rm , actionConfig .KubeClient , obj ))
163+ }
164+
144165 return & actionClient {
145166 conf : actionConfig ,
146167
147168 // For the install and upgrade options, we put the post renderer first in the list
148169 // on purpose because we want user-provided defaults to be able to override the
149170 // post-renderer that we automatically configure for the client.
150171 defaultGetOpts : hcg .defaultGetOpts ,
151- defaultInstallOpts : append ([]InstallOption {WithInstallPostRenderer (postRenderer )}, hcg .defaultInstallOpts ... ),
152- defaultUpgradeOpts : append ([]UpgradeOption {WithUpgradePostRenderer (postRenderer )}, hcg .defaultUpgradeOpts ... ),
172+ defaultInstallOpts : append ([]InstallOption {WithInstallPostRenderer (chainedPostRenderer )}, hcg .defaultInstallOpts ... ),
173+ defaultUpgradeOpts : append ([]UpgradeOption {WithUpgradePostRenderer (chainedPostRenderer )}, hcg .defaultUpgradeOpts ... ),
153174 defaultUninstallOpts : hcg .defaultUninstallOpts ,
154175
155176 installFailureUninstallOpts : hcg .installFailureUninstallOpts ,
0 commit comments