Skip to content

Commit ec00d85

Browse files
Merge pull request #1871 from p0lyn0mial/static-pod-fallback-to-ssa
API-1835: migrate static pod fallback to ssa
2 parents e59cd12 + b3cd643 commit ec00d85

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

pkg/operator/staticpod/controller/staticpodfallback/static_pod_fallback_condition.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
operatorv1 "github.com/openshift/api/operator/v1"
9+
applyoperatorv1 "github.com/openshift/client-go/operator/applyconfigurations/operator/v1"
910
"github.com/openshift/library-go/pkg/controller/factory"
1011
"github.com/openshift/library-go/pkg/operator/events"
1112
"github.com/openshift/library-go/pkg/operator/staticpod/startupmonitor/annotations"
@@ -17,7 +18,8 @@ import (
1718

1819
// staticPodFallbackConditionController knows how to detect and report that a static pod was rolled back to a previous revision
1920
type staticPodFallbackConditionController struct {
20-
operatorClient operatorv1helpers.OperatorClient
21+
controllerInstanceName string
22+
operatorClient operatorv1helpers.OperatorClient
2123

2224
podLabelSelector labels.Selector
2325
podLister corev1listers.PodNamespaceLister
@@ -26,7 +28,8 @@ type staticPodFallbackConditionController struct {
2628
}
2729

2830
// New creates a controller that detects and report roll back of a static pod
29-
func New(targetNamespace string,
31+
func New(
32+
instanceName, targetNamespace string,
3033
podLabelSelector labels.Selector,
3134
operatorClient operatorv1helpers.OperatorClient,
3235
kubeInformersForNamespaces operatorv1helpers.KubeInformersForNamespaces,
@@ -39,6 +42,7 @@ func New(targetNamespace string,
3942
return nil, fmt.Errorf("StaticPodFallbackConditionController: podLabelSelector cannot be empty")
4043
}
4144
fd := &staticPodFallbackConditionController{
45+
controllerInstanceName: factory.ControllerInstanceName(instanceName, "StaticPodStateFallback"),
4246
operatorClient: operatorClient,
4347
podLabelSelector: podLabelSelector,
4448
podLister: kubeInformersForNamespaces.InformersFor(targetNamespace).Core().V1().Pods().Lister().Pods(targetNamespace),
@@ -49,18 +53,20 @@ func New(targetNamespace string,
4953
ResyncEvery(6*time.Minute).
5054
WithInformers(kubeInformersForNamespaces.InformersFor(targetNamespace).Core().V1().Pods().Informer()).
5155
ToController(
52-
"StaticPodStateFallback", // don't change what is passed here unless you also remove the old FooDegraded condition
56+
fd.controllerInstanceName,
5357
eventRecorder,
5458
), nil
5559
}
5660

5761
// sync sets/unsets a StaticPodFallbackRevisionDegraded condition if a pod that matches the given label selector is annotated with FallbackForRevision
5862
func (fd *staticPodFallbackConditionController) sync(ctx context.Context, _ factory.SyncContext) (err error) {
59-
degradedCondition := operatorv1.OperatorCondition{Type: "StaticPodFallbackRevisionDegraded", Status: operatorv1.ConditionFalse}
63+
degradedCondition := applyoperatorv1.OperatorCondition().WithType("StaticPodFallbackRevisionDegraded")
64+
status := applyoperatorv1.OperatorStatus()
6065
defer func() {
6166
if err == nil {
62-
if _, _, updateError := operatorv1helpers.UpdateStatus(ctx, fd.operatorClient, operatorv1helpers.UpdateConditionFn(degradedCondition)); updateError != nil {
63-
err = updateError
67+
status = status.WithConditions(degradedCondition)
68+
if applyError := fd.operatorClient.ApplyOperatorStatus(ctx, fd.controllerInstanceName, status); applyError != nil {
69+
err = applyError
6470
}
6571
}
6672
}()
@@ -70,6 +76,7 @@ func (fd *staticPodFallbackConditionController) sync(ctx context.Context, _ fact
7076
if enabled, err := fd.startupMonitorEnabledFn(); err != nil {
7177
return err
7278
} else if !enabled {
79+
degradedCondition = degradedCondition.WithStatus(operatorv1.ConditionFalse)
7380
return nil
7481
}
7582

@@ -103,11 +110,13 @@ func (fd *staticPodFallbackConditionController) sync(ctx context.Context, _ fact
103110
}
104111
}
105112

113+
// by default, the condition is in a non-degraded state
114+
degradedCondition = degradedCondition.WithStatus(operatorv1.ConditionFalse)
106115
if len(conditionReason) > 0 || len(conditionMessage) > 0 {
107-
degradedCondition.Message = conditionMessage
108-
degradedCondition.Reason = conditionReason
109-
degradedCondition.Status = operatorv1.ConditionTrue
116+
degradedCondition = degradedCondition.
117+
WithMessage(conditionMessage).
118+
WithReason(conditionReason).
119+
WithStatus(operatorv1.ConditionTrue)
110120
}
111-
112121
return nil
113122
}

pkg/operator/staticpod/controllers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ func (b *staticPodOperatorControllerBuilder) ToControllers() (manager.Controller
328328
), 1)
329329

330330
if staticPodFallbackController, err := staticpodfallback.New(
331+
b.operandName,
331332
b.operandNamespace,
332333
b.operandPodLabelSelector,
333334
b.staticPodOperatorClient,

0 commit comments

Comments
 (0)