Skip to content

Commit

Permalink
feat: supports some offline deployment methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangSetSail committed Dec 12, 2023
1 parent b045e89 commit bfd7c09
Show file tree
Hide file tree
Showing 33 changed files with 787 additions and 321 deletions.
5 changes: 5 additions & 0 deletions api/api/api_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ type HelmInterface interface {
CheckHelmApp(w http.ResponseWriter, r *http.Request)
GetChartInformation(w http.ResponseWriter, r *http.Request)
GetYamlByChart(w http.ResponseWriter, r *http.Request)
GetUploadChartInformation(w http.ResponseWriter, r *http.Request)
CheckUploadChart(w http.ResponseWriter, r *http.Request)
GetUploadChartResource(w http.ResponseWriter, r *http.Request)
ImportUploadChartResource(w http.ResponseWriter, r *http.Request)
GetUploadChartValue(w http.ResponseWriter, r *http.Request)
}

// ServiceInterface ServiceInterface
Expand Down
7 changes: 7 additions & 0 deletions api/api_routers/version2/v2Routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func (v2 *V2) helmRouter() chi.Router {
r.Get("/check_helm_app", controller.GetManager().CheckHelmApp)
r.Get("/get_chart_information", controller.GetManager().GetChartInformation)
r.Get("/get_chart_yaml", controller.GetManager().GetYamlByChart)
r.Get("/get_upload_chart_information", controller.GetManager().GetUploadChartInformation)
r.Post("/check_upload_chart", controller.GetManager().CheckUploadChart)
r.Get("/get_upload_chart_resource", controller.GetManager().GetUploadChartResource)
r.Post("/import_upload_chart_resource", controller.GetManager().ImportUploadChartResource)
r.Get("/get_upload_chart_value", controller.GetManager().GetUploadChartValue)
return r
}

Expand Down Expand Up @@ -173,6 +178,8 @@ func (v2 *V2) tenantNameRouter() chi.Router {
//代码检测
r.Post("/code-check", controller.GetManager().CheckCode)
r.Post("/servicecheck", controller.Check)
r.Get("/image-repositories", controller.RegistryImageRepositories)
r.Get("/image-tags", controller.RegistryImageTags)
r.Get("/servicecheck/{uuid}", controller.GetServiceCheckInfo)
r.Get("/resources", controller.GetManager().SingleTenantResources)
r.Get("/services", controller.GetManager().ServicesInfo)
Expand Down
6 changes: 3 additions & 3 deletions api/controller/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (c *ClusterController) MavenSettingDetail(w http.ResponseWriter, r *http.Re
httputil.ReturnSuccess(r, w, setting)
}

//BatchGetGateway batch get resource gateway
// BatchGetGateway batch get resource gateway
func (c *ClusterController) BatchGetGateway(w http.ResponseWriter, r *http.Request) {
ns, err := handler.GetClusterHandler().BatchGetGateway(r.Context())
if err != nil {
Expand Down Expand Up @@ -241,7 +241,7 @@ func (c *ClusterController) DeleteResource(w http.ResponseWriter, r *http.Reques
httputil.ReturnSuccess(r, w, nil)
}

//BatchDeleteResource -
// BatchDeleteResource -
func (c *ClusterController) BatchDeleteResource(w http.ResponseWriter, r *http.Request) {
var req model.SyncResources
if ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &req, nil); !ok {
Expand Down Expand Up @@ -338,7 +338,7 @@ func (c *ClusterController) YamlResourceImport(w http.ResponseWriter, r *http.Re
err.Handle(r, w)
return
}
ac, err := handler.GetClusterHandler().AppYamlResourceImport(yr, ar)
ac, err := handler.GetClusterHandler().AppYamlResourceImport(yr.Namespace, yr.TenantID, yr.AppID, ar)
if err != nil {
err.Handle(r, w)
return
Expand Down
73 changes: 69 additions & 4 deletions api/controller/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"net/http"
)

//HelmStruct -
// HelmStruct -
type HelmStruct struct {
}

//CheckHelmApp check helm app
// CheckHelmApp check helm app
func (t *HelmStruct) CheckHelmApp(w http.ResponseWriter, r *http.Request) {
var checkHelmApp api_model.CheckHelmApp
if ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &checkHelmApp, nil); !ok {
Expand All @@ -40,7 +40,7 @@ func (t *HelmStruct) CheckHelmApp(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, data)
}

//GetChartInformation get helm chart details
// GetChartInformation get helm chart details
func (t *HelmStruct) GetChartInformation(w http.ResponseWriter, r *http.Request) {
var chart api_model.ChartInformation
if ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &chart, nil); !ok {
Expand All @@ -54,7 +54,7 @@ func (t *HelmStruct) GetChartInformation(w http.ResponseWriter, r *http.Request)
httputil.ReturnSuccess(r, w, chartVersion)
}

//GetYamlByChart -
// GetYamlByChart -
func (t *HelmStruct) GetYamlByChart(w http.ResponseWriter, r *http.Request) {
var yc api_model.GetYamlByChart
if ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &yc, nil); !ok {
Expand All @@ -74,3 +74,68 @@ func (t *HelmStruct) GetYamlByChart(w http.ResponseWriter, r *http.Request) {
data["yaml"] = yaml
httputil.ReturnSuccess(r, w, data)
}

// GetUploadChartInformation -
func (t *HelmStruct) GetUploadChartInformation(w http.ResponseWriter, r *http.Request) {
eventID := r.FormValue("event_id")
data, err := handler.GetHelmManager().GetUploadChartInformation(eventID)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
}
httputil.ReturnSuccess(r, w, data)
}

// CheckUploadChart -
func (t *HelmStruct) CheckUploadChart(w http.ResponseWriter, r *http.Request) {
var cuc api_model.UploadChart
if ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &cuc, nil); !ok {
return
}
data := map[string]string{"checkAdopt": "true"}
err := handler.GetHelmManager().CheckUploadChart(cuc.Name, cuc.Version, cuc.Namespace, cuc.EventID)
if err != nil {
data["checkAdopt"] = "false"
data["yaml"] = err.Error()
}
httputil.ReturnSuccess(r, w, data)
}

// GetUploadChartValue -
func (t *HelmStruct) GetUploadChartValue(w http.ResponseWriter, r *http.Request) {
eventID := r.FormValue("event_id")
valueYaml, err := handler.GetHelmManager().GetUploadChartValue(eventID)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
}
httputil.ReturnSuccess(r, w, valueYaml)
}

// GetUploadChartResource -
func (t *HelmStruct) GetUploadChartResource(w http.ResponseWriter, r *http.Request) {
var cuc api_model.UploadChart
if ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &cuc, nil); !ok {
return
}
chartResources, err := handler.GetHelmManager().GetUploadChartResource(cuc.Name, cuc.Version, cuc.Namespace, cuc.EventID, cuc.Overrides)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return
}
httputil.ReturnSuccess(r, w, chartResources)
}

