Skip to content

Commit b8ccdbb

Browse files
committed
Merge branch 'main' into fix-todolistid-empty
2 parents 66ae547 + ff40deb commit b8ccdbb

File tree

26 files changed

+485
-435
lines changed

26 files changed

+485
-435
lines changed

docs/best_practices/gitops.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22

33
## Plugins needed
44

5-
1. github-repo-scaffolding-golang
6-
2. jira-github
7-
3. githubactions-golang
8-
4. argocd
9-
5. argocdapp
5+
1. [github-repo-scaffolding-golang](../plugins/github-repo-scaffolding-golang_plugin.md)
6+
2. [jira-github](../plugins/jira-github-integ_plugin.md)
7+
3. [githubactions-golang](../plugins/githubactions-golang_plugin.md)
8+
4. [argocd](../plugins/argocd_plugin.md)
9+
5. [argocdapp](../plugins/argocdapp_plugin.md)
10+
11+
The dependencies of these plugins are(`a -> b` means for `a depends on b`):
12+
13+
- `jira-github` -> `github-repo-scaffolding-golang`
14+
- `githubactions-golang` -> `github-repo-scaffolding-golang`
15+
- `argocdapp` -> `argocd`
16+
17+
Note: These dependencies are not consistent, such as when the repo operated by `jira-github` and `github-repo-scaffolding-golang` are not the same, the dependencies disappear.
18+
19+
We should use the `dependency` according to the actual usage situation.
1020

1121
## Download DevStream (`dtm`)
1222

