Skip to content

Commit 3e1a6f0

Browse files
erda-botiutx
andauthored
feature: cmp import cluster use single chart (#1516) (#1519)
Co-authored-by: Asher Liu <[email protected]>
1 parent 3348d59 commit 3e1a6f0

File tree

19 files changed

+361
-649
lines changed

19 files changed

+361
-649
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import (
1818
"github.com/erda-project/erda/pkg/common"
1919

2020
_ "github.com/erda-project/erda-infra/providers"
21-
_ "github.com/erda-project/erda/modules/cluster-init"
21+
_ "github.com/erda-project/erda/modules/cluster-ops"
2222
)
2323

2424
func main() {
2525
common.Run(&servicehub.RunOptions{
26-
ConfigFile: "conf/cluster-init/cluster-init.yaml",
26+
ConfigFile: "conf/cluster-ops/cluster-ops.yaml",
2727
})
2828
}

conf/cluster-init/cluster-init.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.

conf/cluster-ops/cluster-ops.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cluster-ops:

modules/cluster-init/config/config.go

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,14 @@ import (
2525
"k8s.io/client-go/rest"
2626

2727
"github.com/erda-project/erda/bundle"
28-
"github.com/erda-project/erda/modules/cluster-init/config"
28+
"github.com/erda-project/erda/modules/cluster-ops/config"
2929
erdahelm "github.com/erda-project/erda/pkg/helm"
3030
kc "github.com/erda-project/erda/pkg/k8sclient/config"
3131
)
3232

3333
const (
3434
defaultRepoName = "stable"
3535
InstallModeRemote = "REMOTE"
36-
RepoModeRemote = "REMOTE"
37-
RepoModeLocal = "LOCAL"
38-
LocalRepoPath = "/app/charts"
39-
ErdaBaseCharts = "erda-base"
40-
ErdaAddonsCharts = "erda-addons"
4136
ErdaCharts = "erda"
4237
)
4338

@@ -65,7 +60,7 @@ func WithConfig(cfg *config.Config) Option {
6560
func (c *Client) Execute() error {
6661
logrus.Debugf("load config: %+v", c.config)
6762

68-
opts, err := c.newHelmClientOptions()
63+
opts, err := c.genHelmClientOptions()
6964
if err != nil {
7065
return fmt.Errorf("get helm client error: %v", err)
7166
}
@@ -75,14 +70,16 @@ func (c *Client) Execute() error {
7570
return err
7671
}
7772

78-
switch strings.ToUpper(c.config.RepoMode) {
79-
case RepoModeRemote:
80-
// TODO: support repo auth info.
81-
e := &repo.Entry{Name: defaultRepoName, URL: c.config.RepoURL}
73+
// TODO: support repo auth info.
74+
e := &repo.Entry{
75+
Name: defaultRepoName,
76+
URL: c.config.RepoURL,
77+
Username: c.config.RepoUsername,
78+
Password: c.config.RepoPassword,
79+
}
8280

83-
if err = hc.AddOrUpdateRepo(e); err != nil {
84-
return err
85-
}
81+
if err = hc.AddOrUpdateRepo(e); err != nil {
82+
return err
8683
}
8784

8885
if c.config.Reinstall {
@@ -96,7 +93,8 @@ func (c *Client) Execute() error {
9693
LocalRepoName: defaultRepoName,
9794
}
9895

99-
if err := m.Execute(); err != nil {
96+
if err = m.Execute(); err != nil {
97+
logrus.Errorf("execute uninstall error: %v", err)
10098
return err
10199
}
102100
}
@@ -107,13 +105,14 @@ func (c *Client) Execute() error {
107105
LocalRepoName: defaultRepoName,
108106
}
109107

110-
if err := m.Execute(); err != nil {
108+
if err = m.Execute(); err != nil {
109+
logrus.Errorf("execute error: %v", err)
111110
return err
112111
}
113112

114113
// Label node only local mode
115114
// TODO: support label remote with rest.config
116-
if strings.ToUpper(c.config.RepoMode) != InstallModeRemote {
115+
if strings.ToUpper(c.config.InstallMode) != InstallModeRemote {
117116
rc, err := rest.InClusterConfig()
118117
if err != nil {
119118
logrus.Errorf("get incluster rest config error: %v", err)
@@ -153,8 +152,8 @@ func (c *Client) Execute() error {
153152
return nil
154153
}
155154

156-
// newHelmClientOptions create helm client options
157-
func (c *Client) newHelmClientOptions() ([]erdahelm.Option, error) {
155+
// genHelmClientOptions create helm client options
156+
func (c *Client) genHelmClientOptions() ([]erdahelm.Option, error) {
158157
opts := make([]erdahelm.Option, 0)
159158

160159
switch strings.ToUpper(c.config.InstallMode) {
@@ -173,36 +172,17 @@ func (c *Client) newHelmClientOptions() ([]erdahelm.Option, error) {
173172
opts = append(opts, erdahelm.WithRESTClientGetter(erdahelm.NewRESTClientGetterImpl(rc)))
174173
}
175174

176-
switch strings.ToUpper(c.config.RepoMode) {
177-
case RepoModeLocal:
178-
opts = append(opts, erdahelm.WithLocalChartDiscoverDir(LocalRepoPath))
179-
}
180-
181175
return opts, nil
182176
}
183177

184178
func (c *Client) getInitCharts() []*erdahelm.ChartSpec {
185179
return []*erdahelm.ChartSpec{
186-
{
187-
ReleaseName: ErdaBaseCharts,
188-
ChartName: ErdaBaseCharts,
189-
Version: c.config.Version,
190-
Action: erdahelm.ActionInstall,
191-
Values: c.config.ChartErdaBaseValues,
192-
},
193-
{
194-
ReleaseName: ErdaAddonsCharts,
195-
ChartName: ErdaAddonsCharts,
196-
Version: c.config.Version,
197-
Action: erdahelm.ActionInstall,
198-
Values: c.config.ChartErdaAddonsValues,
199-
},
200180
{
201181
ReleaseName: ErdaCharts,
202182
ChartName: ErdaCharts,
203183
Version: c.config.Version,
204184
Action: erdahelm.ActionInstall,
205-
Values: c.config.ChartErdaValues,
185+
Values: c.config.SetValues,
206186
},
207187
}
208188
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2021 Terminus, Inc.
2+
//
3+
// This program is free software: you can use, redistribute, and/or modify
4+
// it under the terms of the GNU Affero General Public License, version 3
5+
// or later ("AGPL"), as published by the Free Software Foundation.
6+
//
7+
// This program is distributed in the hope that it will be useful, but WITHOUT
8+
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9+
// FITNESS FOR A PARTICULAR PURPOSE.
10+
//
11+
// You should have received a copy of the GNU Affero General Public License
12+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
13+
14+
package config
15+
16+
type Config struct {
17+
Debug bool `env:"DEBUG" default:"false" desc:"enable debug logging"`
18+
RepoURL string `env:"HELM_REPO_URL" desc:"helm repo url"`
19+
RepoUsername string `env:"HELM_REPO_USERNAME" desc:"helm repo url"`
20+
RepoPassword string `env:"HELM_REPO_PASSWORD" desc:"helm repo url"`
21+
Reinstall bool `env:"REINSTALL" default:"false" desc:"reinstall erda comp"`
22+
Version string `env:"ERDA_CHART_VERSION" desc:"erda chart version"`
23+
SetValues string `env:"ERDA_CHART_VALUES" desc:"provide erda values"`
24+
InstallMode string `env:"INSTALL_MODE" default:"local" desc:"install mode, remote or local"`
25+
TargetCluster string `env:"TARGET_CLUSTER" desc:"special when CREDENTIAL_FROM=CLUSTER_MANAGER"`
26+
NodeLabels string `env:"NODE_LABELS" desc:"node labels after install erda"`
27+
// HELM_NAMESPACE: helm deploy namespace
28+
// HELM_REPO_URL: helm repo address
29+
// HELM_REPOSITORY_CONFIG: helm repository store path
30+
// HELM_REPOSITORY_CACHE: helm charts cache path
31+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"github.com/sirupsen/logrus"
2121

2222
"github.com/erda-project/erda-infra/base/servicehub"
23-
"github.com/erda-project/erda/modules/cluster-init/client"
24-
"github.com/erda-project/erda/modules/cluster-init/config"
23+
"github.com/erda-project/erda/modules/cluster-ops/client"
24+
"github.com/erda-project/erda/modules/cluster-ops/config"
2525
)
2626

2727
type provider struct {
@@ -43,9 +43,9 @@ func (p *provider) Run(ctx context.Context) error {
4343
}
4444

4545
func init() {
46-
servicehub.Register("cluster-init", &servicehub.Spec{
47-
Services: []string{"cluster-init"},
48-
Description: "cluster init",
46+
servicehub.Register("cluster-ops", &servicehub.Spec{
47+
Services: []string{"cluster-ops"},
48+
Description: "cluster ops",
4949
ConfigFunc: func() interface{} {
5050
return &config.Config{}
5151
},

modules/cmp/conf/conf.go

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@ type Conf struct {
4141
OryKratosAddr string `default:"kratos:4433" env:"KRATOS_ADDR"`
4242
OryKratosPrivateAddr string `default:"kratos:4434" env:"KRATOS_PRIVATE_ADDR"`
4343

44-
ErdaNamespace string `default:"erda-system" env:"ERDA_NAMESPACE"`
45-
ErdaHelmChartVersion string `default:"0.1.0" env:"ERDA_HELM_CHART_VERSION"`
46-
ReleaseRepo string `default:"registry.erda.cloud/erda" env:"RELEASE_REPO"`
47-
DialerPublicAddr string `env:"CLUSTER_DIALER_PUBLIC_ADDR"`
44+
ReleaseRegistry string `env:"RELEASE_REGISTRY" default:"registry.erda.cloud/erda"`
45+
ClusterInitVersion string `env:"CLUSTER_INIT_VERSION" default:"0.1"`
46+
47+
HelmChartRepoURL string `env:"HELM_REPO_URL"`
48+
HelmChartRepoUserName string `env:"HELM_REPO_USERNAME"`
49+
HelmChartRepoPassword string `env:"HELM_REPO_PASSWORD"`
50+
51+
ErdaNamespace string `env:"DICE_NAMESPACE" default:"erda-system"`
52+
ErdaVersion string `env:"DICE_VERSION"`
53+
ErdaProtocol string `env:"DICE_PROTOCOL"`
54+
ErdaClusterName string `env:"DICE_CLUSTER_NAME"`
55+
ErdaDomain string `env:"DICE_ROOT_DOMAIN"`
4856
}
4957

5058
var cfg Conf
@@ -59,16 +67,6 @@ func ListenAddr() string {
5967
return cfg.ListenAddr
6068
}
6169

62-
// SoldierAddr return the address of soldier.
63-
func SoldierAddr() string {
64-
return cfg.SoldierAddr
65-
}
66-
67-
// SchedulerAddr Return the address of scheduler.
68-
func SchedulerAddr() string {
69-
return cfg.SchedulerAddr
70-
}
71-
7270
// Debug Return the switch of debug.
7371
func Debug() bool {
7472
return cfg.Debug
@@ -136,18 +134,42 @@ func OryCompatibleClientSecret() string {
136134
return ""
137135
}
138136

137+
func ReleaseRegistry() string {
138+
return cfg.ReleaseRegistry
139+
}
140+
141+
func ClusterInitVersion() string {
142+
return cfg.ClusterInitVersion
143+
}
144+
145+
func HelmRepoURL() string {
146+
return cfg.HelmChartRepoURL
147+
}
148+
149+
func HelmRepoUsername() string {
150+
return cfg.HelmChartRepoUserName
151+
}
152+
153+
func HelmRepoPassword() string {
154+
return cfg.HelmChartRepoPassword
155+
}
156+
139157
func ErdaNamespace() string {
140158
return cfg.ErdaNamespace
141159
}
142160

143-
func ErdaHelmChartVersion() string {
144-
return cfg.ErdaHelmChartVersion
161+
func ErdaVersion() string {
162+
return cfg.ErdaVersion
163+
}
164+
165+
func ErdaProtocol() string {
166+
return cfg.ErdaProtocol
145167
}
146168

147-
func ReleaseRepo() string {
148-
return cfg.ReleaseRepo
169+
func ErdaClusterName() string {
170+
return cfg.ErdaClusterName
149171
}
150172

151-
func DialerPublicAddr() string {
152-
return cfg.DialerPublicAddr
173+
func ErdaDomain() string {
174+
return cfg.ErdaDomain
153175
}

modules/cmp/endpoints/cluster.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -535,18 +535,3 @@ func (e *Endpoints) InitCluster(ctx context.Context, w http.ResponseWriter, r *h
535535

536536
return nil
537537
}
538-
539-
func (e *Endpoints) ClusterHook(ctx context.Context, r *http.Request, vars map[string]string) (resp httpserver.Responser, err error) {
540-
req := apistructs.ClusterEvent{}
541-
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
542-
errstr := fmt.Sprintf("decode clusterhook request fail: %v", err)
543-
logrus.Error(errstr)
544-
return httpserver.HTTPResponse{Status: http.StatusBadRequest, Content: errstr}, nil
545-
}
546-
if err := e.clusters.Hook(&req); err != nil {
547-
errstr := fmt.Sprintf("failed to handle cluster event: %v", err)
548-
logrus.Error(errstr)
549-
return httpserver.HTTPResponse{Status: http.StatusInternalServerError, Content: errstr}, nil
550-
}
551-
return httpserver.HTTPResponse{Status: http.StatusOK}, nil
552-
}

0 commit comments

Comments
 (0)