From c8ef9419e749ad3017aec680a299a406c846b8da Mon Sep 17 00:00:00 2001 From: Keshav Date: Thu, 30 Mar 2023 10:26:15 +0200 Subject: [PATCH 1/5] adding a timeout for helm test --- cmd/integrationArtifactTransport.go | 10 +++++----- cmd/kubernetesDeploy.go | 8 ++++++++ cmd/kubernetesDeploy_generated.go | 11 +++++++++++ resources/metadata/kubernetesDeploy.yaml | 8 ++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/cmd/integrationArtifactTransport.go b/cmd/integrationArtifactTransport.go index cb37bc3f75..fa0435aa68 100644 --- a/cmd/integrationArtifactTransport.go +++ b/cmd/integrationArtifactTransport.go @@ -34,7 +34,7 @@ func runIntegrationArtifactTransport(config *integrationArtifactTransportOptions return CreateIntegrationArtifactTransportRequest(config, apimData) } -//CreateIntegrationArtifactTransportRequest - Create a transport request for Integration Package +// CreateIntegrationArtifactTransportRequest - Create a transport request for Integration Package func CreateIntegrationArtifactTransportRequest(config *integrationArtifactTransportOptions, apistruct apim.Bundle) error { httpMethod := http.MethodPost httpClient := apistruct.Client @@ -90,7 +90,7 @@ func CreateIntegrationArtifactTransportRequest(config *integrationArtifactTransp return errors.Errorf("integration flow deployment failed, response Status code: %v", createTransportRequestResp.StatusCode) } -//pollTransportStatus - Poll the integration package transport processing, return status or error details +// pollTransportStatus - Poll the integration package transport processing, return status or error details func pollTransportStatus(processId string, remainingRetries int, config *integrationArtifactTransportOptions, httpClient piperhttp.Sender, apiHost string) error { if remainingRetries <= 0 { @@ -126,7 +126,7 @@ func pollTransportStatus(processId string, remainingRetries int, config *integra return nil } -//GetJSONPayload -return http payload as byte array +// GetJSONPayload -return http payload as byte array func GetCPITransportReqPayload(config *integrationArtifactTransportOptions) (*bytes.Buffer, error) { jsonObj := gabs.New() jsonObj.Set(rand.Intn(5000), "id") @@ -153,7 +153,7 @@ func GetCPITransportReqPayload(config *integrationArtifactTransportOptions) (*by return bytes.NewBuffer(jsonBody), nil } -//getIntegrationTransportProcessingStatus - Get integration package transport request processing Status +// getIntegrationTransportProcessingStatus - Get integration package transport request processing Status func getIntegrationTransportProcessingStatus(config *integrationArtifactTransportOptions, httpClient piperhttp.Sender, apiHost string, processId string) (string, error) { httpMethod := "GET" header := make(http.Header) @@ -192,7 +192,7 @@ func getIntegrationTransportProcessingStatus(config *integrationArtifactTranspor return "", errors.Errorf("failed to get transport request processing status, response Status code: %v", transportProcStatusResp.StatusCode) } -//getTransportError - Get integration package transport failures error details +// getTransportError - Get integration package transport failures error details func getIntegrationTransportError(config *integrationArtifactTransportOptions, httpClient piperhttp.Sender, apiHost string, processId string) (string, error) { httpMethod := "GET" header := make(http.Header) diff --git a/cmd/kubernetesDeploy.go b/cmd/kubernetesDeploy.go index 034f085c9f..99f97be987 100644 --- a/cmd/kubernetesDeploy.go +++ b/cmd/kubernetesDeploy.go @@ -226,6 +226,14 @@ func runHelmDeploy(config kubernetesDeployOptions, utils kubernetes.DeployUtils, "--namespace", config.Namespace, } + if config.HelmTestWaitSeconds > 0 { + testParams = append( + testParams, + "--timeout", + strconv.Itoa(config.HelmTestWaitSeconds), + ) + } + if config.ShowTestLogs { testParams = append( testParams, diff --git a/cmd/kubernetesDeploy_generated.go b/cmd/kubernetesDeploy_generated.go index 4f13e198dc..b5ac876ed0 100644 --- a/cmd/kubernetesDeploy_generated.go +++ b/cmd/kubernetesDeploy_generated.go @@ -31,6 +31,7 @@ type kubernetesDeployOptions struct { DeployTool string `json:"deployTool,omitempty" validate:"possible-values=kubectl helm helm3"` ForceUpdates bool `json:"forceUpdates,omitempty"` HelmDeployWaitSeconds int `json:"helmDeployWaitSeconds,omitempty"` + HelmTestWaitSeconds int `json:"helmTestWaitSeconds,omitempty"` HelmValues []string `json:"helmValues,omitempty"` ValuesMapping map[string]interface{} `json:"valuesMapping,omitempty"` GithubToken string `json:"githubToken,omitempty"` @@ -185,6 +186,7 @@ func addKubernetesDeployFlags(cmd *cobra.Command, stepConfig *kubernetesDeployOp cmd.Flags().StringVar(&stepConfig.DeployTool, "deployTool", `kubectl`, "Defines the tool which should be used for deployment.") cmd.Flags().BoolVar(&stepConfig.ForceUpdates, "forceUpdates", true, "Adds `--force` flag to a helm resource update command or to a kubectl replace command") cmd.Flags().IntVar(&stepConfig.HelmDeployWaitSeconds, "helmDeployWaitSeconds", 300, "Number of seconds before helm deploy returns.") + cmd.Flags().IntVar(&stepConfig.HelmTestWaitSeconds, "helmTestWaitSeconds", 0, "Time to wait for any individual Kubernetes operation (like Jobs for hooks) . this param gets translated to `--timeout param` for helm cli during helm test. Default value is 5m0s (5 min and 0 seconds) if not set via parameter. 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().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") @@ -416,6 +418,15 @@ func kubernetesDeployMetadata() config.StepData { Aliases: []config.Alias{}, Default: 300, }, + { + Name: "helmTestWaitSeconds", + ResourceRef: []config.ResourceReference{}, + Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, + Type: "int", + Mandatory: false, + Aliases: []config.Alias{}, + Default: 0, + }, { Name: "helmValues", ResourceRef: []config.ResourceReference{}, diff --git a/resources/metadata/kubernetesDeploy.yaml b/resources/metadata/kubernetesDeploy.yaml index f0e75e95bf..6abcb7152f 100644 --- a/resources/metadata/kubernetesDeploy.yaml +++ b/resources/metadata/kubernetesDeploy.yaml @@ -279,6 +279,14 @@ spec: - STAGES - STEPS default: 300 + - name: helmTestWaitSeconds + type: int + description: Time to wait for any individual Kubernetes operation (like Jobs for hooks) . this param gets translated to `--timeout param` for helm cli during helm test. + Default value is 5m0s (5 min and 0 seconds) if not set via parameter. See https://helm.sh/docs/helm/helm_test/#options for further details + scope: + - PARAMETERS + - STAGES + - STEPS - name: helmValues type: "[]string" description: List of helm values as YAML file reference or URL (as per helm parameter description for `-f` / `--values`) From 7dc6f100c5b37da6e108296da456bfb1dd4a29b9 Mon Sep 17 00:00:00 2001 From: Keshav Date: Thu, 30 Mar 2023 10:50:22 +0200 Subject: [PATCH 2/5] extending test cases --- cmd/kubernetesDeploy_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/kubernetesDeploy_test.go b/cmd/kubernetesDeploy_test.go index 0fd3f2f12f..6660f8ffec 100644 --- a/cmd/kubernetesDeploy_test.go +++ b/cmd/kubernetesDeploy_test.go @@ -481,6 +481,7 @@ func TestRunKubernetesDeploy(t *testing.T) { DockerConfigJSON: ".pipeline/docker/config.json", RunHelmTests: true, ShowTestLogs: true, + HelmTestWaitSeconds: 300, } dockerConfigJSON := `{"kind": "Secret","data":{".dockerconfigjson": "ThisIsOurBase64EncodedSecret=="}}` @@ -538,6 +539,8 @@ func TestRunKubernetesDeploy(t *testing.T) { "deploymentName", "--namespace", "deploymentNamespace", + "--timeout", + "300", "--logs", }, mockUtils.Calls[2].Params, "Wrong test parameters") }) From 840c45cc40e5b460a0eca3d6841943516d2bbc31 Mon Sep 17 00:00:00 2001 From: Vyacheslav Starostin Date: Thu, 20 Apr 2023 16:39:01 +0600 Subject: [PATCH 3/5] Upadate the helmTestWaitSeconds parameter --- cmd/kubernetesDeploy_generated.go | 4 ++-- resources/metadata/kubernetesDeploy.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/kubernetesDeploy_generated.go b/cmd/kubernetesDeploy_generated.go index 5b362f193c..0a3a27acc2 100644 --- a/cmd/kubernetesDeploy_generated.go +++ b/cmd/kubernetesDeploy_generated.go @@ -186,7 +186,7 @@ func addKubernetesDeployFlags(cmd *cobra.Command, stepConfig *kubernetesDeployOp cmd.Flags().StringVar(&stepConfig.DeployTool, "deployTool", `kubectl`, "Defines the tool which should be used for deployment.") cmd.Flags().BoolVar(&stepConfig.ForceUpdates, "forceUpdates", true, "Adds `--force` flag to a helm resource update command or to a kubectl replace command") cmd.Flags().IntVar(&stepConfig.HelmDeployWaitSeconds, "helmDeployWaitSeconds", 300, "Number of seconds before helm deploy returns.") - cmd.Flags().IntVar(&stepConfig.HelmTestWaitSeconds, "helmTestWaitSeconds", 0, "Time to wait for any individual Kubernetes operation (like Jobs for hooks) . this param gets translated to `--timeout param` for helm cli during helm test. Default value is 5m0s (5 min and 0 seconds) if not set via parameter. See https://helm.sh/docs/helm/helm_test/#options for further details") + 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().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") @@ -425,7 +425,7 @@ func kubernetesDeployMetadata() config.StepData { Type: "int", Mandatory: false, Aliases: []config.Alias{}, - Default: 0, + Default: 300, }, { Name: "helmValues", diff --git a/resources/metadata/kubernetesDeploy.yaml b/resources/metadata/kubernetesDeploy.yaml index c6649c8b4f..ab0024cf21 100644 --- a/resources/metadata/kubernetesDeploy.yaml +++ b/resources/metadata/kubernetesDeploy.yaml @@ -281,12 +281,12 @@ spec: default: 300 - name: helmTestWaitSeconds type: int - description: Time to wait for any individual Kubernetes operation (like Jobs for hooks) . this param gets translated to `--timeout param` for helm cli during helm test. - Default value is 5m0s (5 min and 0 seconds) if not set via parameter. See https://helm.sh/docs/helm/helm_test/#options for further details + description: 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 scope: - PARAMETERS - STAGES - STEPS + default: 300 - name: helmValues type: "[]string" description: List of helm values as YAML file reference or URL (as per helm parameter description for `-f` / `--values`) From d0ce044a7a6b707a4e56c6a26e77cec189416c36 Mon Sep 17 00:00:00 2001 From: Vyacheslav Starostin Date: Thu, 20 Apr 2023 18:06:27 +0600 Subject: [PATCH 4/5] Add timeout parameter for helm test command --- cmd/kubernetesDeploy.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/kubernetesDeploy.go b/cmd/kubernetesDeploy.go index 03f2252fc5..c1659117a5 100644 --- a/cmd/kubernetesDeploy.go +++ b/cmd/kubernetesDeploy.go @@ -226,12 +226,12 @@ func runHelmDeploy(config kubernetesDeployOptions, utils kubernetes.DeployUtils, "--namespace", config.Namespace, } - if config.HelmTestWaitSeconds > 0 { - testParams = append( - testParams, - "--timeout", - strconv.Itoa(config.HelmTestWaitSeconds), - ) + if config.DeployTool == "helm" { + testParams = append(testParams, "--timeout", strconv.Itoa(config.HelmTestWaitSeconds)) + } + + if config.DeployTool == "helm3" { + testParams = append(testParams, "--timeout", fmt.Sprintf("%vs", config.HelmTestWaitSeconds)) } if config.ShowTestLogs { From 3e166099da18f7f0ceec17608e0d2baae590c694 Mon Sep 17 00:00:00 2001 From: Vyacheslav Starostin Date: Thu, 20 Apr 2023 18:35:46 +0600 Subject: [PATCH 5/5] Update tests --- cmd/kubernetesDeploy_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/kubernetesDeploy_test.go b/cmd/kubernetesDeploy_test.go index 6660f8ffec..f8796192ed 100644 --- a/cmd/kubernetesDeploy_test.go +++ b/cmd/kubernetesDeploy_test.go @@ -402,6 +402,7 @@ func TestRunKubernetesDeploy(t *testing.T) { Namespace: "deploymentNamespace", DockerConfigJSON: ".pipeline/docker/config.json", RunHelmTests: true, + HelmTestWaitSeconds: 400, } dockerConfigJSON := `{"kind": "Secret","data":{".dockerconfigjson": "ThisIsOurBase64EncodedSecret=="}}` @@ -459,6 +460,8 @@ func TestRunKubernetesDeploy(t *testing.T) { "deploymentName", "--namespace", "deploymentNamespace", + "--timeout", + "400s", }, mockUtils.Calls[2].Params, "Wrong test parameters") }) @@ -481,7 +484,7 @@ func TestRunKubernetesDeploy(t *testing.T) { DockerConfigJSON: ".pipeline/docker/config.json", RunHelmTests: true, ShowTestLogs: true, - HelmTestWaitSeconds: 300, + HelmTestWaitSeconds: 400, } dockerConfigJSON := `{"kind": "Secret","data":{".dockerconfigjson": "ThisIsOurBase64EncodedSecret=="}}` @@ -540,7 +543,7 @@ func TestRunKubernetesDeploy(t *testing.T) { "--namespace", "deploymentNamespace", "--timeout", - "300", + "400s", "--logs", }, mockUtils.Calls[2].Params, "Wrong test parameters") })