Skip to content

Commit

Permalink
Running phase should be "" after actionset is completed
Browse files Browse the repository at this point in the history
  • Loading branch information
viveksinghggits committed Dec 29, 2022
1 parent 3c21124 commit fe88d25
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
20 changes: 10 additions & 10 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (c *Controller) onUpdateActionSet(oldAS, newAS *crv1alpha1.ActionSet) error
return nil
}
return reconcile.ActionSet(context.TODO(), c.crClient.CrV1alpha1(), newAS.GetNamespace(), newAS.GetName(), func(ras *crv1alpha1.ActionSet) error {
ras.Status.Progress.RunningPhase = string(crv1alpha1.StateComplete)
ras.Status.Progress.RunningPhase = ""
ras.Status.State = crv1alpha1.StateComplete
return nil
})
Expand Down Expand Up @@ -317,7 +317,7 @@ func (c *Controller) initActionSetStatus(ctx context.Context, as *crv1alpha1.Act
}
if err != nil {
as.Status.State = crv1alpha1.StateFailed
as.Status.Progress.RunningPhase = string(crv1alpha1.StateFailed)
as.Status.Progress.RunningPhase = ""
as.Status.Error = crv1alpha1.Error{
Message: err.Error(),
}
Expand Down Expand Up @@ -406,7 +406,7 @@ func (c *Controller) handleActionSet(ctx context.Context, t *tomb.Tomb, as *crv1
}
if err != nil {
as.Status.State = crv1alpha1.StateFailed
as.Status.Progress.RunningPhase = string(crv1alpha1.StateFailed)
as.Status.Progress.RunningPhase = ""
as.Status.Error = crv1alpha1.Error{
Message: err.Error(),
}
Expand Down Expand Up @@ -479,7 +479,7 @@ func (c *Controller) runAction(ctx context.Context, t *tomb.Tomb, as *crv1alpha1
if err != nil {
coreErr = err
rf = func(ras *crv1alpha1.ActionSet) error {
ras.Status.Progress.RunningPhase = string(crv1alpha1.StateFailed)
ras.Status.Progress.RunningPhase = ""
ras.Status.State = crv1alpha1.StateFailed
ras.Status.Error = crv1alpha1.Error{
Message: err.Error(),
Expand Down Expand Up @@ -557,7 +557,7 @@ func (c *Controller) executeDeferPhase(ctx context.Context,
var rf func(*crv1alpha1.ActionSet) error
if err != nil {
rf = func(as *crv1alpha1.ActionSet) error {
as.Status.Progress.RunningPhase = string(crv1alpha1.StateFailed)
as.Status.Progress.RunningPhase = ""
as.Status.State = crv1alpha1.StateFailed
as.Status.Error = crv1alpha1.Error{
Message: err.Error(),
Expand Down Expand Up @@ -607,11 +607,11 @@ func (c *Controller) renderActionsetArtifacts(ctx context.Context,
if len(artTpls) == 0 {
// No artifacts, set ActionSetStatus to complete
if rErr := reconcile.ActionSet(ctx, c.crClient.CrV1alpha1(), actionsetNS, actionsetName, func(ras *crv1alpha1.ActionSet) error {
// actionset execution is done, set the RunningPhase to empty string
ras.Status.Progress.RunningPhase = ""
if coreErr == nil && deferErr == nil {
ras.Status.Progress.RunningPhase = string(crv1alpha1.StateComplete)
ras.Status.State = crv1alpha1.StateComplete
} else {
ras.Status.Progress.RunningPhase = string(crv1alpha1.StateFailed)
ras.Status.State = crv1alpha1.StateFailed
}

Expand All @@ -629,7 +629,7 @@ func (c *Controller) renderActionsetArtifacts(ctx context.Context,
if err != nil {
af = func(ras *crv1alpha1.ActionSet) error {
ras.Status.State = crv1alpha1.StateFailed
ras.Status.Progress.RunningPhase = string(crv1alpha1.StateFailed)
ras.Status.Progress.RunningPhase = ""
ras.Status.Error = crv1alpha1.Error{
Message: err.Error(),
}
Expand All @@ -638,13 +638,13 @@ func (c *Controller) renderActionsetArtifacts(ctx context.Context,
} else {
af = func(ras *crv1alpha1.ActionSet) error {
ras.Status.Actions[aIDX].Artifacts = arts
// actionset execution is done and artifacts are rendered, set the RunningPhase to empty string
ras.Status.Progress.RunningPhase = ""
// make sure that the core phases that were run also didnt return any error
// and then set actionset's state to be complete
if coreErr == nil && deferErr == nil {
ras.Status.Progress.RunningPhase = string(crv1alpha1.StateComplete)
ras.Status.State = crv1alpha1.StateComplete
} else {
ras.Status.Progress.RunningPhase = string(crv1alpha1.StateFailed)
ras.Status.State = crv1alpha1.StateFailed
}
return nil
Expand Down
10 changes: 6 additions & 4 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,14 +667,14 @@ func (s *ControllerSuite) TestDeferPhase(c *C) {

// we need set and not string becauce we are continuously getting runningPhase and storing
// it, so value would be duplicate, we don't want duplicates
runningPhase := sets.NewString()
runningPhases := sets.NewString()
go func() {
// get actionset and store the onPhase fields to a set
for {
a, err := s.crCli.ActionSets(s.namespace).Get(ctx, as.Name, metav1.GetOptions{})
c.Assert(err, IsNil)
if a.Status.Progress.RunningPhase != "" {
runningPhase.Insert(a.Status.Progress.RunningPhase)
runningPhases.Insert(a.Status.Progress.RunningPhase)
}
}
}()
Expand All @@ -690,8 +690,10 @@ func (s *ControllerSuite) TestDeferPhase(c *C) {
// that would confirm that the actionset's status.progress.onPhase was set
// to those phases
op := sets.NewString()
op.Insert("backupPhaseOne").Insert("backupPhaseTwo").Insert("deferPhase").Insert(string(crv1alpha1.StateComplete)) // these phases are from blueprint that we create above
c.Assert(runningPhase.Equal(op), Equals, true)
// these phases are from blueprint that we create above
// and after actionset completion the runningPhase becomes ""
op.Insert("backupPhaseOne").Insert("backupPhaseTwo").Insert("deferPhase")
c.Assert(runningPhases.Equal(op), Equals, true)

as, err = s.crCli.ActionSets(s.namespace).Get(ctx, as.Name, metav1.GetOptions{})
c.Assert(err, IsNil)
Expand Down
2 changes: 1 addition & 1 deletion pkg/customresource/actionset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ spec:
jsonPath: .status.progress.percentCompleted
- name: RunningPhase
type: string
description: The phase that is being run, if the actionset is completed it would be set to "complete"
description: The phase that is being run, if the actionset is completed it would be set to ""
jsonPath: .status.progress.runningPhase
- name: Last Transition Time
type: string
Expand Down

0 comments on commit fe88d25

Please sign in to comment.