// ImportUploadChartResource -
func (t *HelmStruct) ImportUploadChartResource(w http.ResponseWriter, r *http.Request) {
var uci api_model.UploadChartImport
if ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &uci, nil); !ok {
return
}
ac, err := handler.GetClusterHandler().AppYamlResourceImport(uci.Namespace, uci.TenantID, uci.AppID, uci.AR)
if err != nil {
err.Handle(r, w)
return
}
httputil.ReturnSuccess(r, w, ac)
}
29 changes: 29 additions & 0 deletions api/controller/registry_image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package controller

import (
"github.com/goodrain/rainbond/api/handler"
httputil "github.com/goodrain/rainbond/util/http"
"net/http"
)

// RegistryImageRepositories -
func RegistryImageRepositories(w http.ResponseWriter, r *http.Request) {
namespace := r.FormValue("namespace")
repositories, err := handler.GetServiceManager().RegistryImageRepositories(namespace)
if err != nil {
err.Handle(r, w)
return
}
httputil.ReturnSuccess(r, w, repositories)
}

// RegistryImageTags -
func RegistryImageTags(w http.ResponseWriter, r *http.Request) {
repository := r.FormValue("repository")
tags, err := handler.GetServiceManager().RegistryImageTags(repository)
if err != nil {
err.Handle(r, w)
return
}
httputil.ReturnSuccess(r, w, tags)
}
2 changes: 1 addition & 1 deletion api/handler/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type ClusterHandler interface {
SyncAppK8SResources(ctx context.Context, resources *model.SyncResources) ([]*dbmodel.K8sResource, *util.APIHandleError)
AppYamlResourceName(yamlResource model.YamlResource) (map[string]model.LabelResource, *util.APIHandleError)
AppYamlResourceDetailed(yamlResource model.YamlResource, yamlImport bool) (model.ApplicationResource, *util.APIHandleError)
AppYamlResourceImport(yamlResource model.YamlResource, components model.ApplicationResource) (model.AppComponent, *util.APIHandleError)
AppYamlResourceImport(namespace, tenantID, appID string, components model.ApplicationResource) (model.AppComponent, *util.APIHandleError)
RbdLog(w http.ResponseWriter, r *http.Request, podName string, follow bool) error
GetRbdPods() (rbds []model.RbdResp, err error)
CreateShellPod(regionName string) (pod *corev1.Pod, err error)
Expand Down
10 changes: 5 additions & 5 deletions api/handler/covert_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"strings"
)

