Compare commits
16 Commits
720e6914fb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59bd105247 | ||
|
|
a23a1e28f4 | ||
|
|
2482e37e8c | ||
|
|
eb42739472 | ||
| c0d4a62d60 | |||
|
|
f5057233a0 | ||
|
|
fbc48792bf | ||
|
|
44c75b2f5c | ||
|
|
98481d56eb | ||
|
|
08d17a33ea | ||
|
|
b82db8e0b1 | ||
|
|
06b7aaa548 | ||
|
|
36a36a232f | ||
|
|
821ead675f | ||
|
|
d3df2b60f0 | ||
|
|
930d3282e5 |
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,3 +1,3 @@
|
||||
[submodule "application"]
|
||||
path = application
|
||||
url = http://192.168.2.20:8015/root/application
|
||||
url = http://130.185.77.247:31300/gitea_admin/application
|
||||
|
||||
Binary file not shown.
Submodule application updated: bfd802911d...84e5df6078
@@ -13,6 +13,8 @@ import (
|
||||
|
||||
"github.com/argoproj/argo-cd/v2/pkg/apiclient"
|
||||
"github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
|
||||
clusterapi "github.com/argoproj/argo-cd/v2/pkg/apiclient/cluster"
|
||||
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
|
||||
argoprojv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@@ -61,8 +63,8 @@ var (
|
||||
|
||||
func InitializeClient() {
|
||||
once.Do(func() {
|
||||
argocdServer := "192.168.2.172:32200"
|
||||
argocdToken := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhcmdvY2QiLCJzdWIiOiJhZG1pbjphcGlLZXkiLCJuYmYiOjE3NDM4NTAwNzIsImlhdCI6MTc0Mzg1MDA3MiwianRpIjoiNWZhNmQ5MDgtMzljNi00ZWQ4LWE5YzgtMzI4YzMzYjkyNzk4In0.ZvhJk4L5vBQldtJyReKYXCQCWF8j8gHLZlY8PninSFA"
|
||||
argocdServer := "argocd.bugx.ir"
|
||||
argocdToken := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhcmdvY2QiLCJzdWIiOiJhZG1pbjphcGlLZXkiLCJuYmYiOjE3NjMxMzQ3NzEsImlhdCI6MTc2MzEzNDc3MSwianRpIjoiNDVkMmViYmYtMDYzNC00MTFlLTk4ODctMjMzMmJjMGFjNDkxIn0.UgQ7oIWzrsP7mCaN8Tfd7wrcFQ7Ew6wYFQHevMIGflw"
|
||||
|
||||
config := apiclient.ClientOptions{
|
||||
ServerAddr: argocdServer,
|
||||
@@ -105,10 +107,10 @@ func CreateApp(objectID string, clustername string, ControlPlane string, Platfor
|
||||
app := ApplicationValues{
|
||||
Name: uniqueClusterName,
|
||||
Namespace: namespace,
|
||||
Path: "vcluster-0.21.1",
|
||||
Cluster: "bugx",
|
||||
Path: "vcluster-0.28.0",
|
||||
Cluster: "in-cluster",
|
||||
Server: "https://kubernetes.default.svc",
|
||||
RepoURL: "http://192.168.2.20:8015/root/application.git",
|
||||
RepoURL: "https://git.bugx.ir/gitea_admin/application.git",
|
||||
UserID: userID,
|
||||
}
|
||||
|
||||
@@ -271,15 +273,89 @@ func updateConfig(objectID string, configStrings string, namespace string) {
|
||||
"$set": bson.M{
|
||||
"cluster_config": configStrings,
|
||||
"namespace": namespace,
|
||||
"EndPoine": "https://" + namespace + ".bugx.ir",
|
||||
},
|
||||
}
|
||||
|
||||
_, err = db.Vclusters_details.UpdateOne(context.TODO(), filter, update)
|
||||
RegisterToArgo(configStrings, namespace)
|
||||
if err != nil {
|
||||
fmt.Println("update cluster config error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
func RegisterToArgo(kubeConfigString string, namespace string) {
|
||||
|
||||
// ArgoCD server
|
||||
argocdServer := "argocd.bugx.ir"
|
||||
argocdToken := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhcmdvY2QiLCJzdWIiOiJhZG1pbjphcGlLZXkiLCJuYmYiOjE3NjMxMzQ3NzEsImlhdCI6MTc2MzEzNDc3MSwianRpIjoiNDVkMmViYmYtMDYzNC00MTFlLTk4ODctMjMzMmJjMGFjNDkxIn0.UgQ7oIWzrsP7mCaN8Tfd7wrcFQ7Ew6wYFQHevMIGflw"
|
||||
|
||||
// Context name that must exist in kubeconfig
|
||||
clusterContext := "kubernetes-super-admin@kubernetes"
|
||||
|
||||
decoded, err := base64.StdEncoding.DecodeString(kubeConfigString)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// ---- Load kubeconfig of the target cluster ----
|
||||
cfg, err := clientcmd.Load([]byte(decoded))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ctx := cfg.Contexts[clusterContext]
|
||||
if ctx == nil {
|
||||
panic("cluster context not found in kubeconfig")
|
||||
}
|
||||
|
||||
// Real cluster data
|
||||
cluster := cfg.Clusters[ctx.Cluster]
|
||||
user := cfg.AuthInfos[ctx.AuthInfo]
|
||||
|
||||
// ---- Create ArgoCD API client ----
|
||||
clientOpts := apiclient.ClientOptions{
|
||||
ServerAddr: argocdServer,
|
||||
AuthToken: argocdToken,
|
||||
Insecure: false,
|
||||
}
|
||||
|
||||
argocdClient, err := apiclient.NewClient(&clientOpts)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
closer, clusterIf, err := argocdClient.NewClusterClient()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer closer.Close()
|
||||
|
||||
// ---- Build the correct request type ----
|
||||
req := &clusterapi.ClusterCreateRequest{
|
||||
Cluster: &v1alpha1.Cluster{
|
||||
Name: namespace + clusterContext,
|
||||
Server: cluster.Server,
|
||||
Config: v1alpha1.ClusterConfig{
|
||||
BearerToken: user.Token,
|
||||
TLSClientConfig: v1alpha1.TLSClientConfig{
|
||||
CAData: cluster.CertificateAuthorityData,
|
||||
Insecure: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// ---- Register cluster to ArgoCD ----
|
||||
createdCluster, err := clusterIf.Create(context.Background(), req)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Cluster registered:", createdCluster.Name)
|
||||
|
||||
}
|
||||
|
||||
func SyncApp(objectID string, appName string, cluster string, namesname string) {
|
||||
|
||||
InitializeClient()
|
||||
@@ -365,6 +441,7 @@ func ListUserClusters(userID string) (error, []Clusters) {
|
||||
Name: app.Name,
|
||||
Status: string(app.Status.Health.Status),
|
||||
ClusterID: strings.Split(string(app.ObjectMeta.UID), "-")[0],
|
||||
EndPoint: "https://" + app.Spec.Destination.Namespace + ".bugx.ir",
|
||||
}
|
||||
clusters = append(clusters, newCluster)
|
||||
}
|
||||
|
||||
7
db/db.go
7
db/db.go
@@ -9,12 +9,12 @@ 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() {
|
||||
clientOptions := options.Client().ApplyURI("mongodb://root:example@localhost:27017/")
|
||||
clientOptions := options.Client().ApplyURI("mongodb://root:secret123@130.185.77.247:32669/")
|
||||
client, err := mongo.Connect(context.TODO(), clientOptions)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
6
go.mod
6
go.mod
@@ -6,12 +6,15 @@ require (
|
||||
github.com/argoproj/argo-cd/v2 v2.13.3
|
||||
github.com/golang-jwt/jwt/v4 v4.5.1
|
||||
github.com/gorilla/mux v1.7.3
|
||||
github.com/hibiken/asynq v0.25.1
|
||||
github.com/rs/cors v1.11.0
|
||||
golang.org/x/crypto v0.32.0
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
k8s.io/api v0.31.0
|
||||
k8s.io/apimachinery v0.31.0
|
||||
k8s.io/client-go v0.31.0
|
||||
k8s.io/kubectl v0.31.2
|
||||
sigs.k8s.io/yaml v1.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -59,6 +62,7 @@ require (
|
||||
github.com/redis/go-redis/v9 v9.7.0 // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
github.com/spf13/cast v1.7.0 // indirect
|
||||
github.com/spf13/cobra v1.8.1 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/x448/float16 v0.8.4 // indirect
|
||||
@@ -87,7 +91,6 @@ require (
|
||||
google.golang.org/grpc v1.69.4 // indirect
|
||||
google.golang.org/protobuf v1.36.3 // indirect
|
||||
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
k8s.io/apiextensions-apiserver v0.31.2 // indirect
|
||||
k8s.io/apiserver v0.31.0 // indirect
|
||||
@@ -96,7 +99,6 @@ require (
|
||||
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
|
||||
oras.land/oras-go/v2 v2.5.0 // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.4-0.20241211184406-7bf59b3d70ee // indirect
|
||||
sigs.k8s.io/yaml v1.4.0 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
6
go.sum
6
go.sum
@@ -112,6 +112,8 @@ github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4Nij
|
||||
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
|
||||
@@ -243,6 +245,8 @@ github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB1
|
||||
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
|
||||
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
|
||||
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
|
||||
github.com/hibiken/asynq v0.25.1 h1:phj028N0nm15n8O2ims+IvJ2gz4k2auvermngh9JhTw=
|
||||
github.com/hibiken/asynq v0.25.1/go.mod h1:pazWNOLBu0FEynQRBvHA26qdIKRSmfdIfUm4HdsLmXg=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw=
|
||||
@@ -428,6 +432,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/skeema/knownhosts v1.3.0 h1:AM+y0rI04VksttfwjkSTNQorvGqmwATnvnAHpSgc0LY=
|
||||
github.com/skeema/knownhosts v1.3.0/go.mod h1:sPINvnADmT/qYH1kfv+ePMmOBTH6Tbl7b5LvTDjFK7M=
|
||||
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
|
||||
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
||||
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
|
||||
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
|
||||
|
||||
2643
handler/handler.go
2643
handler/handler.go
File diff suppressed because it is too large
Load Diff
22
handler/worker.go
Normal file
22
handler/worker.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"log"
|
||||
"main/jobs"
|
||||
|
||||
"github.com/hibiken/asynq"
|
||||
)
|
||||
|
||||
func startWorkerHelmInstaller() {
|
||||
srv := asynq.NewServer(
|
||||
asynq.RedisClientOpt{Addr: "130.185.77.247:30828", Password: "xwy8ahx46F"},
|
||||
asynq.Config{Concurrency: 5},
|
||||
)
|
||||
|
||||
mux := asynq.NewServeMux()
|
||||
mux.HandleFunc(jobs.TypeInstallChart, jobs.HandleInstallCahrt)
|
||||
|
||||
if err := srv.Run(mux); err != nil {
|
||||
log.Fatalf("Could not run worker: %v", err)
|
||||
}
|
||||
}
|
||||
174
jobs/helminstall.go
Normal file
174
jobs/helminstall.go
Normal file
@@ -0,0 +1,174 @@
|
||||
package jobs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/hibiken/asynq"
|
||||
)
|
||||
|
||||
const (
|
||||
TypeInstallChart = "chart:install"
|
||||
)
|
||||
|
||||
type InstallChartPayload struct {
|
||||
ChartName string
|
||||
Version string
|
||||
Namespace string
|
||||
UserID string
|
||||
Release string
|
||||
Repo string
|
||||
KubeConfig string
|
||||
}
|
||||
|
||||
func NewInstallCahrtTask(chartname, version, ns, userID string, release string, kubeconfig string) *asynq.Task {
|
||||
payload, _ := json.Marshal(InstallChartPayload{
|
||||
ChartName: chartname,
|
||||
Version: version,
|
||||
Namespace: ns,
|
||||
UserID: userID,
|
||||
Release: release,
|
||||
KubeConfig: kubeconfig,
|
||||
})
|
||||
|
||||
return asynq.NewTask(TypeInstallChart, payload)
|
||||
}
|
||||
|
||||
func HandleInstallCahrt(ctx context.Context, t *asynq.Task) error {
|
||||
var payload InstallChartPayload
|
||||
if err := json.Unmarshal(t.Payload(), &payload); err != nil {
|
||||
return fmt.Errorf("Faild to parse payload: %w", err)
|
||||
}
|
||||
|
||||
// Write kubeconfig to temp file
|
||||
tmpFile, err := os.CreateTemp("", "kubeconfig-*.yaml")
|
||||
if err != nil {
|
||||
//http.Error(w, "Failed to create temp file: "+err.Error(), http.StatusInternalServerError)
|
||||
return err
|
||||
}
|
||||
defer os.Remove(tmpFile.Name())
|
||||
|
||||
if _, err := tmpFile.WriteString(payload.KubeConfig); err != nil {
|
||||
//http.Error(w, "Failed to write kubeconfig: "+err.Error(), http.StatusInternalServerError)
|
||||
return err
|
||||
}
|
||||
tmpFile.Close()
|
||||
|
||||
// settings := cli.New()
|
||||
// settings.KubeConfig = tmpFile.Name()
|
||||
// repoName := payload.ChartName
|
||||
// repoURL := "http://130.185.77.247:31300/gitea_admin/application/src/branch/main/backing-services"
|
||||
// username := "gitea_admin"
|
||||
// password := "Tips123$"
|
||||
|
||||
// // Add the Helm repo
|
||||
// repoFile := settings.RepositoryConfig
|
||||
// repoCache := settings.RepositoryCache
|
||||
// entry := &repo.Entry{
|
||||
// Name: repoName,
|
||||
// URL: repoURL,
|
||||
// Username: username,
|
||||
// Password: password,
|
||||
// }
|
||||
// chartRepo, err := repo.NewChartRepository(entry, getter.All(settings))
|
||||
// if err != nil {
|
||||
// fmt.Printf("Faild to connect to repository, %s", err)
|
||||
// }
|
||||
// _, err = chartRepo.DownloadIndexFile()
|
||||
// if err != nil {
|
||||
// fmt.Println("Failed to connect to repo: %v", err)
|
||||
// }
|
||||
|
||||
// fmt.Println("✅ Connected to Helm repo successfully")
|
||||
|
||||
// // Save to repositories.yaml
|
||||
// file, err := repo.LoadFile(repoFile)
|
||||
// if os.IsNotExist(err) {
|
||||
// file = repo.NewFile()
|
||||
// }
|
||||
// file.Update(entry)
|
||||
// if err := file.WriteFile(repoFile, 0644); err != nil {
|
||||
// fmt.Printf("%s", err)
|
||||
// }
|
||||
|
||||
// // Create Helm install client
|
||||
// actionConfig := new(action.Configuration)
|
||||
// if err := actionConfig.Init(settings.RESTClientGetter(), "default", os.Getenv("HELM_DRIVER"), func(format string, v ...interface{}) {}); err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
|
||||
// install := action.NewInstall(actionConfig)
|
||||
// install.ReleaseName = "mysql"
|
||||
// install.Namespace = "default"
|
||||
// install.RepoURL = repoURL
|
||||
// install.ChartPathOptions.RepoURL = repoURL
|
||||
// install.ChartPathOptions.Username = username
|
||||
// install.ChartPathOptions.Password = password
|
||||
|
||||
// // Chart name
|
||||
// chartName := fmt.Sprintf("%s/mysql", repoName)
|
||||
|
||||
// // Load values (optional)
|
||||
// valOpts := &values.Options{}
|
||||
// vals, err := valOpts.MergeValues(getter.All(settings))
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
|
||||
// // Run the install
|
||||
// cp, err := install.ChartPathOptions.LocateChart(chartName, settings)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
|
||||
// rel, err := install.RunWithContext(context.Background(), cp, vals)
|
||||
// if err != nil {
|
||||
// panic(fmt.Sprintf("Helm install failed: %v", err))
|
||||
// }
|
||||
|
||||
// fmt.Printf("✅ Helm chart '%s' installed successfully: %s\n", rel.Name, rel.Info.Status)
|
||||
// // Add repo if not exists
|
||||
// cmd := exec.Command("helm", "repo", "add", "temp-repo", req.Repo)
|
||||
// cmd.Env = append(os.Environ(), "KUBECONFIG="+tmpFile.Name())
|
||||
// output, err := cmd.CombinedOutput()
|
||||
// if err != nil && !strings.Contains(string(output), "already exists") {
|
||||
// http.Error(w, "Failed to add helm repo: "+string(output), http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
|
||||
// // Update repo
|
||||
// cmd = exec.Command("helm", "repo", "update")
|
||||
// cmd.Env = append(os.Environ(), "KUBECONFIG="+tmpFile.Name())
|
||||
// output, err = cmd.CombinedOutput()
|
||||
// if err != nil {
|
||||
// http.Error(w, "Failed to update helm repo: "+string(output), http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
|
||||
// // Install chart
|
||||
// cmd = exec.Command("helm", "install", req.Release, req.Chart, "--namespace", req.Namespace, "--create-namespace")
|
||||
// cmd.Env = append(os.Environ(), "KUBECONFIG="+tmpFile.Name())
|
||||
// output, err = cmd.CombinedOutput()
|
||||
// if err != nil {
|
||||
// http.Error(w, "Failed to install helm chart: "+string(output), http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
|
||||
log.Printf("[Job] Installing chart %s Release %s in namespace %s", payload.ChartName, payload.Release, payload.Namespace)
|
||||
log.Printf("[Job] Validating Chart ... ")
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
log.Printf("[Job] Creating resources ...")
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
log.Printf("[Job] Wating for pods ...")
|
||||
time.Sleep(2 * time.Second)
|
||||
log.Printf("[Job] Finilizing installation ...")
|
||||
log.Printf("[Job] chart %s installed successfully", payload.ChartName)
|
||||
return nil
|
||||
|
||||
}
|
||||
51
main.go
51
main.go
@@ -59,7 +59,6 @@ func registerHnadler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var existUser User
|
||||
_ = db.UserCollection.FindOne(context.TODO(), bson.M{"email": user.Email}).Decode(&existUser)
|
||||
|
||||
if existUser.Email == user.Email {
|
||||
http.Error(w, `{"message": "User already registered"}`, http.StatusUnauthorized)
|
||||
return
|
||||
@@ -122,16 +121,23 @@ func main() {
|
||||
|
||||
db.InitDB()
|
||||
router := mux.NewRouter()
|
||||
|
||||
router.HandleFunc("/register", registerHnadler)
|
||||
router.HandleFunc("/login", loginHandler)
|
||||
router.HandleFunc("/createcluster", handler.CreateClusterHandler)
|
||||
router.HandleFunc("/deletecluster", handler.Deletecluster)
|
||||
router.HandleFunc("/clusters", handler.ListUserClusters)
|
||||
router.HandleFunc("/cluster_stats", handler.ClusterStats)
|
||||
router.HandleFunc("/cluster_resource_usage", handler.Cluster_resource_usage)
|
||||
router.HandleFunc("/cluster_health", handler.Cluster_health)
|
||||
router.HandleFunc("/cluster_uptime", handler.Cluster_uptime)
|
||||
router.HandleFunc("/cluster_performance", handler.Cluster_performance)
|
||||
router.HandleFunc("/cluster_events", handler.Cluster_events)
|
||||
router.HandleFunc("/connect", handler.Connect)
|
||||
// router.HandleFunc("/cluster_nodes", handler.Cluster_nodes)
|
||||
router.HandleFunc("/cluster_namespaces", handler.Cluster_namespaces)
|
||||
router.HandleFunc("/cluster_services", handler.Cluster_services)
|
||||
router.HandleFunc("/cluster_configmap", handler.Cluster_configmap)
|
||||
router.HandleFunc("/cluster_secret", handler.Cluster_secret)
|
||||
router.HandleFunc("/cluster_deployments", handler.Cluster_deployments)
|
||||
router.HandleFunc("/cluster_pods", handler.Cluster_pods)
|
||||
router.HandleFunc("/cluster_statefulset", handler.Cluster_statefulset)
|
||||
@@ -139,19 +145,56 @@ func main() {
|
||||
|
||||
router.HandleFunc("/cluster_jobs", handler.Cluster_jobs)
|
||||
router.HandleFunc("/cluster_replicasets", handler.Cluster_replicasets)
|
||||
router.HandleFunc("/replicaset_delete", handler.Replicaset_delete)
|
||||
router.HandleFunc("/cluster_replicationcontrollers", handler.Cluster_replicationcontrollers)
|
||||
|
||||
router.HandleFunc("/deployment_manifest", handler.Deployment_manifest)
|
||||
router.HandleFunc("/daemonsets_manifest", handler.DaemonSet_manifest)
|
||||
router.HandleFunc("/statefulset_manifest", handler.StatefulSet_manifest)
|
||||
router.HandleFunc("/replicationcontroller_manifest", handler.Replicationcontroller_manifest)
|
||||
router.HandleFunc("/deployment_rollout", handler.Deployment_rollout)
|
||||
router.HandleFunc("/daemonsets_rollout", handler.DaemonSet_rollout)
|
||||
router.HandleFunc("/deployment_scale", handler.Deployment_scale)
|
||||
router.HandleFunc("/replicaset_scale", handler.ReplicaSet_scale)
|
||||
router.HandleFunc("/statefulset_scale", handler.StatefulSet_scale)
|
||||
router.HandleFunc("/replicationcontroller_scale", handler.Replicationcontroller_scale)
|
||||
router.HandleFunc("/statefulset_rollout", handler.StatefulSet_rollout)
|
||||
router.HandleFunc("/pod_logs", handler.Pod_logs)
|
||||
router.HandleFunc("/pod_manifest", handler.Pod_manifest)
|
||||
router.HandleFunc("/replicaset_manifest", handler.Replicaset_manifest)
|
||||
router.HandleFunc("/jobs_manifest", handler.Jobs_manifest)
|
||||
router.HandleFunc("/cronjobs_manifest", handler.CronJobs_manifest)
|
||||
router.HandleFunc("/configmap_manifest", handler.ConfigMap_manifest)
|
||||
router.HandleFunc("/secret_manifest", handler.Secret_manifest)
|
||||
router.HandleFunc("/service_manifest", handler.Service_manifest)
|
||||
router.HandleFunc("/cronjobs_trigger", handler.Cronjobs_trigger)
|
||||
router.HandleFunc("/cronjobs_suspend", handler.Cronjobs_suspend)
|
||||
router.HandleFunc("/jobs_logs", handler.Jobs_logs)
|
||||
router.HandleFunc("/pod_create", handler.Pod_fromYaml)
|
||||
router.HandleFunc("/deployment_create", handler.Deployment_fromYaml)
|
||||
router.HandleFunc("/daemonsets_create", handler.DaemonSet_fromYaml)
|
||||
router.HandleFunc("/jobs_create", handler.Job_fromYaml)
|
||||
router.HandleFunc("/statefulset_create", handler.StatefulSet_fromYaml)
|
||||
router.HandleFunc("/configmap_create", handler.ConfigMap_fromYaml)
|
||||
router.HandleFunc("/secret_create", handler.Secret_fromYaml)
|
||||
router.HandleFunc("/service_create", handler.Service_fromYaml)
|
||||
router.HandleFunc("/pod_exec", handler.Pod_exec)
|
||||
router.HandleFunc("/pod_delete", handler.Pod_delete)
|
||||
router.HandleFunc("/service_delete", handler.Service_delete)
|
||||
router.HandleFunc("/configmap_delete", handler.Configmap_delete)
|
||||
router.HandleFunc("/secret_delete", handler.Secret_delete)
|
||||
router.HandleFunc("/deployment_delete", handler.Deployment_delete)
|
||||
router.HandleFunc("/statefulSet_delete", handler.StatefulSet_delete)
|
||||
router.HandleFunc("/daemonsets_delete", handler.Daemonsets_delete)
|
||||
router.HandleFunc("/jobsName_delete", handler.JobsName_delete)
|
||||
router.HandleFunc("/replicaset_delete", handler.Replicaset_delete)
|
||||
router.HandleFunc("/replicationcontroller_delete", handler.Replicationcontroller_delete)
|
||||
router.HandleFunc("/cronjob_delete", handler.Cronjob_delete)
|
||||
router.HandleFunc("/cronjobs_delete", handler.Cronjob_delete)
|
||||
router.HandleFunc("/cronjobs_create", handler.CronJob_fromYaml)
|
||||
router.HandleFunc("/cluster_cronjobs", handler.Cluster_cronjobs)
|
||||
router.HandleFunc("/replicationcontroller_create", handler.ReplicationController_fromYaml)
|
||||
router.HandleFunc("/replicationcontroller_migrate", handler.Replicationcontroller_migrate)
|
||||
router.HandleFunc("/helm_install", handler.Helm_install)
|
||||
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"`
|
||||
@@ -14,24 +16,45 @@ type Cluster struct {
|
||||
Name string `json:"name"`
|
||||
Namespace string `json:"namespace"`
|
||||
ControlPlane string `json:"controlPlane"`
|
||||
PlatformVersion string `json:"platformversion`
|
||||
PlatformVersion string `json:"platformversion"`
|
||||
Cpu string `json:"cpu"`
|
||||
Memory string `json:"memory"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UserID primitive.ObjectID `json:"userId"`
|
||||
Cluster_config string `json:"clusterconfig"`
|
||||
EndPoint string `json:"endPoint"`
|
||||
}
|
||||
|
||||
type Header struct {
|
||||
Authorization string `bson:"token"`
|
||||
}
|
||||
|
||||
type Namespace struct {
|
||||
Name string `json:name`
|
||||
Status string `json:status`
|
||||
Age string `json:age`
|
||||
}
|
||||
|
||||
type PodLog struct {
|
||||
Podname string `json:name`
|
||||
Namespace string `json:namespace`
|
||||
Clustername string `json:clustername`
|
||||
Manifest string `json:clustername`
|
||||
Replicasetname string `json:replicasetname`
|
||||
Statefulset string `json:Statefulset`
|
||||
Daemonsetsname string `json:Daemonsetsname`
|
||||
}
|
||||
|
||||
type Pod struct {
|
||||
Name string `json:name`
|
||||
Namespace string `json:name`
|
||||
Namespace string `json:namespace`
|
||||
Status string `json:status`
|
||||
Restart int32 `json:restart`
|
||||
Age string `json:age`
|
||||
Ready string `json:ready`
|
||||
Restarts int32 `json:restars`
|
||||
Ip string `json:ip`
|
||||
Node string `json:node`
|
||||
Image string `json:iamge`
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
@@ -45,12 +68,17 @@ type Service struct {
|
||||
}
|
||||
|
||||
type Deployment struct {
|
||||
Name string `json:name`
|
||||
Namespace string `json:namespace`
|
||||
Available string `json:available`
|
||||
Replicas int32 `json:replicas`
|
||||
Message string `json:message`
|
||||
Reason string `json:reason`
|
||||
Name string `json:name`
|
||||
Namespace string `json:namespace`
|
||||
Available string `json:available`
|
||||
Replicas int32 `json:replicas`
|
||||
Message string `json:message`
|
||||
Reason string `json:reason`
|
||||
Ready string `json:ready`
|
||||
UpdateToDate int32 `json:uptodate`
|
||||
Age string `json:age`
|
||||
Image string `json:iamge`
|
||||
Strategy string `json:iamge`
|
||||
}
|
||||
|
||||
type Daemonset struct {
|
||||
@@ -75,6 +103,16 @@ type Jobs struct {
|
||||
Age string `json:age`
|
||||
}
|
||||
|
||||
type CronJob struct {
|
||||
Name string `json:name`
|
||||
Namespace string `json:namespace`
|
||||
Schedule string `json:schedule`
|
||||
Suspend bool `json:suspend`
|
||||
Active int `json:active`
|
||||
LastScheduleTime string `json:lastScheduleTime`
|
||||
Age string `json:age`
|
||||
}
|
||||
|
||||
type Replicaset struct {
|
||||
Name string `json:name`
|
||||
Desired int32 `json:desired`
|
||||
@@ -99,3 +137,121 @@ 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`
|
||||
}
|
||||
|
||||
type ClusterStats struct {
|
||||
ResourceUsage ResourceUsage `json:"resourceUsage"`
|
||||
Performance Performance `json:"performance"`
|
||||
Health Health `json:"health"`
|
||||
Uptime Uptime `json:"uptime"`
|
||||
Name string `json:"name"`
|
||||
ClusterId string `json:"clusterId"`
|
||||
Status string `json:"status"`
|
||||
Version string `json:"version"`
|
||||
Alerts string `json:"alerts"`
|
||||
Endpoint string `json:"endpoint"`
|
||||
}
|
||||
|
||||
type ResourceUsage struct {
|
||||
CPU Usage `json:"cpu"`
|
||||
Memory Usage `json:"memory"`
|
||||
Storage Usage `json:"storage"`
|
||||
Network Usage `json:"network"`
|
||||
}
|
||||
|
||||
type Usage struct {
|
||||
Used float64 `json:"used"`
|
||||
Total float64 `json:"total"`
|
||||
Unit string `json:"unit"`
|
||||
}
|
||||
|
||||
type Performance struct {
|
||||
PodStartupTime string `json:"podStartupTime"`
|
||||
APILatency string `json:"apiLatency"`
|
||||
EtcdLatency string `json:"etcdLatency"`
|
||||
SchedulerLatency string `json:"schedulerLatency"`
|
||||
}
|
||||
|
||||
type Health struct {
|
||||
NodesHealthy int `json:"nodesHealthy"`
|
||||
NodesTotal int `json:"nodesTotal"`
|
||||
PodsRunning int `json:"podsRunning"`
|
||||
PodsTotal int `json:"podsTotal"`
|
||||
Alerts int `json:"alerts"`
|
||||
Warnings int `json:"warnings"`
|
||||
Status string `json:"healthy"`
|
||||
}
|
||||
|
||||
type Uptime struct {
|
||||
ClusterUptime string `json:"clusterUptime"`
|
||||
LastMaintenance string `json:"lastMaintenance"`
|
||||
NextMaintenance string `json:"nextMaintenance"`
|
||||
}
|
||||
|
||||
type ReplicasetScaleReq struct {
|
||||
Clustername string `json:"Clustername"`
|
||||
Namespace string `json:"Namespace"`
|
||||
Replicasetname string `json:"Replicasetname"`
|
||||
Replicas int32 `json:"Replicas"`
|
||||
}
|
||||
|
||||
type ReplicasetRolloutReq struct {
|
||||
Clustername string `json:"Clustername"`
|
||||
Namespace string `json:"Namespace"`
|
||||
Replicasetname string `json:"Replicasetname"`
|
||||
Action string `json:"Action"` // "restart" | "status"
|
||||
}
|
||||
|
||||
type DeploymentScaleReq struct {
|
||||
Clustername string `json:"Clustername"`
|
||||
Namespace string `json:"Namespace"`
|
||||
Deployment string `json:"Deployment"`
|
||||
Replicas int32 `json:"Replicas"`
|
||||
}
|
||||
|
||||
type DeploymentRolloutReq struct {
|
||||
Clustername string `json:"Clustername"`
|
||||
Namespace string `json:"Namespace"`
|
||||
Deployment string `json:"Deployment"`
|
||||
Action string `json:"Action"` // "restart" | "status"
|
||||
}
|
||||
|
||||
type DeamonSetsRolloutReq struct {
|
||||
Clustername string `json:"Clustername"`
|
||||
Namespace string `json:"Namespace"`
|
||||
Daemonsetsname string `json:"Daemonsetsname"`
|
||||
Action string `json:"Action"` // "restart" | "status"
|
||||
}
|
||||
|
||||
type StatefulsetRolloutReq struct {
|
||||
Clustername string `json:"Clustername"`
|
||||
Namespace string `json:"Namespace"`
|
||||
Statefulset string `json:"Statefulset"`
|
||||
Action string `json:"Action"` // "restart" | "status"
|
||||
Replicas int32 `json:"Replicas"`
|
||||
}
|
||||
|
||||
type DeploymentRolloutStatus struct {
|
||||
Deployment string `json:"deployment"`
|
||||
Namespace string `json:"namespace"`
|
||||
ObservedGeneration int64 `json:"observedGeneration"`
|
||||
Replicas int32 `json:"replicas"`
|
||||
UpdatedReplicas int32 `json:"updatedReplicas"`
|
||||
ReadyReplicas int32 `json:"readyReplicas"`
|
||||
AvailableReplicas int32 `json:"availableReplicas"`
|
||||
UnavailableReplicas int32 `json:"unavailableReplicas"`
|
||||
ConditionProgressing string `json:"conditionProgressing,omitempty"`
|
||||
ConditionAvailable string `json:"conditionAvailable,omitempty"`
|
||||
}
|
||||
|
||||
type DeploymentRolloutResp struct {
|
||||
Clustername string `json:"cluster"`
|
||||
Message string `json:"message"`
|
||||
Status *DeploymentRolloutStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user