From 35a55044b4e0785b6220657b91202b13b6df7cdf Mon Sep 17 00:00:00 2001 From: Pavel Busko Date: Fri, 5 May 2023 14:23:11 +0200 Subject: [PATCH] Add renderSubchartNotes property to helmExecute and kubernetesDeploy (#4238) Co-authored-by: Philipp Stehle Co-authored-by: Ralf Pannemans --- cmd/helmExecute.go | 1 + cmd/helmExecute_generated.go | 11 +++++++++++ cmd/kubernetesDeploy.go | 4 ++++ cmd/kubernetesDeploy_generated.go | 11 +++++++++++ cmd/kubernetesDeploy_test.go | 2 ++ pkg/kubernetes/helm.go | 13 +++++++++++++ pkg/kubernetes/helm_test.go | 6 ++++-- resources/metadata/helmExecute.yaml | 9 +++++++++ resources/metadata/kubernetesDeploy.yaml | 9 +++++++++ 9 files changed, 64 insertions(+), 2 deletions(-) diff --git a/cmd/helmExecute.go b/cmd/helmExecute.go index f6d92dc2f..51175c006 100644 --- a/cmd/helmExecute.go +++ b/cmd/helmExecute.go @@ -41,6 +41,7 @@ func helmExecute(config helmExecuteOptions, telemetryData *telemetry.CustomData, CustomTLSCertificateLinks: config.CustomTLSCertificateLinks, Version: config.Version, PublishVersion: config.Version, + RenderSubchartNotes: config.RenderSubchartNotes, } utils := kubernetes.NewDeployUtilsBundle(helmConfig.CustomTLSCertificateLinks) diff --git a/cmd/helmExecute_generated.go b/cmd/helmExecute_generated.go index 1f0341cf0..1d12b8f6f 100644 --- a/cmd/helmExecute_generated.go +++ b/cmd/helmExecute_generated.go @@ -45,6 +45,7 @@ type helmExecuteOptions struct { CustomTLSCertificateLinks []string `json:"customTlsCertificateLinks,omitempty"` Publish bool `json:"publish,omitempty"` Version string `json:"version,omitempty"` + RenderSubchartNotes bool `json:"renderSubchartNotes,omitempty"` } type helmExecuteCommonPipelineEnvironment struct { @@ -224,6 +225,7 @@ func addHelmExecuteFlags(cmd *cobra.Command, stepConfig *helmExecuteOptions) { cmd.Flags().StringSliceVar(&stepConfig.CustomTLSCertificateLinks, "customTlsCertificateLinks", []string{}, "List of download links to custom TLS certificates. This is required to ensure trusted connections to instances with repositories (like nexus) when publish flag is set to true.") cmd.Flags().BoolVar(&stepConfig.Publish, "publish", false, "Configures helm to run the deploy command to publish artifacts to a repository.") cmd.Flags().StringVar(&stepConfig.Version, "version", os.Getenv("PIPER_version"), "Defines the artifact version to use from helm package/publish commands.") + cmd.Flags().BoolVar(&stepConfig.RenderSubchartNotes, "renderSubchartNotes", true, "If set, render subchart notes along with the parent.") cmd.MarkFlagRequired("image") } @@ -595,6 +597,15 @@ func helmExecuteMetadata() config.StepData { Aliases: []config.Alias{}, Default: os.Getenv("PIPER_version"), }, + { + Name: "renderSubchartNotes", + ResourceRef: []config.ResourceReference{}, + Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"}, + Type: "bool", + Mandatory: false, + Aliases: []config.Alias{}, + Default: true, + }, }, }, Containers: []config.Container{ diff --git a/cmd/kubernetesDeploy.go b/cmd/kubernetesDeploy.go index c1659117a..b181c9791 100644 --- a/cmd/kubernetesDeploy.go +++ b/cmd/kubernetesDeploy.go @@ -200,6 +200,10 @@ func runHelmDeploy(config kubernetesDeployOptions, utils kubernetes.DeployUtils, upgradeParams = append(upgradeParams, "--kube-context", config.KubeContext) } + if config.RenderSubchartNotes { + upgradeParams = append(upgradeParams, "--render-subchart-notes") + } + if len(config.AdditionalParameters) > 0 { upgradeParams = append(upgradeParams, config.AdditionalParameters...) } diff --git a/cmd/kubernetesDeploy_generated.go b/cmd/kubernetesDeploy_generated.go index 0a3a27acc..cbb966ec4 100644 --- a/cmd/kubernetesDeploy_generated.go +++ b/cmd/kubernetesDeploy_generated.go @@ -34,6 +34,7 @@ type kubernetesDeployOptions struct { HelmTestWaitSeconds int `json:"helmTestWaitSeconds,omitempty"` HelmValues []string `json:"helmValues,omitempty"` ValuesMapping map[string]interface{} `json:"valuesMapping,omitempty"` + RenderSubchartNotes bool `json:"renderSubchartNotes,omitempty"` GithubToken string `json:"githubToken,omitempty"` Image string `json:"image,omitempty"` ImageNames []string `json:"imageNames,omitempty"` @@ -189,6 +190,7 @@ func addKubernetesDeployFlags(cmd *cobra.Command, stepConfig *kubernetesDeployOp cmd.Flags().IntVar(&stepConfig.HelmTestWaitSeconds, "helmTestWaitSeconds", 300, "Number of seconds to wait for any individual Kubernetes operation (like Jobs for hooks). See https://helm.sh/docs/helm/helm_test/#options for further details") cmd.Flags().StringSliceVar(&stepConfig.HelmValues, "helmValues", []string{}, "List of helm values as YAML file reference or URL (as per helm parameter description for `-f` / `--values`)") + cmd.Flags().BoolVar(&stepConfig.RenderSubchartNotes, "renderSubchartNotes", true, "If set, render subchart notes along with the parent.") cmd.Flags().StringVar(&stepConfig.GithubToken, "githubToken", os.Getenv("PIPER_githubToken"), "GitHub personal access token as per https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line") cmd.Flags().StringVar(&stepConfig.Image, "image", os.Getenv("PIPER_image"), "Full name of the image to be deployed.") cmd.Flags().StringSliceVar(&stepConfig.ImageNames, "imageNames", []string{}, "List of names of the images to be deployed.") @@ -444,6 +446,15 @@ func kubernetesDeployMetadata() config.StepData { Mandatory: false, Aliases: []config.Alias{}, }, + { + Name: "renderSubchartNotes", + ResourceRef: []config.ResourceReference{}, + Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"}, + Type: "bool", + Mandatory: false, + Aliases: []config.Alias{}, + Default: true, + }, { Name: "githubToken", ResourceRef: []config.ResourceReference{ diff --git a/cmd/kubernetesDeploy_test.go b/cmd/kubernetesDeploy_test.go index ac4826c33..436de8367 100644 --- a/cmd/kubernetesDeploy_test.go +++ b/cmd/kubernetesDeploy_test.go @@ -43,6 +43,7 @@ func TestRunKubernetesDeploy(t *testing.T) { DeploymentName: "deploymentName", DeployTool: "helm", ForceUpdates: true, + RenderSubchartNotes: true, HelmDeployWaitSeconds: 400, IngressHosts: []string{"ingress.host1", "ingress.host2"}, Image: "path/to/Image:latest", @@ -90,6 +91,7 @@ func TestRunKubernetesDeploy(t *testing.T) { "--atomic", "--kube-context", "testCluster", + "--render-subchart-notes", "--testParam", "testValue", }, mockUtils.Calls[2].Params, "Wrong upgrade parameters") diff --git a/pkg/kubernetes/helm.go b/pkg/kubernetes/helm.go index 11f4afd42..c5d5c1be9 100644 --- a/pkg/kubernetes/helm.go +++ b/pkg/kubernetes/helm.go @@ -61,6 +61,7 @@ type HelmExecuteOptions struct { SourceRepositoryPassword string `json:"sourceRepositoryPassword,omitempty"` HelmCommand string `json:"helmCommand,omitempty"` CustomTLSCertificateLinks []string `json:"customTlsCertificateLinks,omitempty"` + RenderSubchartNotes bool `json:"renderSubchartNotes,omitempty"` } // NewHelmExecutor creates HelmExecute instance @@ -168,6 +169,10 @@ func (h *HelmExecute) RunHelmUpgrade() error { helmParams = append(helmParams, "--atomic") } + if h.config.RenderSubchartNotes { + helmParams = append(helmParams, "--render-subchart-notes") + } + if len(h.config.AdditionalParameters) > 0 { helmParams = append(helmParams, h.config.AdditionalParameters...) } @@ -230,16 +235,24 @@ func (h *HelmExecute) RunHelmInstall() error { } helmParams = append(helmParams, "--namespace", h.config.Namespace) helmParams = append(helmParams, "--create-namespace") + if !h.config.KeepFailedDeployments { helmParams = append(helmParams, "--atomic") } + helmParams = append(helmParams, "--wait", "--timeout", fmt.Sprintf("%vs", h.config.HelmDeployWaitSeconds)) for _, v := range h.config.HelmValues { helmParams = append(helmParams, "--values", v) } + + if h.config.RenderSubchartNotes { + helmParams = append(helmParams, "--render-subchart-notes") + } + if len(h.config.AdditionalParameters) > 0 { helmParams = append(helmParams, h.config.AdditionalParameters...) } + if h.verbose { helmParams = append(helmParams, "--debug") } diff --git a/pkg/kubernetes/helm_test.go b/pkg/kubernetes/helm_test.go index 7f1b19a04..9623701dc 100644 --- a/pkg/kubernetes/helm_test.go +++ b/pkg/kubernetes/helm_test.go @@ -131,11 +131,12 @@ func TestRunHelmUpgrade(t *testing.T) { Image: "dtzar/helm-kubectl:3.4.1", TargetRepositoryName: "test", TargetRepositoryURL: "https://charts.helm.sh/stable", + RenderSubchartNotes: true, }, generalVerbose: true, expectedExecCalls: []mock.ExecCall{ {Exec: "helm", Params: []string{"repo", "add", "test", "https://charts.helm.sh/stable", "--debug"}}, - {Exec: "helm", Params: []string{"upgrade", "test_deployment", "test", "--debug", "--install", "--namespace", "test_namespace", "--force", "--wait", "--timeout", "3456s", "--atomic", "additional parameter"}}, + {Exec: "helm", Params: []string{"upgrade", "test_deployment", "test", "--debug", "--install", "--namespace", "test_namespace", "--force", "--wait", "--timeout", "3456s", "--atomic", "--render-subchart-notes", "additional parameter"}}, }, }, { @@ -231,11 +232,12 @@ func TestRunHelmInstall(t *testing.T) { HelmDeployWaitSeconds: 525, TargetRepositoryURL: "https://charts.helm.sh/stable", TargetRepositoryName: "test", + RenderSubchartNotes: true, }, generalVerbose: false, expectedExecCalls: []mock.ExecCall{ {Exec: "helm", Params: []string{"repo", "add", "test", "https://charts.helm.sh/stable"}}, - {Exec: "helm", Params: []string{"install", "testPackage", "test", "--namespace", "test-namespace", "--create-namespace", "--atomic", "--wait", "--timeout", "525s"}}, + {Exec: "helm", Params: []string{"install", "testPackage", "test", "--namespace", "test-namespace", "--create-namespace", "--atomic", "--wait", "--timeout", "525s", "--render-subchart-notes"}}, }, }, { diff --git a/resources/metadata/helmExecute.yaml b/resources/metadata/helmExecute.yaml index 64ed60024..8c57b3eae 100644 --- a/resources/metadata/helmExecute.yaml +++ b/resources/metadata/helmExecute.yaml @@ -336,6 +336,15 @@ spec: - PARAMETERS - STAGES - STEPS + - name: renderSubchartNotes + type: bool + description: If set, render subchart notes along with the parent. + default: true + scope: + - GENERAL + - PARAMETERS + - STAGES + - STEPS containers: - image: dtzar/helm-kubectl:3 workingDir: /config diff --git a/resources/metadata/kubernetesDeploy.yaml b/resources/metadata/kubernetesDeploy.yaml index ab0024cf2..2d7819c6f 100644 --- a/resources/metadata/kubernetesDeploy.yaml +++ b/resources/metadata/kubernetesDeploy.yaml @@ -310,6 +310,15 @@ spec: - PARAMETERS - STAGES - STEPS + - name: renderSubchartNotes + type: bool + description: If set, render subchart notes along with the parent. + default: true + scope: + - GENERAL + - PARAMETERS + - STAGES + - STEPS - name: githubToken description: "GitHub personal access token as per https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line"