fix registry address

This commit is contained in:
behrooz razzaghi
2025-04-05 16:58:47 +03:30
parent fd1e1f1d2e
commit 61a9fbe9f2
8 changed files with 23 additions and 42 deletions

View File

@@ -3,6 +3,7 @@ package handler
import (
"context"
"encoding/json"
"main/argohandler"
"main/db"
"net/http"
@@ -25,24 +26,31 @@ type Cluster struct {
func createClusterHandler(w http.ResponseWriter, r *http.Request) {
vclusterCollection := db.Client.Database("vcluster").Collection("vclusters_details")
var cluster Cluster
_ = json.NewDecoder(r.Body).Decode(&cluster)
// vclusterCollection := db.Vclusters_details.FindOne(context.TODO(), bson.M{"name": Cluster.Name}).Decode(&existsCluster)
if cluster.Name == "" || cluster.ControlPlane == "" || cluster.PlatformVersion == "" || cluster.Cpu == "" || cluster.Memory == "" {
http.Error(w, "Invalid input", http.StatusBadRequest)
return
}
var existsCluster Cluster
_ = vclusterCollection.FindOne(context.TODO(), bson.M{"name": cluster.Name}).Decode(&existsCluster)
_ = db.Vclusters_details.FindOne(context.TODO(), bson.M{"name": cluster.Name}).Decode(&existsCluster)
if existsCluster.Name == cluster.Name {
http.Error(w, "Cluster name is duplicated", http.StatusBadRequest)
return
}
_, err := db.Vclusters_details.InsertOne(context.TODO(), cluster)
if err != nil {
http.Error(w, `{"message": "Could not create cluster"}`, http.StatusInternalServerError)
}
argohandler.CreateApp(cluster.Name)
response := map[string]string{"message": "Cluster created"}
w.Header().Set("Content-Type", "application/json")