Skip to content

Commit 4c1f8b4

Browse files
Merge pull request #1848 from p0lyn0mial/trigger-err-on-status-apply
NO-JIRA: ability to trigger an err on status apply
2 parents 5a0879d + 2913b2c commit 4c1f8b4

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

pkg/operator/staticpod/controller/node/node_controller_test.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ func validateJSONPatch(expected, actual *jsonpatch.PatchSet) error {
8282

8383
func TestNodeControllerDegradedConditionType(t *testing.T) {
8484
scenarios := []struct {
85-
name string
86-
masterNodes []runtime.Object
87-
existingNodeStatuses []operatorv1.NodeStatus
88-
existingConditions []operatorv1.OperatorCondition
89-
triggerStatusApplyError error
85+
name string
86+
masterNodes []runtime.Object
87+
existingNodeStatuses []operatorv1.NodeStatus
88+
existingConditions []operatorv1.OperatorCondition
89+
triggerStatusApplyErrorFn func(rv string, spec *operatorv1.StaticPodOperatorStatus) error
9090

9191
verifyNodeStatus func([]operatorv1.OperatorCondition) error
9292
verifyJSONPatch func(*jsonpatch.PatchSet) error
@@ -197,7 +197,16 @@ func TestNodeControllerDegradedConditionType(t *testing.T) {
197197
NodeName: "test-node-4",
198198
},
199199
},
200-
triggerStatusApplyError: fmt.Errorf("nasty err"),
200+
triggerStatusApplyErrorFn: func() func(rv string, spec *operatorv1.StaticPodOperatorStatus) error {
201+
var counter int
202+
return func(rv string, spec *operatorv1.StaticPodOperatorStatus) error {
203+
if counter == 0 {
204+
counter++
205+
return fmt.Errorf("nasty err")
206+
}
207+
return nil
208+
}
209+
}(),
201210
verifyNodeStatus: func(conditions []operatorv1.OperatorCondition) error {
202211
var expectedCondition operatorv1.OperatorCondition
203212
expectedCondition.Type = condition.NodeControllerDegradedConditionType
@@ -442,11 +451,9 @@ func TestNodeControllerDegradedConditionType(t *testing.T) {
442451
kubeClient := fake.NewSimpleClientset(scenario.masterNodes...)
443452
fakeLister := v1helpers.NewFakeNodeLister(kubeClient)
444453

445-
var triggerStatusUpdateError func(rv string, spec *operatorv1.StaticPodOperatorStatus) error
446-
if scenario.triggerStatusApplyError != nil {
447-
triggerStatusUpdateError = func(rv string, spec *operatorv1.StaticPodOperatorStatus) error {
448-
return scenario.triggerStatusApplyError
449-
}
454+
var triggerStatusUpdateErrorFn func(rv string, spec *operatorv1.StaticPodOperatorStatus) error
455+
if scenario.triggerStatusApplyErrorFn != nil {
456+
triggerStatusUpdateErrorFn = scenario.triggerStatusApplyErrorFn
450457
}
451458
fakeStaticPodOperatorClient := v1helpers.NewFakeStaticPodOperatorClient(
452459
&operatorv1.StaticPodOperatorSpec{
@@ -461,7 +468,7 @@ func TestNodeControllerDegradedConditionType(t *testing.T) {
461468
},
462469
NodeStatuses: scenario.existingNodeStatuses,
463470
},
464-
triggerStatusUpdateError,
471+
triggerStatusUpdateErrorFn,
465472
nil,
466473
)
467474

pkg/operator/v1helpers/test_helpers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ func (c *fakeStaticPodOperatorClient) ApplyStaticPodOperatorSpec(ctx context.Con
183183
}
184184

185185
func (c *fakeStaticPodOperatorClient) ApplyStaticPodOperatorStatus(ctx context.Context, fieldManager string, applyConfiguration *applyoperatorv1.StaticPodOperatorStatusApplyConfiguration) (err error) {
186+
if c.triggerStatusUpdateError != nil {
187+
operatorStatus := convertStaticPodOperatorStatusApplyConfiguration(applyConfiguration)
188+
if err := c.triggerStatusUpdateError("", operatorStatus); err != nil {
189+
return err
190+
}
191+
}
186192
c.fakeStaticPodOperatorStatus = convertStaticPodOperatorStatusApplyConfiguration(applyConfiguration)
187193
return nil
188194
}

0 commit comments

Comments
 (0)