From af298a2a480fb7143786cf4f9990e741855f08e9 Mon Sep 17 00:00:00 2001 From: Vince Prignano Date: Tue, 12 Mar 2019 06:26:38 -0700 Subject: [PATCH] Fix GetMachinesForCluster returning duplicate results (#816) Signed-off-by: Vince Prignano --- .../clusterdeployer/clusterclient/clusterclient.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/clusterctl/clusterdeployer/clusterclient/clusterclient.go b/cmd/clusterctl/clusterdeployer/clusterclient/clusterclient.go index 1b6d19e6efa7..1b40363d5be8 100644 --- a/cmd/clusterctl/clusterdeployer/clusterclient/clusterclient.go +++ b/cmd/clusterctl/clusterdeployer/clusterclient/clusterclient.go @@ -388,17 +388,18 @@ func (c *client) GetMachinesForCluster(cluster *clusterv1.Cluster) ([]*clusterv1 return nil, errors.Wrapf(err, "error listing Machines for Cluster %s/%s", cluster.Namespace, cluster.Name) } var machines []*clusterv1.Machine - for _, m := range machineslist.Items { + + for i := 0; i < len(machineslist.Items); i++ { + m := &machineslist.Items[i] + for _, or := range m.GetOwnerReferences() { if or.Kind == cluster.Kind && or.Name == cluster.Name { - machines = append(machines, &m) - continue + machines = append(machines, m) + break } } } - for i := 0; i < len(machineslist.Items); i++ { - machines = append(machines, &machineslist.Items[i]) - } + return machines, nil }