Skip to content

Commit

Permalink
Return error on infra cluster and control plane discovery
Browse files Browse the repository at this point in the history
If no control plane reference is set in the Cluster object the describe cluster
command will fail. We should validate the error in any case.

Signed-off-by: Tobias Giese <[email protected]>
  • Loading branch information
tobiasgiese committed May 4, 2023
1 parent 7edbaf0 commit f928305
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cmd/clusterctl/client/tree/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package tree
import (
"context"

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
unstructured "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -83,9 +84,11 @@ func Discovery(ctx context.Context, c client.Client, namespace, name string, opt
tree := NewObjectTree(cluster, options.toObjectTreeOptions())

// Adds cluster infra
if clusterInfra, err := external.Get(ctx, c, cluster.Spec.InfrastructureRef, cluster.Namespace); err == nil {
tree.Add(cluster, clusterInfra, ObjectMetaName("ClusterInfrastructure"))
clusterInfra, err := external.Get(ctx, c, cluster.Spec.InfrastructureRef, cluster.Namespace)
if err != nil {
return nil, errors.Wrap(err, "get InfraCluster reference from Cluster")
}
tree.Add(cluster, clusterInfra, ObjectMetaName("ClusterInfrastructure"))

if options.ShowClusterResourceSets {
addClusterResourceSetsToObjectTree(ctx, c, cluster, tree)
Expand Down Expand Up @@ -119,9 +122,11 @@ func Discovery(ctx context.Context, c client.Client, namespace, name string, opt
}

controlPlaneMachines := selectControlPlaneMachines(machinesList)
for i := range controlPlaneMachines {
cp := controlPlaneMachines[i]
addMachineFunc(controlPlane, cp)
if controlPlane != nil {
for i := range controlPlaneMachines {
cp := controlPlaneMachines[i]
addMachineFunc(controlPlane, cp)
}
}

machinePoolList, err := getMachinePoolsInCluster(ctx, c, cluster.Namespace, cluster.Name)
Expand Down

0 comments on commit f928305

Please sign in to comment.