Compare commits

...

10 Commits

Author SHA1 Message Date
behrooz
fbc48792bf init 2025-11-02 13:00:11 +03:30
behrooz
44c75b2f5c add more features 2025-09-27 17:01:54 +03:30
behrooz
98481d56eb add online mongodb 2025-09-04 20:13:40 +03:30
behrooz
08d17a33ea fix 2025-09-03 16:48:20 +03:30
Ybehrooz
b82db8e0b1 fix stats 2025-08-31 19:35:41 +03:30
Ybehrooz
06b7aaa548 fix issues 2025-08-30 20:08:19 +03:30
behrooz
36a36a232f fix kubeconfig issue 2025-08-27 18:00:14 +03:30
Ybehrooz
821ead675f add worker ndoes 2025-08-26 19:52:27 +03:30
behrooz
d3df2b60f0 argo 2025-08-18 12:44:52 +03:30
behrooz
930d3282e5 fix token issue 2025-08-15 18:25:29 +03:30
7 changed files with 2853 additions and 57 deletions

Binary file not shown.

View File

@@ -61,8 +61,8 @@ var (
func InitializeClient() { func InitializeClient() {
once.Do(func() { once.Do(func() {
argocdServer := "192.168.2.172:32200" argocdServer := "130.185.77.247:30966"
argocdToken := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhcmdvY2QiLCJzdWIiOiJhZG1pbjphcGlLZXkiLCJuYmYiOjE3NDM4NTAwNzIsImlhdCI6MTc0Mzg1MDA3MiwianRpIjoiNWZhNmQ5MDgtMzljNi00ZWQ4LWE5YzgtMzI4YzMzYjkyNzk4In0.ZvhJk4L5vBQldtJyReKYXCQCWF8j8gHLZlY8PninSFA" argocdToken := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhcmdvY2QiLCJzdWIiOiJhZG1pbjphcGlLZXkiLCJuYmYiOjE3NjAwMjE1NjAsImlhdCI6MTc2MDAyMTU2MCwianRpIjoiZTdjMzMyNWQtZDU0Yy00M2Q0LWIzOGYtYjc3NGQ4OTcxZGZmIn0.35lU-UOwl3XxjvqEfnEXIhaVoug90-J2WWj5x0OihC0"
config := apiclient.ClientOptions{ config := apiclient.ClientOptions{
ServerAddr: argocdServer, ServerAddr: argocdServer,
@@ -105,10 +105,10 @@ func CreateApp(objectID string, clustername string, ControlPlane string, Platfor
app := ApplicationValues{ app := ApplicationValues{
Name: uniqueClusterName, Name: uniqueClusterName,
Namespace: namespace, Namespace: namespace,
Path: "vcluster-0.21.1", Path: "vcluster-0.28.0",
Cluster: "bugx", Cluster: "in-cluster",
Server: "https://kubernetes.default.svc", Server: "https://kubernetes.default.svc",
RepoURL: "http://192.168.2.20:8015/root/application.git", RepoURL: "http://130.185.77.247:31300/gitea_admin/application.git",
UserID: userID, UserID: userID,
} }
@@ -271,6 +271,7 @@ func updateConfig(objectID string, configStrings string, namespace string) {
"$set": bson.M{ "$set": bson.M{
"cluster_config": configStrings, "cluster_config": configStrings,
"namespace": namespace, "namespace": namespace,
"EndPoine": "https://" + namespace + ".bugx.ir",
}, },
} }
@@ -365,6 +366,7 @@ func ListUserClusters(userID string) (error, []Clusters) {
Name: app.Name, Name: app.Name,
Status: string(app.Status.Health.Status), Status: string(app.Status.Health.Status),
ClusterID: strings.Split(string(app.ObjectMeta.UID), "-")[0], ClusterID: strings.Split(string(app.ObjectMeta.UID), "-")[0],
EndPoint: "https://" + app.Spec.Destination.Namespace + ".bugx.ir",
} }
clusters = append(clusters, newCluster) clusters = append(clusters, newCluster)
} }

View File

@@ -10,11 +10,11 @@ import (
var ( var (
Client *mongo.Client Client *mongo.Client
UserCollection, Vclusters_details, Host_cluster_details *mongo.Collection UserCollection, Vclusters_details, Host_cluster_details, Worker_nodes_plan *mongo.Collection
) )
func InitDB() { 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) client, err := mongo.Connect(context.TODO(), clientOptions)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@@ -23,4 +23,5 @@ func InitDB() {
UserCollection = client.Database("vcluster").Collection("users") UserCollection = client.Database("vcluster").Collection("users")
Vclusters_details = client.Database("vcluster").Collection("vclusters_details") Vclusters_details = client.Database("vcluster").Collection("vclusters_details")
Host_cluster_details = client.Database("vcluster").Collection("hostdetail") Host_cluster_details = client.Database("vcluster").Collection("hostdetail")
Worker_nodes_plan = client.Database("vcluster").Collection("worker_nodes_plans")
} }

File diff suppressed because it is too large Load Diff

49
main.go
View File

@@ -128,10 +128,18 @@ func main() {
router.HandleFunc("/createcluster", handler.CreateClusterHandler) router.HandleFunc("/createcluster", handler.CreateClusterHandler)
router.HandleFunc("/deletecluster", handler.Deletecluster) router.HandleFunc("/deletecluster", handler.Deletecluster)
router.HandleFunc("/clusters", handler.ListUserClusters) 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("/connect", handler.Connect)
// router.HandleFunc("/cluster_nodes", handler.Cluster_nodes) // router.HandleFunc("/cluster_nodes", handler.Cluster_nodes)
router.HandleFunc("/cluster_namespaces", handler.Cluster_namespaces) router.HandleFunc("/cluster_namespaces", handler.Cluster_namespaces)
router.HandleFunc("/cluster_services", handler.Cluster_services) 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_deployments", handler.Cluster_deployments)
router.HandleFunc("/cluster_pods", handler.Cluster_pods) router.HandleFunc("/cluster_pods", handler.Cluster_pods)
router.HandleFunc("/cluster_statefulset", handler.Cluster_statefulset) router.HandleFunc("/cluster_statefulset", handler.Cluster_statefulset)
@@ -139,19 +147,56 @@ func main() {
router.HandleFunc("/cluster_jobs", handler.Cluster_jobs) router.HandleFunc("/cluster_jobs", handler.Cluster_jobs)
router.HandleFunc("/cluster_replicasets", handler.Cluster_replicasets) router.HandleFunc("/cluster_replicasets", handler.Cluster_replicasets)
router.HandleFunc("/replicaset_delete", handler.Replicaset_delete)
router.HandleFunc("/cluster_replicationcontrollers", handler.Cluster_replicationcontrollers) 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_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_exec", handler.Pod_exec)
router.HandleFunc("/pod_delete", handler.Pod_delete) router.HandleFunc("/pod_delete", handler.Pod_delete)
router.HandleFunc("/service_delete", handler.Service_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("/deployment_delete", handler.Deployment_delete)
router.HandleFunc("/statefulSet_delete", handler.StatefulSet_delete) router.HandleFunc("/statefulSet_delete", handler.StatefulSet_delete)
router.HandleFunc("/daemonsets_delete", handler.Daemonsets_delete) router.HandleFunc("/daemonsets_delete", handler.Daemonsets_delete)
router.HandleFunc("/jobsName_delete", handler.JobsName_delete) router.HandleFunc("/jobsName_delete", handler.JobsName_delete)
router.HandleFunc("/replicaset_delete", handler.Replicaset_delete)
router.HandleFunc("/replicationcontroller_delete", handler.Replicationcontroller_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) //handler.RegsiterClusterRoute(router)
// Enable CORS // Enable CORS
// c := cors.New(cors.Options{ // c := cors.New(cors.Options{

View File

@@ -1,6 +1,8 @@
package models package models
import "go.mongodb.org/mongo-driver/bson/primitive" import (
"go.mongodb.org/mongo-driver/bson/primitive"
)
type User struct { type User struct {
ID string `json:"id,omitempty"` ID string `json:"id,omitempty"`
@@ -14,24 +16,45 @@ type Cluster struct {
Name string `json:"name"` Name string `json:"name"`
Namespace string `json:"namespace"` Namespace string `json:"namespace"`
ControlPlane string `json:"controlPlane"` ControlPlane string `json:"controlPlane"`
PlatformVersion string `json:"platformversion` PlatformVersion string `json:"platformversion"`
Cpu string `json:"cpu"` Cpu string `json:"cpu"`
Memory string `json:"memory"` Memory string `json:"memory"`
CreatedAt string `json:"createdAt"` CreatedAt string `json:"createdAt"`
UserID primitive.ObjectID `json:"userId"` UserID primitive.ObjectID `json:"userId"`
Cluster_config string `json:"clusterconfig"` Cluster_config string `json:"clusterconfig"`
EndPoint string `json:"endPoint"`
} }
type Header struct { type Header struct {
Authorization string `bson:"token"` 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 { type Pod struct {
Name string `json:name` Name string `json:name`
Namespace string `json:name` Namespace string `json:namespace`
Status string `json:status` Status string `json:status`
Restart int32 `json:restart`
Age string `json:age` 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 { type Service struct {
@@ -51,6 +74,11 @@ type Deployment struct {
Replicas int32 `json:replicas` Replicas int32 `json:replicas`
Message string `json:message` Message string `json:message`
Reason string `json:reason` 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 { type Daemonset struct {
@@ -75,6 +103,16 @@ type Jobs struct {
Age string `json:age` 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 { type Replicaset struct {
Name string `json:name` Name string `json:name`
Desired int32 `json:desired` Desired int32 `json:desired`
@@ -99,3 +137,121 @@ type StatefulSet struct {
Ready string `json:Ready` Ready string `json:Ready`
Age string `json:age` 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"`
}