Fix: fix the bug of cluster list (#4772)

Signed-off-by: HanMengnan <1448189829@qq.com>

Signed-off-by: HanMengnan <1448189829@qq.com>
This commit is contained in:
Siege Lion
2022-09-26 14:49:50 +08:00
committed by GitHub
parent 6e986d8db1
commit 6287a9caeb
4 changed files with 16 additions and 13 deletions
+14 -11
View File
@@ -58,16 +58,19 @@ func ListClusters(ctx context.Context, c client.Client) (ClusterList, error) {
}
}
clusters, _ := prismclusterv1alpha1.NewClusterClient(c).List(context.Background())
list := make(ClusterList, len(clusters.Items))
for index, cluster := range clusters.Items {
if _, ok := clusterSet[cluster.Name]; ok {
clusterInfo := Cluster{
name: cluster.Name,
alias: cluster.Spec.Alias,
clusterType: string(cluster.Spec.CredentialType),
endpoint: cluster.Spec.Endpoint,
}
list := make(ClusterList, 0)
for key := range clusterSet {
clusterInfo := Cluster{
name: key,
}
cluster, err := prismclusterv1alpha1.NewClusterClient(c).Get(context.Background(), key)
if err != nil {
continue
} else {
clusterInfo.alias = cluster.Spec.Alias
clusterInfo.clusterType = string(cluster.Spec.CredentialType)
clusterInfo.endpoint = cluster.Spec.Endpoint
var labels []string
for k, v := range cluster.Labels {
if !strings.HasPrefix(k, config.MetaApiGroupName) {
@@ -75,8 +78,8 @@ func ListClusters(ctx context.Context, c client.Client) (ClusterList, error) {
}
}
clusterInfo.labels = strings.Join(labels, ",")
list[index] = clusterInfo
}
list = append(list, clusterInfo)
}
return list, nil
}
@@ -137,6 +137,7 @@ func (v *ClusterNamespaceView) managedResourceView(event *tcell.EventKey) *tcell
clusterNamespace = ""
}
v.app.content.PopView()
v.app.content.PopView()
v.ctx = context.WithValue(v.ctx, &model.CtxKeyClusterNamespace, clusterNamespace)
v.app.command.run(v.ctx, "resource")
return event
+1
View File
@@ -119,6 +119,7 @@ func (v *ClusterView) managedResourceView(event *tcell.EventKey) *tcell.EventKey
clusterName = ""
}
v.app.content.PopView()
v.app.content.PopView()
v.ctx = context.WithValue(v.ctx, &model.CtxKeyCluster, clusterName)
v.app.command.run(v.ctx, "resource")
return event
@@ -149,14 +149,12 @@ func (v *ManagedResourceView) bindKeys() {
// clusterView switch managed resource view to the cluster view
func (v *ManagedResourceView) clusterView(event *tcell.EventKey) *tcell.EventKey {
v.app.content.PopView()
v.app.command.run(v.ctx, "cluster")
return event
}
// clusterView switch managed resource view to the cluster Namespace view
func (v *ManagedResourceView) clusterNamespaceView(event *tcell.EventKey) *tcell.EventKey {
v.app.content.PopView()
v.app.command.run(v.ctx, "cns")
return event
}