Skip to content

Commit

Permalink
Merge pull request #1848 from p0lyn0mial/trigger-err-on-status-apply
Browse files Browse the repository at this point in the history
NO-JIRA: ability to trigger an err on status apply
  • Loading branch information
openshift-merge-bot[bot] authored Oct 22, 2024
2 parents 5a0879d + 2913b2c commit 4c1f8b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
31 changes: 19 additions & 12 deletions pkg/operator/staticpod/controller/node/node_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ func validateJSONPatch(expected, actual *jsonpatch.PatchSet) error {

func TestNodeControllerDegradedConditionType(t *testing.T) {
scenarios := []struct {
name string
masterNodes []runtime.Object
existingNodeStatuses []operatorv1.NodeStatus
existingConditions []operatorv1.OperatorCondition
triggerStatusApplyError error
name string
masterNodes []runtime.Object
existingNodeStatuses []operatorv1.NodeStatus
existingConditions []operatorv1.OperatorCondition
triggerStatusApplyErrorFn func(rv string, spec *operatorv1.StaticPodOperatorStatus) error

verifyNodeStatus func([]operatorv1.OperatorCondition) error
verifyJSONPatch func(*jsonpatch.PatchSet) error
Expand Down Expand Up @@ -197,7 +197,16 @@ func TestNodeControllerDegradedConditionType(t *testing.T) {
NodeName: "test-node-4",
},
},
triggerStatusApplyError: fmt.Errorf("nasty err"),
triggerStatusApplyErrorFn: func() func(rv string, spec *operatorv1.StaticPodOperatorStatus) error {
var counter int
return func(rv string, spec *operatorv1.StaticPodOperatorStatus) error {
if counter == 0 {
counter++
return fmt.Errorf("nasty err")
}
return nil
}
}(),
verifyNodeStatus: func(conditions []operatorv1.OperatorCondition) error {
var expectedCondition operatorv1.OperatorCondition
expectedCondition.Type = condition.NodeControllerDegradedConditionType
Expand Down Expand Up @@ -442,11 +451,9 @@ func TestNodeControllerDegradedConditionType(t *testing.T) {
kubeClient := fake.NewSimpleClientset(scenario.masterNodes...)
fakeLister := v1helpers.NewFakeNodeLister(kubeClient)

var triggerStatusUpdateError func(rv string, spec *operatorv1.StaticPodOperatorStatus) error
if scenario.triggerStatusApplyError != nil {
triggerStatusUpdateError = func(rv string, spec *operatorv1.StaticPodOperatorStatus) error {
return scenario.triggerStatusApplyError
}
var triggerStatusUpdateErrorFn func(rv string, spec *operatorv1.StaticPodOperatorStatus) error
if scenario.triggerStatusApplyErrorFn != nil {
triggerStatusUpdateErrorFn = scenario.triggerStatusApplyErrorFn
}
fakeStaticPodOperatorClient := v1helpers.NewFakeStaticPodOperatorClient(
&operatorv1.StaticPodOperatorSpec{
Expand All @@ -461,7 +468,7 @@ func TestNodeControllerDegradedConditionType(t *testing.T) {
},
NodeStatuses: scenario.existingNodeStatuses,
},
triggerStatusUpdateError,
triggerStatusUpdateErrorFn,
nil,
)

Expand Down
6 changes: 6 additions & 0 deletions pkg/operator/v1helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ func (c *fakeStaticPodOperatorClient) ApplyStaticPodOperatorSpec(ctx context.Con
}

func (c *fakeStaticPodOperatorClient) ApplyStaticPodOperatorStatus(ctx context.Context, fieldManager string, applyConfiguration *applyoperatorv1.StaticPodOperatorStatusApplyConfiguration) (err error) {
if c.triggerStatusUpdateError != nil {
operatorStatus := convertStaticPodOperatorStatusApplyConfiguration(applyConfiguration)
if err := c.triggerStatusUpdateError("", operatorStatus); err != nil {
return err
}
}
c.fakeStaticPodOperatorStatus = convertStaticPodOperatorStatusApplyConfiguration(applyConfiguration)
return nil
}
Expand Down

0 comments on commit 4c1f8b4

Please sign in to comment.