Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pkg/controller/artifactworkflow_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ var _ = Describe("ArtifactWorkflowController", func() {
Expect(k8sClient.Get(ctx, namespacedName(aw.Namespace, aw.Name), aw)).To(Succeed())
return aw.Status.Phase
}).To(Equal(arcv1alpha1.WorkflowSucceeded))

Eventually(func() int64 {
Expect(k8sClient.Get(ctx, namespacedName(aw.Namespace, aw.Name), aw)).To(Succeed())
return aw.Status.Succeeded
}).Should(Equal(int64(1)))
})

It("should track failed Workflow information of created ArtifactWorkflows", func() {
Expand Down Expand Up @@ -220,6 +225,11 @@ var _ = Describe("ArtifactWorkflowController", func() {
Expect(k8sClient.Get(ctx, namespacedName(aw.Namespace, aw.Name), aw)).To(Succeed())
return aw.Status.Message
}).To(ContainSubstring("Step 'step1' failed"))

Eventually(func() int64 {
Expect(k8sClient.Get(ctx, namespacedName(aw.Namespace, aw.Name), aw)).To(Succeed())
return aw.Status.Failed
}).Should(Equal(int64(1)))
})

It("should track error Workflow status of created ArtifactWorkflows", func() {
Expand Down Expand Up @@ -253,6 +263,11 @@ var _ = Describe("ArtifactWorkflowController", func() {
Expect(k8sClient.Get(ctx, namespacedName(aw.Namespace, aw.Name), aw)).To(Succeed())
return aw.Status.Phase
}).To(Equal(arcv1alpha1.WorkflowError))

Eventually(func() int64 {
Expect(k8sClient.Get(ctx, namespacedName(aw.Namespace, aw.Name), aw)).To(Succeed())
return aw.Status.Failed
}).Should(Equal(int64(1)))
})

It("should track pending Workflow status of created ArtifactWorkflows", func() {
Expand Down
17 changes: 10 additions & 7 deletions pkg/controller/order_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (r *OrderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
r.Recorder.Eventf(order, aw, corev1.EventTypeNormal, "Deleted", "Delete", "Deleted finished artifact workflow '%s'", sha)
}

anyPhaseChanged := false
anyStatusChanged := false
for sha, daw := range desiredAWs {
if slices.Contains(createAWs, sha) {
// If it was just created we skip the update
Expand All @@ -357,18 +357,21 @@ func (r *OrderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
return ctrlResult, errLogAndWrap(log, err, "failed to get artifact workflow")
}
orderAWStatus := order.Status.ArtifactWorkflows[sha]
if orderAWStatus.Phase != aw.Status.Phase ||
orderAWStatus.Succeeded != aw.Status.Succeeded ||
orderAWStatus.Failed != aw.Status.Failed ||
!orderAWStatus.LastScheduled.Equal(aw.Status.LastScheduled) {

phaseChanged := orderAWStatus.Phase != aw.Status.Phase
succeededChanged := orderAWStatus.Succeeded != aw.Status.Succeeded
failedChanged := orderAWStatus.Failed != aw.Status.Failed
lastScheduledChanged := !orderAWStatus.LastScheduled.Equal(aw.Status.LastScheduled)

if phaseChanged || succeededChanged || failedChanged || lastScheduledChanged {
orderAWStatus.WorkflowStatus = aw.Status.WorkflowStatus
order.Status.ArtifactWorkflows[sha] = orderAWStatus
anyPhaseChanged = true
anyStatusChanged = true
}
}

// Update status
if len(createAWs) > 0 || len(deleteAWs) > 0 || anyPhaseChanged {
if len(createAWs) > 0 || len(deleteAWs) > 0 || anyStatusChanged {
log.V(1).Info("Updating order status")
// Make sure ArtifactIndex is up to date
for sha, daw := range desiredAWs {
Expand Down
19 changes: 17 additions & 2 deletions pkg/controller/workflow_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,23 @@ func (h *SingleWorkflowHandler) CheckArgoResources(ctx context.Context) error {
return errLogAndWrap(h.log, err, "failed to get workflow")
}

if updated := h.setStatusFromWorkflow(ctx, h.log, h.aw, &wf); !updated {
return nil // nothing updated
updated := h.setStatusFromWorkflow(ctx, h.log, h.aw, &wf)

if wf.Status.Phase == wfv1alpha1.WorkflowSucceeded && h.aw.Status.Succeeded != 1 {
h.aw.Status.Succeeded = 1
updated = true
}

failed := wf.Status.Phase == wfv1alpha1.WorkflowError ||
wf.Status.Phase == wfv1alpha1.WorkflowFailed

if failed && h.aw.Status.Failed != 1 {
h.aw.Status.Failed = 1
updated = true
}

if !updated {
return nil
}

if err := h.Status().Update(ctx, h.aw); err != nil {
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ var _ = Describe("ARC", Ordered, func() {
}).Should(BeTrue())

Expect(orderState(resourceName, stateSucceeded)).To(BeTrue())
cmd := exec.Command("kubectl", "get", "-n", "default", "orders", resourceName, "-o", "go-template={{ range .status.artifactWorkflows }}{{.succeeded}}\t{{ end }}")
output, err := run(cmd)
Expect(err).NotTo(HaveOccurred())
fields := strings.Fields(output)
Expect(fields).NotTo(BeEmpty())
for _, field := range fields {
numSucceeded, err := strconv.Atoi(field)
Expect(err).NotTo(HaveOccurred())
Expect(numSucceeded).To(BeNumerically(">", 0))
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
})
}

Expand Down
Loading