//ConvertResource 处理资源
// ConvertResource 处理资源
func (c *clusterAction) ConvertResource(ctx context.Context, namespace string, lr map[string]model.LabelResource) (map[string]model.ApplicationResource, *util.APIHandleError) {
logrus.Infof("ConvertResource function begin")
appsServices := make(map[string]model.ApplicationResource)
Expand Down Expand Up @@ -72,7 +72,7 @@ func (c *clusterAction) workloadDeployments(dmNames []string, namespace string)
Name: dmName,
RsLabel: resources.Labels,
}
c.PodTemplateSpecResource(parameter, nil)
PodTemplateSpecResource(parameter, nil, c.clientset)
}
return componentsCR
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func (c *clusterAction) workloadStateFulSets(stsNames []string, namespace string
Name: stsName,
RsLabel: resources.Labels,
}
c.PodTemplateSpecResource(parameter, resources.Spec.VolumeClaimTemplates)
PodTemplateSpecResource(parameter, resources.Spec.VolumeClaimTemplates, c.clientset)
}
return componentsCR
}
Expand Down Expand Up @@ -167,7 +167,7 @@ func (c *clusterAction) workloadJobs(jobNames []string, namespace string) []mode
Name: jobName,
RsLabel: resources.Labels,
}
c.PodTemplateSpecResource(parameter, nil)
PodTemplateSpecResource(parameter, nil, c.clientset)
}
return componentsCR
}
Expand Down Expand Up @@ -225,7 +225,7 @@ func (c *clusterAction) workloadCronJobs(cjNames []string, namespace string) []m
Name: cjName,
RsLabel: resources.Labels,
}
c.PodTemplateSpecResource(parameter, nil)
PodTemplateSpecResource(parameter, nil, c.clientset)
}
return componentsCR
}
Expand Down
6 changes: 4 additions & 2 deletions api/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
api_db "github.com/goodrain/rainbond/api/db"
"github.com/goodrain/rainbond/api/handler/group"
"github.com/goodrain/rainbond/api/handler/share"
"github.com/goodrain/rainbond/builder/sources/registry"
"github.com/goodrain/rainbond/cmd/api/option"
"github.com/goodrain/rainbond/db"
"github.com/goodrain/rainbond/pkg/generated/clientset/versioned"
Expand Down Expand Up @@ -52,6 +53,7 @@ func InitHandle(conf option.Config,
dynamicClient dynamic.Interface,
gatewayClient *gateway.GatewayV1beta1Client,
kubevirtCli kubecli.KubevirtClient,
registryCli *registry.Registry,
) error {
mq := api_db.MQManager{
EtcdClientArgs: etcdClientArgs,
Expand All @@ -70,11 +72,11 @@ func InitHandle(conf option.Config,
return err
}
dbmanager := db.GetManager()
defaultServieHandler = CreateManager(conf, mqClient, etcdcli, statusCli, prometheusCli, rainbondClient, kubeClient, kubevirtCli, dbmanager)
defaultServieHandler = CreateManager(conf, mqClient, etcdcli, statusCli, prometheusCli, rainbondClient, kubeClient, kubevirtCli, dbmanager, registryCli)
defaultPluginHandler = CreatePluginManager(mqClient)
defaultAppHandler = CreateAppManager(mqClient)
defaultTenantHandler = CreateTenManager(mqClient, statusCli, &conf, kubeClient, prometheusCli, k8sClient)
defaultHelmHandler = CreateHelmManager(kubeClient, rainbondClient)
defaultHelmHandler = CreateHelmManager(kubeClient, rainbondClient, config, mapper)
defaultNetRulesHandler = CreateNetRulesManager(etcdcli)
defaultCloudHandler = CreateCloudManager(conf)
defaultAPPBackupHandler = group.CreateBackupHandle(mqClient, statusCli, etcdcli)
Expand Down
Loading

0 comments on commit bfd7c09

Please sign in to comment.