add worker ndoes
This commit is contained in:
Submodule application updated: e2ea0f9fe2...cfaba19c22
3
db/db.go
3
db/db.go
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
var (
|
||||
Client *mongo.Client
|
||||
UserCollection, Vclusters_details, Host_cluster_details *mongo.Collection
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
1
main.go
1
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{
|
||||
|
||||
@@ -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`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user