From d98f2eea1da4e1a3334c4f67c81f7e70985d3a13 Mon Sep 17 00:00:00 2001 From: zhangsetsail Date: Wed, 2 Aug 2023 14:52:28 +0800 Subject: [PATCH 1/3] fix: export schema does not match import --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f84495729d..93e07b95d8 100644 --- a/go.mod +++ b/go.mod @@ -299,7 +299,7 @@ replace ( github.com/docker/docker => github.com/docker/docker v20.10.2+incompatible github.com/envoyproxy/go-control-plane => github.com/envoyproxy/go-control-plane v0.9.5 github.com/godbus/dbus => github.com/godbus/dbus/v5 v5.0.4 - github.com/goodrain/rainbond-oam => github.com/goodrain/rainbond-oam v0.0.0-20230117125005-98bcc9233a7f + github.com/goodrain/rainbond-oam => github.com/goodrain/rainbond-oam v0.0.0-20230614023629-d4b302e90dfa github.com/prometheus/common => github.com/prometheus/common v0.15.0 google.golang.org/grpc => google.golang.org/grpc v1.27.1 helm.sh/helm/v3 => helm.sh/helm/v3 v3.9.0 diff --git a/go.sum b/go.sum index b36252a475..db2178bb47 100644 --- a/go.sum +++ b/go.sum @@ -870,8 +870,8 @@ github.com/gomodule/redigo v1.8.2 h1:H5XSIre1MB5NbPYFp+i1NBbb5qN1W8Y8YAQoAYbkm8k github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= github.com/goodrain/gorm-bulk-upsert v1.0.1-0.20210608013724-7e7870d16357 h1:kdSSrpA5yNvgqbfpMlEr8bvQWiLc1Uz9g0vYf3JVT7s= github.com/goodrain/gorm-bulk-upsert v1.0.1-0.20210608013724-7e7870d16357/go.mod h1:b7/GgeVNbf/SFw4FYIWslxNV5I10C9Mhf/++3jsDk3M= -github.com/goodrain/rainbond-oam v0.0.0-20230117125005-98bcc9233a7f h1:lP3vUduSD4YlyznmmMkeZW4icM4zNZR7daEdXhqw3uk= -github.com/goodrain/rainbond-oam v0.0.0-20230117125005-98bcc9233a7f/go.mod h1:LVLCqKFl0n+huV8Q9f1yFNhcBvF9U4c/q5UQF9nba4A= +github.com/goodrain/rainbond-oam v0.0.0-20230614023629-d4b302e90dfa h1:/fqrFF8oyPUkvb+r8B1sRd0GHfmBkragUBPDv8t74wI= +github.com/goodrain/rainbond-oam v0.0.0-20230614023629-d4b302e90dfa/go.mod h1:LVLCqKFl0n+huV8Q9f1yFNhcBvF9U4c/q5UQF9nba4A= github.com/goodrain/rainbond-operator v1.3.1-0.20210401055914-f8fe4bf89a21 h1:iCPI96slvJv88iPc1NJW8zhpkiza0kwB0jtsuZIJLRQ= github.com/goodrain/rainbond-operator v1.3.1-0.20210401055914-f8fe4bf89a21/go.mod h1:jcQfNoxO67nkLalCmgihYrdWF82TKyuPW032tgGdqVY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= From 1a73ac996ee41b7aeaffcce621b52a52249aa560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=AF=E8=88=AA?= <101104760+ZhangSetSail@users.noreply.github.com> Date: Wed, 9 Aug 2023 15:45:31 +0800 Subject: [PATCH 2/3] fix: storage type created by sts is incorrect (#1737) --- worker/appm/volume/other.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/worker/appm/volume/other.go b/worker/appm/volume/other.go index 598a6642dc..6de5229982 100644 --- a/worker/appm/volume/other.go +++ b/worker/appm/volume/other.go @@ -65,18 +65,18 @@ func (v *OtherVolume) CreateVolume(define *Define) error { return "linux" }(), } - v.as.SetClaim(claim) // store claim to appService + v.as.SetClaim(claim) // store claim to appService + statefulset := v.as.GetStatefulSet() //有状态组件 vo := corev1.Volume{Name: volumeMountName} vo.PersistentVolumeClaim = &corev1.PersistentVolumeClaimVolumeSource{ClaimName: claim.GetName(), ReadOnly: volumeReadOnly} - define.volumes = append(define.volumes, vo) - if shareFile { - v.as.SetClaimManually(claim) + if statefulset != nil { + statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, *claim) + logrus.Debugf("stateset.Spec.VolumeClaimTemplates: %+v", statefulset.Spec.VolumeClaimTemplates) } else { - statefulset := v.as.GetStatefulSet() //有状态组件 - if statefulset != nil { - statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, *claim) - logrus.Debugf("stateset.Spec.VolumeClaimTemplates: %+v", statefulset.Spec.VolumeClaimTemplates) + if shareFile { + v.as.SetClaimManually(claim) } + define.volumes = append(define.volumes, vo) } vm := corev1.VolumeMount{ From b859881b497052b390c3c368c5cc0f34ac1c4af6 Mon Sep 17 00:00:00 2001 From: Quyc <94251049@qq.com> Date: Wed, 23 Aug 2023 16:42:19 +0800 Subject: [PATCH 3/3] perf: deploy helm app by upload chart (#1741) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 曲源成 --- api/api/api_interface.go | 1 + api/api_routers/version2/v2Routers.go | 1 + api/controller/app.go | 2 +- api/controller/helm.go | 21 +++++++++++++++++++++ api/handler/helm.go | 15 ++++++++++++--- api/handler/helmhandler.go | 1 + api/model/model.go | 9 +++++++++ pkg/helm/helm.go | 22 +++++++++++++--------- worker/master/controller/helmapp/app.go | 2 +- 9 files changed, 60 insertions(+), 14 deletions(-) diff --git a/api/api/api_interface.go b/api/api/api_interface.go index df73b116f1..f09011545d 100644 --- a/api/api/api_interface.go +++ b/api/api/api_interface.go @@ -96,6 +96,7 @@ type TenantInterface interface { type HelmInterface interface { CheckHelmApp(w http.ResponseWriter, r *http.Request) GetChartInformation(w http.ResponseWriter, r *http.Request) + GetYamlByChart(w http.ResponseWriter, r *http.Request) } // ServiceInterface ServiceInterface diff --git a/api/api_routers/version2/v2Routers.go b/api/api_routers/version2/v2Routers.go index 715dd8f93e..896b8aea35 100644 --- a/api/api_routers/version2/v2Routers.go +++ b/api/api_routers/version2/v2Routers.go @@ -70,6 +70,7 @@ func (v2 *V2) helmRouter() chi.Router { r := chi.NewRouter() r.Get("/check_helm_app", controller.GetManager().CheckHelmApp) r.Get("/get_chart_information", controller.GetManager().GetChartInformation) + r.Get("/get_chart_yaml", controller.GetManager().GetYamlByChart) return r } diff --git a/api/controller/app.go b/api/controller/app.go index e430e38a7d..c9246c64d6 100644 --- a/api/controller/app.go +++ b/api/controller/app.go @@ -128,7 +128,7 @@ func (a *AppStruct) ImportID(w http.ResponseWriter, r *http.Request) { continue } ex := filepath.Ext(dir.Name()) - if ex != ".zip" && ex != ".tar.gz" && ex != ".gz" { + if ex != ".zip" && ex != ".tar.gz" && ex != ".gz" && ex != ".tgz" { continue } appArr = append(appArr, dir.Name()) diff --git a/api/controller/helm.go b/api/controller/helm.go index d08b15956a..d1455a6f18 100644 --- a/api/controller/helm.go +++ b/api/controller/helm.go @@ -53,3 +53,24 @@ func (t *HelmStruct) GetChartInformation(w http.ResponseWriter, r *http.Request) } httputil.ReturnSuccess(r, w, chartVersion) } + +//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 { + return + } + data := map[string]string{"checkAdopt": "true"} + if yc.EventID == "" { + httputil.ReturnError(r, w, 400, "Failed to parse eventID.") + return + } + chartPath := fmt.Sprintf("%s/import/%s/%s", handler.GetAppHandler().GetStaticDir(), yc.EventID, yc.FileName) + yaml, err := handler.GetHelmManager().GetYamlByChart(chartPath, yc.Namespace, yc.Name, yc.Version, []string{}) + if err != nil { + data["checkAdopt"] = "false" + data["yaml"] = err.Error() + } + data["yaml"] = yaml + httputil.ReturnSuccess(r, w, data) +} diff --git a/api/handler/helm.go b/api/handler/helm.go index 42917d3388..a39e1a8ea1 100644 --- a/api/handler/helm.go +++ b/api/handler/helm.go @@ -94,7 +94,7 @@ func (h *HelmAction) GetChartInformation(chart api_model.ChartInformation) (*[]a // CheckHelmApp check helm app func (h *HelmAction) CheckHelmApp(checkHelmApp api_model.CheckHelmApp) (string, error) { - helmAppYaml, err := GetHelmAppYaml(checkHelmApp.Name, checkHelmApp.Chart, checkHelmApp.Version, checkHelmApp.Namespace, checkHelmApp.Overrides) + helmAppYaml, err := GetHelmAppYaml(checkHelmApp.Name, checkHelmApp.Chart, checkHelmApp.Version, checkHelmApp.Namespace, "", checkHelmApp.Overrides) if err != nil { return "", errors.Wrap(err, "helm app check failed") } @@ -121,14 +121,14 @@ func (h *HelmAction) AddHelmRepo(helmRepo api_model.CheckHelmApp) error { } //GetHelmAppYaml get helm app yaml -func GetHelmAppYaml(name, chart, version, namespace string, overrides []string) (string, error) { +func GetHelmAppYaml(name, chart, version, namespace, chartPath string, overrides []string) (string, error) { logrus.Info("get into GetHelmAppYaml function") helmCmd, err := helm.NewHelm(namespace, repoFile, repoCache) if err != nil { logrus.Errorf("Failed to create help client:%v", err) return "", err } - release, err := helmCmd.Install(name, chart, version, overrides) + release, err := helmCmd.Install(chartPath, name, chart, version, overrides) if err != nil { logrus.Errorf("helm --dry-run install failure: %v", err) return "", err @@ -150,3 +150,12 @@ func UpdateRepo(names string) error { } return nil } + +// GetYamlByChart get yaml by chart +func (h *HelmAction) GetYamlByChart(chartPath, namespace, name, version string, overrides []string) (string, error) { + helmAppYaml, err := GetHelmAppYaml(name, "", version, namespace, chartPath, overrides) + if err != nil { + return "", errors.Wrap(err, "helm app check failed") + } + return helmAppYaml, nil +} diff --git a/api/handler/helmhandler.go b/api/handler/helmhandler.go index b4c3c61798..4c64bb4739 100644 --- a/api/handler/helmhandler.go +++ b/api/handler/helmhandler.go @@ -11,4 +11,5 @@ type HelmHandler interface { CheckHelmApp(checkHelmApp api_model.CheckHelmApp) (string, error) GetChartInformation(chart api_model.ChartInformation) (*[]api_model.HelmChartInformation, *util.APIHandleError) UpdateHelmRepo(names string) error + GetYamlByChart(chartPath, namespace, name, version string, overrides []string) (string, error) } diff --git a/api/model/model.go b/api/model/model.go index 982aa5dffd..8005997257 100644 --- a/api/model/model.go +++ b/api/model/model.go @@ -525,6 +525,15 @@ type ChartInformation struct { ChartName string `json:"chart_name"` } +// GetYamlByChart - +type GetYamlByChart struct { + EventID string `json:"event_id"` + Name string `json:"name"` + FileName string `json:"file_name"` + Version string `json:"version"` + Namespace string `json:"namespace"` +} + const ( //CreateSuccess - CreateSuccess = 1 diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index 52f81cc2a7..81bd539491 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -96,13 +96,13 @@ func (h *Helm) UpdateRepo(names string) error { // PreInstall - func (h *Helm) PreInstall(name, chart, version string) error { - _, err := h.install(name, chart, version, nil, true, ioutil.Discard) + _, err := h.install(name, chart, version, "", nil, true, ioutil.Discard) return err } // Install - -func (h *Helm) Install(name, chart, version string, overrides []string) (*release.Release, error) { - release, err := h.install(name, chart, version, overrides, true, ioutil.Discard) +func (h *Helm) Install(chartPath, name, chart, version string, overrides []string) (*release.Release, error) { + release, err := h.install(name, chart, version, chartPath, overrides, true, ioutil.Discard) return release, err } @@ -171,7 +171,7 @@ func (h *Helm) getDigest(chart, version string) (string, error) { return "", errors.New(fmt.Sprintf("chart(%s) version(%s) not found", chart, version)) } -func (h *Helm) install(name, chart, version string, overrides []string, dryRun bool, out io.Writer) (*release.Release, error) { +func (h *Helm) install(name, chart, version, chartPath string, overrides []string, dryRun bool, out io.Writer) (*release.Release, error) { client := action.NewInstall(h.cfg) client.ReleaseName = name client.Namespace = h.namespace @@ -179,12 +179,16 @@ func (h *Helm) install(name, chart, version string, overrides []string, dryRun b client.DryRun = dryRun //client.IsUpgrade = true client.ClientOnly = true - - cp, err := h.locateChart(chart, version) - if err != nil { - return nil, err + var cp string + if chartPath != ""{ + cp = chartPath + } else { + res, err := h.locateChart(chart, version) + if err != nil { + return nil, err + } + cp = res } - logrus.Debugf("CHART PATH: %s\n", cp) p := getter.All(h.settings) diff --git a/worker/master/controller/helmapp/app.go b/worker/master/controller/helmapp/app.go index 237ebebb76..445825587c 100644 --- a/worker/master/controller/helmapp/app.go +++ b/worker/master/controller/helmapp/app.go @@ -305,7 +305,7 @@ func (a *App) installOrUpdate() error { if errors.Is(err, driver.ErrReleaseNotFound) { logrus.Debugf("name: %s; namespace: %s; chart: %s; install helm app", a.name, a.namespace, a.Chart()) - if _, err := a.helmCmd.Install(a.name, a.Chart(), a.version, a.overrides); err != nil { + if _, err := a.helmCmd.Install("", a.name, a.Chart(), a.version, a.overrides); err != nil { return err }