Skip to content

Commit

Permalink
Adding some missing transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
edcdavid committed Sep 20, 2024
1 parent 44ab8ed commit a688a82
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 1 addition & 2 deletions docs/dev/config_fsm.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configuration applied state machine
The State diagram of the configuration state machine is generated below in dot format.
A Link to the rendered diagram is at: [link](https://dreampuf.github.io/GraphvizOnline/?presentation#digraph%20%7B%0A%09compound=true%3B%0A%09node%20%5Bshape=Mrecord%5D%3B%0A%09rankdir=%22LR%22%3B%0A%0A%09ClusterNotReady%20%5Blabel=%22ClusterNotReady%7Centry%20%2F%20func1%22%5D%3B%0A%09Completed%20%5Blabel=%22Completed%7Centry%20%2F%20func4%22%5D%3B%0A%09InProgress%20%5Blabel=%22InProgress%7Centry%20%2F%20func2%22%5D%3B%0A%09Missing%20%5Blabel=%22Missing%7Centry%20%2F%20func5%22%5D%3B%0A%09OutOfDate%20%5Blabel=%22OutOfDate%7Centry%20%2F%20func3%22%5D%3B%0A%09Start%20%5Blabel=%22Start%22%5D%3B%0A%09TimedOut%20%5Blabel=%22TimedOut%7Centry%20%2F%20func6%22%5D%3B%0A%09ClusterNotReady%20-%3E%20ClusterNotReady%20%5Blabel=%22ClusterNotReady-&gt%3BClusterNotReady%22%5D%3B%0A%09ClusterNotReady%20-%3E%20InProgress%20%5Blabel=%22ClusterNotReady-&gt%3BInProgress%22%5D%3B%0A%09ClusterNotReady%20-%3E%20Missing%20%5Blabel=%22ClusterNotReady-&gt%3BMissing%22%5D%3B%0A%09ClusterNotReady%20-%3E%20OutOfDate%20%5Blabel=%22ClusterNotReady-&gt%3BOutOfDate%22%5D%3B%0A%09ClusterNotReady%20-%3E%20TimedOut%20%5Blabel=%22ClusterNotReady-&gt%3BTimedOut%22%5D%3B%0A%09Completed%20-%3E%20ClusterNotReady%20%5Blabel=%22Completed-&gt%3BClusterNotReady%22%5D%3B%0A%09Completed%20-%3E%20Completed%20%5Blabel=%22Completed-&gt%3BCompleted%22%5D%3B%0A%09Completed%20-%3E%20InProgress%20%5Blabel=%22Completed-&gt%3BInProgress%22%5D%3B%0A%09Completed%20-%3E%20Missing%20%5Blabel=%22Completed-&gt%3BMissing%22%5D%3B%0A%09Completed%20-%3E%20OutOfDate%20%5Blabel=%22Completed-&gt%3BOutOfDate%22%5D%3B%0A%09InProgress%20-%3E%20ClusterNotReady%20%5Blabel=%22InProgress-&gt%3BClusterNotReady%22%5D%3B%0A%09InProgress%20-%3E%20Completed%20%5Blabel=%22InProgress-&gt%3BCompleted%22%5D%3B%0A%09InProgress%20-%3E%20InProgress%20%5Blabel=%22InProgress-&gt%3BInProgress%22%5D%3B%0A%09InProgress%20-%3E%20Missing%20%5Blabel=%22InProgress-&gt%3BMissing%22%5D%3B%0A%09InProgress%20-%3E%20OutOfDate%20%5Blabel=%22InProgress-&gt%3BOutOfDate%22%5D%3B%0A%09InProgress%20-%3E%20TimedOut%20%5Blabel=%22InProgress-&gt%3BTimedOut%22%5D%3B%0A%09Missing%20-%3E%20ClusterNotReady%20%5Blabel=%22Missing-&gt%3BClusterNotReady%22%5D%3B%0A%09Missing%20-%3E%20Missing%20%5Blabel=%22Missing-&gt%3BMissing%22%5D%3B%0A%09OutOfDate%20-%3E%20ClusterNotReady%20%5Blabel=%22OutOfDate-&gt%3BClusterNotReady%22%5D%3B%0A%09OutOfDate%20-%3E%20InProgress%20%5Blabel=%22OutOfDate-&gt%3BInProgress%22%5D%3B%0A%09OutOfDate%20-%3E%20Missing%20%5Blabel=%22OutOfDate-&gt%3BMissing%22%5D%3B%0A%09OutOfDate%20-%3E%20OutOfDate%20%5Blabel=%22OutOfDate-&gt%3BOutOfDate%22%5D%3B%0A%09Start%20-%3E%20Missing%20%5Blabel=%22Start-&gt%3BMissing%22%5D%3B%0A%09TimedOut%20-%3E%20ClusterNotReady%20%5Blabel=%22TimedOut-&gt%3BClusterNotReady%22%5D%3B%0A%09TimedOut%20-%3E%20Missing%20%5Blabel=%22TimedOut-&gt%3BMissing%22%5D%3B%0A%09TimedOut%20-%3E%20OutOfDate%20%5Blabel=%22TimedOut-&gt%3BOutOfDate%22%5D%3B%0A%09TimedOut%20-%3E%20TimedOut%20%5Blabel=%22TimedOut-&gt%3BTimedOut%22%5D%3B%0A%09init%20%5Blabel=%22%22%2C%20shape=point%5D%3B%0A%09init%20-%3E%20Start%0A%7D%0A)
A Link to the rendered diagram is at: [link](https://dreampuf.github.io/GraphvizOnline/?presentation#digraph%20%7B%0A%09compound=true%3B%0A%09node%20%5Bshape=Mrecord%5D%3B%0A%09rankdir=%22LR%22%3B%0A%0A%09ClusterNotReady%20%5Blabel=%22ClusterNotReady%7Centry%20%2F%20func1%22%5D%3B%0A%09Completed%20%5Blabel=%22Completed%7Centry%20%2F%20func4%22%5D%3B%0A%09InProgress%20%5Blabel=%22InProgress%7Centry%20%2F%20func2%22%5D%3B%0A%09Missing%20%5Blabel=%22Missing%7Centry%20%2F%20func5%22%5D%3B%0A%09OutOfDate%20%5Blabel=%22OutOfDate%7Centry%20%2F%20func3%22%5D%3B%0A%09Start%20%5Blabel=%22Start%22%5D%3B%0A%09TimedOut%20%5Blabel=%22TimedOut%7Centry%20%2F%20func6%22%5D%3B%0A%09ClusterNotReady%20-%3E%20ClusterNotReady%20%5Blabel=%22ClusterNotReady-&gt%3BClusterNotReady%22%5D%3B%0A%09ClusterNotReady%20-%3E%20InProgress%20%5Blabel=%22ClusterNotReady-&gt%3BInProgress%22%5D%3B%0A%09ClusterNotReady%20-%3E%20Missing%20%5Blabel=%22ClusterNotReady-&gt%3BMissing%22%5D%3B%0A%09ClusterNotReady%20-%3E%20OutOfDate%20%5Blabel=%22ClusterNotReady-&gt%3BOutOfDate%22%5D%3B%0A%09ClusterNotReady%20-%3E%20TimedOut%20%5Blabel=%22ClusterNotReady-&gt%3BTimedOut%22%5D%3B%0A%09Completed%20-%3E%20ClusterNotReady%20%5Blabel=%22Completed-&gt%3BClusterNotReady%22%5D%3B%0A%09Completed%20-%3E%20Completed%20%5Blabel=%22Completed-&gt%3BCompleted%22%5D%3B%0A%09Completed%20-%3E%20InProgress%20%5Blabel=%22Completed-&gt%3BInProgress%22%5D%3B%0A%09Completed%20-%3E%20Missing%20%5Blabel=%22Completed-&gt%3BMissing%22%5D%3B%0A%09Completed%20-%3E%20OutOfDate%20%5Blabel=%22Completed-&gt%3BOutOfDate%22%5D%3B%0A%09InProgress%20-%3E%20ClusterNotReady%20%5Blabel=%22InProgress-&gt%3BClusterNotReady%22%5D%3B%0A%09InProgress%20-%3E%20Completed%20%5Blabel=%22InProgress-&gt%3BCompleted%22%5D%3B%0A%09InProgress%20-%3E%20InProgress%20%5Blabel=%22InProgress-&gt%3BInProgress%22%5D%3B%0A%09InProgress%20-%3E%20Missing%20%5Blabel=%22InProgress-&gt%3BMissing%22%5D%3B%0A%09InProgress%20-%3E%20OutOfDate%20%5Blabel=%22InProgress-&gt%3BOutOfDate%22%5D%3B%0A%09InProgress%20-%3E%20TimedOut%20%5Blabel=%22InProgress-&gt%3BTimedOut%22%5D%3B%0A%09Missing%20-%3E%20ClusterNotReady%20%5Blabel=%22Missing-&gt%3BClusterNotReady%22%5D%3B%0A%09Missing%20-%3E%20Missing%20%5Blabel=%22Missing-&gt%3BMissing%22%5D%3B%0A%09OutOfDate%20-%3E%20ClusterNotReady%20%5Blabel=%22OutOfDate-&gt%3BClusterNotReady%22%5D%3B%0A%09OutOfDate%20-%3E%20InProgress%20%5Blabel=%22OutOfDate-&gt%3BInProgress%22%5D%3B%0A%09OutOfDate%20-%3E%20Missing%20%5Blabel=%22OutOfDate-&gt%3BMissing%22%5D%3B%0A%09OutOfDate%20-%3E%20OutOfDate%20%5Blabel=%22OutOfDate-&gt%3BOutOfDate%22%5D%3B%0A%09Start%20-%3E%20Missing%20%5Blabel=%22Start-&gt%3BMissing%22%5D%3B%0A%09TimedOut%20-%3E%20Missing%20%5Blabel=%22TimedOut-&gt%3BMissing%22%5D%3B%0A%09TimedOut%20-%3E%20OutOfDate%20%5Blabel=%22TimedOut-&gt%3BOutOfDate%22%5D%3B%0A%09TimedOut%20-%3E%20TimedOut%20%5Blabel=%22TimedOut-&gt%3BTimedOut%22%5D%3B%0A%09init%20%5Blabel=%22%22%2C%20shape=point%5D%3B%0A%09init%20-%3E%20Start%0A%7D%0A)
```
digraph {
compound=true;
Expand Down Expand Up @@ -37,7 +37,6 @@ digraph {
OutOfDate -> Missing [label="OutOfDate->Missing"];
OutOfDate -> OutOfDate [label="OutOfDate->OutOfDate"];
Start -> Missing [label="Start->Missing"];
TimedOut -> ClusterNotReady [label="TimedOut->ClusterNotReady"];
TimedOut -> Missing [label="TimedOut->Missing"];
TimedOut -> OutOfDate [label="TimedOut->OutOfDate"];
TimedOut -> TimedOut [label="TimedOut->TimedOut"];
Expand Down
9 changes: 7 additions & 2 deletions internal/configfsm/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const (
// Transitions to ClusterNotReady state
MissingToClusterNotReady Trigger = "Missing->ClusterNotReady"
InProgressToClusterNotReady Trigger = "InProgress->ClusterNotReady"
TimedOutToClusterNotReady Trigger = "TimedOut->ClusterNotReady"
CompletedToClusterNotReady Trigger = "Completed->ClusterNotReady"
OutOfDateToClusterNotReady Trigger = "OutOfDate->ClusterNotReady"

Expand Down Expand Up @@ -173,6 +172,9 @@ func InitFSM(state string) (fsm *stateless.StateMachine, err error) {
fsmHelper := args[0].(FsmHelper)
fmt.Println("Entering InProgress")
fsmHelper.ResetNonCompliantAt()
if !fsmHelper.IsPoliciesMatched() {
return fsm.Fire(OutOfDateToMissing, fsmHelper)
}
if !fsmHelper.IsClusterReady() {
return fsm.Fire(OutOfDateToClusterNotReady, fsmHelper)
}
Expand All @@ -197,6 +199,10 @@ func InitFSM(state string) (fsm *stateless.StateMachine, err error) {
if !fsmHelper.IsClusterReady() {
return fsm.Fire(CompletedToClusterNotReady, fsmHelper)
}
if fsmHelper.IsNonCompliantPolicyInEnforce() &&
!fsmHelper.IsAllPoliciesCompliant() {
return fsm.Fire(CompletedToInProgress, fsmHelper)
}
if !fsmHelper.IsNonCompliantPolicyInEnforce() &&
!fsmHelper.IsAllPoliciesCompliant() {
return fsm.Fire(CompletedToOutOfDate, fsmHelper)
Expand Down Expand Up @@ -236,7 +242,6 @@ func InitFSM(state string) (fsm *stateless.StateMachine, err error) {
}
return nil
}).
Permit(TimedOutToClusterNotReady, ClusterNotReady).
Permit(TimedOutToOutOfDate, OutOfDate).
Permit(TimedOutToMissing, Missing).
PermitReentry(TimedOutToTimedOut)
Expand Down
11 changes: 11 additions & 0 deletions internal/configfsm/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ func TestFSMCompleted(t *testing.T) {
state, err = aFSM.State(context.Background())
assert.Equal(t, nil, err, "err should be nil")
assert.Equal(t, "Completed", state, "State should be Completed")

aTestHelper.AllPoliciesCompliant = false

_, err = RunFSM(context.Background(), aFSM, &aTestHelper)
if err != nil {
fmt.Println(err)
}

state, err = aFSM.State(context.Background())
assert.Equal(t, nil, err, "err should be nil")
assert.Equal(t, "InProgress", state, "State should be InProgress")
}

func TestFSMCompletedAllCompliant(t *testing.T) {
Expand Down

0 comments on commit a688a82

Please sign in to comment.