cluster list
This commit is contained in:
Submodule application updated: f93574db8f...eba337fb68
@@ -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
|
||||
}
|
||||
|
||||
2
db/db.go
2
db/db.go
@@ -14,7 +14,7 @@ var (
|
||||
)
|
||||
|
||||
func InitDB() {
|
||||
clientOptions := options.Client().ApplyURI("mongodb://root:example@192.168.2.177:27017/")
|
||||
clientOptions := options.Client().ApplyURI("mongodb://root:example@192.168.1.10:27017/")
|
||||
client, err := mongo.Connect(context.TODO(), clientOptions)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
@@ -65,6 +65,15 @@ func CreateClusterHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
func ListUserClusters(w http.ResponseWriter, r *http.Request) {
|
||||
// var cluster Cluster
|
||||
_, clusterList := argohandler.ListUserClusters("userid")
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(clusterList)
|
||||
|
||||
}
|
||||
|
||||
// func RegsiterClusterRoute(r *mux.Router) {
|
||||
// r.HandleFunc("/createcluster", createClusterHandler).Methods("POST", "OPTIONS")
|
||||
// }
|
||||
|
||||
1
main.go
1
main.go
@@ -126,6 +126,7 @@ func main() {
|
||||
router.HandleFunc("/register", registerHnadler)
|
||||
router.HandleFunc("/login", loginHandler)
|
||||
router.HandleFunc("/createcluster", handler.CreateClusterHandler)
|
||||
router.HandleFunc("/clusters", handler.ListUserClusters)
|
||||
//handler.RegsiterClusterRoute(router)
|
||||
// Enable CORS
|
||||
c := cors.New(cors.Options{
|
||||
|
||||
Reference in New Issue
Block a user