cluster list

This commit is contained in:
behrooz razzaghi
2025-05-23 20:59:36 +03:30
parent 35bdfb1248
commit 393a7650c1
5 changed files with 35 additions and 8 deletions

View File

@@ -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
}