From 7fdecc5cc4b4174ab5c540a027fcfccc7183f66f Mon Sep 17 00:00:00 2001 From: Rob Leidle Date: Sun, 10 Jun 2018 17:09:00 -0700 Subject: [PATCH] Fix a bug in ClusterClient's GetClusterObjects() and GetMachineObjects() (#321) The previous implementation took the address of the iteration variable. While the value of the iteration value changes on each iteration, the address does not change for the entirety of the loop. Previously, the slice returned by these functions would be a collection of the exact same iterator variable address and which of course would be filled with a value of the last value in the loop iteration. --- clusterctl/clusterdeployer/clusterclient.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clusterctl/clusterdeployer/clusterclient.go b/clusterctl/clusterdeployer/clusterclient.go index 08dd37f9e746..1f3b329906d2 100644 --- a/clusterctl/clusterdeployer/clusterclient.go +++ b/clusterctl/clusterdeployer/clusterclient.go @@ -95,8 +95,8 @@ func (c *clusterClient) GetClusterObjects() ([]*clusterv1.Cluster, error) { return nil, err } - for _, cluster := range clusterlist.Items { - clusters = append(clusters, &cluster) + for i := 0; i < len(clusterlist.Items); i++ { + clusters = append(clusters, &clusterlist.Items[i]) } return clusters, nil } @@ -109,8 +109,8 @@ func (c *clusterClient) GetMachineObjects() ([]*clusterv1.Machine, error) { return nil, err } - for _, machine := range machineslist.Items { - machines = append(machines, &machine) + for i := 0; i < len(machineslist.Items); i++ { + machines = append(machines, &machineslist.Items[i]) } return machines, nil }