docs/plugins/argocdapp_plugin.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
This plugin creates an [ArgoCD Application](https://argo-cd.readthedocs.io/en/stable/core_concepts/) custom resource.
44

55
**Notes:**
6-
- ArgoCD itself must have been already installed before the usage of this plugin. To install ArgoCD, use the [argocd plugin](https://github.com/merico-dev/stream/blob/main/docs/argocd_plugin.md).
6+
- ArgoCD itself must have been already installed before the usage of this plugin.
7+
To install ArgoCD, use the [argocd plugin](../plugins/argocd_plugin.md).
8+
Or you can use both plugins(argocd+argocdapp) at the same time.
9+
See [GitOps Toolchain](../best_practices/gitops.md) for more info.
710
- Currently, only the Helm chart is supported when creating the ArgoCD application.
8-
- At the moment, DevStream doesn't support dependency or concurrency yet. So, in the config file, the ArgoCD app plugin must be placed _after_ the ArgoCD plugin if you want to install ArgoCD first then create the ArgoCD application.
9-
11+
- Modify the file accordingly. Especially remember to modify `ARGOCD_TOOL_NAME`.
1012
## 2 Usage:
1113

1214
```yaml
@@ -18,8 +20,8 @@ tools:
1820
# version of the plugin
1921
# checkout the version from the GitHub releases
2022
version: 0.2.0
21-
# optional; if specified, dtm will make sure the dependency is applied first before handling this tool.
22-
dependsOn: [ "TOOL1_NAME.TOOL1_KIND", "TOOL2_NAME.TOOL2_KIND" ]
23+
# if specified, dtm will make sure the dependency is applied first before handling this tool.
24+
dependsOn: [ "ARGOCD_TOOL_NAME.argocd" ]
2325
# options for the plugin
2426
options:
2527
# information on the ArgoCD Application

examples/gitops.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ tools:
2424
# version of the plugin
2525
# checkout the version from the GitHub releases
2626
version: 0.2.0
27+
# optional; if specified, dtm will make sure the dependency is applied first before handling this tool.
28+
dependsOn: [ "go-webapp-repo.github-repo-scaffolding-golang" ]
2729
# options for the plugin
2830
options:
2931
# the repo's owner
@@ -45,6 +47,8 @@ tools:
4547
# version of the plugin
4648
# checkout the version from the GitHub releases
4749
version: 0.2.0
50+
# optional; if specified, dtm will make sure the dependency is applied first before handling this tool.
51+
dependsOn: [ "go-webapp-repo.github-repo-scaffolding-golang" ]
4852
# options for the plugin
4953
options:
5054
# the repo's owner. It should be case-sensitive here; strictly use your GitHub user name; please change the value below.
@@ -79,7 +83,7 @@ tools:
7983
enable: False
8084
# dockerhub image repo; please change the value below.
8185
repo: YOUR_DOCKERHUB_IMAGE_REPO_NAME
82-
- name: argocd
86+
- name: argocd-dev
8387
plugin:
8488
# name of the plugin
8589
kind: argocd
@@ -115,6 +119,8 @@ tools:
115119
# version of the plugin
116120
# checkout the version from the GitHub releases
117121
version: 0.2.0
122+
# if specified, dtm will make sure the dependency is applied first before handling this tool.
123+
dependsOn: [ "argocd-dev.argocd" ]
118124
# options for the plugin
119125
options:
120126
# information on the ArgoCD application

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ require (
129129
github.com/modern-go/reflect2 v1.0.2 // indirect
130130
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
131131
github.com/morikuni/aec v1.0.0 // indirect
132-
github.com/onsi/ginkgo v1.16.5 // indirect
133132
github.com/opencontainers/go-digest v1.0.0 // indirect
134133
github.com/opencontainers/image-spec v1.0.1 // indirect
135134
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect

go.sum

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,9 +965,8 @@ github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+
965965
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
966966
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
967967
github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
968+
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
968969
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
969-
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
970-
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
971970
github.com/onsi/ginkgo/v2 v2.0.0 h1:CcuG/HvWNkkaqCUpJifQY8z7qEMBJya6aLPx6ftGyjQ=
972971
github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
973972
github.com/onsi/gomega v0.0.0-20151007035656-2152b45fa28a/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=

internal/pkg/plugin/argocd/create.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
"github.com/mitchellh/mapstructure"
77

88
. "github.com/merico-dev/stream/internal/pkg/plugin/common/helm"
9-
"github.com/merico-dev/stream/pkg/util/helm"
109
"github.com/merico-dev/stream/pkg/util/log"
1110
)
1211

1312
// Create creates ArgoCD with provided options.
1413
func Create(options map[string]interface{}) (map[string]interface{}, error) {
14+
// 1. decode options
1515
var param Param
1616
if err := mapstructure.Decode(options, &param); err != nil {
1717
return nil, err
@@ -24,6 +24,7 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) {
2424
return nil, fmt.Errorf("params are illegal")
2525
}
2626

27+
// 2. deal with ns
2728
if err := DealWithNsWhenInstall(&param); err != nil {
2829
return nil, err
2930
}
@@ -39,18 +40,12 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) {
3940
log.Debugf("Deal with namespace when interruption succeeded.")
4041
}()
4142

42-
var h *helm.Helm
43-
h, retErr = helm.NewHelm(param.GetHelmParam())
44-
if retErr != nil {
45-
return nil, retErr
46-
}
47-
48-
log.Info("Creating or updating argocd helm chart ...")
49-
if retErr = h.InstallOrUpgradeChart(); retErr != nil {
50-
log.Debugf("Failed to install or upgrade the Chart: %s.", retErr)
43+
// 3. install or upgrade
44+
if retErr = InstallOrUpgradeChart(&param); retErr != nil {
5145
return nil, retErr
5246
}
5347

48+
// 4. fill the return map
5449
retMap := GetStaticState().ToStringInterfaceMap()
5550
log.Debugf("Return map: %v", retMap)
5651

internal/pkg/plugin/argocd/state.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package argocd
33
import "github.com/merico-dev/stream/pkg/util/helm"
44

55
var DefaultDeploymentList = []string{
6-
"argocd-application-controller",
6+
"argocd-applicationset-controller",
77
"argocd-dex-server",
8+
"argocd-notifications-controller",
89
"argocd-redis",
910
"argocd-repo-server",
1011
"argocd-server",
Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
package argocd
22

33
import (
4-
"time"
4+
"fmt"
55

6+
"github.com/mitchellh/mapstructure"
7+
8+
. "github.com/merico-dev/stream/internal/pkg/plugin/common/helm"
69
"github.com/merico-dev/stream/pkg/util/log"
710
)
811

912
func Update(options map[string]interface{}) (map[string]interface{}, error) {
10-
_, err := Delete(options)
11-
if err != nil {
12-
log.Errorf("Failed to delete the ArgoCD: %s.", err)
13+
// 1. decode options
14+
var param Param
15+
if err := mapstructure.Decode(options, &param); err != nil {
1316
return nil, err
1417
}
1518

16-
<-time.NewTicker(3 * time.Second).C
17-
return Create(options)
19+
if errs := validate(&param); len(errs) != 0 {
20+
for _, e := range errs {
21+
log.Errorf("Param error: %s.", e)
22+
}
23+
return nil, fmt.Errorf("params are illegal")
24+
}
25+
26+
// 2. install or upgrade
27+
if err := InstallOrUpgradeChart(&param); err != nil {
28+
return nil, err
29+
}
30+
31+
// 3. fill the return map
32+
retMap := GetStaticState().ToStringInterfaceMap()
33+
log.Debugf("Return map: %v", retMap)
34+
35+
return retMap, nil
1836
}

internal/pkg/plugin/common/helm/helm.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ func (p *Param) GetHelmParam() *helm.HelmParam {
3232
}
3333
}
3434

35+
func InstallOrUpgradeChart(param *Param) error {
36+
h, err := helm.NewHelm(param.GetHelmParam())
37+
if err != nil {
38+
return err
39+
}
40+
41+
log.Info("Creating or updating helm chart ...")
42+
if err := h.InstallOrUpgradeChart(); err != nil {
43+
log.Debugf("Failed to install or upgrade the chart: %s.", err)
44+
return err
45+
}
46+
return nil
47+
}
48+
3549
func DealWithNsWhenInstall(param *Param) error {
3650
if !param.CreateNamespace {
3751
log.Debugf("There's no need to delete the namespace for the create_namespace == false in the config file.")

internal/pkg/plugin/jenkins/create.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
"github.com/mitchellh/mapstructure"
77

88
. "github.com/merico-dev/stream/internal/pkg/plugin/common/helm"
9-
"github.com/merico-dev/stream/pkg/util/helm"
109
"github.com/merico-dev/stream/pkg/util/log"
1110
)
1211

1312
// Create creates jenkins with provided options.
1413
func Create(options map[string]interface{}) (map[string]interface{}, error) {
14+
// 1. decode options
1515
var param Param
1616
if err := mapstructure.Decode(options, &param); err != nil {
1717
return nil, err
@@ -24,6 +24,7 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) {
2424
return nil, fmt.Errorf("params are illegal")
2525
}
2626

27+
// 2. deal with ns
2728
if err := DealWithNsWhenInstall(&param); err != nil {
2829
return nil, err
2930
}
@@ -44,24 +45,18 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) {
4445
}
4546
}()
4647

47-
var h *helm.Helm
48-
h, retErr = helm.NewHelm(param.GetHelmParam())
49-
if retErr != nil {
50-
return nil, retErr
51-
}
52-
53-
// pre-create
48+
// 3. pre-create
5449
if retErr = preCreate(); retErr != nil {
5550
log.Errorf("The pre-create logic failed: %s.", retErr)
5651
return nil, retErr
5752
}
5853

59-
log.Info("Installing or updating jenkins helm chart ...")
60-
if retErr = h.InstallOrUpgradeChart(); retErr != nil {
61-
log.Debugf("Failed to install or upgrade the Chart: %s.", retErr)
54+
// 4. install or upgrade
55+
if retErr = InstallOrUpgradeChart(&param); retErr != nil {
6256
return nil, retErr
6357
}
6458

59+
// 5. fill the return map
6560
releaseName := param.Chart.ReleaseName
6661
retMap := GetStaticState(releaseName).ToStringInterfaceMap()
6762
log.Debugf("Return map: %v.", retMap)

0 commit comments

Comments
 (0)