cluster list
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -24,6 +25,16 @@ type ApplicationValues struct {
|
||||
UserID string `yaml:"userID"`
|
||||
}
|
||||
|
||||
type Clusters struct {
|
||||
Name string `yaml:"name"`
|
||||
ClusterID string `yaml:"clusterid"`
|
||||
Status string `yaml:"status"`
|
||||
Version string `yaml:version`
|
||||
HealthCheck string `yaml:"healthcheck`
|
||||
Alert string `yaml:"alert"`
|
||||
EndPoint string `yaml:"endpoint"`
|
||||
}
|
||||
|
||||
var (
|
||||
client apiclient.Client
|
||||
once sync.Once
|
||||
@@ -176,12 +187,12 @@ func SyncApp(appName string) {
|
||||
|
||||
}
|
||||
|
||||
func ListUserClusters(userID string) ([]string, error) {
|
||||
func ListUserClusters(userID string) (error, []Clusters) {
|
||||
InitializeClient()
|
||||
|
||||
_, appClient, err := client.NewApplicationClient()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create application client: %v", err)
|
||||
return fmt.Errorf("failed to create application client: %v", err), nil
|
||||
}
|
||||
|
||||
// List all applications with the user's label
|
||||
@@ -190,13 +201,19 @@ func ListUserClusters(userID string) ([]string, error) {
|
||||
Selector: &selector,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list applications: %v", err)
|
||||
return fmt.Errorf("failed to list applications: %v", err), nil
|
||||
}
|
||||
|
||||
var clusterNames []string
|
||||
clusters := []Clusters{}
|
||||
|
||||
for _, app := range apps.Items {
|
||||
clusterNames = append(clusterNames, app.Name)
|
||||
newCluster := Clusters{
|
||||
Name: app.Name,
|
||||
Status: string(app.Status.Health.Status),
|
||||
ClusterID: strings.Split(string(app.ObjectMeta.UID), "-")[0],
|
||||
}
|
||||
clusters = append(clusters, newCluster)
|
||||
}
|
||||
|
||||
return clusterNames, nil
|
||||
return nil, clusters
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user