Skip to content

Commit

Permalink
Succeed RC deletion when resource not found (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmendesky authored Jun 20, 2022
1 parent d9426a1 commit d0fae7b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
4 changes: 3 additions & 1 deletion controllers/pipelines/runconfiguration_workflow_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
))
Expand Down Expand Up @@ -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,
Expand All @@ -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))
}),
)
})

0 comments on commit d0fae7b

Please sign in to comment.