From d0fae7bef114e4d505f59cb876407d1f571e5ffc Mon Sep 17 00:00:00 2001 From: jmendesky Date: Mon, 20 Jun 2022 13:32:18 +0100 Subject: [PATCH] Succeed RC deletion when resource not found (#123) --- .../runconfiguration_workflow_factory.go | 4 ++- ...configuration_workflow_integration_test.go | 27 ++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/controllers/pipelines/runconfiguration_workflow_factory.go b/controllers/pipelines/runconfiguration_workflow_factory.go index ad99a4770..e27f12f34 100644 --- a/controllers/pipelines/runconfiguration_workflow_factory.go +++ b/controllers/pipelines/runconfiguration_workflow_factory.go @@ -219,9 +219,11 @@ func (workflows *RunConfigurationWorkflowFactory) deleter(runConfiguration *pipe return argo.Template{}, err } + succeedOnNotFound := fmt.Sprintf(`KFP_RESULT=$(%s 2>&1) || echo $KFP_RESULT | grep -o 'HTTP response body: {.*}' | cut -d ':' -f 2- | jq -e 'select(.code==5)'`, kfpScript) + return argo.Template{ Name: RunConfigurationWorkflowConstants.DeletionStepName, Metadata: workflows.Config.Argo.MetadataDefaults, - Script: workflows.ScriptTemplate(kfpScript), + Script: workflows.ScriptTemplate(succeedOnNotFound), }, nil } diff --git a/controllers/pipelines/runconfiguration_workflow_integration_test.go b/controllers/pipelines/runconfiguration_workflow_integration_test.go index 93cef201e..f338b21e4 100644 --- a/controllers/pipelines/runconfiguration_workflow_integration_test.go +++ b/controllers/pipelines/runconfiguration_workflow_integration_test.go @@ -97,10 +97,10 @@ var _ = Context("RunConfiguration Workflows", Serial, func() { )) } - var FailDeletion = func(jobKfpId string) error { + var FailDeletionWithCode = func(jobKfpId string, code int64) error { return wiremockClient.StubFor(wiremock.Delete(wiremock.URLPathEqualTo("/apis/v1beta1/jobs/"+jobKfpId)). WillReturn( - `{"status": "failed"}`, + fmt.Sprintf(`HTTP response body: {"status": "failed", "code": %d}`, code), map[string]string{"Content-Type": "application/json"}, 404, )) @@ -174,13 +174,22 @@ var _ = Context("RunConfiguration Workflows", Serial, func() { ), Entry("Deletion fails", func(runconfiguration *pipelinesv1.RunConfiguration) { - Expect(FailDeletion(jobKfpId)).To(Succeed()) + Expect(FailDeletionWithCode(jobKfpId, 7)).To(Succeed()) }, workflowFactory.ConstructDeletionWorkflow, func(g Gomega, workflow *argo.Workflow) { g.Expect(workflow.Status.Phase).To(Equal(argo.WorkflowFailed)) }, ), + Entry("Deletion fails with RC not found", + func(runconfiguration *pipelinesv1.RunConfiguration) { + Expect(FailDeletionWithCode(jobKfpId, 5)).To(Succeed()) + }, + workflowFactory.ConstructDeletionWorkflow, + func(g Gomega, workflow *argo.Workflow) { + g.Expect(workflow.Status.Phase).To(Equal(argo.WorkflowSucceeded)) + }, + ), ) DescribeTable("Update Workflow", AssertWorkflow, @@ -205,11 +214,21 @@ var _ = Context("RunConfiguration Workflows", Serial, func() { To(Equal("")) }), Entry("Deletion fails", func(runconfiguration *pipelinesv1.RunConfiguration) { - Expect(FailDeletion(jobKfpId)).To(Succeed()) + Expect(FailDeletionWithCode(jobKfpId, 55)).To(Succeed()) }, workflowFactory.ConstructUpdateWorkflow, func(g Gomega, workflow *argo.Workflow) { g.Expect(workflow.Status.Phase).To(Equal(argo.WorkflowFailed)) }), + Entry("Deletion fails with RC not found and creation succeeds", func(runconfiguration *pipelinesv1.RunConfiguration) { + Expect(FailDeletionWithCode(jobKfpId, 5)).To(Succeed()) + Expect(SucceedCreation(runconfiguration, newJobKfpId)).To(Succeed()) + }, + workflowFactory.ConstructUpdateWorkflow, + func(g Gomega, workflow *argo.Workflow) { + g.Expect(workflow.Status.Phase).To(Equal(argo.WorkflowSucceeded)) + g.Expect(getWorkflowOutput(workflow, RunConfigurationWorkflowConstants.RunConfigurationIdParameterName)). + To(Equal(newJobKfpId)) + }), ) })