Skip to content

Commit

Permalink
feat: add default repo config for argo
Browse files Browse the repository at this point in the history
Signed-off-by: homily707 <homily707@outlook.com>
  • Loading branch information
homily707 committed Jul 14, 2022
1 parent bde8999 commit 117fad9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 23 deletions.
43 changes: 43 additions & 0 deletions internal/pkg/plugin/argocd/argocd.go
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
package argocd

import (
. "github.com/devstream-io/devstream/internal/pkg/plugin/common/helm"
"github.com/devstream-io/devstream/pkg/util/helm"
)

const (
defaultRepoName = "argo"
defaultRepoURL = "https://argoproj.github.io/argo-helm"
)

var DefaultDeploymentList = []string{
"argocd-applicationset-controller",
"argocd-dex-server",
"argocd-notifications-controller",
"argocd-redis",
"argocd-repo-server",
"argocd-server",
}

func GetStaticState() *helm.InstanceState {
retState := &helm.InstanceState{}
for _, dpName := range DefaultDeploymentList {
retState.Workflows.AddDeployment(dpName, true)
}
return retState
}

func defaultMissedOptions(opts *Options) error {
emptyRepo := helm.Repo{}
if opts.Repo == emptyRepo {
opts.Repo.Name = defaultRepoName
opts.Repo.URL = defaultRepoURL
} else {
if opts.Repo.URL == "" {
opts.Repo.URL = defaultRepoURL
}
if opts.Repo.Name == "" {
opts.Repo.Name = defaultRepoName
}
}
return nil
}
6 changes: 5 additions & 1 deletion internal/pkg/plugin/argocd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ import (

// Create creates ArgoCD with provided options.
func Create(options map[string]interface{}) (map[string]interface{}, error) {
// 1. decode options
// 1. decode options and fill default options if miss
var opts Options
if err := mapstructure.Decode(options, &opts); err != nil {
return nil, err
}

if err := defaultMissedOptions(&opts); err != nil {
return nil, err
}

if errs := validate(&opts); len(errs) != 0 {
for _, e := range errs {
log.Errorf("Options error: %s.", e)
Expand Down
20 changes: 0 additions & 20 deletions internal/pkg/plugin/argocd/state.go

This file was deleted.

6 changes: 5 additions & 1 deletion internal/pkg/plugin/argocd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import (
)

func Update(options map[string]interface{}) (map[string]interface{}, error) {
// 1. decode options
// 1. decode options and fill default options if miss
var opts Options
if err := mapstructure.Decode(options, &opts); err != nil {
return nil, err
}

if err := defaultMissedOptions(&opts); err != nil {
return nil, err
}

if errs := validate(&opts); len(errs) != 0 {
for _, e := range errs {
log.Errorf("Options error: %s.", e)
Expand Down
3 changes: 2 additions & 1 deletion internal/pkg/show/config/plugins/argocd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tools:
options:
# need to create the namespace or not, default: false
create_namespace: true
# Helm repo information, this section is optional
repo:
# name of the Helm repo
name: argo
Expand All @@ -31,5 +32,5 @@ tools:
# custom configuration (Optional). You can refer to [ArgoCD values.yaml](https://github.com/argoproj/argo-helm/blob/master/charts/argo-cd/values.yaml)
values_yaml: |
controller:
service:
service:
port: 8080

0 comments on commit 117fad9

Please sign in to comment.