mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
parent
5f5450449e
commit
ab3362849a
@ -149,12 +149,15 @@ func runHelmDeploy(config kubernetesDeployOptions, command command.ExecRunner, s
|
|||||||
upgradeParams = append(
|
upgradeParams = append(
|
||||||
upgradeParams,
|
upgradeParams,
|
||||||
"--install",
|
"--install",
|
||||||
"--force",
|
|
||||||
"--namespace", config.Namespace,
|
"--namespace", config.Namespace,
|
||||||
"--set",
|
"--set",
|
||||||
fmt.Sprintf("image.repository=%v/%v,image.tag=%v%v%v", containerRegistry, containerImageName, containerImageTag, secretsData, ingressHosts),
|
fmt.Sprintf("image.repository=%v/%v,image.tag=%v%v%v", containerRegistry, containerImageName, containerImageTag, secretsData, ingressHosts),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if config.ForceUpdates {
|
||||||
|
upgradeParams = append(upgradeParams, "--force")
|
||||||
|
}
|
||||||
|
|
||||||
if config.DeployTool == "helm" {
|
if config.DeployTool == "helm" {
|
||||||
upgradeParams = append(upgradeParams, "--wait", "--timeout", strconv.Itoa(config.HelmDeployWaitSeconds))
|
upgradeParams = append(upgradeParams, "--wait", "--timeout", strconv.Itoa(config.HelmDeployWaitSeconds))
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ type kubernetesDeployOptions struct {
|
|||||||
CreateDockerRegistrySecret bool `json:"createDockerRegistrySecret,omitempty"`
|
CreateDockerRegistrySecret bool `json:"createDockerRegistrySecret,omitempty"`
|
||||||
DeploymentName string `json:"deploymentName,omitempty"`
|
DeploymentName string `json:"deploymentName,omitempty"`
|
||||||
DeployTool string `json:"deployTool,omitempty"`
|
DeployTool string `json:"deployTool,omitempty"`
|
||||||
|
ForceUpdates bool `json:"forceUpdates,omitempty"`
|
||||||
HelmDeployWaitSeconds int `json:"helmDeployWaitSeconds,omitempty"`
|
HelmDeployWaitSeconds int `json:"helmDeployWaitSeconds,omitempty"`
|
||||||
HelmValues []string `json:"helmValues,omitempty"`
|
HelmValues []string `json:"helmValues,omitempty"`
|
||||||
Image string `json:"image,omitempty"`
|
Image string `json:"image,omitempty"`
|
||||||
@ -126,6 +127,7 @@ func addKubernetesDeployFlags(cmd *cobra.Command, stepConfig *kubernetesDeployOp
|
|||||||
cmd.Flags().BoolVar(&stepConfig.CreateDockerRegistrySecret, "createDockerRegistrySecret", false, "Only for `deployTool:kubectl`: Toggle to turn on `containerRegistrySecret` creation.")
|
cmd.Flags().BoolVar(&stepConfig.CreateDockerRegistrySecret, "createDockerRegistrySecret", false, "Only for `deployTool:kubectl`: Toggle to turn on `containerRegistrySecret` creation.")
|
||||||
cmd.Flags().StringVar(&stepConfig.DeploymentName, "deploymentName", os.Getenv("PIPER_deploymentName"), "Defines the name of the deployment.")
|
cmd.Flags().StringVar(&stepConfig.DeploymentName, "deploymentName", os.Getenv("PIPER_deploymentName"), "Defines the name of the deployment.")
|
||||||
cmd.Flags().StringVar(&stepConfig.DeployTool, "deployTool", `kubectl`, "Defines the tool which should be used for deployment.")
|
cmd.Flags().StringVar(&stepConfig.DeployTool, "deployTool", `kubectl`, "Defines the tool which should be used for deployment.")
|
||||||
|
cmd.Flags().BoolVar(&stepConfig.ForceUpdates, "forceUpdates", true, "Helm only: force resource updates with helm parameter `--force`")
|
||||||
cmd.Flags().IntVar(&stepConfig.HelmDeployWaitSeconds, "helmDeployWaitSeconds", 300, "Number of seconds before helm deploy returns.")
|
cmd.Flags().IntVar(&stepConfig.HelmDeployWaitSeconds, "helmDeployWaitSeconds", 300, "Number of seconds before helm deploy returns.")
|
||||||
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().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().StringVar(&stepConfig.Image, "image", os.Getenv("PIPER_image"), "Full name of the image to be deployed.")
|
cmd.Flags().StringVar(&stepConfig.Image, "image", os.Getenv("PIPER_image"), "Full name of the image to be deployed.")
|
||||||
@ -260,6 +262,14 @@ func kubernetesDeployMetadata() config.StepData {
|
|||||||
Mandatory: true,
|
Mandatory: true,
|
||||||
Aliases: []config.Alias{},
|
Aliases: []config.Alias{},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "forceUpdates",
|
||||||
|
ResourceRef: []config.ResourceReference{},
|
||||||
|
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||||
|
Type: "bool",
|
||||||
|
Mandatory: false,
|
||||||
|
Aliases: []config.Alias{},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "helmDeployWaitSeconds",
|
Name: "helmDeployWaitSeconds",
|
||||||
ResourceRef: []config.ResourceReference{},
|
ResourceRef: []config.ResourceReference{},
|
||||||
|
@ -24,6 +24,7 @@ func TestRunKubernetesDeploy(t *testing.T) {
|
|||||||
ChartPath: "path/to/chart",
|
ChartPath: "path/to/chart",
|
||||||
DeploymentName: "deploymentName",
|
DeploymentName: "deploymentName",
|
||||||
DeployTool: "helm",
|
DeployTool: "helm",
|
||||||
|
ForceUpdates: true,
|
||||||
HelmDeployWaitSeconds: 400,
|
HelmDeployWaitSeconds: 400,
|
||||||
IngressHosts: []string{"ingress.host1", "ingress.host2"},
|
IngressHosts: []string{"ingress.host1", "ingress.host2"},
|
||||||
Image: "path/to/Image:latest",
|
Image: "path/to/Image:latest",
|
||||||
@ -56,11 +57,11 @@ func TestRunKubernetesDeploy(t *testing.T) {
|
|||||||
"deploymentName",
|
"deploymentName",
|
||||||
"path/to/chart",
|
"path/to/chart",
|
||||||
"--install",
|
"--install",
|
||||||
"--force",
|
|
||||||
"--namespace",
|
"--namespace",
|
||||||
"deploymentNamespace",
|
"deploymentNamespace",
|
||||||
"--set",
|
"--set",
|
||||||
"image.repository=my.registry:55555/path/to/Image,image.tag=latest,secret.name=testSecret,secret.dockerconfigjson=ThisIsOurBase64EncodedSecret==,imagePullSecrets[0].name=testSecret,ingress.hosts[0]=ingress.host1,ingress.hosts[1]=ingress.host2",
|
"image.repository=my.registry:55555/path/to/Image,image.tag=latest,secret.name=testSecret,secret.dockerconfigjson=ThisIsOurBase64EncodedSecret==,imagePullSecrets[0].name=testSecret,ingress.hosts[0]=ingress.host1,ingress.hosts[1]=ingress.host2",
|
||||||
|
"--force",
|
||||||
"--wait",
|
"--wait",
|
||||||
"--timeout",
|
"--timeout",
|
||||||
"400",
|
"400",
|
||||||
@ -81,6 +82,7 @@ func TestRunKubernetesDeploy(t *testing.T) {
|
|||||||
ChartPath: "path/to/chart",
|
ChartPath: "path/to/chart",
|
||||||
DeploymentName: "deploymentName",
|
DeploymentName: "deploymentName",
|
||||||
DeployTool: "helm",
|
DeployTool: "helm",
|
||||||
|
ForceUpdates: true,
|
||||||
HelmDeployWaitSeconds: 400,
|
HelmDeployWaitSeconds: 400,
|
||||||
IngressHosts: []string{"ingress.host1", "ingress.host2"},
|
IngressHosts: []string{"ingress.host1", "ingress.host2"},
|
||||||
Image: "path/to/Image:latest",
|
Image: "path/to/Image:latest",
|
||||||
@ -114,11 +116,11 @@ func TestRunKubernetesDeploy(t *testing.T) {
|
|||||||
"deploymentName",
|
"deploymentName",
|
||||||
"path/to/chart",
|
"path/to/chart",
|
||||||
"--install",
|
"--install",
|
||||||
"--force",
|
|
||||||
"--namespace",
|
"--namespace",
|
||||||
"deploymentNamespace",
|
"deploymentNamespace",
|
||||||
"--set",
|
"--set",
|
||||||
"image.repository=my.registry:55555/path/to/Image,image.tag=latest,secret.name=testSecret,secret.dockerconfigjson=ThisIsOurBase64EncodedSecret==,imagePullSecrets[0].name=testSecret,ingress.hosts[0]=ingress.host1,ingress.hosts[1]=ingress.host2",
|
"image.repository=my.registry:55555/path/to/Image,image.tag=latest,secret.name=testSecret,secret.dockerconfigjson=ThisIsOurBase64EncodedSecret==,imagePullSecrets[0].name=testSecret,ingress.hosts[0]=ingress.host1,ingress.hosts[1]=ingress.host2",
|
||||||
|
"--force",
|
||||||
"--wait",
|
"--wait",
|
||||||
"--timeout",
|
"--timeout",
|
||||||
"400",
|
"400",
|
||||||
@ -138,6 +140,7 @@ func TestRunKubernetesDeploy(t *testing.T) {
|
|||||||
ChartPath: "path/to/chart",
|
ChartPath: "path/to/chart",
|
||||||
DeploymentName: "deploymentName",
|
DeploymentName: "deploymentName",
|
||||||
DeployTool: "helm3",
|
DeployTool: "helm3",
|
||||||
|
ForceUpdates: true,
|
||||||
HelmDeployWaitSeconds: 400,
|
HelmDeployWaitSeconds: 400,
|
||||||
HelmValues: []string{"values1.yaml", "values2.yaml"},
|
HelmValues: []string{"values1.yaml", "values2.yaml"},
|
||||||
Image: "path/to/Image:latest",
|
Image: "path/to/Image:latest",
|
||||||
@ -171,11 +174,11 @@ func TestRunKubernetesDeploy(t *testing.T) {
|
|||||||
"--values",
|
"--values",
|
||||||
"values2.yaml",
|
"values2.yaml",
|
||||||
"--install",
|
"--install",
|
||||||
"--force",
|
|
||||||
"--namespace",
|
"--namespace",
|
||||||
"deploymentNamespace",
|
"deploymentNamespace",
|
||||||
"--set",
|
"--set",
|
||||||
"image.repository=my.registry:55555/path/to/Image,image.tag=latest,secret.name=testSecret,secret.dockerconfigjson=ThisIsOurBase64EncodedSecret==,imagePullSecrets[0].name=testSecret",
|
"image.repository=my.registry:55555/path/to/Image,image.tag=latest,secret.name=testSecret,secret.dockerconfigjson=ThisIsOurBase64EncodedSecret==,imagePullSecrets[0].name=testSecret",
|
||||||
|
"--force",
|
||||||
"--wait",
|
"--wait",
|
||||||
"--timeout",
|
"--timeout",
|
||||||
"400s",
|
"400s",
|
||||||
@ -196,6 +199,7 @@ func TestRunKubernetesDeploy(t *testing.T) {
|
|||||||
ChartPath: "path/to/chart",
|
ChartPath: "path/to/chart",
|
||||||
DeploymentName: "deploymentName",
|
DeploymentName: "deploymentName",
|
||||||
DeployTool: "helm3",
|
DeployTool: "helm3",
|
||||||
|
ForceUpdates: true,
|
||||||
HelmDeployWaitSeconds: 400,
|
HelmDeployWaitSeconds: 400,
|
||||||
HelmValues: []string{"values1.yaml", "values2.yaml"},
|
HelmValues: []string{"values1.yaml", "values2.yaml"},
|
||||||
Image: "path/to/Image:latest",
|
Image: "path/to/Image:latest",
|
||||||
@ -230,11 +234,11 @@ func TestRunKubernetesDeploy(t *testing.T) {
|
|||||||
"--values",
|
"--values",
|
||||||
"values2.yaml",
|
"values2.yaml",
|
||||||
"--install",
|
"--install",
|
||||||
"--force",
|
|
||||||
"--namespace",
|
"--namespace",
|
||||||
"deploymentNamespace",
|
"deploymentNamespace",
|
||||||
"--set",
|
"--set",
|
||||||
"image.repository=my.registry:55555/path/to/Image,image.tag=latest,secret.name=testSecret,secret.dockerconfigjson=ThisIsOurBase64EncodedSecret==,imagePullSecrets[0].name=testSecret",
|
"image.repository=my.registry:55555/path/to/Image,image.tag=latest,secret.name=testSecret,secret.dockerconfigjson=ThisIsOurBase64EncodedSecret==,imagePullSecrets[0].name=testSecret",
|
||||||
|
"--force",
|
||||||
"--wait",
|
"--wait",
|
||||||
"--timeout",
|
"--timeout",
|
||||||
"400s",
|
"400s",
|
||||||
@ -252,6 +256,7 @@ func TestRunKubernetesDeploy(t *testing.T) {
|
|||||||
ContainerRegistrySecret: "testSecret",
|
ContainerRegistrySecret: "testSecret",
|
||||||
DeploymentName: "deploymentName",
|
DeploymentName: "deploymentName",
|
||||||
DeployTool: "helm3",
|
DeployTool: "helm3",
|
||||||
|
ForceUpdates: true,
|
||||||
HelmDeployWaitSeconds: 400,
|
HelmDeployWaitSeconds: 400,
|
||||||
IngressHosts: []string{},
|
IngressHosts: []string{},
|
||||||
Image: "path/to/Image:latest",
|
Image: "path/to/Image:latest",
|
||||||
@ -272,7 +277,46 @@ func TestRunKubernetesDeploy(t *testing.T) {
|
|||||||
"deploymentName",
|
"deploymentName",
|
||||||
"path/to/chart",
|
"path/to/chart",
|
||||||
"--install",
|
"--install",
|
||||||
|
"--namespace",
|
||||||
|
"deploymentNamespace",
|
||||||
|
"--set",
|
||||||
|
"image.repository=my.registry:55555/path/to/Image,image.tag=latest,imagePullSecrets[0].name=testSecret",
|
||||||
"--force",
|
"--force",
|
||||||
|
"--wait",
|
||||||
|
"--timeout",
|
||||||
|
"400s",
|
||||||
|
"--atomic",
|
||||||
|
"--kube-context",
|
||||||
|
"testCluster",
|
||||||
|
"--testParam",
|
||||||
|
"testValue",
|
||||||
|
}, e.Calls[0].Params, "Wrong upgrade parameters")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("test helm v3 - no force", func(t *testing.T) {
|
||||||
|
opts := kubernetesDeployOptions{
|
||||||
|
ContainerRegistryURL: "https://my.registry:55555",
|
||||||
|
ChartPath: "path/to/chart",
|
||||||
|
ContainerRegistrySecret: "testSecret",
|
||||||
|
DeploymentName: "deploymentName",
|
||||||
|
DeployTool: "helm3",
|
||||||
|
HelmDeployWaitSeconds: 400,
|
||||||
|
IngressHosts: []string{},
|
||||||
|
Image: "path/to/Image:latest",
|
||||||
|
AdditionalParameters: []string{"--testParam", "testValue"},
|
||||||
|
KubeContext: "testCluster",
|
||||||
|
Namespace: "deploymentNamespace",
|
||||||
|
}
|
||||||
|
e := mock.ExecMockRunner{}
|
||||||
|
|
||||||
|
var stdout bytes.Buffer
|
||||||
|
|
||||||
|
runKubernetesDeploy(opts, &e, &stdout)
|
||||||
|
assert.Equal(t, []string{
|
||||||
|
"upgrade",
|
||||||
|
"deploymentName",
|
||||||
|
"path/to/chart",
|
||||||
|
"--install",
|
||||||
"--namespace",
|
"--namespace",
|
||||||
"deploymentNamespace",
|
"deploymentNamespace",
|
||||||
"--set",
|
"--set",
|
||||||
|
@ -170,6 +170,15 @@ spec:
|
|||||||
- kubectl
|
- kubectl
|
||||||
- helm
|
- helm
|
||||||
- helm3
|
- helm3
|
||||||
|
- name: forceUpdates
|
||||||
|
type: bool
|
||||||
|
description: "Helm only: force resource updates with helm parameter `--force`"
|
||||||
|
mandatory: false
|
||||||
|
scope:
|
||||||
|
- PARAMETERS
|
||||||
|
- STAGES
|
||||||
|
- STEPS
|
||||||
|
default: true
|
||||||
- name: helmDeployWaitSeconds
|
- name: helmDeployWaitSeconds
|
||||||
type: int
|
type: int
|
||||||
description: Number of seconds before helm deploy returns.
|
description: Number of seconds before helm deploy returns.
|
||||||
|
Loading…
Reference in New Issue
Block a user