@@ -92,7 +92,7 @@ type DiscoveryAndWaitForMachinePoolsInput struct {
92
92
Cluster * clusterv1.Cluster
93
93
}
94
94
95
- // DiscoveryAndWaitForMachinePools discovers the MachinePools existing in a cluster and waits for them to be ready (all the machine provisioned).
95
+ // DiscoveryAndWaitForMachinePools discovers the MachinePools existing in a cluster and waits for them to be ready (all the machines provisioned).
96
96
func DiscoveryAndWaitForMachinePools (ctx context.Context , input DiscoveryAndWaitForMachinePoolsInput , intervals ... interface {}) []* clusterv1exp.MachinePool {
97
97
Expect (ctx ).NotTo (BeNil (), "ctx is required for DiscoveryAndWaitForMachinePools" )
98
98
Expect (input .Lister ).ToNot (BeNil (), "Invalid argument. input.Lister can't be nil when calling DiscoveryAndWaitForMachinePools" )
@@ -131,7 +131,7 @@ func UpgradeMachinePoolAndWait(ctx context.Context, input UpgradeMachinePoolAndW
131
131
mgmtClient := input .ClusterProxy .GetClient ()
132
132
for i := range input .MachinePools {
133
133
mp := input .MachinePools [i ]
134
- log .Logf ("Patching the new kubernetes version to Machine Pool %s/%s" , mp .Namespace , mp .Name )
134
+ log .Logf ("Patching the new Kubernetes version to Machine Pool %s/%s" , mp .Namespace , mp .Name )
135
135
patchHelper , err := patch .NewHelper (mp , mgmtClient )
136
136
Expect (err ).ToNot (HaveOccurred ())
137
137
@@ -145,7 +145,7 @@ func UpgradeMachinePoolAndWait(ctx context.Context, input UpgradeMachinePoolAndW
145
145
log .Logf ("Waiting for Kubernetes versions of machines in MachinePool %s/%s to be upgraded from %s to %s" ,
146
146
mp .Namespace , mp .Name , * oldVersion , input .UpgradeVersion )
147
147
WaitForMachinePoolInstancesToBeUpgraded (ctx , WaitForMachinePoolInstancesToBeUpgradedInput {
148
- Getter : mgmtClient ,
148
+ Getter : input . ClusterProxy . GetWorkloadCluster ( ctx , input . Cluster . Namespace , input . Cluster . Name ). GetClient () ,
149
149
Cluster : input .Cluster ,
150
150
MachineCount : int (* mp .Spec .Replicas ),
151
151
KubernetesUpgradeVersion : input .UpgradeVersion ,
@@ -207,7 +207,7 @@ func WaitForMachinePoolInstancesToBeUpgraded(ctx context.Context, input WaitForM
207
207
208
208
log .Logf ("Ensuring all MachinePool Instances have upgraded kubernetes version %s" , input .KubernetesUpgradeVersion )
209
209
Eventually (func () (int , error ) {
210
- versions := GetMachinePoolInstanceVersions (ctx , GetMachinesPoolInstancesInput {
210
+ versions := getMachinePoolInstanceVersions (ctx , GetMachinesPoolInstancesInput {
211
211
Getter : input .Getter ,
212
212
Namespace : input .Cluster .Namespace ,
213
213
MachinePool : input .MachinePool ,
@@ -235,25 +235,24 @@ type GetMachinesPoolInstancesInput struct {
235
235
MachinePool clusterv1exp.MachinePool
236
236
}
237
237
238
- // GetMachinePoolInstanceVersions returns the.
239
- func GetMachinePoolInstanceVersions (ctx context.Context , input GetMachinesPoolInstancesInput ) []string {
240
- Expect (ctx ).NotTo (BeNil (), "ctx is required for GetMachinePoolInstanceVersions" )
241
- Expect (input .Namespace ).ToNot (BeEmpty (), "Invalid argument. input.Namespace can't be empty when calling GetMachinePoolInstanceVersions" )
242
- Expect (input .MachinePool ).ToNot (BeNil (), "Invalid argument. input.MachineDeployment can't be nil when calling GetMachinePoolInstanceVersions" )
243
-
244
- obj := getUnstructuredRef (ctx , input .Getter , & input .MachinePool .Spec .Template .Spec .InfrastructureRef , input .Namespace )
245
- instances , found , err := unstructured .NestedSlice (obj .Object , "status" , "instances" )
246
- Expect (err ).ToNot (HaveOccurred (), "failed to extract machines from unstructured" )
247
- if ! found {
248
- return nil
249
- }
238
+ // getMachinePoolInstanceVersions returns the Kubernetes versions of the machine pool instances.
239
+ func getMachinePoolInstanceVersions (ctx context.Context , input GetMachinesPoolInstancesInput ) []string {
240
+ Expect (ctx ).NotTo (BeNil (), "ctx is required for getMachinePoolInstanceVersions" )
241
+ Expect (input .Getter ).ToNot (BeNil (), "Invalid argument. input.Getter can't be nil when calling getMachinePoolInstanceVersions" )
242
+ Expect (input .Namespace ).ToNot (BeEmpty (), "Invalid argument. input.Namespace can't be empty when calling getMachinePoolInstanceVersions" )
243
+ Expect (input .MachinePool ).ToNot (BeNil (), "Invalid argument. input.MachineDeployment can't be nil when calling getMachinePoolInstanceVersions" )
250
244
245
+ instances := input .MachinePool .Status .NodeRefs
251
246
versions := make ([]string , len (instances ))
252
247
for i , instance := range instances {
253
- version , found , err := unstructured .NestedString (instance .(map [string ]interface {}), "version" )
254
- Expect (err ).ToNot (HaveOccurred (), "failed to extract versions from unstructured instance" )
255
- Expect (found ).To (BeTrue (), "unable to find nested version string in unstructured instance" )
256
- versions [i ] = version
248
+ node := & corev1.Node {}
249
+ err := input .Getter .Get (ctx , client.ObjectKey {Name : instance .Name }, node )
250
+ if err != nil {
251
+ versions [i ] = "unknown"
252
+ } else {
253
+ versions [i ] = node .Status .NodeInfo .KubeletVersion
254
+ }
255
+ log .Logf ("Node %s version is %s" , instance .Name , versions [i ])
257
256
}
258
257
259
258
return versions
0 commit comments