From 821ead675f3ee0626eca3531acbd2e035083497d Mon Sep 17 00:00:00 2001 From: Ybehrooz Date: Tue, 26 Aug 2025 19:52:27 +0330 Subject: [PATCH] add worker ndoes --- application | 2 +- db/db.go | 5 +++-- handler/handler.go | 30 ++++++++++++++++++++++++++++++ main.go | 1 + models/workloads.go | 11 ++++++++++- 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/application b/application index e2ea0f9..cfaba19 160000 --- a/application +++ b/application @@ -1 +1 @@ -Subproject commit e2ea0f9fe25f53b92b281d9ef3e5b8cc711bfcf6 +Subproject commit cfaba19c22308cbc6e0f140ae0c834bf0ac7d78c diff --git a/db/db.go b/db/db.go index 2fb7996..a978936 100644 --- a/db/db.go +++ b/db/db.go @@ -9,8 +9,8 @@ import ( ) var ( - Client *mongo.Client - UserCollection, Vclusters_details, Host_cluster_details *mongo.Collection + Client *mongo.Client + UserCollection, Vclusters_details, Host_cluster_details, Worker_nodes_plan *mongo.Collection ) func InitDB() { @@ -23,4 +23,5 @@ func InitDB() { UserCollection = client.Database("vcluster").Collection("users") Vclusters_details = client.Database("vcluster").Collection("vclusters_details") Host_cluster_details = client.Database("vcluster").Collection("hostdetail") + Worker_nodes_plan = client.Database("vcluster").Collection("worker_nodes_plans") } diff --git a/handler/handler.go b/handler/handler.go index 144d5b7..528b506 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -1040,3 +1040,33 @@ func Cronjob_delete(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(cronjobName + " Has been deleted") } + +func Worker_nodes_plan(w http.ResponseWriter, r *http.Request) { + Authorization(w, r) + + var workerNodesPlan []models.WorkerNodesPlans + + cursor, err := db.Worker_nodes_plan.Find(context.TODO(), bson.M{}) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + defer cursor.Close(context.TODO()) + + for cursor.Next(context.TODO()) { + var plan models.WorkerNodesPlans + if err := cursor.Decode(&plan); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + workerNodesPlan = append(workerNodesPlan, plan) + } + + if err := cursor.Err(); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(workerNodesPlan) +} diff --git a/main.go b/main.go index 86b817f..40a4731 100644 --- a/main.go +++ b/main.go @@ -152,6 +152,7 @@ func main() { router.HandleFunc("/replicaset_delete", handler.Replicaset_delete) router.HandleFunc("/replicationcontroller_delete", handler.Replicationcontroller_delete) router.HandleFunc("/cronjob_delete", handler.Cronjob_delete) + router.HandleFunc("/worker_nodes_plan", handler.Worker_nodes_plan) //handler.RegsiterClusterRoute(router) // Enable CORS // c := cors.New(cors.Options{ diff --git a/models/workloads.go b/models/workloads.go index 19db578..394bdaa 100644 --- a/models/workloads.go +++ b/models/workloads.go @@ -1,6 +1,8 @@ package models -import "go.mongodb.org/mongo-driver/bson/primitive" +import ( + "go.mongodb.org/mongo-driver/bson/primitive" +) type User struct { ID string `json:"id,omitempty"` @@ -99,3 +101,10 @@ type StatefulSet struct { Ready string `json:Ready` Age string `json:age` } + +type WorkerNodesPlans struct { + Plan string `json:plan` + Cpu string `json:cpu` + Memory string `json:memory` + Storage string `;sjon:storage` +}