@@ -14,7 +14,7 @@ import (
1414 corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
1515
1616 operatorv1 "github.com/openshift/api/operator/v1"
17-
17+ applyoperatorv1 "github.com/openshift/client-go/operator/applyconfigurations/operator/v1"
1818 "github.com/openshift/library-go/pkg/controller/factory"
1919 "github.com/openshift/library-go/pkg/operator/events"
2020 "github.com/openshift/library-go/pkg/operator/v1helpers"
@@ -27,35 +27,38 @@ var maxToleratedPodPendingDuration = 5 * time.Minute
2727
2828// InstallerStateController analyzes installer pods and sets degraded conditions suggesting different root causes.
2929type InstallerStateController struct {
30- podsGetter corev1client.PodsGetter
31- eventsGetter corev1client.EventsGetter
32- targetNamespace string
33- operatorClient v1helpers.StaticPodOperatorClient
30+ controllerInstanceName string
31+ podsGetter corev1client.PodsGetter
32+ eventsGetter corev1client.EventsGetter
33+ targetNamespace string
34+ operatorClient v1helpers.StaticPodOperatorClient
3435
3536 timeNowFn func () time.Time
3637}
3738
38- func NewInstallerStateController (kubeInformersForTargetNamespace informers.SharedInformerFactory ,
39+ func NewInstallerStateController (instanceName string ,
40+ kubeInformersForTargetNamespace informers.SharedInformerFactory ,
3941 podsGetter corev1client.PodsGetter ,
4042 eventsGetter corev1client.EventsGetter ,
4143 operatorClient v1helpers.StaticPodOperatorClient ,
4244 targetNamespace string ,
4345 recorder events.Recorder ,
4446) factory.Controller {
4547 c := & InstallerStateController {
46- podsGetter : podsGetter ,
47- eventsGetter : eventsGetter ,
48- targetNamespace : targetNamespace ,
49- operatorClient : operatorClient ,
50- timeNowFn : time .Now ,
48+ controllerInstanceName : factory .ControllerInstanceName (instanceName , "InstallerState" ),
49+ podsGetter : podsGetter ,
50+ eventsGetter : eventsGetter ,
51+ targetNamespace : targetNamespace ,
52+ operatorClient : operatorClient ,
53+ timeNowFn : time .Now ,
5154 }
5255
5356 return factory .New ().
5457 WithInformers (kubeInformersForTargetNamespace .Core ().V1 ().Pods ().Informer ()).
5558 WithSync (c .sync ).
5659 ResyncEvery (1 * time .Minute ).
5760 ToController (
58- "InstallerStateController" , // don't change what is passed here unless you also remove the old FooDegraded condition
61+ c . controllerInstanceName ,
5962 recorder ,
6063 )
6164}
@@ -128,26 +131,25 @@ func (c *InstallerStateController) sync(ctx context.Context, syncCtx factory.Syn
128131 }
129132 foundConditions = append (foundConditions , networkConditions ... )
130133
131- updateConditionFuncs := []v1helpers.UpdateStaticPodStatusFunc {}
132-
134+ updateConditions := []* applyoperatorv1.OperatorConditionApplyConfiguration {}
133135 // check the supported degraded foundConditions and check if any pending pod matching them.
134136 for _ , degradedConditionName := range degradedConditionNames {
135137 // clean up existing foundConditions
136- updatedCondition := operatorv1 .OperatorCondition {
137- Type : degradedConditionName ,
138- Status : operatorv1 .ConditionFalse ,
139- }
138+ updatedCondition := applyoperatorv1 .OperatorCondition ().
139+ WithType ( degradedConditionName ).
140+ WithStatus ( operatorv1 .ConditionFalse )
141+
140142 if condition := v1helpers .FindOperatorCondition (foundConditions , degradedConditionName ); condition != nil {
141- updatedCondition = * condition
143+ updatedCondition = updatedCondition .
144+ WithStatus (condition .Status ).
145+ WithReason (condition .Reason ).
146+ WithMessage (condition .Message )
142147 }
143- updateConditionFuncs = append (updateConditionFuncs , v1helpers .UpdateStaticPodConditionFn (updatedCondition ))
144- }
145-
146- if _ , _ , err := v1helpers .UpdateStaticPodStatus (ctx , c .operatorClient , updateConditionFuncs ... ); err != nil {
147- return err
148+ updateConditions = append (updateConditions , updatedCondition )
148149 }
149150
150- return nil
151+ status := applyoperatorv1 .StaticPodOperatorStatus ().WithConditions (updateConditions ... )
152+ return c .operatorClient .ApplyStaticPodOperatorStatus (ctx , c .controllerInstanceName , status )
151153}
152154
153155func (c * InstallerStateController ) handlePendingInstallerPodsNetworkEvents (ctx context.Context , recorder events.Recorder , pods []* v1.Pod ) ([]operatorv1.OperatorCondition , error ) {
0 commit comments