Skip to content

Commit

Permalink
ROX-18085: Allow custom post-renderer (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludydoo authored Jul 11, 2023
1 parent 41612fb commit 08cc945
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 @@ -100,13 +103,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 PostRendererGetter func(rm meta.RESTMapper, kubeClient kube.Interface, obj client.Object) postrender.PostRenderer

func AppendPostRenderers(postRendererGetters ...PostRendererGetter) ActionClientGetterOption {
return func(getter *actionClientGetter) error {
getter.postRendererGetters = append(getter.postRendererGetters, postRendererGetters...)
return nil
}
}

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

installFailureUninstallOpts []UninstallOption
upgradeFailureRollbackOpts []RollbackOption

postRendererGetters []PostRendererGetter
}

var _ ActionClientGetter = &actionClientGetter{}
Expand All @@ -140,16 +155,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 _, postRendererGetter := range hcg.postRendererGetters {
chainedPostRenderer = append(chainedPostRenderer, postRendererGetter(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 08cc945

Please sign in to comment.