Skip to content

Commit

Permalink
Switch case usage for conditionMessage of a failure
Browse files Browse the repository at this point in the history
It helps us forgetting this part when adding another reason to the case statement above.
  • Loading branch information
razo7 committed Aug 16, 2023
1 parent 01241d6 commit c0e69f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions controllers/fenceagentsremediation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,17 @@ func updateConditions(reason v1alpha1.ConditionsChangeReason, currentConditions
processingConditionStatus = metav1.ConditionFalse
fenceAgentActionSucceededConditionStatus = metav1.ConditionFalse
succeededConditionStatus = metav1.ConditionFalse
if reason == v1alpha1.RemediationFinishedNodeNotFound {
// Different reasons share the same effect to the conditions, but they have different message
switch reason {
case v1alpha1.RemediationFinishedNodeNotFound:
conditionMessage = v1alpha1.RemediationFinishedNodeNotFoundConditionMessage
} else {
case v1alpha1.RemediationInterruptedByNHC:
conditionMessage = v1alpha1.RemediationInterruptedByNHCConditionMessage
default:
err := fmt.Errorf("unknown ConditionsChangeReason:%s", reason)
log.Error(err, "couldn't update FAR Status Conditions")
return err
}

case v1alpha1.RemediationStarted:
processingConditionStatus = metav1.ConditionTrue
fenceAgentActionSucceededConditionStatus = metav1.ConditionUnknown
Expand Down
4 changes: 2 additions & 2 deletions controllers/fenceagentsremediation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ var _ = Describe("FAR Controller", func() {
testVADeletion(vaName2, resourceDeletionWasTriggered)
testPodDeletion(testPodName, resourceDeletionWasTriggered)

By("Having Succeed condition set to true")
By("Having Succeeded, FenceAgentActionSucceeded conditions set to true, and Processing set to false")
verifyStatusCondition(workerNode, commonConditions.ProcessingType, conditionStatusPointer(metav1.ConditionFalse))
verifyStatusCondition(workerNode, v1alpha1.FenceAgentActionSucceededType, conditionStatusPointer(metav1.ConditionTrue))
verifyStatusCondition(workerNode, commonConditions.SucceededType, conditionStatusPointer(metav1.ConditionTrue))
Expand Down Expand Up @@ -199,7 +199,7 @@ var _ = Describe("FAR Controller", func() {
testVADeletion(vaName2, resourceDeletionWasTriggered)
testPodDeletion(testPodName, resourceDeletionWasTriggered)

By("Not having any condition set")
By("Having all three conditions set to false")
verifyStatusCondition(dummyNode, commonConditions.ProcessingType, conditionStatusPointer(metav1.ConditionFalse))
verifyStatusCondition(dummyNode, v1alpha1.FenceAgentActionSucceededType, conditionStatusPointer(metav1.ConditionFalse))
verifyStatusCondition(dummyNode, commonConditions.SucceededType, conditionStatusPointer(metav1.ConditionFalse))
Expand Down

0 comments on commit c0e69f2

Please sign in to comment.