Skip to content

Commit 341c07a

Browse files
author
Cecile Robert-Michon
committed
Update machinepool_helpers.go
1 parent a086f0c commit 341c07a

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

test/framework/machinepool_helpers.go

+19-20
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type DiscoveryAndWaitForMachinePoolsInput struct {
9292
Cluster *clusterv1.Cluster
9393
}
9494

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).
9696
func DiscoveryAndWaitForMachinePools(ctx context.Context, input DiscoveryAndWaitForMachinePoolsInput, intervals ...interface{}) []*clusterv1exp.MachinePool {
9797
Expect(ctx).NotTo(BeNil(), "ctx is required for DiscoveryAndWaitForMachinePools")
9898
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
131131
mgmtClient := input.ClusterProxy.GetClient()
132132
for i := range input.MachinePools {
133133
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)
135135
patchHelper, err := patch.NewHelper(mp, mgmtClient)
136136
Expect(err).ToNot(HaveOccurred())
137137

@@ -145,7 +145,7 @@ func UpgradeMachinePoolAndWait(ctx context.Context, input UpgradeMachinePoolAndW
145145
log.Logf("Waiting for Kubernetes versions of machines in MachinePool %s/%s to be upgraded from %s to %s",
146146
mp.Namespace, mp.Name, *oldVersion, input.UpgradeVersion)
147147
WaitForMachinePoolInstancesToBeUpgraded(ctx, WaitForMachinePoolInstancesToBeUpgradedInput{
148-
Getter: mgmtClient,
148+
Getter: input.ClusterProxy.GetWorkloadCluster(ctx, input.Cluster.Namespace, input.Cluster.Name).GetClient(),
149149
Cluster: input.Cluster,
150150
MachineCount: int(*mp.Spec.Replicas),
151151
KubernetesUpgradeVersion: input.UpgradeVersion,
@@ -207,7 +207,7 @@ func WaitForMachinePoolInstancesToBeUpgraded(ctx context.Context, input WaitForM
207207

208208
log.Logf("Ensuring all MachinePool Instances have upgraded kubernetes version %s", input.KubernetesUpgradeVersion)
209209
Eventually(func() (int, error) {
210-
versions := GetMachinePoolInstanceVersions(ctx, GetMachinesPoolInstancesInput{
210+
versions := getMachinePoolInstanceVersions(ctx, GetMachinesPoolInstancesInput{
211211
Getter: input.Getter,
212212
Namespace: input.Cluster.Namespace,
213213
MachinePool: input.MachinePool,
@@ -235,25 +235,24 @@ type GetMachinesPoolInstancesInput struct {
235235
MachinePool clusterv1exp.MachinePool
236236
}
237237

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")
250244

245+
instances := input.MachinePool.Status.NodeRefs
251246
versions := make([]string, len(instances))
252247
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])
257256
}
258257

259258
return versions

0 commit comments

Comments
 (0)