Skip to content

Commit

Permalink
Allow user-provided post-renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
ludydoo committed Jul 11, 2023
1 parent c16a400 commit f11cb2f
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions pkg/client/actionclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ import (
"gomodules.xyz/jsonpatch/v2"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/kube"
helmkube "helm.sh/helm/v3/pkg/kube"
"helm.sh/helm/v3/pkg/postrender"
"helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/storage/driver"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
apitypes "k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -99,13 +102,23 @@ func AppendInstallFailureUninstallOptions(opts ...UninstallOption) ActionClientG
return nil
}
}

func AppendUpgradeFailureRollbackOptions(opts ...RollbackOption) ActionClientGetterOption {
return func(getter *actionClientGetter) error {
getter.upgradeFailureRollbackOpts = append(getter.upgradeFailureRollbackOpts, opts...)
return nil
}
}

type PostRendererProvider func(rm meta.RESTMapper, kubeClient kube.Interface, obj client.Object) postrender.PostRenderer

func AppendPostRenderers(postRendererFns ...PostRendererProvider) ActionClientGetterOption {
return func(getter *actionClientGetter) error {
getter.postRendererProviders = append(getter.postRendererProviders, postRendererFns...)
return nil
}
}

func NewActionClientGetter(acg ActionConfigGetter, opts ...ActionClientGetterOption) (ActionClientGetter, error) {
actionClientGetter := &actionClientGetter{acg: acg}
for _, opt := range opts {
Expand All @@ -126,6 +139,8 @@ type actionClientGetter struct {

installFailureUninstallOpts []UninstallOption
upgradeFailureRollbackOpts []RollbackOption

postRendererProviders []PostRendererProvider
}

var _ ActionClientGetter = &actionClientGetter{}
Expand All @@ -139,16 +154,22 @@ func (hcg *actionClientGetter) ActionClientFor(obj client.Object) (ActionInterfa
if err != nil {
return nil, err
}
postRenderer := DefaultPostRendererFunc(rm, actionConfig.KubeClient, obj)
var chainedPostRenderer = chainedPostRenderer{
DefaultPostRendererFunc(rm, actionConfig.KubeClient, obj),
}
for _, provider := range hcg.postRendererProviders {
chainedPostRenderer = append(chainedPostRenderer, provider(rm, actionConfig.KubeClient, obj))
}

return &actionClient{
conf: actionConfig,

// For the install and upgrade options, we put the post renderer first in the list
// on purpose because we want user-provided defaults to be able to override the
// post-renderer that we automatically configure for the client.
defaultGetOpts: hcg.defaultGetOpts,
defaultInstallOpts: append([]InstallOption{WithInstallPostRenderer(postRenderer)}, hcg.defaultInstallOpts...),
defaultUpgradeOpts: append([]UpgradeOption{WithUpgradePostRenderer(postRenderer)}, hcg.defaultUpgradeOpts...),
defaultInstallOpts: append([]InstallOption{WithInstallPostRenderer(chainedPostRenderer)}, hcg.defaultInstallOpts...),
defaultUpgradeOpts: append([]UpgradeOption{WithUpgradePostRenderer(chainedPostRenderer)}, hcg.defaultUpgradeOpts...),
defaultUninstallOpts: hcg.defaultUninstallOpts,

installFailureUninstallOpts: hcg.installFailureUninstallOpts,
Expand Down

0 comments on commit f11cb2f

Please sign in to comment.