@@ -15,12 +15,15 @@ import (
1515 configv1 "github.com/openshift/api/config/v1"
1616 features "github.com/openshift/api/features"
1717 mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
18+ opv1 "github.com/openshift/api/operator/v1"
1819
1920 cligoinformersv1 "github.com/openshift/client-go/config/informers/externalversions/config/v1"
2021 cligolistersv1 "github.com/openshift/client-go/config/listers/config/v1"
2122 mcfgclientset "github.com/openshift/client-go/machineconfiguration/clientset/versioned"
2223 "github.com/openshift/client-go/machineconfiguration/clientset/versioned/scheme"
2324 mcfginformersv1 "github.com/openshift/client-go/machineconfiguration/informers/externalversions/machineconfiguration/v1"
25+ mcopinformersv1 "github.com/openshift/client-go/operator/informers/externalversions/operator/v1"
26+ mcoplistersv1 "github.com/openshift/client-go/operator/listers/operator/v1"
2427
2528 mcfglistersv1 "github.com/openshift/client-go/machineconfiguration/listers/machineconfiguration/v1"
2629 "github.com/openshift/library-go/pkg/operator/v1helpers"
@@ -108,6 +111,9 @@ type Controller struct {
108111 schedulerList cligolistersv1.SchedulerLister
109112 schedulerListerSynced cache.InformerSynced
110113
114+ mcopLister mcoplistersv1.MachineConfigurationLister
115+ mcopListerSynced cache.InformerSynced
116+
111117 queue workqueue.TypedRateLimitingInterface [string ]
112118
113119 fgHandler ctrlcommon.FeatureGatesHandler
@@ -127,6 +133,7 @@ func New(
127133 mosbInformer mcfginformersv1.MachineOSBuildInformer ,
128134 mcnInformer mcfginformersv1.MachineConfigNodeInformer ,
129135 schedulerInformer cligoinformersv1.SchedulerInformer ,
136+ mcopInformer mcopinformersv1.MachineConfigurationInformer ,
130137 kubeClient clientset.Interface ,
131138 mcfgClient mcfgclientset.Interface ,
132139 fgHandler ctrlcommon.FeatureGatesHandler ,
@@ -141,6 +148,7 @@ func New(
141148 podInformer ,
142149 mcnInformer ,
143150 schedulerInformer ,
151+ mcopInformer ,
144152 kubeClient ,
145153 mcfgClient ,
146154 defaultUpdateDelay ,
@@ -158,6 +166,7 @@ func NewWithCustomUpdateDelay(
158166 mosbInformer mcfginformersv1.MachineOSBuildInformer ,
159167 mcnInformer mcfginformersv1.MachineConfigNodeInformer ,
160168 schedulerInformer cligoinformersv1.SchedulerInformer ,
169+ mcopInformer mcopinformersv1.MachineConfigurationInformer ,
161170 kubeClient clientset.Interface ,
162171 mcfgClient mcfgclientset.Interface ,
163172 updateDelay time.Duration ,
@@ -173,6 +182,7 @@ func NewWithCustomUpdateDelay(
173182 podInformer ,
174183 mcnInformer ,
175184 schedulerInformer ,
185+ mcopInformer ,
176186 kubeClient ,
177187 mcfgClient ,
178188 updateDelay ,
@@ -191,6 +201,7 @@ func newController(
191201 podInformer coreinformersv1.PodInformer ,
192202 mcnInformer mcfginformersv1.MachineConfigNodeInformer ,
193203 schedulerInformer cligoinformersv1.SchedulerInformer ,
204+ mcopInformer mcopinformersv1.MachineConfigurationInformer ,
194205 kubeClient clientset.Interface ,
195206 mcfgClient mcfgclientset.Interface ,
196207 updateDelay time.Duration ,
@@ -263,6 +274,9 @@ func newController(
263274 ctrl .schedulerList = schedulerInformer .Lister ()
264275 ctrl .schedulerListerSynced = schedulerInformer .Informer ().HasSynced
265276
277+ ctrl .mcopLister = mcopInformer .Lister ()
278+ ctrl .mcopListerSynced = mcopInformer .Informer ().HasSynced
279+
266280 return ctrl
267281}
268282
@@ -271,7 +285,7 @@ func (ctrl *Controller) Run(workers int, stopCh <-chan struct{}) {
271285 defer utilruntime .HandleCrash ()
272286 defer ctrl .queue .ShutDown ()
273287
274- if ! cache .WaitForCacheSync (stopCh , ctrl .ccListerSynced , ctrl .mcListerSynced , ctrl .mcpListerSynced , ctrl .moscListerSynced , ctrl .mosbListerSynced , ctrl .nodeListerSynced , ctrl .schedulerListerSynced ) {
288+ if ! cache .WaitForCacheSync (stopCh , ctrl .ccListerSynced , ctrl .mcListerSynced , ctrl .mcpListerSynced , ctrl .moscListerSynced , ctrl .mosbListerSynced , ctrl .nodeListerSynced , ctrl .schedulerListerSynced , ctrl . mcopListerSynced ) {
275289 return
276290 }
277291
@@ -1847,5 +1861,31 @@ func (ctrl *Controller) syncMetrics() error {
18471861 ctrlcommon .MCCDegradedMachineCount .WithLabelValues (pool .Name ).Set (float64 (pool .Status .DegradedMachineCount ))
18481862 ctrlcommon .MCCUnavailableMachineCount .WithLabelValues (pool .Name ).Set (float64 (pool .Status .UnavailableMachineCount ))
18491863 }
1864+
1865+ // Update boot image skew enforcement metric
1866+ ctrl .syncBootImageSkewEnforcementMetric ()
1867+
18501868 return nil
18511869}
1870+
1871+ // syncBootImageSkewEnforcementMetric updates the mcc_boot_image_skew_enforcement_none metric
1872+ // based on the current BootImageSkewEnforcementStatus mode in MachineConfiguration.
1873+ // The metric is set to 1 when mode is "None", indicating that scaling operations may
1874+ // not be successful.
1875+ func (ctrl * Controller ) syncBootImageSkewEnforcementMetric () {
1876+ if ctrl .fgHandler == nil || ! ctrl .fgHandler .Enabled (features .FeatureGateBootImageSkewEnforcement ) {
1877+ return
1878+ }
1879+
1880+ mcop , err := ctrl .mcopLister .Get (ctrlcommon .MCOOperatorKnobsObjectName )
1881+ if err != nil {
1882+ klog .V (4 ).Infof ("Failed to get MachineConfiguration for boot image skew enforcement metric: %v" , err )
1883+ return
1884+ }
1885+
1886+ if mcop .Status .BootImageSkewEnforcementStatus .Mode == opv1 .BootImageSkewEnforcementModeStatusNone {
1887+ ctrlcommon .MCCBootImageSkewEnforcementNone .Set (1 )
1888+ } else {
1889+ ctrlcommon .MCCBootImageSkewEnforcementNone .Set (0 )
1890+ }
1891+ }
0 commit comments