Skip to content

Commit ae9bd9f

Browse files
committed
stop, or resume if suspended
1 parent c5b056b commit ae9bd9f

File tree

1 file changed

+39
-24
lines changed

1 file changed

+39
-24
lines changed

service/cluster/cluster.go

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -523,28 +523,27 @@ func (s *clusterImpl) Delete(ctx context.Context, req *v1.ResourceByID) (*empty.
523523
return nil, err
524524
}
525525

526-
log.Infow("resuming argo workflow", "workflow-name", workflow.GetName())
527-
528-
// Resume the workflow so that it may move to the destroy phase without
529-
// waiting for cleanupExpiredClusters() to kick in.
530-
_, err = s.argoWorkflowsClient.ResumeWorkflow(s.argoClientCtx, &workflowpkg.WorkflowResumeRequest{
531-
Name: workflow.GetName(),
532-
Namespace: s.workflowNamespace,
533-
})
534-
if err != nil {
535-
log.Warnw("failed to resume workflow, this is OK if the workflow is not waiting",
536-
"workflow-name", req.GetId(),
537-
"error", err,
538-
)
539-
}
540-
if value, exists := workflow.GetLabels()["needsExit"]; exists {
541-
log.Infow("argo workflow requires exit to stop looping", "needsExit", value)
526+
if workflow.Spec.Suspend != nil && *workflow.Spec.Suspend {
527+
// Resume the workflow so that it may move to the destroy phase without
528+
// waiting for cleanupExpiredClusters() to kick in.
529+
log.Infow("resuming argo workflow", "workflow-name", workflow.GetName())
530+
_, err = s.argoWorkflowsClient.ResumeWorkflow(s.argoClientCtx, &workflowpkg.WorkflowResumeRequest{
531+
Name: workflow.GetName(),
532+
Namespace: s.workflowNamespace,
533+
})
534+
if err != nil {
535+
log.Warnw("failed to resume workflow, this is OK if the workflow is not waiting",
536+
"workflow-name", req.GetId(),
537+
"error", err,
538+
)
539+
}
540+
} else {
542541
log.Infow("stopping argo workflow", "workflow-name", workflow.GetName())
543542
_, err = s.argoWorkflowsClient.StopWorkflow(s.argoClientCtx, &workflowpkg.WorkflowStopRequest{
544543
Name: workflow.GetName(),
545544
Namespace: s.workflowNamespace,
546545
NodeFieldSelector: "",
547-
Message: "Seeking end",
546+
Message: "Destroying cluster. End workflow loop.",
548547
})
549548
if err != nil {
550549
log.Warnw("failed to stop workflow, this is OK if the workflow is not running",
@@ -663,13 +662,29 @@ func (s *clusterImpl) cleanupExpiredClusters() {
663662
continue
664663
}
665664

666-
log.Infow("resuming an argo workflow that has expired", "workflow-name", workflow.GetName())
667-
_, err = s.argoWorkflowsClient.ResumeWorkflow(s.argoClientCtx, &workflowpkg.WorkflowResumeRequest{
668-
Name: workflow.GetName(),
669-
Namespace: s.workflowNamespace,
670-
})
671-
if err != nil {
672-
log.Warnw("failed to resume argo workflow", "workflow-name", workflow.GetName(), "error", err)
665+
if workflow.Spec.Suspend != nil && *workflow.Spec.Suspend {
666+
log.Infow("resuming an argo workflow that has expired", "workflow-name", workflow.GetName())
667+
_, err = s.argoWorkflowsClient.ResumeWorkflow(s.argoClientCtx, &workflowpkg.WorkflowResumeRequest{
668+
Name: workflow.GetName(),
669+
Namespace: s.workflowNamespace,
670+
})
671+
if err != nil {
672+
log.Warnw("failed to resume argo workflow", "workflow-name", workflow.GetName(), "error", err)
673+
}
674+
} else {
675+
log.Infow("stopping argo workflow that expired", "workflow-name", workflow.GetName())
676+
_, err = s.argoWorkflowsClient.StopWorkflow(s.argoClientCtx, &workflowpkg.WorkflowStopRequest{
677+
Name: workflow.GetName(),
678+
Namespace: s.workflowNamespace,
679+
NodeFieldSelector: "",
680+
Message: "Destroying cluster. End workflow loop.",
681+
})
682+
if err != nil {
683+
log.Warnw("failed to stop workflow, this is OK if the workflow is not running",
684+
"workflow-name", req.GetId(),
685+
"error", err,
686+
)
687+
}
673688
}
674689
}
675690

0 commit comments

Comments
 (0)