@@ -2,7 +2,6 @@ package updatestatus
2
2
3
3
import (
4
4
"context"
5
- "errors"
6
5
"fmt"
7
6
"strings"
8
7
"time"
@@ -20,19 +19,22 @@ import (
20
19
21
20
machineconfigv1 "github.com/openshift/api/machineconfiguration/v1"
22
21
configv1client "github.com/openshift/client-go/config/clientset/versioned"
23
- machineconfigv1client "github.com/openshift/client-go/machineconfiguration/clientset/versioned "
24
- "github.com/openshift/cluster-version-operator/pkg/updatestatus/mco "
22
+ machineconfiginformers "github.com/openshift/client-go/machineconfiguration/informers/externalversions "
23
+ machineconfigv1listers "github.com/openshift/client-go/machineconfiguration/listers/machineconfiguration/v1 "
25
24
"github.com/openshift/library-go/pkg/controller/factory"
26
25
"github.com/openshift/library-go/pkg/operator/events"
26
+
27
+ "github.com/openshift/cluster-version-operator/pkg/updatestatus/mco"
27
28
)
28
29
29
30
// nodeInformerController is the controller that monitors health of the node resources
30
31
// and produces insights for node update.
31
32
type nodeInformerController struct {
32
- configClient configv1client.Interface
33
- machineConfigClient machineconfigv1client.Interface
34
- nodes corelistersv1.NodeLister
35
- recorder events.Recorder
33
+ configClient configv1client.Interface
34
+ machineConfigs machineconfigv1listers.MachineConfigLister
35
+ machineConfigPools machineconfigv1listers.MachineConfigPoolLister
36
+ nodes corelistersv1.NodeLister
37
+ recorder events.Recorder
36
38
37
39
// sendInsight should be called to send produced insights to the update status controller
38
40
sendInsight sendInsightFn
@@ -43,19 +45,20 @@ type nodeInformerController struct {
43
45
44
46
func newNodeInformerController (
45
47
configClient configv1client.Interface ,
46
- machineConfigClient machineconfigv1client.Interface ,
47
48
coreInformers kubeinformers.SharedInformerFactory ,
49
+ machineConfigInformers machineconfiginformers.SharedInformerFactory ,
48
50
recorder events.Recorder ,
49
51
sendInsight sendInsightFn ,
50
52
) factory.Controller {
51
53
cpiRecorder := recorder .WithComponentSuffix ("node-informer" )
52
54
53
55
c := & nodeInformerController {
54
- configClient : configClient ,
55
- machineConfigClient : machineConfigClient ,
56
- nodes : coreInformers .Core ().V1 ().Nodes ().Lister (),
57
- recorder : cpiRecorder ,
58
- sendInsight : sendInsight ,
56
+ configClient : configClient ,
57
+ machineConfigs : machineConfigInformers .Machineconfiguration ().V1 ().MachineConfigs ().Lister (),
58
+ machineConfigPools : machineConfigInformers .Machineconfiguration ().V1 ().MachineConfigPools ().Lister (),
59
+ nodes : coreInformers .Core ().V1 ().Nodes ().Lister (),
60
+ recorder : cpiRecorder ,
61
+ sendInsight : sendInsight ,
59
62
60
63
now : metav1 .Now ,
61
64
}
@@ -91,27 +94,24 @@ func (c *nodeInformerController) sync(ctx context.Context, syncCtx factory.SyncC
91
94
return err
92
95
}
93
96
94
- mcpList , err := c .machineConfigClient . MachineconfigurationV1 (). MachineConfigPools (). List ( ctx , metav1. ListOptions {} )
97
+ pools , err := c .machineConfigPools . List ( labels . Everything () )
95
98
if err != nil {
96
99
return err
97
100
}
98
- mcp , err := whichMCP (node , mcpList . Items )
101
+ mcp , err := whichMCP (node , pools )
99
102
if err != nil {
100
103
return fmt .Errorf ("failed to determine which machine config pool the node belongs to: %w" , err )
101
104
}
102
105
103
- machineConfigs := map [string ]* machineconfigv1.MachineConfig {}
104
- for _ , key := range []string {mco .CurrentMachineConfigAnnotationKey , mco .DesiredMachineConfigAnnotationKey } {
105
- machineConfigName , ok := node .Annotations [key ]
106
- if ! ok || machineConfigName == "" {
107
- continue
108
- }
109
- if _ , ok := machineConfigs [machineConfigName ]; ! ok {
110
- machineConfig , err := c .machineConfigClient .MachineconfigurationV1 ().MachineConfigs ().Get (ctx , machineConfigName , metav1.GetOptions {})
111
- if err != nil {
112
- return err
113
- }
114
- machineConfigs [machineConfigName ] = machineConfig
106
+ machineConfigs , err := c .machineConfigs .List (labels .Everything ())
107
+ if err != nil {
108
+ return err
109
+ }
110
+
111
+ machineConfigVersions := map [string ]string {}
112
+ for _ , mc := range machineConfigs {
113
+ if openshiftVersion , ok := mc .Annotations [mco .ReleaseImageVersionAnnotationKey ]; ok && openshiftVersion != "" {
114
+ machineConfigVersions [mc .Name ] = openshiftVersion
115
115
}
116
116
}
117
117
@@ -125,7 +125,7 @@ func (c *nodeInformerController) sync(ctx context.Context, syncCtx factory.SyncC
125
125
}
126
126
127
127
now := c .now ()
128
- if insight := assessNode (node , mcp , machineConfigs , mostRecentVersionInCVHistory , now ); insight != nil {
128
+ if insight := assessNode (node , mcp , machineConfigVersions , mostRecentVersionInCVHistory , now ); insight != nil {
129
129
msg = makeInsightMsgForNode (insight , now )
130
130
}
131
131
default :
@@ -158,13 +158,13 @@ func makeInsightMsgForNode(nodeInsight *NodeStatusInsight, acquiredAt metav1.Tim
158
158
}
159
159
}
160
160
161
- func whichMCP (node * corev1.Node , pools []machineconfigv1.MachineConfigPool ) (* machineconfigv1.MachineConfigPool , error ) {
161
+ func whichMCP (node * corev1.Node , pools []* machineconfigv1.MachineConfigPool ) (* machineconfigv1.MachineConfigPool , error ) {
162
162
var masterSelector labels.Selector
163
163
var workerSelector labels.Selector
164
164
customSelectors := map [string ]labels.Selector {}
165
165
poolsMap := make (map [string ]* machineconfigv1.MachineConfigPool , len (pools ))
166
166
for _ , pool := range pools {
167
- poolsMap [pool .Name ] = & pool
167
+ poolsMap [pool .Name ] = pool
168
168
s , err := metav1 .LabelSelectorAsSelector (pool .Spec .NodeSelector )
169
169
if err != nil {
170
170
return nil , fmt .Errorf ("failed to get label selector from the pool %s: %w" , pool .Name , err )
@@ -190,17 +190,7 @@ func whichMCP(node *corev1.Node, pools []machineconfigv1.MachineConfigPool) (*ma
190
190
if workerSelector != nil && workerSelector .Matches (labels .Set (node .Labels )) {
191
191
return poolsMap [mco .MachineConfigPoolWorker ], nil
192
192
}
193
- return nil , errors .New ("failed to find a matching node selector" )
194
- }
195
-
196
- func getOpenShiftVersionOfMachineConfig (machineConfigs map [string ]* machineconfigv1.MachineConfig , name string ) (string , bool ) {
197
- for _ , mc := range machineConfigs {
198
- if mc .Name == name {
199
- openshiftVersion := mc .Annotations [mco .ReleaseImageVersionAnnotationKey ]
200
- return openshiftVersion , openshiftVersion != ""
201
- }
202
- }
203
- return "" , false
193
+ return nil , fmt .Errorf ("failed to find a matching node selector from %d machine config pools" , len (pools ))
204
194
}
205
195
206
196
func isNodeDegraded (node * corev1.Node ) bool {
@@ -332,14 +322,14 @@ func toPointer(d time.Duration) *metav1.Duration {
332
322
return & v
333
323
}
334
324
335
- func assessNode (node * corev1.Node , mcp * machineconfigv1.MachineConfigPool , machineConfigs map [string ]* machineconfigv1. MachineConfig , mostRecentVersionInCVHistory string , now metav1.Time ) * NodeStatusInsight {
325
+ func assessNode (node * corev1.Node , mcp * machineconfigv1.MachineConfigPool , machineConfigVersions map [string ]string , mostRecentVersionInCVHistory string , now metav1.Time ) * NodeStatusInsight {
336
326
if node == nil || mcp == nil {
337
327
return nil
338
328
}
339
329
340
330
desiredConfig , ok := node .Annotations [mco .DesiredMachineConfigAnnotationKey ]
341
- currentVersion , foundCurrent := getOpenShiftVersionOfMachineConfig ( machineConfigs , node .Annotations [mco .CurrentMachineConfigAnnotationKey ])
342
- desiredVersion , foundDesired := getOpenShiftVersionOfMachineConfig ( machineConfigs , desiredConfig )
331
+ currentVersion , foundCurrent := machineConfigVersions [ node.Annotations [mco.CurrentMachineConfigAnnotationKey ]]
332
+ desiredVersion , foundDesired := machineConfigVersions [ desiredConfig ]
343
333
344
334
lns := mco .NewLayeredNodeState (node )
345
335
isUnavailable := lns .IsUnavailable (mcp )
0 commit comments