11package status
22
33import (
4- "context"
54 "fmt"
65 "io"
76 "sort"
@@ -10,12 +9,10 @@ import (
109 "time"
1110
1211 corev1 "k8s.io/api/core/v1"
13- v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1412 "k8s.io/apimachinery/pkg/labels"
1513
1614 configv1 "github.com/openshift/api/config/v1"
1715 mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
18- mcfgv1client "github.com/openshift/client-go/machineconfiguration/clientset/versioned"
1916 "github.com/openshift/oc/pkg/cli/admin/upgrade/status/mco"
2017)
2118
@@ -114,15 +111,6 @@ type poolDisplayData struct {
114111 Nodes []nodeDisplayData
115112}
116113
117- func getMachineConfig (ctx context.Context , client mcfgv1client.Interface , machineConfigs []mcfgv1.MachineConfig , machineConfigName string ) (* mcfgv1.MachineConfig , error ) {
118- for _ , mc := range machineConfigs {
119- if mc .Name == machineConfigName {
120- return nil , nil
121- }
122- }
123- return client .MachineconfigurationV1 ().MachineConfigs ().Get (ctx , machineConfigName , v1.GetOptions {})
124- }
125-
126114func whichPool (master , worker labels.Selector , custom map [string ]labels.Selector , node corev1.Node ) string {
127115 if master .Matches (labels .Set (node .Labels )) {
128116 return "master"
@@ -146,13 +134,13 @@ func ellipsizeNames(message string, name string) string {
146134 return strings .Replace (message , name , "<node>" , - 1 )
147135}
148136
149- func assessNodesStatus (cv * configv1.ClusterVersion , pool mcfgv1.MachineConfigPool , nodes []corev1.Node , machineConfigs []mcfgv1. MachineConfig , multiArchMigrationInProgress bool ) ([]nodeDisplayData , []updateInsight ) {
137+ func assessNodesStatus (cv * configv1.ClusterVersion , pool mcfgv1.MachineConfigPool , nodes []corev1.Node , machineConfigVersionMap map [ string ] string , multiArchMigrationInProgress bool ) ([]nodeDisplayData , []updateInsight ) {
150138 var nodesStatusData []nodeDisplayData
151139 var insights []updateInsight
152140 for _ , node := range nodes {
153141 desiredConfig , ok := node .Annotations [mco .DesiredMachineConfigAnnotationKey ]
154- currentVersion , foundCurrent := getOpenShiftVersionOfMachineConfig (machineConfigs , node .Annotations [mco .CurrentMachineConfigAnnotationKey ])
155- desiredVersion , foundDesired := getOpenShiftVersionOfMachineConfig (machineConfigs , desiredConfig )
142+ currentVersion , foundCurrent := getOpenShiftVersionOfMachineConfig (machineConfigVersionMap , node .Annotations [mco .CurrentMachineConfigAnnotationKey ])
143+ desiredVersion , foundDesired := getOpenShiftVersionOfMachineConfig (machineConfigVersionMap , desiredConfig )
156144
157145 lns := mco .NewLayeredNodeState (& node )
158146 isUnavailable := lns .IsUnavailable (& pool )
@@ -245,14 +233,19 @@ func assessNodesStatus(cv *configv1.ClusterVersion, pool mcfgv1.MachineConfigPoo
245233 return nodesStatusData , insights
246234}
247235
248- func getOpenShiftVersionOfMachineConfig (machineConfigs []mcfgv1.MachineConfig , name string ) (string , bool ) {
236+ func buildMachineConfigVersionMap (machineConfigs []mcfgv1.MachineConfig ) map [string ]string {
237+ versionMap := make (map [string ]string , len (machineConfigs ))
249238 for _ , mc := range machineConfigs {
250- if mc .Name == name {
251- openshiftVersion := mc .Annotations [mco .ReleaseImageVersionAnnotationKey ]
252- return openshiftVersion , openshiftVersion != ""
239+ if version := mc .Annotations [mco .ReleaseImageVersionAnnotationKey ]; version != "" {
240+ versionMap [mc .Name ] = version
253241 }
254242 }
255- return "" , false
243+ return versionMap
244+ }
245+
246+ func getOpenShiftVersionOfMachineConfig (versionMap map [string ]string , name string ) (string , bool ) {
247+ version , found := versionMap [name ]
248+ return version , found
256249}
257250
258251func isNodeDraining (node corev1.Node , isUpdating bool ) bool {
0 commit comments