diff --git a/cmd/cli/plugin/cluster/get.go b/cmd/cli/plugin/cluster/get.go index e095858828..ef38d362cd 100644 --- a/cmd/cli/plugin/cluster/get.go +++ b/cmd/cli/plugin/cluster/get.go @@ -11,7 +11,6 @@ import ( "strings" "time" - "github.com/aunum/log" "github.com/fatih/color" "github.com/gosuri/uitable" "github.com/spf13/cobra" @@ -25,6 +24,7 @@ import ( "github.com/vmware-tanzu/tanzu-framework/pkg/v1/cli" "github.com/vmware-tanzu/tanzu-framework/pkg/v1/cli/component" "github.com/vmware-tanzu/tanzu-framework/pkg/v1/config" + "github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkg/log" "github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkg/tkgctl" ) @@ -144,20 +144,14 @@ func getCluster(server *v1alpha1.Server, clusterName string) error { t.Render() - isPacific, err := tkgctlClient.IsPacificRegionalCluster() - if err != nil { - return errors.New("error determining 'Tanzu Kubernetes Cluster service for vSphere' management cluster") - } - - if isPacific { - return nil + if results.Objs != nil && results.Cluster != nil { + log.Infof("\n\nDetails:\n\n") + treeView(results.Objs, results.Cluster) + } else { + // printing the below at log level 1, so that if users want to know why the tree view is not available(for TKGS) it could provide insights + log.V(1).Infof("\n\n Warning! Unable to get cluster ObjectTree/cluster objects, so detailed(tree) view of cluster resources is not available!!\n\n") } - // TODO: Can be removed when TKGS and TKGm converge to the same CAPI version. - // https://github.com/vmware-tanzu/tanzu-framework/issues/1063 - log.Infof("\n\nDetails:\n\n") - treeView(results.Objs, results.Cluster) - // If it is a Management Cluster, output the providers if results.InstalledProviders != nil { log.Infof("\n\nProviders:\n\n") diff --git a/pkg/v1/tkg/tkgctl/describe_cluster.go b/pkg/v1/tkg/tkgctl/describe_cluster.go index 020b1a3a7b..015c5b5e5c 100644 --- a/pkg/v1/tkg/tkgctl/describe_cluster.go +++ b/pkg/v1/tkg/tkgctl/describe_cluster.go @@ -16,6 +16,7 @@ import ( "github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkg/client" "github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkg/constants" + "github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkg/log" ) // DescribeTKGClustersOptions options that can be passed while requesting to describe a cluster @@ -103,14 +104,14 @@ func (t *tkgctl) DescribeCluster(options DescribeTKGClustersOptions) (DescribeCl } } - // TODO: Can be removed when TKGS and TKGm converge to the same CAPI version. - // https://github.com/vmware-tanzu/tanzu-framework/issues/1063 - if isPacific { - return results, nil - } - objs, cluster, installedProviders, err := t.tkgClient.DescribeCluster(DescribeTKGClustersOptions) if err != nil { + // If it is pacific(TKGS), it would be the best effort to return the objectTree and cluster, so if there is an error + // fetching these objects, return empty objects without error. + if isPacific { + log.V(5).Infof("Failed to get cluster ObjectTree/cluster objects(so detailed(tree) view of cluster resources may be affected), reason: %v", err) + return results, nil + } return results, err } results.Objs = objs diff --git a/pkg/v1/tkg/tkgctl/describe_cluster_test.go b/pkg/v1/tkg/tkgctl/describe_cluster_test.go index fe23d5da42..efa51585af 100644 --- a/pkg/v1/tkg/tkgctl/describe_cluster_test.go +++ b/pkg/v1/tkg/tkgctl/describe_cluster_test.go @@ -21,7 +21,8 @@ var _ = Describe("Unit test for describe cluster", func() { ClusterName: "my-cluster", Namespace: "", } - err error + err error + result DescribeClusterResult ) JustBeforeEach(func() { @@ -31,7 +32,7 @@ var _ = Describe("Unit test for describe cluster", func() { kubeconfig: "./kube", featureGateHelper: featureGateHelper, } - _, err = ctl.DescribeCluster(ops) + result, err = ctl.DescribeCluster(ops) }) Context("when failed to determine the management cluster is Pacific(TKGS) supervisor cluster ", func() { @@ -100,4 +101,16 @@ var _ = Describe("Unit test for describe cluster", func() { Expect(options.IsTKGSClusterClassFeatureActivated).To(BeTrue()) }) }) + Context("when the management cluster is Pacific(TKGS) supervisor cluster and when tkgClient failed to describe the cluster", func() { + BeforeEach(func() { + tkgClient.IsPacificManagementClusterReturns(true, nil) + tkgClient.ListTKGClustersReturns([]client.ClusterInfo{{Name: "my-cluster", Roles: []string{""}}}, nil) + tkgClient.DescribeClusterReturns(nil, nil, nil, errors.New("failed to describe cluster")) + }) + It("should not return an error but ObjectTree and cluster objects should be nil", func() { + Expect(err).ToNot(HaveOccurred()) + Expect(result.Objs).To(BeNil()) + Expect(result.Cluster).To(BeNil()) + }) + }) })