Skip to content

Commit 636f95d

Browse files
Merge pull request #1816 from p0lyn0mial/apply-static-pod-state
API-1835: Update the static pod state controller to use Apply
2 parents 45b605e + 833d549 commit 636f95d

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

pkg/operator/staticpod/controller/staticpodstate/staticpodstate_controller.go

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
operatorv1 "github.com/openshift/api/operator/v1"
10+
applyoperatorv1 "github.com/openshift/client-go/operator/applyconfigurations/operator/v1"
1011
v1 "k8s.io/api/core/v1"
1112
apierrors "k8s.io/apimachinery/pkg/api/errors"
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -25,9 +26,10 @@ import (
2526
// StaticPodStateController is a controller that watches static pods and will produce a failing status if the
2627
// // static pods start crashing for some reason.
2728
type StaticPodStateController struct {
28-
targetNamespace string
29-
staticPodName string
30-
operandName string
29+
controllerInstanceName string
30+
targetNamespace string
31+
staticPodName string
32+
operandName string
3133

3234
operatorClient v1helpers.StaticPodOperatorClient
3335
podsGetter corev1client.PodsGetter
@@ -37,20 +39,21 @@ type StaticPodStateController struct {
3739
// NewStaticPodStateController creates a controller that watches static pods and will produce a failing status if the
3840
// static pods start crashing for some reason.
3941
func NewStaticPodStateController(
40-
targetNamespace, staticPodName, operandName string,
42+
instanceName, targetNamespace, staticPodName, operandName string,
4143
kubeInformersForTargetNamespace informers.SharedInformerFactory,
4244
operatorClient v1helpers.StaticPodOperatorClient,
4345
podsGetter corev1client.PodsGetter,
4446
versionRecorder status.VersionGetter,
4547
eventRecorder events.Recorder,
4648
) factory.Controller {
4749
c := &StaticPodStateController{
48-
targetNamespace: targetNamespace,
49-
staticPodName: staticPodName,
50-
operandName: operandName,
51-
operatorClient: operatorClient,
52-
podsGetter: podsGetter,
53-
versionRecorder: versionRecorder,
50+
controllerInstanceName: factory.ControllerInstanceName(instanceName, "StaticPodState"),
51+
targetNamespace: targetNamespace,
52+
staticPodName: staticPodName,
53+
operandName: operandName,
54+
operatorClient: operatorClient,
55+
podsGetter: podsGetter,
56+
versionRecorder: versionRecorder,
5457
}
5558
return factory.New().
5659
WithInformers(
@@ -60,7 +63,7 @@ func NewStaticPodStateController(
6063
WithSync(c.sync).
6164
ResyncEvery(time.Minute).
6265
ToController(
63-
"StaticPodStateController", // don't change what is passed here unless you also remove the old FooDegraded condition
66+
c.controllerInstanceName,
6467
eventRecorder,
6568
)
6669
}
@@ -162,25 +165,25 @@ func (c *StaticPodStateController) sync(ctx context.Context, syncCtx factory.Syn
162165
}
163166

164167
// update failing condition
165-
cond := operatorv1.OperatorCondition{
166-
Type: condition.StaticPodsDegradedConditionType,
167-
Status: operatorv1.ConditionFalse,
168-
}
168+
cond := applyoperatorv1.OperatorCondition().
169+
WithType(condition.StaticPodsDegradedConditionType).
170+
WithStatus(operatorv1.ConditionFalse)
169171
// Failing errors
170172
if failingErrorCount > 0 {
171-
cond.Status = operatorv1.ConditionTrue
172-
cond.Reason = "Error"
173-
cond.Message = v1helpers.NewMultiLineAggregate(errs).Error()
173+
cond = cond.WithStatus(operatorv1.ConditionTrue).
174+
WithReason("Error").
175+
WithMessage(v1helpers.NewMultiLineAggregate(errs).Error())
174176
}
175177
// Not failing errors
176178
if failingErrorCount == 0 && len(errs) > 0 {
177-
cond.Reason = "Error"
178-
cond.Message = v1helpers.NewMultiLineAggregate(errs).Error()
179+
cond = cond.WithReason("Error").
180+
WithMessage(v1helpers.NewMultiLineAggregate(errs).Error())
179181
}
180-
if _, _, updateError := v1helpers.UpdateStaticPodStatus(ctx, c.operatorClient, v1helpers.UpdateStaticPodConditionFn(cond), v1helpers.UpdateStaticPodConditionFn(cond)); updateError != nil {
182+
183+
status := applyoperatorv1.StaticPodOperatorStatus().WithConditions(cond)
184+
if updateError := c.operatorClient.ApplyStaticPodOperatorStatus(ctx, c.controllerInstanceName, status); updateError != nil {
181185
return updateError
182186
}
183-
184187
return err
185188
}
186189

pkg/operator/staticpod/controllers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ func (b *staticPodOperatorControllerBuilder) ToControllers() (manager.Controller
285285
if len(b.operandName) > 0 {
286286
// TODO add handling for operator configmap changes to get version-mapping changes
287287
manager.WithController(staticpodstate.NewStaticPodStateController(
288+
b.operandName,
288289
b.operandNamespace,
289290
b.staticPodName,
290291
b.operandName,

0 commit comments

Comments
 (0)