From 56862aa32c472e798a452d7e5072059c77e1227c Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Thu, 21 Apr 2022 22:49:40 +0800 Subject: [PATCH 01/11] chore: make 'githubactions' package have a consistent alias 'ga' Signed-off-by: Daniel Hu --- internal/pkg/plugin/githubactions/nodejs/create.go | 6 +++--- internal/pkg/plugin/githubactions/nodejs/delete.go | 4 ++-- internal/pkg/plugin/githubactions/nodejs/read.go | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/pkg/plugin/githubactions/nodejs/create.go b/internal/pkg/plugin/githubactions/nodejs/create.go index a549f00f2..883540a9b 100644 --- a/internal/pkg/plugin/githubactions/nodejs/create.go +++ b/internal/pkg/plugin/githubactions/nodejs/create.go @@ -5,7 +5,7 @@ import ( "github.com/mitchellh/mapstructure" - "github.com/devstream-io/devstream/internal/pkg/plugin/githubactions" + ga "github.com/devstream-io/devstream/internal/pkg/plugin/githubactions" "github.com/devstream-io/devstream/pkg/util/github" "github.com/devstream-io/devstream/pkg/util/log" ) @@ -38,7 +38,7 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) { return nil, err } - log.Debugf("Language is: %s.", githubactions.GetLanguage(opts.Language)) + log.Debugf("Language is: %s.", ga.GetLanguage(opts.Language)) for _, w := range workflows { if err := ghClient.AddWorkflow(w, opts.Branch); err != nil { @@ -46,5 +46,5 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) { } } - return githubactions.BuildState(opts.Owner, opts.Org, opts.Repo), nil + return ga.BuildState(opts.Owner, opts.Org, opts.Repo), nil } diff --git a/internal/pkg/plugin/githubactions/nodejs/delete.go b/internal/pkg/plugin/githubactions/nodejs/delete.go index eda88262f..60fab772e 100644 --- a/internal/pkg/plugin/githubactions/nodejs/delete.go +++ b/internal/pkg/plugin/githubactions/nodejs/delete.go @@ -5,7 +5,7 @@ import ( "github.com/mitchellh/mapstructure" - "github.com/devstream-io/devstream/internal/pkg/plugin/githubactions" + ga "github.com/devstream-io/devstream/internal/pkg/plugin/githubactions" "github.com/devstream-io/devstream/pkg/util/github" "github.com/devstream-io/devstream/pkg/util/log" ) @@ -37,7 +37,7 @@ func Delete(options map[string]interface{}) (bool, error) { return false, err } - log.Debugf("Language is %s.", githubactions.GetLanguage(opts.Language)) + log.Debugf("Language is %s.", ga.GetLanguage(opts.Language)) for _, pipeline := range workflows { err := ghClient.DeleteWorkflow(pipeline, opts.Branch) diff --git a/internal/pkg/plugin/githubactions/nodejs/read.go b/internal/pkg/plugin/githubactions/nodejs/read.go index 5380988ab..30b651055 100644 --- a/internal/pkg/plugin/githubactions/nodejs/read.go +++ b/internal/pkg/plugin/githubactions/nodejs/read.go @@ -5,7 +5,7 @@ import ( "github.com/mitchellh/mapstructure" - "github.com/devstream-io/devstream/internal/pkg/plugin/githubactions" + ga "github.com/devstream-io/devstream/internal/pkg/plugin/githubactions" "github.com/devstream-io/devstream/pkg/util/github" "github.com/devstream-io/devstream/pkg/util/log" ) @@ -45,7 +45,7 @@ func Read(options map[string]interface{}) (map[string]interface{}, error) { return nil, nil } - log.Debugf("Language is: %s.", githubactions.GetLanguage(opts.Language)) + log.Debugf("Language is: %s.", ga.GetLanguage(opts.Language)) - return githubactions.BuildReadState(path), nil + return ga.BuildReadState(path), nil } From 13605c821faefc2d3c4e3e4235e098198020398e Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Thu, 21 Apr 2022 23:23:31 +0800 Subject: [PATCH 02/11] docs: update gitops example to use the variables Signed-off-by: Daniel Hu --- examples/gitops-variables.yaml | 9 ++++ examples/gitops.yaml | 94 +++++++++------------------------- 2 files changed, 32 insertions(+), 71 deletions(-) create mode 100644 examples/gitops-variables.yaml diff --git a/examples/gitops-variables.yaml b/examples/gitops-variables.yaml new file mode 100644 index 000000000..56cd19ec8 --- /dev/null +++ b/examples/gitops-variables.yaml @@ -0,0 +1,9 @@ +defaultBranch: main +githubUsername: daniel-hutao +repoName: dtm-test-go +jiraID: merico +jiraUserEmail: tao.hu@merico.dev +jiraProjectKey: DT +dockerhubUsername: exploitht +argocdNameSpace: argocd +argocdDeployTimeout: 10m diff --git a/examples/gitops.yaml b/examples/gitops.yaml index d43f98521..aefc711d7 100644 --- a/examples/gitops.yaml +++ b/examples/gitops.yaml @@ -1,119 +1,71 @@ tools: -# name of the instance with github-repo-scaffolding-golang - name: go-webapp-repo plugin: github-repo-scaffolding-golang - # options for the plugin options: - # the repo's owner. It should be case-sensitive here; strictly use your GitHub username; please change the value below. - owner: YOUR_GITHUB_USERNAME - # the repo which you'd like to create; please change the value below. - repo: YOUR_REPO_NAME - # the branch of the repo you'd like to hold the code - branch: main - # the image repo you'd like to push the container image; please change the value below. - image_repo: YOUR_DOCKERHUB_USERNAME/YOUR_DOCKERHUB_REPOSITORY + owner: [[ githubUsername ]] + org: "" + repo: [[ repoName ]] + branch: [[ defaultBranch ]] + image_repo: [[ dockerhubUsername ]]/[[ repoName ]] - name: jira-github-default plugin: jira-github-integ - # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "go-webapp-repo.github-repo-scaffolding-golang" ] - # options for the plugin options: - # the repo's owner - owner: YOUR_GITHUB_USERNAME - # the repo where you'd like to setup GitHub Actions - repo: YOUR_REPO_NAME - # "base url: https://id.atlassian.net" - jiraBaseUrl: https://JIRA_ID.atlassian.net - # "need real user email in cloud Jira" - jiraUserEmail: JIRA_USER_EMAIL - # "get it from project url, like 'HEAP' from https://merico.atlassian.net/jira/software/projects/HEAP/pages" - jiraProjectKey: JIRA_PROJECT_KEY - # main branch of the repo (to which branch the plugin will submit the workflows) + owner: [[ githubUsername ]] + repo: [[ repoName ]] + jiraBaseUrl: https://[[ jiraID ]].atlassian.net + jiraUserEmail: [[ jiraUserEmail ]] + jiraProjectKey: [[ jiraProjectKey ]] branch: main - name: golang-webapp-actions plugin: githubactions-golang - # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "go-webapp-repo.github-repo-scaffolding-golang" ] - # options for the plugin options: - # the repo's owner. It should be case-sensitive here; strictly use your GitHub user name; please change the value below. - owner: YOUR_GITHUB_USERNAME - # the repo where you'd like to setup GitHub Actions; please change the value below to an existing repo. - repo: YOUR_REPO_NAME - # programming language specific settings + owner: ${{go-webapp-repo.github-repo-scaffolding-golang.outputs.owner}} + org: "" + repo: ${{go-webapp-repo.github-repo-scaffolding-golang.outputs.repo}} language: name: go - # version of the language version: "1.17" - # main branch of the repo (to which branch the plugin will submit the workflows) - branch: main + branch: [[ defaultBranch ]] build: - # default to false enable: True - # build command, OPTIONAL, the given value below is default value command: "go build ./..." test: - # default to false enable: True - # test command, OPTIONAL, the given value below is default value command: "go test ./..." coverage: - # default to false enable: True - # go test profile subcommand, OPTIONAL, the given value below is default value profile: "-race -covermode=atomic" output: "coverage.out" docker: - # docker build/push related, default to false enable: False - # dockerhub image repo; please change the value below. - repo: YOUR_DOCKERHUB_REPOSITORY + repo: ${{go-webapp-repo.github-repo-scaffolding-golang.outputs.repo}} - name: argocd-dev plugin: argocd options: - # need to create the namespace or not, default: false create_namespace: true repo: - # name of the Helm repo name: argo - # url of the Helm repo url: https://argoproj.github.io/argo-helm - # Helm chart information chart: - # name of the chart chart_name: argo/argo-cd - # release name of the chart release_name: argocd - # k8s namespace where ArgoCD will be installed - namespace: argocd - # whether to wait for the release to be deployed or not + namespace: [[ argocdNameSpace ]] wait: true - # the time to wait for any individual Kubernetes operation (like Jobs for hooks). This defaults to 5m0s - timeout: 5m - # whether to perform a CRD upgrade during installation + timeout: [[ argocdDeployTimeout ]] upgradeCRDs: true -- name: helloworld +- name: go-webapp-argocd-deploy plugin: argocdapp - dependsOn: [ "argocd-dev.argocd" ] - # options for the plugin + dependsOn: ["argocd.argocd-dev", "go-webapp-repo.github-repo-scaffolding-golang"] options: - # information on the ArgoCD application app: - # name of the ArgoCD application - name: hello - # where the ArgoCD application CRD will be created - namespace: argocd - # destination of the application + name: ${{go-webapp-repo.github-repo-scaffolding-golang.outputs.repo}} + namespace: [[ argocdNameSpace ]] destination: - # on which server to deploy server: https://kubernetes.default.svc - # in which namespace to deploy namespace: default - # source of the application source: - # which values file to use in the Helm chart valuefile: values.yaml - # path of the Helm chart - path: charts/go-hello-http - # Helm chart repo URL - repoURL: YOUR_CHART_REPO_URL + path: helm/${{go-webapp-repo.github-repo-scaffolding-golang.outputs.repo}} + repoURL: ${{go-webapp-repo.github-repo-scaffolding-golang.outputs.repoURL}} From e38f62dbd0fca4dad58b3ceb96920d1abf0afcde Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Fri, 22 Apr 2022 14:18:23 +0800 Subject: [PATCH 03/11] fix: missing gitops-variables Signed-off-by: Daniel Hu --- gitops-variables.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 gitops-variables.yaml diff --git a/gitops-variables.yaml b/gitops-variables.yaml new file mode 100644 index 000000000..56cd19ec8 --- /dev/null +++ b/gitops-variables.yaml @@ -0,0 +1,9 @@ +defaultBranch: main +githubUsername: daniel-hutao +repoName: dtm-test-go +jiraID: merico +jiraUserEmail: tao.hu@merico.dev +jiraProjectKey: DT +dockerhubUsername: exploitht +argocdNameSpace: argocd +argocdDeployTimeout: 10m From 5c542aaf82cd92f1bb6de34c4f860ae347253c44 Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Fri, 22 Apr 2022 14:32:52 +0800 Subject: [PATCH 04/11] refactor: change "Name", "Plugin" to "InstanceID", "Name" in Config and State Signed-off-by: Daniel Hu --- internal/pkg/configloader/config.go | 20 +++---- .../pkg/configloader/configloader_test.go | 16 +++--- internal/pkg/configloader/validation.go | 16 +++--- internal/pkg/pluginengine/change.go | 24 ++++---- internal/pkg/pluginengine/change_helper.go | 28 +++++----- .../pkg/pluginengine/pluginengine_test.go | 52 ++++++++--------- internal/pkg/pluginengine/topological_sort.go | 10 ++-- .../pkg/pluginengine/topological_sort_test.go | 56 +++++++++---------- internal/pkg/pluginmanager/pluginmd5_test.go | 10 ++-- internal/pkg/show/status/status.go | 12 ++-- internal/pkg/statemanager/manager_test.go | 32 +++++------ internal/pkg/statemanager/state.go | 16 +++--- 12 files changed, 146 insertions(+), 146 deletions(-) diff --git a/internal/pkg/configloader/config.go b/internal/pkg/configloader/config.go index aafbe6647..f1c358fab 100644 --- a/internal/pkg/configloader/config.go +++ b/internal/pkg/configloader/config.go @@ -23,23 +23,23 @@ type Config struct { // Tool is the struct for one section of the DevStream configuration file. type Tool struct { + Name string `yaml:"plugin"` // RFC 1123 - DNS Subdomain Names style // contain no more than 253 characters // contain only lowercase alphanumeric characters, '-' or '.' // start with an alphanumeric character // end with an alphanumeric character - Name string `yaml:"name"` - Plugin string `yaml:"plugin"` - DependsOn []string `yaml:"dependsOn"` - Options map[string]interface{} `yaml:"options"` + InstanceID string `yaml:"name"` + DependsOn []string `yaml:"dependsOn"` + Options map[string]interface{} `yaml:"options"` } func (t *Tool) DeepCopy() *Tool { var retTool = Tool{ - Name: t.Name, - Plugin: t.Plugin, - DependsOn: t.DependsOn, - Options: map[string]interface{}{}, + Name: t.Name, + InstanceID: t.InstanceID, + DependsOn: t.DependsOn, + Options: map[string]interface{}{}, } for k, v := range t.Options { retTool.Options[k] = v @@ -91,12 +91,12 @@ func LoadConf(configFileName, varFileName string) *Config { // GetPluginFileName creates the file name based on the tool's name and version // If the plugin {githubactions 0.0.1}, the generated name will be "githubactions_0.0.1.so" func GetPluginFileName(t *Tool) string { - return fmt.Sprintf("%s-%s-%s_%s.so", t.Plugin, GOOS, GOARCH, version.Version) + return fmt.Sprintf("%s-%s-%s_%s.so", t.Name, GOOS, GOARCH, version.Version) } // GetPluginMD5FileName If the plugin {githubactions 0.0.1}, the generated name will be "githubactions_0.0.1.md5" func GetPluginMD5FileName(t *Tool) string { - return fmt.Sprintf("%s-%s-%s_%s.md5", t.Plugin, GOOS, GOARCH, version.Version) + return fmt.Sprintf("%s-%s-%s_%s.md5", t.Name, GOOS, GOARCH, version.Version) } // GetDtmMD5FileName format likes dtm-linux-amd64 diff --git a/internal/pkg/configloader/configloader_test.go b/internal/pkg/configloader/configloader_test.go index be0eb73c5..6e92948e7 100644 --- a/internal/pkg/configloader/configloader_test.go +++ b/internal/pkg/configloader/configloader_test.go @@ -8,8 +8,8 @@ import ( func TestDependencyPass(t *testing.T) { tools := []Tool{ - {Name: "argocd", Plugin: "argocd"}, - {Name: "argocdapp", Plugin: "argocdapp", DependsOn: []string{"argocd.argocd"}}, + {InstanceID: "argocd", Name: "argocd"}, + {InstanceID: "argocdapp", Name: "argocdapp", DependsOn: []string{"argocd.argocd"}}, } errors := validateDependency(tools) assert.Equal(t, len(errors), 0, "Dependency check passed.") @@ -18,7 +18,7 @@ func TestDependencyPass(t *testing.T) { func TestDependencyNotExist(t *testing.T) { tools := []Tool{ - {Name: "argocdapp", Plugin: "argocdapp", DependsOn: []string{"argocd.argocd"}}, + {InstanceID: "argocdapp", Name: "argocdapp", DependsOn: []string{"argocd.argocd"}}, } errors := validateDependency(tools) assert.Equal(t, len(errors), 1) @@ -27,9 +27,9 @@ func TestDependencyNotExist(t *testing.T) { func TestMultipleDependencies(t *testing.T) { tools := []Tool{ - {Name: "argocd", Plugin: "argocd"}, - {Name: "repo", Plugin: "github"}, - {Name: "argocdapp", Plugin: "argocdapp", DependsOn: []string{"argocd.argocd", "repo.github"}}, + {InstanceID: "argocd", Name: "argocd"}, + {InstanceID: "repo", Name: "github"}, + {InstanceID: "argocdapp", Name: "argocdapp", DependsOn: []string{"argocd.argocd", "repo.github"}}, } errors := validateDependency(tools) assert.Equal(t, len(errors), 0) @@ -37,8 +37,8 @@ func TestMultipleDependencies(t *testing.T) { func TestEmptyDependency(t *testing.T) { tools := []Tool{ - {Name: "argocd", Plugin: "argocd"}, - {Name: "argocdapp", Plugin: "argocdapp", DependsOn: []string{}}, + {InstanceID: "argocd", Name: "argocd"}, + {InstanceID: "argocdapp", Name: "argocdapp", DependsOn: []string{}}, } errors := validateDependency(tools) assert.Equal(t, len(errors), 0) diff --git a/internal/pkg/configloader/validation.go b/internal/pkg/configloader/validation.go index 6006051c2..4842d8398 100644 --- a/internal/pkg/configloader/validation.go +++ b/internal/pkg/configloader/validation.go @@ -22,18 +22,18 @@ func validateConfig(config *Config) []error { func validateTool(t *Tool) []error { errors := make([]error, 0) - // Name - if t.Name == "" { + // InstanceID + if t.InstanceID == "" { errors = append(errors, fmt.Errorf("name is empty")) } - errs := validation.IsDNS1123Subdomain(t.Name) + errs := validation.IsDNS1123Subdomain(t.InstanceID) for _, e := range errs { - errors = append(errors, fmt.Errorf("name %s is invalid: %s", t.Name, e)) + errors = append(errors, fmt.Errorf("name %s is invalid: %s", t.InstanceID, e)) } - // Plugin - if t.Plugin == "" { + // InstanceID + if t.Name == "" { errors = append(errors, fmt.Errorf("plugin is empty")) } @@ -47,7 +47,7 @@ func validateDependency(tools []Tool) []error { toolMap := make(map[string]bool) // creating the set for _, tool := range tools { - key := fmt.Sprintf("%s.%s", tool.Name, tool.Plugin) + key := fmt.Sprintf("%s.%s", tool.InstanceID, tool.Name) toolMap[key] = true } @@ -67,7 +67,7 @@ func validateDependency(tools []Tool) []error { // generate an error if the dependency isn't in the config set, if _, ok := toolMap[dependency]; !ok { - errors = append(errors, fmt.Errorf("tool %s's dependency %s doesn't exist in the config", tool.Name, dependency)) + errors = append(errors, fmt.Errorf("tool %s's dependency %s doesn't exist in the config", tool.InstanceID, dependency)) } } } diff --git a/internal/pkg/pluginengine/change.go b/internal/pkg/pluginengine/change.go index 1f026ba1b..402150b7c 100644 --- a/internal/pkg/pluginengine/change.go +++ b/internal/pkg/pluginengine/change.go @@ -26,8 +26,8 @@ type ChangeResult struct { } func (c *Change) String() string { - return fmt.Sprintf("\n{\n ActionName: %s,\n Tool: {Name: %s, Plugin: %s}}\n}", - c.ActionName, c.Tool.Name, c.Tool.Plugin) + return fmt.Sprintf("\n{\n ActionName: %s,\n Tool: {InstanceID: %s, InstanceID: %s}}\n}", + c.ActionName, c.Tool.InstanceID, c.Tool.Name) } type CommandType string @@ -86,7 +86,7 @@ func execute(smgr statemanager.Manager, changes []*Change) map[string]error { for i, c := range changes { log.Separatorf("Processing progress: %d/%d.", i+1, numOfChanges) - log.Infof("Processing: %s (%s) -> %s ...", c.Tool.Name, c.Tool.Plugin, c.ActionName) + log.Infof("Processing: %s (%s) -> %s ...", c.Tool.InstanceID, c.Tool.Name, c.ActionName) var succeeded bool var err error @@ -101,7 +101,7 @@ func execute(smgr statemanager.Manager, changes []*Change) map[string]error { for _, e := range errs { log.Errorf("Error: %s.", e) } - log.Errorf("The outputs reference in tool %s (%s) can't be resolved. Please double check your config.", c.Tool.Name, c.Tool.Plugin) + log.Errorf("The outputs reference in tool %s (%s) can't be resolved. Please double check your config.", c.Tool.InstanceID, c.Tool.Name) // not executing this change since its input isn't valid continue @@ -121,7 +121,7 @@ func execute(smgr statemanager.Manager, changes []*Change) map[string]error { } if err != nil { - key := fmt.Sprintf("%s/%s-%s", c.Tool.Plugin, c.Tool.Name, c.ActionName) + key := fmt.Sprintf("%s/%s-%s", c.Tool.Name, c.Tool.InstanceID, c.ActionName) errorsMap[key] = err } @@ -162,23 +162,23 @@ func handleResult(smgr statemanager.Manager, change *Change) error { log.Debugf("Failed to delete state %s: %s.", key, err) return err } - log.Successf("Plugin %s (%s) delete done.", change.Tool.Name, change.Tool.Plugin) + log.Successf("Tool %s (%s) delete done.", change.Tool.InstanceID, change.Tool.Name) return nil } key := statemanager.StateKeyGenerateFunc(change.Tool) state := statemanager.State{ - Name: change.Tool.Name, - Plugin: change.Tool.Plugin, - DependsOn: change.Tool.DependsOn, - Options: change.Tool.Options, - Resource: change.Result.ReturnValue, + InstanceID: change.Tool.InstanceID, + Name: change.Tool.Name, + DependsOn: change.Tool.DependsOn, + Options: change.Tool.Options, + Resource: change.Result.ReturnValue, } err := smgr.AddState(key, state) if err != nil { log.Debugf("Failed to add state %s: %s.", key, err) return err } - log.Successf("Plugin %s(%s) %s done.", change.Tool.Name, change.Tool.Plugin, change.ActionName) + log.Successf("InstanceID %s(%s) %s done.", change.Tool.InstanceID, change.Tool.Name, change.ActionName) return nil } diff --git a/internal/pkg/pluginengine/change_helper.go b/internal/pkg/pluginengine/change_helper.go index eebe39268..cc23e7550 100644 --- a/internal/pkg/pluginengine/change_helper.go +++ b/internal/pkg/pluginengine/change_helper.go @@ -26,9 +26,9 @@ func generateDeleteAction(tool *configloader.Tool, description string) *Change { func generateDeleteActionFromState(state statemanager.State) *Change { return &Change{ Tool: &configloader.Tool{ - Name: state.Name, - Plugin: state.Plugin, - Options: state.Options, + InstanceID: state.InstanceID, + Name: state.Name, + Options: state.Options, }, ActionName: statemanager.ActionDelete, } @@ -79,7 +79,7 @@ func changesForApply(smgr statemanager.Manager, cfg *configloader.Config) ([]*Ch if state == nil { // tool not in the state, create, no need to Read resource before Create - description := fmt.Sprintf("Tool %s (%s) found in config but doesn't exist in the state, will be created.", tool.Name, tool.Plugin) + description := fmt.Sprintf("Tool %s (%s) found in config but doesn't exist in the state, will be created.", tool.InstanceID, tool.Name) changes = append(changes, generateCreateAction(&tool, description)) } else { // tool found in the state @@ -90,7 +90,7 @@ func changesForApply(smgr statemanager.Manager, cfg *configloader.Config) ([]*Ch if drifted(tool.Options, state.Options) { // tool's config differs from State's, Update - description := fmt.Sprintf("Tool %s (%s) config drifted from the state, will be updated.", tool.Name, tool.Plugin) + description := fmt.Sprintf("Tool %s (%s) config drifted from the state, will be updated.", tool.InstanceID, tool.Name) changes = append(changes, generateUpdateAction(&tool, description)) } else { // tool's config is the same as State's @@ -103,15 +103,15 @@ func changesForApply(smgr statemanager.Manager, cfg *configloader.Config) ([]*Ch if resource == nil { // tool exists in the state, but resource doesn't exist, Create - description := fmt.Sprintf("Tool %s (%s) state found but it seems the tool isn't created, will be created.", tool.Name, tool.Plugin) + description := fmt.Sprintf("Tool %s (%s) state found but it seems the tool isn't created, will be created.", tool.InstanceID, tool.Name) changes = append(changes, generateCreateAction(&tool, description)) } else if drifted(resource, state.Resource) { // resource drifted from state, Update - description := fmt.Sprintf("Tool %s (%s) drifted from the state, will be updated.", tool.Name, tool.Plugin) + description := fmt.Sprintf("Tool %s (%s) drifted from the state, will be updated.", tool.InstanceID, tool.Name) changes = append(changes, generateUpdateAction(&tool, description)) } else { // resource is the same as the state, do nothing - log.Debugf("Tool %s (%s) is the same as the state, do nothing.", tool.Name, tool.Plugin) + log.Debugf("Tool %s (%s) is the same as the state, do nothing.", tool.InstanceID, tool.Name) } } } @@ -152,7 +152,7 @@ func changesForDelete(smgr statemanager.Manager, cfg *configloader.Config, isFor } } - description := fmt.Sprintf("Tool %s (%s) will be deleted.", tool.Name, tool.Plugin) + description := fmt.Sprintf("Tool %s (%s) will be deleted.", tool.InstanceID, tool.Name) changes = append(changes, generateDeleteAction(&tool, description)) } } @@ -168,10 +168,10 @@ func GetChangesForDestroy(smgr statemanager.Manager) ([]*Change, error) { var tools []configloader.Tool for _, state := range smgr.GetStatesMap().ToList() { tool := configloader.Tool{ - Name: state.Name, - Plugin: state.Plugin, - DependsOn: state.DependsOn, - Options: state.Options, + InstanceID: state.InstanceID, + Name: state.Name, + DependsOn: state.DependsOn, + Options: state.Options, } tools = append(tools, tool) } @@ -185,7 +185,7 @@ func GetChangesForDestroy(smgr statemanager.Manager) ([]*Change, error) { for i := len(batchesOfTools) - 1; i >= 0; i-- { batch := batchesOfTools[i] for _, tool := range batch { - description := fmt.Sprintf("Tool %s (%s) will be deleted.", tool.Name, tool.Plugin) + description := fmt.Sprintf("Tool %s (%s) will be deleted.", tool.InstanceID, tool.Name) changes = append(changes, generateDeleteAction(&tool, description)) } } diff --git a/internal/pkg/pluginengine/pluginengine_test.go b/internal/pkg/pluginengine/pluginengine_test.go index 11a08dbbb..f4bd7e42f 100644 --- a/internal/pkg/pluginengine/pluginengine_test.go +++ b/internal/pkg/pluginengine/pluginengine_test.go @@ -49,7 +49,7 @@ var _ = Describe("Pluginengine", func() { GinkgoWriter.Print(changes) Expect(len(changes)).To(Equal(1)) c := changes[0] - Expect(c.Tool.Name).To(Equal(name)) + Expect(c.Tool.InstanceID).To(Equal(name)) Expect(c.ActionName).To(Equal(statemanager.ActionCreate)) }) @@ -64,13 +64,13 @@ var _ = Describe("Pluginengine", func() { Expect(len(changes)).To(Equal(2)) c1 := changes[0] - Expect(c1.Tool.Name).To(Equal(name1)) - Expect(c1.Tool.Plugin).To(Equal(plugin1)) + Expect(c1.Tool.InstanceID).To(Equal(name1)) + Expect(c1.Tool.Name).To(Equal(plugin1)) Expect(c1.ActionName).To(Equal(statemanager.ActionCreate)) c2 := changes[1] - Expect(c2.Tool.Name).To(Equal(name2)) - Expect(c2.Tool.Plugin).To(Equal(plugin2)) + Expect(c2.Tool.InstanceID).To(Equal(name2)) + Expect(c2.Tool.Name).To(Equal(plugin2)) Expect(c2.ActionName).To(Equal(statemanager.ActionCreate)) }) @@ -88,16 +88,16 @@ var _ = Describe("Pluginengine", func() { Expect(len(changes)).To(Equal(1)) c := changes[0] - Expect(c.Tool.Name).To(Equal(name)) - Expect(c.Tool.Plugin).To(Equal(plugin)) + Expect(c.Tool.InstanceID).To(Equal(name)) + Expect(c.Tool.Name).To(Equal(plugin)) Expect(c.ActionName).To(Equal(statemanager.ActionDelete)) }) It("should handle outputs correctly", func() { trelloState := statemanager.State{ - Name: "mytrelloboard", - Plugin: "trello", - Options: map[string]interface{}{}, + InstanceID: "mytrelloboard", + Name: "trello", + Options: map[string]interface{}{}, Resource: map[string]interface{}{ "outputs": map[string]interface{}{ "boardId": expectedBoardId, @@ -123,9 +123,9 @@ var _ = Describe("Pluginengine", func() { It("should handle output interpolation correctly", func() { trelloState := statemanager.State{ - Name: "mytrelloboard", - Plugin: "trello", - Options: map[string]interface{}{}, + InstanceID: "mytrelloboard", + Name: "trello", + Options: map[string]interface{}{}, Resource: map[string]interface{}{ "outputs": map[string]interface{}{ "boardId": expectedBoardId, @@ -148,10 +148,10 @@ var _ = Describe("Pluginengine", func() { It("should give an error when output doesn't exist in the state", func() { trelloState := statemanager.State{ - Name: "mytrelloboard", - Plugin: "trello", - Options: map[string]interface{}{}, - Resource: map[string]interface{}{}, + InstanceID: "mytrelloboard", + Name: "trello", + Options: map[string]interface{}{}, + Resource: map[string]interface{}{}, } err = smgr.AddState(trelloKey, trelloState) Expect(err).NotTo(HaveOccurred()) @@ -169,9 +169,9 @@ var _ = Describe("Pluginengine", func() { It("should give an error when the referred key doesn't exist", func() { trelloState := statemanager.State{ - Name: "mytrelloboard", - Plugin: "trello", - Options: map[string]interface{}{}, + InstanceID: "mytrelloboard", + Name: "trello", + Options: map[string]interface{}{}, Resource: map[string]interface{}{ "outputs": map[string]interface{}{ "boardId": expectedBoardId, @@ -199,9 +199,9 @@ var _ = Describe("Pluginengine", func() { It("should work for nested maps", func() { trelloState := statemanager.State{ - Name: "mytrelloboard", - Plugin: "trello", - Options: map[string]interface{}{}, + InstanceID: "mytrelloboard", + Name: "trello", + Options: map[string]interface{}{}, Resource: map[string]interface{}{ "outputs": map[string]interface{}{ "boardId": expectedBoardId, @@ -229,8 +229,8 @@ var _ = Describe("Pluginengine", func() { func getTool(name, kind string) *configloader.Tool { return &configloader.Tool{ - Name: name, - Plugin: kind, - Options: map[string]interface{}{"key": "value"}, + InstanceID: name, + Name: kind, + Options: map[string]interface{}{"key": "value"}, } } diff --git a/internal/pkg/pluginengine/topological_sort.go b/internal/pkg/pluginengine/topological_sort.go index b67c9e584..1608ed0e2 100644 --- a/internal/pkg/pluginengine/topological_sort.go +++ b/internal/pkg/pluginengine/topological_sort.go @@ -8,7 +8,7 @@ import ( ) func generateKeyFromTool(tool configloader.Tool) string { - return fmt.Sprintf("%s.%s", tool.Name, tool.Plugin) + return fmt.Sprintf("%s.%s", tool.InstanceID, tool.Name) } func dependencyResolved(tool configloader.Tool, unprocessedNodeSet map[string]bool) bool { @@ -16,14 +16,14 @@ func dependencyResolved(tool configloader.Tool, unprocessedNodeSet map[string]bo for _, dep := range tool.DependsOn { // if the tool's dependency is still not processed yet / still in the graph - log.Debugf("TOOL %s.%s dependency NOT solved\n", tool.Name, tool.Plugin) + log.Debugf("TOOL %s.%s dependency NOT solved\n", tool.InstanceID, tool.Name) if _, ok := unprocessedNodeSet[dep]; ok { res = false break } } - log.Debugf("TOOL %s %s %t\n", tool.Name, tool.Plugin, res) + log.Debugf("TOOL %s %s %t\n", tool.InstanceID, tool.Name, res) return res } @@ -55,11 +55,11 @@ func topologicalSort(tools []configloader.Tool) ([][]configloader.Tool, error) { // if there isn't any dependency: it's the "start" of the graph // we can put it into the first batch if len(tool.DependsOn) == 0 { - log.Debugf("TOOL %s.%s dependency already solved\n", tool.Name, tool.Plugin) + log.Debugf("TOOL %s.%s dependency already solved\n", tool.InstanceID, tool.Name) batch = append(batch, tool) } else { if dependencyResolved(tool, unprocessedNodeSet) { - log.Debugf("TOOL %s.%s dependency already solved\n", tool.Name, tool.Plugin) + log.Debugf("TOOL %s.%s dependency already solved\n", tool.InstanceID, tool.Name) batch = append(batch, tool) } } diff --git a/internal/pkg/pluginengine/topological_sort_test.go b/internal/pkg/pluginengine/topological_sort_test.go index 65b73958c..269b59b1b 100644 --- a/internal/pkg/pluginengine/topological_sort_test.go +++ b/internal/pkg/pluginengine/topological_sort_test.go @@ -11,18 +11,18 @@ import ( func TestNoDependency(t *testing.T) { tools := []configloader.Tool{ - {Name: "a", Plugin: "a"}, - {Name: "b", Plugin: "b"}, - {Name: "c", Plugin: "c"}, - {Name: "d", Plugin: "d"}, + {InstanceID: "a", Name: "a"}, + {InstanceID: "b", Name: "b"}, + {InstanceID: "c", Name: "c"}, + {InstanceID: "d", Name: "d"}, } expectedRes := [][]configloader.Tool{ { - {Name: "a", Plugin: "a"}, - {Name: "b", Plugin: "b"}, - {Name: "c", Plugin: "c"}, - {Name: "d", Plugin: "d"}, + {InstanceID: "a", Name: "a"}, + {InstanceID: "b", Name: "b"}, + {InstanceID: "c", Name: "c"}, + {InstanceID: "d", Name: "d"}, }, } actualRes, err := topologicalSort(tools) @@ -32,16 +32,16 @@ func TestNoDependency(t *testing.T) { func TestSingleDependency(t *testing.T) { tools := []configloader.Tool{ - {Name: "a", Plugin: "a"}, - {Name: "c", Plugin: "c", DependsOn: []string{"a.a"}}, + {InstanceID: "a", Name: "a"}, + {InstanceID: "c", Name: "c", DependsOn: []string{"a.a"}}, } expectedRes := [][]configloader.Tool{ { - {Name: "a", Plugin: "a"}, + {InstanceID: "a", Name: "a"}, }, { - {Name: "c", Plugin: "c", DependsOn: []string{"a.a"}}, + {InstanceID: "c", Name: "c", DependsOn: []string{"a.a"}}, }, } actualRes, err := topologicalSort(tools) @@ -51,22 +51,22 @@ func TestSingleDependency(t *testing.T) { func TestMultiDependencies(t *testing.T) { tools := []configloader.Tool{ - {Name: "a", Plugin: "a"}, - {Name: "b", Plugin: "b"}, - {Name: "c", Plugin: "c", DependsOn: []string{"a.a", "b.b"}}, - {Name: "d", Plugin: "d", DependsOn: []string{"c.c"}}, + {InstanceID: "a", Name: "a"}, + {InstanceID: "b", Name: "b"}, + {InstanceID: "c", Name: "c", DependsOn: []string{"a.a", "b.b"}}, + {InstanceID: "d", Name: "d", DependsOn: []string{"c.c"}}, } expectedRes := [][]configloader.Tool{ { - {Name: "a", Plugin: "a"}, - {Name: "b", Plugin: "b"}, + {InstanceID: "a", Name: "a"}, + {InstanceID: "b", Name: "b"}, }, { - {Name: "c", Plugin: "c", DependsOn: []string{"a.a", "b.b"}}, + {InstanceID: "c", Name: "c", DependsOn: []string{"a.a", "b.b"}}, }, { - {Name: "d", Plugin: "d", DependsOn: []string{"c.c"}}, + {InstanceID: "d", Name: "d", DependsOn: []string{"c.c"}}, }, } actualRes, err := topologicalSort(tools) @@ -76,22 +76,22 @@ func TestMultiDependencies(t *testing.T) { func TestDependencyLoop(t *testing.T) { tools := []configloader.Tool{ - {Name: "a", Plugin: "a"}, - {Name: "b", Plugin: "b", DependsOn: []string{"d.d"}}, - {Name: "c", Plugin: "c", DependsOn: []string{"b.b"}}, - {Name: "d", Plugin: "d", DependsOn: []string{"c.c"}}, + {InstanceID: "a", Name: "a"}, + {InstanceID: "b", Name: "b", DependsOn: []string{"d.d"}}, + {InstanceID: "c", Name: "c", DependsOn: []string{"b.b"}}, + {InstanceID: "d", Name: "d", DependsOn: []string{"c.c"}}, } expectedRes := [][]configloader.Tool{ { - {Name: "a", Plugin: "a"}, - {Name: "b", Plugin: "b"}, + {InstanceID: "a", Name: "a"}, + {InstanceID: "b", Name: "b"}, }, { - {Name: "c", Plugin: "c", DependsOn: []string{"a.a", "b.b"}}, + {InstanceID: "c", Name: "c", DependsOn: []string{"a.a", "b.b"}}, }, { - {Name: "d", Plugin: "d", DependsOn: []string{"c.c"}}, + {InstanceID: "d", Name: "d", DependsOn: []string{"c.c"}}, }, } actualRes, err := topologicalSort(tools) diff --git a/internal/pkg/pluginmanager/pluginmd5_test.go b/internal/pkg/pluginmanager/pluginmd5_test.go index 000435ca1..334136dae 100644 --- a/internal/pkg/pluginmanager/pluginmd5_test.go +++ b/internal/pkg/pluginmanager/pluginmd5_test.go @@ -22,7 +22,7 @@ var _ = Describe("CheckLocalPlugins", func() { BeforeEach(func() { viper.Set("plugin-dir", "./") tools = []configloader.Tool{ - {Name: "a", Plugin: "a"}, + {InstanceID: "a", Name: "a"}, } config = &configloader.Config{Tools: tools} @@ -45,7 +45,7 @@ var _ = Describe("CheckLocalPlugins", func() { Expect(err).NotTo(HaveOccurred()) err = CheckLocalPlugins(config) - expectErrMsg := fmt.Sprintf("plugin %s doesn't match with .md5", tools[0].Name) + expectErrMsg := fmt.Sprintf("plugin %s doesn't match with .md5", tools[0].InstanceID) Expect(err.Error()).To(Equal(expectErrMsg)) }) @@ -53,7 +53,7 @@ var _ = Describe("CheckLocalPlugins", func() { err = addMD5File(file, fileMD5) Expect(err).NotTo(HaveOccurred()) - err = pluginAndMD5Matches(viper.GetString("plugin-dir"), file, fileMD5, tools[0].Name) + err = pluginAndMD5Matches(viper.GetString("plugin-dir"), file, fileMD5, tools[0].InstanceID) Expect(err).NotTo(HaveOccurred()) }) @@ -61,8 +61,8 @@ var _ = Describe("CheckLocalPlugins", func() { err = createNewFile(fileMD5) Expect(err).NotTo(HaveOccurred()) - err = pluginAndMD5Matches(viper.GetString("plugin-dir"), file, fileMD5, tools[0].Name) - expectErrMsg := fmt.Sprintf("plugin %s doesn't match with .md5", tools[0].Name) + err = pluginAndMD5Matches(viper.GetString("plugin-dir"), file, fileMD5, tools[0].InstanceID) + expectErrMsg := fmt.Sprintf("plugin %s doesn't match with .md5", tools[0].InstanceID) Expect(err.Error()).To(Equal(expectErrMsg)) }) diff --git a/internal/pkg/show/status/status.go b/internal/pkg/show/status/status.go index c72329e8e..e235b3683 100644 --- a/internal/pkg/show/status/status.go +++ b/internal/pkg/show/status/status.go @@ -56,8 +56,8 @@ func showAll(smgr statemanager.Manager) error { var retErrs = make([]string, 0) for i, state := range stateList { fmt.Printf("================= %d/%d =================\n\n", i+1, len(stateList)) - if err := showOne(smgr, state.Name, state.Plugin); err != nil { - fmt.Printf("Failed to show the status with %s.%s.", state.Name, state.Plugin) + if err := showOne(smgr, state.InstanceID, state.Name); err != nil { + fmt.Printf("Failed to show the status with %s.%s.", state.InstanceID, state.Name) retErrs = append(retErrs, err.Error()) // the "continue" here is used to tell you we don't need to return when ONE plugin show failed continue @@ -81,10 +81,10 @@ func showOne(smgr statemanager.Manager, name, plugin string) error { // get state from read tool := &configloader.Tool{ - Name: name, - Plugin: plugin, - DependsOn: state.DependsOn, - Options: state.Options, + InstanceID: name, + Name: plugin, + DependsOn: state.DependsOn, + Options: state.Options, } stateFromRead, err := pluginengine.Read(tool) if err != nil { diff --git a/internal/pkg/statemanager/manager_test.go b/internal/pkg/statemanager/manager_test.go index ea1ff4985..c049a2be3 100644 --- a/internal/pkg/statemanager/manager_test.go +++ b/internal/pkg/statemanager/manager_test.go @@ -24,10 +24,10 @@ var _ = Describe("Statemanager", func() { It("Should get the state right", func() { key := statemanager.StateKey("name_githubactions") stateA := statemanager.State{ - Name: "name", - Plugin: "githubactions", - Options: map[string]interface{}{"a": "value"}, - Resource: map[string]interface{}{"a": "value"}, + InstanceID: "name", + Name: "githubactions", + Options: map[string]interface{}{"a": "value"}, + Resource: map[string]interface{}{"a": "value"}, } err = smgr.AddState(key, stateA) @@ -48,30 +48,30 @@ var _ = Describe("Statemanager", func() { // List order should be: A,B,C key := statemanager.StateKey("a_githubactions") stateA := statemanager.State{ - Name: "a", - Plugin: "githubactions", - Options: map[string]interface{}{"a": "value"}, - Resource: map[string]interface{}{"a": "value"}, + InstanceID: "a", + Name: "githubactions", + Options: map[string]interface{}{"a": "value"}, + Resource: map[string]interface{}{"a": "value"}, } err = smgr.AddState(key, stateA) Expect(err).NotTo(HaveOccurred()) key = statemanager.StateKey("c_githubactions") stateC := statemanager.State{ - Name: "c", - Plugin: "githubactions", - Options: map[string]interface{}{"c": "value"}, - Resource: map[string]interface{}{"c": "value"}, + InstanceID: "c", + Name: "githubactions", + Options: map[string]interface{}{"c": "value"}, + Resource: map[string]interface{}{"c": "value"}, } err = smgr.AddState(key, stateC) Expect(err).NotTo(HaveOccurred()) key = statemanager.StateKey("b_githubactions") stateB := statemanager.State{ - Name: "b", - Plugin: "githubactions", - Options: map[string]interface{}{"b": "value"}, - Resource: map[string]interface{}{"b": "value"}, + InstanceID: "b", + Name: "githubactions", + Options: map[string]interface{}{"b": "value"}, + Resource: map[string]interface{}{"b": "value"}, } err = smgr.AddState(key, stateB) Expect(err).NotTo(HaveOccurred()) diff --git a/internal/pkg/statemanager/state.go b/internal/pkg/statemanager/state.go index e70a6b32a..18c325789 100644 --- a/internal/pkg/statemanager/state.go +++ b/internal/pkg/statemanager/state.go @@ -14,11 +14,11 @@ import ( // State is the single component's state. type State struct { - Name string - Plugin string - DependsOn []string - Options map[string]interface{} - Resource map[string]interface{} + Name string + InstanceID string + DependsOn []string + Options map[string]interface{} + Resource map[string]interface{} } type StatesMap struct { @@ -48,8 +48,8 @@ func (s StatesMap) ToList() []State { }) sort.Slice(res, func(i, j int) bool { - keyi := fmt.Sprintf("%s.%s", res[i].Name, res[i].Plugin) - keyj := fmt.Sprintf("%s.%s", res[j].Name, res[j].Plugin) + keyi := fmt.Sprintf("%s.%s", res[i].InstanceID, res[i].Name) + keyj := fmt.Sprintf("%s.%s", res[j].InstanceID, res[j].Name) return keyi < keyj }) @@ -83,7 +83,7 @@ func (s StatesMap) Format() []byte { type StateKey string func StateKeyGenerateFunc(t *configloader.Tool) StateKey { - return StateKey(fmt.Sprintf("%s_%s", t.Name, t.Plugin)) + return StateKey(fmt.Sprintf("%s_%s", t.InstanceID, t.Name)) } func GenerateStateKeyByToolNameAndPluginKind(toolName string, pluginKind string) StateKey { From 39685278ad494974680795d3aee83e1ef3f8bfe0 Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Fri, 22 Apr 2022 14:53:27 +0800 Subject: [PATCH 05/11] refactor: update all configs with `dtm show config` Signed-off-by: Daniel Hu --- internal/pkg/configloader/config.go | 4 ++-- internal/pkg/show/config/plugin/argocd.go | 5 +++-- internal/pkg/show/config/plugin/argocdapp.go | 7 ++++--- internal/pkg/show/config/plugin/devlake.go | 5 +++-- .../show/config/plugin/github-repo-scaffolding-golang.go | 8 ++++---- internal/pkg/show/config/plugin/githubactions-golang.go | 7 ++++--- internal/pkg/show/config/plugin/githubactions-nodejs.go | 7 ++++--- internal/pkg/show/config/plugin/githubactions-python.go | 7 ++++--- internal/pkg/show/config/plugin/gitlabci-generic.go | 7 ++++--- internal/pkg/show/config/plugin/gitlabci-golang.go | 7 ++++--- internal/pkg/show/config/plugin/jenkins.go | 8 ++++---- internal/pkg/show/config/plugin/jira-github-integ.go | 7 ++++--- internal/pkg/show/config/plugin/kube-prometheus.go | 8 ++++---- internal/pkg/show/config/plugin/openldap.go | 5 +++-- internal/pkg/show/config/plugin/trello-github-integ.go | 7 ++++--- internal/pkg/show/config/plugin/trello.go | 7 ++++--- 16 files changed, 59 insertions(+), 47 deletions(-) diff --git a/internal/pkg/configloader/config.go b/internal/pkg/configloader/config.go index f1c358fab..88e991d80 100644 --- a/internal/pkg/configloader/config.go +++ b/internal/pkg/configloader/config.go @@ -23,13 +23,13 @@ type Config struct { // Tool is the struct for one section of the DevStream configuration file. type Tool struct { - Name string `yaml:"plugin"` + Name string `yaml:"name"` // RFC 1123 - DNS Subdomain Names style // contain no more than 253 characters // contain only lowercase alphanumeric characters, '-' or '.' // start with an alphanumeric character // end with an alphanumeric character - InstanceID string `yaml:"name"` + InstanceID string `yaml:"instance_id"` DependsOn []string `yaml:"dependsOn"` Options map[string]interface{} `yaml:"options"` } diff --git a/internal/pkg/show/config/plugin/argocd.go b/internal/pkg/show/config/plugin/argocd.go index c29b104fc..50ce9f202 100644 --- a/internal/pkg/show/config/plugin/argocd.go +++ b/internal/pkg/show/config/plugin/argocd.go @@ -1,9 +1,10 @@ package plugin var ArgocdDefaultConfig = `tools: +# name of the tool - name: argocd - # name of the plugin - plugin: argocd + # id of the tool instance + instanceID: argocd # if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/argocdapp.go b/internal/pkg/show/config/plugin/argocdapp.go index 14cc4d236..ca5de3998 100644 --- a/internal/pkg/show/config/plugin/argocdapp.go +++ b/internal/pkg/show/config/plugin/argocdapp.go @@ -1,9 +1,10 @@ package plugin var ArgocdappDefaultConfig = `tools: -- name: helloworld - # name of the plugin - plugin: argocdapp +# name of the tool +- name: argocdapp + # id of the tool instance + instanceID: helloworld # if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "ARGOCD_TOOL_NAME.argocd" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/devlake.go b/internal/pkg/show/config/plugin/devlake.go index af9408b17..d9f088b7c 100644 --- a/internal/pkg/show/config/plugin/devlake.go +++ b/internal/pkg/show/config/plugin/devlake.go @@ -1,8 +1,9 @@ package plugin var DevlakeDefaultConfig = `tools: +# name of the tool - name: devlake - # name of the plugin - plugin: devlake + # id of the tool instance + instanceID: devlake # if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ]` diff --git a/internal/pkg/show/config/plugin/github-repo-scaffolding-golang.go b/internal/pkg/show/config/plugin/github-repo-scaffolding-golang.go index 05dcabc7b..7adef7ff5 100644 --- a/internal/pkg/show/config/plugin/github-repo-scaffolding-golang.go +++ b/internal/pkg/show/config/plugin/github-repo-scaffolding-golang.go @@ -1,10 +1,10 @@ package plugin var GithubRepoScaffoldingGolangDefaultConfig = `tools: -# name of the instance with github-repo-scaffolding-golang -- name: go-webapp-repo - # name of the plugin - plugin: github-repo-scaffolding-golang +# name of the tool +- name: github-repo-scaffolding-golang + # id of the tool instance + instanceID: go-webapp-repo # if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/githubactions-golang.go b/internal/pkg/show/config/plugin/githubactions-golang.go index c2f1d6f66..3e1ce712c 100644 --- a/internal/pkg/show/config/plugin/githubactions-golang.go +++ b/internal/pkg/show/config/plugin/githubactions-golang.go @@ -1,9 +1,10 @@ package plugin var GithubActionsGolangDefaultConfig = `tools: -- name: golang-demo-app - # name of the plugin - plugin: githubactions-golang +# name of the tool +- name: githubactions-golang + # id of the tool instance + instanceID: golang-demo-app # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/githubactions-nodejs.go b/internal/pkg/show/config/plugin/githubactions-nodejs.go index b75e83c52..b4220fac2 100644 --- a/internal/pkg/show/config/plugin/githubactions-nodejs.go +++ b/internal/pkg/show/config/plugin/githubactions-nodejs.go @@ -1,9 +1,10 @@ package plugin var GithubActionsNodejsDefaultConfig = `tools: -- name: nodejs-demo-app - # name of the plugin - plugin: githubactions-nodejs +# name of the tool +- name: githubactions-nodejs + # id of the tool instance + instanceID: nodejs-demo-app # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/githubactions-python.go b/internal/pkg/show/config/plugin/githubactions-python.go index a18930c2a..ee8a1b207 100644 --- a/internal/pkg/show/config/plugin/githubactions-python.go +++ b/internal/pkg/show/config/plugin/githubactions-python.go @@ -1,9 +1,10 @@ package plugin var GithubActionsPythonDefaultConfig = `tools: -- name: python-demo-app - # name of the plugin - plugin: githubactions-python +# name of the tool +- name: githubactions-python + # id of the tool instance + instanceID: python-demo-app # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/gitlabci-generic.go b/internal/pkg/show/config/plugin/gitlabci-generic.go index 966a90ec0..863ff4046 100644 --- a/internal/pkg/show/config/plugin/gitlabci-generic.go +++ b/internal/pkg/show/config/plugin/gitlabci-generic.go @@ -1,9 +1,10 @@ package plugin var GitlabCIGenericDefaultConfig = `tools: -- name: myapp-ci - # name of the plugin - plugin: gitlabci-generic +# name of the tool +- name: gitlabci-generic + # id of the tool instance + instanceID: myapp-ci # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/gitlabci-golang.go b/internal/pkg/show/config/plugin/gitlabci-golang.go index 62c6526c1..ea20d4741 100644 --- a/internal/pkg/show/config/plugin/gitlabci-golang.go +++ b/internal/pkg/show/config/plugin/gitlabci-golang.go @@ -1,9 +1,10 @@ package plugin var GitlabCIGolangDefaultConfig = `tools: -- name: go-hello-world - # name of the plugin - plugin: gitlabci-golang +# name of the tool +- name: gitlabci-golang + # id of the tool instance + instanceID: go-hello-world # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/jenkins.go b/internal/pkg/show/config/plugin/jenkins.go index bb1d7483a..39b533d1c 100644 --- a/internal/pkg/show/config/plugin/jenkins.go +++ b/internal/pkg/show/config/plugin/jenkins.go @@ -1,10 +1,10 @@ package plugin var JenkinsDefaultConfig = `tools: -# name of the instance with jenkins -- name: jenkins-dev - # name of the plugin - plugin: jenkins +# name of the tool +- name: jenkins + # id of the tool instance + instanceID: jenkins-dev # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/jira-github-integ.go b/internal/pkg/show/config/plugin/jira-github-integ.go index 8977601f8..eef2bd88f 100644 --- a/internal/pkg/show/config/plugin/jira-github-integ.go +++ b/internal/pkg/show/config/plugin/jira-github-integ.go @@ -1,9 +1,10 @@ package plugin var JiraGithubDefaultConfig = `tools: -- name: default - # name of the plugin - plugin: jira-github-integ +# name of the tool +- name: jira-github-integ + # id of the tool instance + instanceID: default # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/kube-prometheus.go b/internal/pkg/show/config/plugin/kube-prometheus.go index 42c8316b2..604b5e5e5 100644 --- a/internal/pkg/show/config/plugin/kube-prometheus.go +++ b/internal/pkg/show/config/plugin/kube-prometheus.go @@ -1,10 +1,10 @@ package plugin var KubePrometheusDefaultConfig = `tools: -# name of the instance with kube-prometheus -- name: kube-prometheus-dev - # name of the plugin - plugin: kube-prometheus +# name of the tool +- name: kube-prometheus + # id of the tool instance + instanceID: kube-prometheus-dev # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/openldap.go b/internal/pkg/show/config/plugin/openldap.go index bbc6a8c7a..b69c24ccb 100644 --- a/internal/pkg/show/config/plugin/openldap.go +++ b/internal/pkg/show/config/plugin/openldap.go @@ -1,9 +1,10 @@ package plugin var OpenldapDefaultConfig = `tools: +# name of the tool - name: openldap - # name of the plugin - plugin: openldap + # id of the tool instance + instanceID: openldap # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/trello-github-integ.go b/internal/pkg/show/config/plugin/trello-github-integ.go index c8f3021ce..d460c930c 100644 --- a/internal/pkg/show/config/plugin/trello-github-integ.go +++ b/internal/pkg/show/config/plugin/trello-github-integ.go @@ -1,9 +1,10 @@ package plugin var TrelloGithubDefaultConfig = `tools: -- name: trello-github - # name of the plugin - plugin: trello-github-integ +# name of the tool +- name: trello-github-integ + # id of the tool instance + instanceID: trello-github # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TRELLO_TOOL_NAME.trello" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/trello.go b/internal/pkg/show/config/plugin/trello.go index 4cddb2be2..38eaac802 100644 --- a/internal/pkg/show/config/plugin/trello.go +++ b/internal/pkg/show/config/plugin/trello.go @@ -1,9 +1,10 @@ package plugin var TrelloDefaultConfig = `tools: -- name: my-trello-board - # name of the plugin - plugin: trello +# name of the tool +- name: trello + # id of the tool instance + instanceID: my-trello-board # optional; if specified, dtm will make sure the dependency is applied first before handling this tool dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin From a6c91489c5346c5a780f0d40b424cd6d596d20ef Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Fri, 22 Apr 2022 15:23:11 +0800 Subject: [PATCH 06/11] refactor: modify all instanceID to "default" Signed-off-by: Daniel Hu --- examples/gitops.yaml | 36 +++++++++---------- examples/quickstart.yaml | 10 +++--- internal/pkg/configloader/config.go | 2 +- internal/pkg/show/config/plugin/argocd.go | 2 +- internal/pkg/show/config/plugin/argocdapp.go | 2 +- internal/pkg/show/config/plugin/devlake.go | 2 +- .../plugin/github-repo-scaffolding-golang.go | 2 +- .../config/plugin/githubactions-golang.go | 2 +- .../config/plugin/githubactions-nodejs.go | 2 +- .../config/plugin/githubactions-python.go | 2 +- .../show/config/plugin/gitlabci-generic.go | 2 +- .../pkg/show/config/plugin/gitlabci-golang.go | 2 +- internal/pkg/show/config/plugin/jenkins.go | 2 +- .../pkg/show/config/plugin/kube-prometheus.go | 2 +- internal/pkg/show/config/plugin/openldap.go | 2 +- .../show/config/plugin/trello-github-integ.go | 2 +- internal/pkg/show/config/plugin/trello.go | 2 +- test/e2e/yaml/e2e-config.yaml | 28 +++++++-------- 18 files changed, 52 insertions(+), 52 deletions(-) diff --git a/examples/gitops.yaml b/examples/gitops.yaml index aefc711d7..3921057c2 100644 --- a/examples/gitops.yaml +++ b/examples/gitops.yaml @@ -1,6 +1,6 @@ tools: -- name: go-webapp-repo - plugin: github-repo-scaffolding-golang +- name: github-repo-scaffolding-golang + instanceID: default options: owner: [[ githubUsername ]] org: "" @@ -8,8 +8,8 @@ tools: branch: [[ defaultBranch ]] image_repo: [[ dockerhubUsername ]]/[[ repoName ]] - name: jira-github-default - plugin: jira-github-integ - dependsOn: [ "go-webapp-repo.github-repo-scaffolding-golang" ] + instanceID: default + dependsOn: [ "github-repo-scaffolding-golang.default" ] options: owner: [[ githubUsername ]] repo: [[ repoName ]] @@ -17,13 +17,13 @@ tools: jiraUserEmail: [[ jiraUserEmail ]] jiraProjectKey: [[ jiraProjectKey ]] branch: main -- name: golang-webapp-actions - plugin: githubactions-golang - dependsOn: [ "go-webapp-repo.github-repo-scaffolding-golang" ] +- name: githubactions-golang + instanceID: default + dependsOn: [ "github-repo-scaffolding-golang.default" ] options: - owner: ${{go-webapp-repo.github-repo-scaffolding-golang.outputs.owner}} + owner: ${{github-repo-scaffolding-golang.default.outputs.owner}} org: "" - repo: ${{go-webapp-repo.github-repo-scaffolding-golang.outputs.repo}} + repo: ${{github-repo-scaffolding-golang.default.outputs.repo}} language: name: go version: "1.17" @@ -40,9 +40,9 @@ tools: output: "coverage.out" docker: enable: False - repo: ${{go-webapp-repo.github-repo-scaffolding-golang.outputs.repo}} -- name: argocd-dev - plugin: argocd + repo: ${{github-repo-scaffolding-golang.default.outputs.repo}} +- name: argocd + instanceID: default options: create_namespace: true repo: @@ -55,17 +55,17 @@ tools: wait: true timeout: [[ argocdDeployTimeout ]] upgradeCRDs: true -- name: go-webapp-argocd-deploy - plugin: argocdapp - dependsOn: ["argocd.argocd-dev", "go-webapp-repo.github-repo-scaffolding-golang"] +- name: argocdapp + instanceID: default + dependsOn: ["argocd.default", "github-repo-scaffolding-golang.default"] options: app: - name: ${{go-webapp-repo.github-repo-scaffolding-golang.outputs.repo}} + name: ${{github-repo-scaffolding-golang.default.outputs.repo}} namespace: [[ argocdNameSpace ]] destination: server: https://kubernetes.default.svc namespace: default source: valuefile: values.yaml - path: helm/${{go-webapp-repo.github-repo-scaffolding-golang.outputs.repo}} - repoURL: ${{go-webapp-repo.github-repo-scaffolding-golang.outputs.repoURL}} + path: helm/${{github-repo-scaffolding-golang.default.outputs.repo}} + repoURL: ${{github-repo-scaffolding-golang.default.outputs.repoURL}} diff --git a/examples/quickstart.yaml b/examples/quickstart.yaml index 09bcf1bb0..6797c5477 100644 --- a/examples/quickstart.yaml +++ b/examples/quickstart.yaml @@ -1,15 +1,15 @@ --- tools: -- name: go-webapp-repo - plugin: github-repo-scaffolding-golang +- name: github-repo-scaffolding-golang + instanceID: default options: owner: YOUR_GITHUB_USERNAME_CASE_SENSITIVE repo: go-webapp-devstream-demo branch: main image_repo: YOUR_DOCKER_USERNAME/go-webapp-devstream-demo -- name: golang-demo-actions - plugin: githubactions-golang - dependsOn: ["go-webapp-repo.github-repo-scaffolding-golang"] +- name: githubactions-golang + instanceID: default + dependsOn: ["github-repo-scaffolding-golang.default"] options: owner: YOUR_GITHUB_USERNAME_CASE_SENSITIVE repo: go-webapp-devstream-demo diff --git a/internal/pkg/configloader/config.go b/internal/pkg/configloader/config.go index 88e991d80..d3a05a9ff 100644 --- a/internal/pkg/configloader/config.go +++ b/internal/pkg/configloader/config.go @@ -29,7 +29,7 @@ type Tool struct { // contain only lowercase alphanumeric characters, '-' or '.' // start with an alphanumeric character // end with an alphanumeric character - InstanceID string `yaml:"instance_id"` + InstanceID string `yaml:"instanceID"` DependsOn []string `yaml:"dependsOn"` Options map[string]interface{} `yaml:"options"` } diff --git a/internal/pkg/show/config/plugin/argocd.go b/internal/pkg/show/config/plugin/argocd.go index 50ce9f202..a93348ed6 100644 --- a/internal/pkg/show/config/plugin/argocd.go +++ b/internal/pkg/show/config/plugin/argocd.go @@ -4,7 +4,7 @@ var ArgocdDefaultConfig = `tools: # name of the tool - name: argocd # id of the tool instance - instanceID: argocd + instanceID: default # if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/argocdapp.go b/internal/pkg/show/config/plugin/argocdapp.go index ca5de3998..a701544a0 100644 --- a/internal/pkg/show/config/plugin/argocdapp.go +++ b/internal/pkg/show/config/plugin/argocdapp.go @@ -4,7 +4,7 @@ var ArgocdappDefaultConfig = `tools: # name of the tool - name: argocdapp # id of the tool instance - instanceID: helloworld + instanceID: default # if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "ARGOCD_TOOL_NAME.argocd" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/devlake.go b/internal/pkg/show/config/plugin/devlake.go index d9f088b7c..3fc8abf5e 100644 --- a/internal/pkg/show/config/plugin/devlake.go +++ b/internal/pkg/show/config/plugin/devlake.go @@ -4,6 +4,6 @@ var DevlakeDefaultConfig = `tools: # name of the tool - name: devlake # id of the tool instance - instanceID: devlake + instanceID: default # if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ]` diff --git a/internal/pkg/show/config/plugin/github-repo-scaffolding-golang.go b/internal/pkg/show/config/plugin/github-repo-scaffolding-golang.go index 7adef7ff5..c6353ee99 100644 --- a/internal/pkg/show/config/plugin/github-repo-scaffolding-golang.go +++ b/internal/pkg/show/config/plugin/github-repo-scaffolding-golang.go @@ -4,7 +4,7 @@ var GithubRepoScaffoldingGolangDefaultConfig = `tools: # name of the tool - name: github-repo-scaffolding-golang # id of the tool instance - instanceID: go-webapp-repo + instanceID: default # if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/githubactions-golang.go b/internal/pkg/show/config/plugin/githubactions-golang.go index 3e1ce712c..a151b1480 100644 --- a/internal/pkg/show/config/plugin/githubactions-golang.go +++ b/internal/pkg/show/config/plugin/githubactions-golang.go @@ -4,7 +4,7 @@ var GithubActionsGolangDefaultConfig = `tools: # name of the tool - name: githubactions-golang # id of the tool instance - instanceID: golang-demo-app + instanceID: default # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/githubactions-nodejs.go b/internal/pkg/show/config/plugin/githubactions-nodejs.go index b4220fac2..8cb9eb085 100644 --- a/internal/pkg/show/config/plugin/githubactions-nodejs.go +++ b/internal/pkg/show/config/plugin/githubactions-nodejs.go @@ -4,7 +4,7 @@ var GithubActionsNodejsDefaultConfig = `tools: # name of the tool - name: githubactions-nodejs # id of the tool instance - instanceID: nodejs-demo-app + instanceID: default # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/githubactions-python.go b/internal/pkg/show/config/plugin/githubactions-python.go index ee8a1b207..e86948a0e 100644 --- a/internal/pkg/show/config/plugin/githubactions-python.go +++ b/internal/pkg/show/config/plugin/githubactions-python.go @@ -4,7 +4,7 @@ var GithubActionsPythonDefaultConfig = `tools: # name of the tool - name: githubactions-python # id of the tool instance - instanceID: python-demo-app + instanceID: default # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/gitlabci-generic.go b/internal/pkg/show/config/plugin/gitlabci-generic.go index 863ff4046..36c48bf96 100644 --- a/internal/pkg/show/config/plugin/gitlabci-generic.go +++ b/internal/pkg/show/config/plugin/gitlabci-generic.go @@ -4,7 +4,7 @@ var GitlabCIGenericDefaultConfig = `tools: # name of the tool - name: gitlabci-generic # id of the tool instance - instanceID: myapp-ci + instanceID: default # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/gitlabci-golang.go b/internal/pkg/show/config/plugin/gitlabci-golang.go index ea20d4741..5c2d3f3bd 100644 --- a/internal/pkg/show/config/plugin/gitlabci-golang.go +++ b/internal/pkg/show/config/plugin/gitlabci-golang.go @@ -4,7 +4,7 @@ var GitlabCIGolangDefaultConfig = `tools: # name of the tool - name: gitlabci-golang # id of the tool instance - instanceID: go-hello-world + instanceID: default # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/jenkins.go b/internal/pkg/show/config/plugin/jenkins.go index 39b533d1c..e54779a36 100644 --- a/internal/pkg/show/config/plugin/jenkins.go +++ b/internal/pkg/show/config/plugin/jenkins.go @@ -4,7 +4,7 @@ var JenkinsDefaultConfig = `tools: # name of the tool - name: jenkins # id of the tool instance - instanceID: jenkins-dev + instanceID: default # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/kube-prometheus.go b/internal/pkg/show/config/plugin/kube-prometheus.go index 604b5e5e5..6a0f9f2eb 100644 --- a/internal/pkg/show/config/plugin/kube-prometheus.go +++ b/internal/pkg/show/config/plugin/kube-prometheus.go @@ -4,7 +4,7 @@ var KubePrometheusDefaultConfig = `tools: # name of the tool - name: kube-prometheus # id of the tool instance - instanceID: kube-prometheus-dev + instanceID: default # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/openldap.go b/internal/pkg/show/config/plugin/openldap.go index b69c24ccb..166c2e26e 100644 --- a/internal/pkg/show/config/plugin/openldap.go +++ b/internal/pkg/show/config/plugin/openldap.go @@ -4,7 +4,7 @@ var OpenldapDefaultConfig = `tools: # name of the tool - name: openldap # id of the tool instance - instanceID: openldap + instanceID: default # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/trello-github-integ.go b/internal/pkg/show/config/plugin/trello-github-integ.go index d460c930c..6f51d3e24 100644 --- a/internal/pkg/show/config/plugin/trello-github-integ.go +++ b/internal/pkg/show/config/plugin/trello-github-integ.go @@ -4,7 +4,7 @@ var TrelloGithubDefaultConfig = `tools: # name of the tool - name: trello-github-integ # id of the tool instance - instanceID: trello-github + instanceID: default # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. dependsOn: [ "TRELLO_TOOL_NAME.trello" ] # options for the plugin diff --git a/internal/pkg/show/config/plugin/trello.go b/internal/pkg/show/config/plugin/trello.go index 38eaac802..67c52002c 100644 --- a/internal/pkg/show/config/plugin/trello.go +++ b/internal/pkg/show/config/plugin/trello.go @@ -4,7 +4,7 @@ var TrelloDefaultConfig = `tools: # name of the tool - name: trello # id of the tool instance - instanceID: my-trello-board + instanceID: default # optional; if specified, dtm will make sure the dependency is applied first before handling this tool dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] # options for the plugin diff --git a/test/e2e/yaml/e2e-config.yaml b/test/e2e/yaml/e2e-config.yaml index 3f4eb624f..26eed5f51 100644 --- a/test/e2e/yaml/e2e-config.yaml +++ b/test/e2e/yaml/e2e-config.yaml @@ -1,17 +1,17 @@ tools: -- name: go-webapp-repo - plugin: github-repo-scaffolding-golang +- name: github-repo-scaffolding-golang + instanceID: default options: org: [[ githubOrganization ]] repo: [[ repoName ]] branch: [[ defaultBranch ]] image_repo: [[ dockerRegistryUserName ]]/[[ repoName ]] -- name: golang-demo-actions - plugin: githubactions-golang - dependsOn: ["go-webapp-repo.github-repo-scaffolding-golang"] +- name: githubactions-golang + instanceID: default + dependsOn: ["github-repo-scaffolding-golang.default"] options: - org: ${{go-webapp-repo.github-repo-scaffolding-golang.outputs.org}} - repo: ${{go-webapp-repo.github-repo-scaffolding-golang.outputs.repo}} + org: ${{github-repo-scaffolding-golang.default.outputs.org}} + repo: ${{github-repo-scaffolding-golang.default.outputs.repo}} language: name: go version: "1.17" @@ -25,7 +25,7 @@ tools: docker: enable: True - name: argocd - plugin: argocd + instanceID: default options: create_namespace: true repo: @@ -38,17 +38,17 @@ tools: wait: true timeout: [[ argocdDeployTimeout ]] upgradeCRDs: true -- name: go-webapp-argocd-deploy - plugin: argocdapp - dependsOn: ["argocd.argocd", "go-webapp-repo.github-repo-scaffolding-golang"] +- name: argocdapp + instanceID: default + dependsOn: ["argocd.default", "github-repo-scaffolding-golang.default"] options: app: - name: ${{go-webapp-repo.github-repo-scaffolding-golang.outputs.repo}} + name: ${{github-repo-scaffolding-golang.default.outputs.repo}} namespace: [[ argocdNameSpace ]] destination: server: https://kubernetes.default.svc namespace: default source: valuefile: values.yaml - path: helm/${{go-webapp-repo.github-repo-scaffolding-golang.outputs.repo}} - repoURL: ${{go-webapp-repo.github-repo-scaffolding-golang.outputs.repoURL}} + path: helm/${{github-repo-scaffolding-golang.default.outputs.repo}} + repoURL: ${{github-repo-scaffolding-golang.default.outputs.repoURL}} From 26757c046784403b9c1fadc023d2b1e8c54b80f5 Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Fri, 22 Apr 2022 15:37:44 +0800 Subject: [PATCH 07/11] refactor: update the dependsOn at al config Signed-off-by: Daniel Hu --- internal/pkg/show/config/plugin/argocd.go | 4 ++-- internal/pkg/show/config/plugin/argocdapp.go | 4 ++-- internal/pkg/show/config/plugin/devlake.go | 4 ++-- .../config/plugin/github-repo-scaffolding-golang.go | 4 ++-- .../pkg/show/config/plugin/githubactions-golang.go | 4 ++-- .../pkg/show/config/plugin/githubactions-nodejs.go | 4 ++-- .../pkg/show/config/plugin/githubactions-python.go | 4 ++-- internal/pkg/show/config/plugin/gitlabci-generic.go | 4 ++-- internal/pkg/show/config/plugin/gitlabci-golang.go | 4 ++-- internal/pkg/show/config/plugin/jenkins.go | 4 ++-- internal/pkg/show/config/plugin/jira-github-integ.go | 4 ++-- internal/pkg/show/config/plugin/kube-prometheus.go | 4 ++-- internal/pkg/show/config/plugin/openldap.go | 4 ++-- .../pkg/show/config/plugin/trello-github-integ.go | 12 ++++++------ internal/pkg/show/config/plugin/trello.go | 4 ++-- 15 files changed, 34 insertions(+), 34 deletions(-) diff --git a/internal/pkg/show/config/plugin/argocd.go b/internal/pkg/show/config/plugin/argocd.go index a93348ed6..eb1bd3acc 100644 --- a/internal/pkg/show/config/plugin/argocd.go +++ b/internal/pkg/show/config/plugin/argocd.go @@ -5,8 +5,8 @@ var ArgocdDefaultConfig = `tools: - name: argocd # id of the tool instance instanceID: default - # if specified, dtm will make sure the dependency is applied first before handling this tool. - dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool. + dependsOn: [] # options for the plugin options: # need to create the namespace or not, default: false diff --git a/internal/pkg/show/config/plugin/argocdapp.go b/internal/pkg/show/config/plugin/argocdapp.go index a701544a0..337c1c12f 100644 --- a/internal/pkg/show/config/plugin/argocdapp.go +++ b/internal/pkg/show/config/plugin/argocdapp.go @@ -5,8 +5,8 @@ var ArgocdappDefaultConfig = `tools: - name: argocdapp # id of the tool instance instanceID: default - # if specified, dtm will make sure the dependency is applied first before handling this tool. - dependsOn: [ "ARGOCD_TOOL_NAME.argocd" ] + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool. + dependsOn: [ "argocd.ARGOCD_INSTANCE_NAME" ] # options for the plugin options: # information on the ArgoCD Application diff --git a/internal/pkg/show/config/plugin/devlake.go b/internal/pkg/show/config/plugin/devlake.go index 3fc8abf5e..72c998c66 100644 --- a/internal/pkg/show/config/plugin/devlake.go +++ b/internal/pkg/show/config/plugin/devlake.go @@ -5,5 +5,5 @@ var DevlakeDefaultConfig = `tools: - name: devlake # id of the tool instance instanceID: default - # if specified, dtm will make sure the dependency is applied first before handling this tool. - dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ]` + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool. + dependsOn: []` diff --git a/internal/pkg/show/config/plugin/github-repo-scaffolding-golang.go b/internal/pkg/show/config/plugin/github-repo-scaffolding-golang.go index c6353ee99..9c60ad95d 100644 --- a/internal/pkg/show/config/plugin/github-repo-scaffolding-golang.go +++ b/internal/pkg/show/config/plugin/github-repo-scaffolding-golang.go @@ -5,8 +5,8 @@ var GithubRepoScaffoldingGolangDefaultConfig = `tools: - name: github-repo-scaffolding-golang # id of the tool instance instanceID: default - # if specified, dtm will make sure the dependency is applied first before handling this tool. - dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool. + dependsOn: [] # options for the plugin options: # the repo's owner. It should be case-sensitive here; strictly use your GitHub user name; please change the value below. diff --git a/internal/pkg/show/config/plugin/githubactions-golang.go b/internal/pkg/show/config/plugin/githubactions-golang.go index a151b1480..e929ec3ce 100644 --- a/internal/pkg/show/config/plugin/githubactions-golang.go +++ b/internal/pkg/show/config/plugin/githubactions-golang.go @@ -5,8 +5,8 @@ var GithubActionsGolangDefaultConfig = `tools: - name: githubactions-golang # id of the tool instance instanceID: default - # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. - dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool. + dependsOn: [] # options for the plugin options: # the repo's owner. It should be case-sensitive here; strictly use your GitHub user name; please change the value below. diff --git a/internal/pkg/show/config/plugin/githubactions-nodejs.go b/internal/pkg/show/config/plugin/githubactions-nodejs.go index 8cb9eb085..48f58ff09 100644 --- a/internal/pkg/show/config/plugin/githubactions-nodejs.go +++ b/internal/pkg/show/config/plugin/githubactions-nodejs.go @@ -5,8 +5,8 @@ var GithubActionsNodejsDefaultConfig = `tools: - name: githubactions-nodejs # id of the tool instance instanceID: default - # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. - dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool. + dependsOn: [] # options for the plugin options: # the repo's owner. It should be case-sensitive here; strictly use your GitHub user name; please change the value below. diff --git a/internal/pkg/show/config/plugin/githubactions-python.go b/internal/pkg/show/config/plugin/githubactions-python.go index e86948a0e..47e10ee5c 100644 --- a/internal/pkg/show/config/plugin/githubactions-python.go +++ b/internal/pkg/show/config/plugin/githubactions-python.go @@ -5,8 +5,8 @@ var GithubActionsPythonDefaultConfig = `tools: - name: githubactions-python # id of the tool instance instanceID: default - # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. - dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool. + dependsOn: [] # options for the plugin options: # the repo's owner. It should be case-sensitive here; strictly use your GitHub user name; please change the value below. diff --git a/internal/pkg/show/config/plugin/gitlabci-generic.go b/internal/pkg/show/config/plugin/gitlabci-generic.go index 36c48bf96..d1aa8fe02 100644 --- a/internal/pkg/show/config/plugin/gitlabci-generic.go +++ b/internal/pkg/show/config/plugin/gitlabci-generic.go @@ -5,8 +5,8 @@ var GitlabCIGenericDefaultConfig = `tools: - name: gitlabci-generic # id of the tool instance instanceID: default - # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. - dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool. + dependsOn: [] # options for the plugin options: # owner/repo; "path with namespace" is only GitLab API's way of saying the same thing; please change the values below. diff --git a/internal/pkg/show/config/plugin/gitlabci-golang.go b/internal/pkg/show/config/plugin/gitlabci-golang.go index 5c2d3f3bd..3a79a3adb 100644 --- a/internal/pkg/show/config/plugin/gitlabci-golang.go +++ b/internal/pkg/show/config/plugin/gitlabci-golang.go @@ -5,8 +5,8 @@ var GitlabCIGolangDefaultConfig = `tools: - name: gitlabci-golang # id of the tool instance instanceID: default - # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. - dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool. + dependsOn: [] # options for the plugin options: # owner/repo; "path with namespace" is only GitLab API's way of saying the same thing; please change the values below. diff --git a/internal/pkg/show/config/plugin/jenkins.go b/internal/pkg/show/config/plugin/jenkins.go index e54779a36..32574674f 100644 --- a/internal/pkg/show/config/plugin/jenkins.go +++ b/internal/pkg/show/config/plugin/jenkins.go @@ -5,8 +5,8 @@ var JenkinsDefaultConfig = `tools: - name: jenkins # id of the tool instance instanceID: default - # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. - dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool. + dependsOn: [] # options for the plugin options: # need to create the namespace or not, default: false diff --git a/internal/pkg/show/config/plugin/jira-github-integ.go b/internal/pkg/show/config/plugin/jira-github-integ.go index eef2bd88f..937475767 100644 --- a/internal/pkg/show/config/plugin/jira-github-integ.go +++ b/internal/pkg/show/config/plugin/jira-github-integ.go @@ -5,8 +5,8 @@ var JiraGithubDefaultConfig = `tools: - name: jira-github-integ # id of the tool instance instanceID: default - # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. - dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool. + dependsOn: [] # options for the plugin options: # the repo's owner diff --git a/internal/pkg/show/config/plugin/kube-prometheus.go b/internal/pkg/show/config/plugin/kube-prometheus.go index 6a0f9f2eb..bf660da25 100644 --- a/internal/pkg/show/config/plugin/kube-prometheus.go +++ b/internal/pkg/show/config/plugin/kube-prometheus.go @@ -5,8 +5,8 @@ var KubePrometheusDefaultConfig = `tools: - name: kube-prometheus # id of the tool instance instanceID: default - # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. - dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool. + dependsOn: [] # options for the plugin options: # need to create the namespace or not, default: false diff --git a/internal/pkg/show/config/plugin/openldap.go b/internal/pkg/show/config/plugin/openldap.go index 166c2e26e..b318f1b89 100644 --- a/internal/pkg/show/config/plugin/openldap.go +++ b/internal/pkg/show/config/plugin/openldap.go @@ -5,8 +5,8 @@ var OpenldapDefaultConfig = `tools: - name: openldap # id of the tool instance instanceID: default - # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. - dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool. + dependsOn: [] # options for the plugin options: # need to create the namespace or not, default: false diff --git a/internal/pkg/show/config/plugin/trello-github-integ.go b/internal/pkg/show/config/plugin/trello-github-integ.go index 6f51d3e24..f6a6b98ba 100644 --- a/internal/pkg/show/config/plugin/trello-github-integ.go +++ b/internal/pkg/show/config/plugin/trello-github-integ.go @@ -5,8 +5,8 @@ var TrelloGithubDefaultConfig = `tools: - name: trello-github-integ # id of the tool instance instanceID: default - # optional; if specified, dtm will make sure the dependency is applied first before handling this tool. - dependsOn: [ "TRELLO_TOOL_NAME.trello" ] + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool. + dependsOn: [ "trello.default" ] # options for the plugin options: # the repo's owner. It should be case-sensitive here; strictly use your GitHub user name; please change the value below. @@ -16,9 +16,9 @@ var TrelloGithubDefaultConfig = `tools: org: YOUR_ORGANIZATION_NAME repo: YOUR_REPO_NAME # reference parameters come from dependency, their usage will be explained later - boardId: ${{ TRELLO_TOOL_NAME.trello.outputs.boardId }} - todoListId: ${{ TRELLO_TOOL_NAME.trello.outputs.todoListId }} - doingListId: ${{ TRELLO_TOOL_NAME.trello.outputs.doingListId }} - doneListId: ${{ TRELLO_TOOL_NAME.trello.outputs.doneListId }} + boardId: ${{ trello.default.outputs.boardId }} + todoListId: ${{ trello.default.outputs.todoListId }} + doingListId: ${{ trello.default.outputs.doingListId }} + doneListId: ${{ trello.default.outputs.doneListId }} # main branch of the repo (to which branch the plugin will submit the workflows) branch: main` diff --git a/internal/pkg/show/config/plugin/trello.go b/internal/pkg/show/config/plugin/trello.go index 67c52002c..c7e481ae1 100644 --- a/internal/pkg/show/config/plugin/trello.go +++ b/internal/pkg/show/config/plugin/trello.go @@ -5,8 +5,8 @@ var TrelloDefaultConfig = `tools: - name: trello # id of the tool instance instanceID: default - # optional; if specified, dtm will make sure the dependency is applied first before handling this tool - dependsOn: [ "TOOL1_NAME.TOOL1_PLUGIN", "TOOL2_NAME.TOOL2_PLUGIN" ] + # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool + dependsOn: [] # options for the plugin options: # the repo's owner From 04696e4d60266a23cd0d2c021fd22f7402b912fe Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Fri, 22 Apr 2022 15:42:00 +0800 Subject: [PATCH 08/11] refactor: topological sort updated according the dependOn refactor Signed-off-by: Daniel Hu --- internal/pkg/pluginengine/topological_sort.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/pkg/pluginengine/topological_sort.go b/internal/pkg/pluginengine/topological_sort.go index 1608ed0e2..5e88a7239 100644 --- a/internal/pkg/pluginengine/topological_sort.go +++ b/internal/pkg/pluginengine/topological_sort.go @@ -8,7 +8,7 @@ import ( ) func generateKeyFromTool(tool configloader.Tool) string { - return fmt.Sprintf("%s.%s", tool.InstanceID, tool.Name) + return fmt.Sprintf("%s.%s", tool.Name, tool.InstanceID) } func dependencyResolved(tool configloader.Tool, unprocessedNodeSet map[string]bool) bool { @@ -16,14 +16,14 @@ func dependencyResolved(tool configloader.Tool, unprocessedNodeSet map[string]bo for _, dep := range tool.DependsOn { // if the tool's dependency is still not processed yet / still in the graph - log.Debugf("TOOL %s.%s dependency NOT solved\n", tool.InstanceID, tool.Name) + log.Debugf("TOOL %s.%s dependency NOT solved\n", tool.Name, tool.InstanceID) if _, ok := unprocessedNodeSet[dep]; ok { res = false break } } - log.Debugf("TOOL %s %s %t\n", tool.InstanceID, tool.Name, res) + log.Debugf("TOOL %s %s %t\n", tool.Name, tool.InstanceID, res) return res } @@ -55,11 +55,11 @@ func topologicalSort(tools []configloader.Tool) ([][]configloader.Tool, error) { // if there isn't any dependency: it's the "start" of the graph // we can put it into the first batch if len(tool.DependsOn) == 0 { - log.Debugf("TOOL %s.%s dependency already solved\n", tool.InstanceID, tool.Name) + log.Debugf("TOOL %s.%s dependency already solved\n", tool.Name, tool.InstanceID) batch = append(batch, tool) } else { if dependencyResolved(tool, unprocessedNodeSet) { - log.Debugf("TOOL %s.%s dependency already solved\n", tool.InstanceID, tool.Name) + log.Debugf("TOOL %s.%s dependency already solved\n", tool.Name, tool.InstanceID) batch = append(batch, tool) } } From f6388fa57121d6d95ad70cf0fd7702636752c200 Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Fri, 22 Apr 2022 15:48:48 +0800 Subject: [PATCH 09/11] refactor: outputs update according the refactor with outputs reference Signed-off-by: Daniel Hu --- internal/pkg/pluginengine/outputs.go | 28 +++------------------------- internal/pkg/statemanager/state.go | 6 +++--- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/internal/pkg/pluginengine/outputs.go b/internal/pkg/pluginengine/outputs.go index 317d2d4c7..07bb3d2cf 100644 --- a/internal/pkg/pluginengine/outputs.go +++ b/internal/pkg/pluginengine/outputs.go @@ -7,28 +7,6 @@ import ( "github.com/devstream-io/devstream/internal/pkg/statemanager" ) -const ( - // a legal output reference should be in the format of ${{ abc }} - OUTPUT_REFERENCE_PREFIX = "${{" - OUTPUT_REFERENCE_SUFFIX = "}}" - - // e.g., ${{ TOOL_NAME.PLUGIN.outputs.some_key }} - - // it has 4 sections, separated by "." - OUTPUT_REFERENCE_TOTAL_SECTIONS = 4 - SECTION_SEPARATOR = "." - - // the first section is the tool's name - TOOL_NAME = 0 - - // the second section is the plugin's kind - PLUGIN = 1 - - // the third section is a constant string "outputs" - // and the last section is the key to refer to - OUTPUT_REFERENCE_KEY = 3 -) - func HandleOutputsReferences(smgr statemanager.Manager, options map[string]interface{}) []error { errorsList := make([]error, 0) @@ -36,13 +14,13 @@ func HandleOutputsReferences(smgr statemanager.Manager, options map[string]inter // only process string values in the options // since all outputs references are strings, not ints, not booleans, not maps if optionValueStr, ok := optionValue.(string); ok { - match, toolName, pluginKind, outputReferenceKey := getToolNamePluginOutputKey(optionValueStr) + match, toolName, instanceID, outputReferenceKey := getToolNamePluginOutputKey(optionValueStr) // do nothing, if the value string isn't in the format of a valid output reference if !match { continue } - outputs, err := smgr.GetOutputs(statemanager.GenerateStateKeyByToolNameAndPluginKind(toolName, pluginKind)) + outputs, err := smgr.GetOutputs(statemanager.GenerateStateKeyByToolNameAndPluginKind(toolName, instanceID)) if err != nil { errorsList = append(errorsList, err) continue @@ -65,7 +43,7 @@ func HandleOutputsReferences(smgr statemanager.Manager, options map[string]inter } // getToolNamePluginKindAndOutputReferenceKey returns (false, "", "", "") if regex doesn't match -// if match, returns (true, name, kind, key) +// if match, returns (true, name, instanceID, key) func getToolNamePluginOutputKey(s string) (bool, string, string, string) { regex := `.*\${{\s*([^.]*)\.([^.]*)\.outputs\.([^.\s]*)\s*}}.*` r := regexp.MustCompile(regex) diff --git a/internal/pkg/statemanager/state.go b/internal/pkg/statemanager/state.go index 18c325789..578a4416e 100644 --- a/internal/pkg/statemanager/state.go +++ b/internal/pkg/statemanager/state.go @@ -83,9 +83,9 @@ func (s StatesMap) Format() []byte { type StateKey string func StateKeyGenerateFunc(t *configloader.Tool) StateKey { - return StateKey(fmt.Sprintf("%s_%s", t.InstanceID, t.Name)) + return StateKey(fmt.Sprintf("%s_%s", t.Name, t.InstanceID)) } -func GenerateStateKeyByToolNameAndPluginKind(toolName string, pluginKind string) StateKey { - return StateKey(fmt.Sprintf("%s_%s", toolName, pluginKind)) +func GenerateStateKeyByToolNameAndPluginKind(toolName string, instalceID string) StateKey { + return StateKey(fmt.Sprintf("%s_%s", toolName, instalceID)) } From 550049c902d98ddc77de975e8390e730e85cc9e9 Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Fri, 22 Apr 2022 16:31:07 +0800 Subject: [PATCH 10/11] fix: some bugfix according test Signed-off-by: Daniel Hu --- examples/gitops.yaml | 2 +- internal/pkg/configloader/validation.go | 2 +- internal/pkg/pluginengine/change.go | 14 +++++++------- internal/pkg/pluginengine/change_helper.go | 14 +++++++------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/gitops.yaml b/examples/gitops.yaml index 3921057c2..1a8c64fa9 100644 --- a/examples/gitops.yaml +++ b/examples/gitops.yaml @@ -7,7 +7,7 @@ tools: repo: [[ repoName ]] branch: [[ defaultBranch ]] image_repo: [[ dockerhubUsername ]]/[[ repoName ]] -- name: jira-github-default +- name: jira-github-integ instanceID: default dependsOn: [ "github-repo-scaffolding-golang.default" ] options: diff --git a/internal/pkg/configloader/validation.go b/internal/pkg/configloader/validation.go index 4842d8398..1ad48a468 100644 --- a/internal/pkg/configloader/validation.go +++ b/internal/pkg/configloader/validation.go @@ -47,7 +47,7 @@ func validateDependency(tools []Tool) []error { toolMap := make(map[string]bool) // creating the set for _, tool := range tools { - key := fmt.Sprintf("%s.%s", tool.InstanceID, tool.Name) + key := fmt.Sprintf("%s.%s", tool.Name, tool.InstanceID) toolMap[key] = true } diff --git a/internal/pkg/pluginengine/change.go b/internal/pkg/pluginengine/change.go index 402150b7c..2cfbda2ef 100644 --- a/internal/pkg/pluginengine/change.go +++ b/internal/pkg/pluginengine/change.go @@ -26,8 +26,8 @@ type ChangeResult struct { } func (c *Change) String() string { - return fmt.Sprintf("\n{\n ActionName: %s,\n Tool: {InstanceID: %s, InstanceID: %s}}\n}", - c.ActionName, c.Tool.InstanceID, c.Tool.Name) + return fmt.Sprintf("\n{\n ActionName: %s,\n Tool: {Name: %s, InstanceID: %s}}\n}", + c.ActionName, c.Tool.Name, c.Tool.InstanceID) } type CommandType string @@ -86,7 +86,7 @@ func execute(smgr statemanager.Manager, changes []*Change) map[string]error { for i, c := range changes { log.Separatorf("Processing progress: %d/%d.", i+1, numOfChanges) - log.Infof("Processing: %s (%s) -> %s ...", c.Tool.InstanceID, c.Tool.Name, c.ActionName) + log.Infof("Processing: %s (%s) -> %s ...", c.Tool.Name, c.Tool.InstanceID, c.ActionName) var succeeded bool var err error @@ -101,7 +101,7 @@ func execute(smgr statemanager.Manager, changes []*Change) map[string]error { for _, e := range errs { log.Errorf("Error: %s.", e) } - log.Errorf("The outputs reference in tool %s (%s) can't be resolved. Please double check your config.", c.Tool.InstanceID, c.Tool.Name) + log.Errorf("The outputs reference in tool %s (%s) can't be resolved. Please double check your config.", c.Tool.Name, c.Tool.InstanceID) // not executing this change since its input isn't valid continue @@ -162,14 +162,14 @@ func handleResult(smgr statemanager.Manager, change *Change) error { log.Debugf("Failed to delete state %s: %s.", key, err) return err } - log.Successf("Tool %s (%s) delete done.", change.Tool.InstanceID, change.Tool.Name) + log.Successf("Tool %s (%s) delete done.", change.Tool.Name, change.Tool.InstanceID) return nil } key := statemanager.StateKeyGenerateFunc(change.Tool) state := statemanager.State{ - InstanceID: change.Tool.InstanceID, Name: change.Tool.Name, + InstanceID: change.Tool.InstanceID, DependsOn: change.Tool.DependsOn, Options: change.Tool.Options, Resource: change.Result.ReturnValue, @@ -179,6 +179,6 @@ func handleResult(smgr statemanager.Manager, change *Change) error { log.Debugf("Failed to add state %s: %s.", key, err) return err } - log.Successf("InstanceID %s(%s) %s done.", change.Tool.InstanceID, change.Tool.Name, change.ActionName) + log.Successf("Tool %s(%s) %s done.", change.Tool.Name, change.Tool.InstanceID, change.ActionName) return nil } diff --git a/internal/pkg/pluginengine/change_helper.go b/internal/pkg/pluginengine/change_helper.go index cc23e7550..ee5496b86 100644 --- a/internal/pkg/pluginengine/change_helper.go +++ b/internal/pkg/pluginengine/change_helper.go @@ -79,7 +79,7 @@ func changesForApply(smgr statemanager.Manager, cfg *configloader.Config) ([]*Ch if state == nil { // tool not in the state, create, no need to Read resource before Create - description := fmt.Sprintf("Tool %s (%s) found in config but doesn't exist in the state, will be created.", tool.InstanceID, tool.Name) + description := fmt.Sprintf("Tool %s (%s) found in config but doesn't exist in the state, will be created.", tool.Name, tool.InstanceID) changes = append(changes, generateCreateAction(&tool, description)) } else { // tool found in the state @@ -90,7 +90,7 @@ func changesForApply(smgr statemanager.Manager, cfg *configloader.Config) ([]*Ch if drifted(tool.Options, state.Options) { // tool's config differs from State's, Update - description := fmt.Sprintf("Tool %s (%s) config drifted from the state, will be updated.", tool.InstanceID, tool.Name) + description := fmt.Sprintf("Tool %s (%s) config drifted from the state, will be updated.", tool.Name, tool.InstanceID) changes = append(changes, generateUpdateAction(&tool, description)) } else { // tool's config is the same as State's @@ -103,15 +103,15 @@ func changesForApply(smgr statemanager.Manager, cfg *configloader.Config) ([]*Ch if resource == nil { // tool exists in the state, but resource doesn't exist, Create - description := fmt.Sprintf("Tool %s (%s) state found but it seems the tool isn't created, will be created.", tool.InstanceID, tool.Name) + description := fmt.Sprintf("Tool %s (%s) state found but it seems the tool isn't created, will be created.", tool.Name, tool.InstanceID) changes = append(changes, generateCreateAction(&tool, description)) } else if drifted(resource, state.Resource) { // resource drifted from state, Update - description := fmt.Sprintf("Tool %s (%s) drifted from the state, will be updated.", tool.InstanceID, tool.Name) + description := fmt.Sprintf("Tool %s (%s) drifted from the state, will be updated.", tool.Name, tool.InstanceID) changes = append(changes, generateUpdateAction(&tool, description)) } else { // resource is the same as the state, do nothing - log.Debugf("Tool %s (%s) is the same as the state, do nothing.", tool.InstanceID, tool.Name) + log.Debugf("Tool %s (%s) is the same as the state, do nothing.", tool.Name, tool.InstanceID) } } } @@ -152,7 +152,7 @@ func changesForDelete(smgr statemanager.Manager, cfg *configloader.Config, isFor } } - description := fmt.Sprintf("Tool %s (%s) will be deleted.", tool.InstanceID, tool.Name) + description := fmt.Sprintf("Tool %s (%s) will be deleted.", tool.Name, tool.InstanceID) changes = append(changes, generateDeleteAction(&tool, description)) } } @@ -185,7 +185,7 @@ func GetChangesForDestroy(smgr statemanager.Manager) ([]*Change, error) { for i := len(batchesOfTools) - 1; i >= 0; i-- { batch := batchesOfTools[i] for _, tool := range batch { - description := fmt.Sprintf("Tool %s (%s) will be deleted.", tool.InstanceID, tool.Name) + description := fmt.Sprintf("Tool %s (%s) will be deleted.", tool.Name, tool.InstanceID) changes = append(changes, generateDeleteAction(&tool, description)) } } From fb11c2f5ff186534a8a6e6aeb3c332c49e545832 Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Fri, 22 Apr 2022 17:52:34 +0800 Subject: [PATCH 11/11] test: fix ut error according name/instanceID refactor Signed-off-by: Daniel Hu --- .../pkg/configloader/configloader_test.go | 2 +- .../pkg/pluginengine/pluginengine_test.go | 72 +++++++++---------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/internal/pkg/configloader/configloader_test.go b/internal/pkg/configloader/configloader_test.go index 6e92948e7..3c7fec5f7 100644 --- a/internal/pkg/configloader/configloader_test.go +++ b/internal/pkg/configloader/configloader_test.go @@ -29,7 +29,7 @@ func TestMultipleDependencies(t *testing.T) { tools := []Tool{ {InstanceID: "argocd", Name: "argocd"}, {InstanceID: "repo", Name: "github"}, - {InstanceID: "argocdapp", Name: "argocdapp", DependsOn: []string{"argocd.argocd", "repo.github"}}, + {InstanceID: "argocdapp", Name: "argocdapp", DependsOn: []string{"argocd.argocd", "github.repo"}}, } errors := validateDependency(tools) assert.Equal(t, len(errors), 0) diff --git a/internal/pkg/pluginengine/pluginengine_test.go b/internal/pkg/pluginengine/pluginengine_test.go index f4bd7e42f..510cd648f 100644 --- a/internal/pkg/pluginengine/pluginengine_test.go +++ b/internal/pkg/pluginengine/pluginengine_test.go @@ -18,11 +18,11 @@ var _ = Describe("Pluginengine", func() { smgr statemanager.Manager err error - trelloToolName = "mytrelloboard" - trelloPluginKind = "trello" + trelloInstance = "mytrelloboard" + trelloName = "trello" expectedBoardId = "1" expectedTodoListId = "2" - trelloKey = statemanager.StateKey(fmt.Sprintf("%s_%s", trelloToolName, trelloPluginKind)) + trelloKey = statemanager.StateKey(fmt.Sprintf("%s_%s", trelloName, trelloInstance)) ) BeforeEach(func() { @@ -39,57 +39,57 @@ var _ = Describe("Pluginengine", func() { }) It("should be 'one install'", func() { - name := "a" - kind := "tool-a" + instanceID := "a" + name := "tool-a" cfg := &configloader.Config{ - Tools: []configloader.Tool{*getTool(name, kind)}, + Tools: []configloader.Tool{*getTool(name, instanceID)}, } changes, _ := pluginengine.GetChangesForApply(smgr, cfg) GinkgoWriter.Print(changes) Expect(len(changes)).To(Equal(1)) c := changes[0] - Expect(c.Tool.InstanceID).To(Equal(name)) + Expect(c.Tool.InstanceID).To(Equal(instanceID)) Expect(c.ActionName).To(Equal(statemanager.ActionCreate)) }) It("should be 'two install'", func() { - name1, name2 := "a", "b" - plugin1, plugin2 := "tool-a", "too-b" + instanceID1, instanceID2 := "a", "b" + name1, name2 := "tool-a", "too-b" cfg := &configloader.Config{ - Tools: []configloader.Tool{*getTool(name1, plugin1), *getTool(name2, plugin2)}, + Tools: []configloader.Tool{*getTool(name1, instanceID1), *getTool(name2, instanceID2)}, } changes, _ := pluginengine.GetChangesForApply(smgr, cfg) Expect(len(changes)).To(Equal(2)) c1 := changes[0] - Expect(c1.Tool.InstanceID).To(Equal(name1)) - Expect(c1.Tool.Name).To(Equal(plugin1)) + Expect(c1.Tool.InstanceID).To(Equal(instanceID1)) + Expect(c1.Tool.Name).To(Equal(name1)) Expect(c1.ActionName).To(Equal(statemanager.ActionCreate)) c2 := changes[1] - Expect(c2.Tool.InstanceID).To(Equal(name2)) - Expect(c2.Tool.Name).To(Equal(plugin2)) + Expect(c2.Tool.InstanceID).To(Equal(instanceID2)) + Expect(c2.Tool.Name).To(Equal(name2)) Expect(c2.ActionName).To(Equal(statemanager.ActionCreate)) }) It("should be 1 uninstall when `dtm delete` is triggered against a config with 1 tool and a successful state", func() { - name := "a" - plugin := "tool-a" + instanceID := "a" + name := "tool-a" cfg := &configloader.Config{ - Tools: []configloader.Tool{*getTool(name, plugin)}, + Tools: []configloader.Tool{*getTool(name, instanceID)}, } - err = smgr.AddState(statemanager.StateKey(fmt.Sprintf("%s_%s", name, plugin)), statemanager.State{}) + err = smgr.AddState(statemanager.StateKey(fmt.Sprintf("%s_%s", name, instanceID)), statemanager.State{}) Expect(err).NotTo(HaveOccurred()) changes, _ := pluginengine.GetChangesForDelete(smgr, cfg, false) Expect(len(changes)).To(Equal(1)) c := changes[0] - Expect(c.Tool.InstanceID).To(Equal(name)) - Expect(c.Tool.Name).To(Equal(plugin)) + Expect(c.Tool.InstanceID).To(Equal(instanceID)) + Expect(c.Tool.Name).To(Equal(name)) Expect(c.ActionName).To(Equal(statemanager.ActionDelete)) }) @@ -109,8 +109,8 @@ var _ = Describe("Pluginengine", func() { Expect(err).NotTo(HaveOccurred()) dependantOptions := map[string]interface{}{ - "boardId": fmt.Sprintf("${{ %s.%s.outputs.boardId }}", trelloToolName, trelloPluginKind), - "todoListId": fmt.Sprintf("${{ %s.%s.outputs.todoListId }}", trelloToolName, trelloPluginKind), + "boardId": fmt.Sprintf("${{ %s.%s.outputs.boardId }}", trelloName, trelloInstance), + "todoListId": fmt.Sprintf("${{ %s.%s.outputs.todoListId }}", trelloName, trelloInstance), } expectResult := map[string]interface{}{ "boardId": expectedBoardId, @@ -136,7 +136,7 @@ var _ = Describe("Pluginengine", func() { Expect(err).NotTo(HaveOccurred()) dependantOptions := map[string]interface{}{ - "boardId": fmt.Sprintf("prefix/${{ %s.%s.outputs.boardId }}/suffix", trelloToolName, trelloPluginKind), + "boardId": fmt.Sprintf("prefix/${{ %s.%s.outputs.boardId }}/suffix", trelloName, trelloInstance), } expectResult := map[string]interface{}{ "boardId": fmt.Sprintf("prefix/%s/suffix", expectedBoardId), @@ -148,8 +148,8 @@ var _ = Describe("Pluginengine", func() { It("should give an error when output doesn't exist in the state", func() { trelloState := statemanager.State{ - InstanceID: "mytrelloboard", Name: "trello", + InstanceID: "mytrelloboard", Options: map[string]interface{}{}, Resource: map[string]interface{}{}, } @@ -157,10 +157,10 @@ var _ = Describe("Pluginengine", func() { Expect(err).NotTo(HaveOccurred()) dependantOptions := map[string]interface{}{ - "boardId": fmt.Sprintf("${{ %s.%s.outputs.boardId }}", trelloToolName, trelloPluginKind), + "boardId": fmt.Sprintf("${{ %s.%s.outputs.boardId }}", trelloName, trelloInstance), } expectResult := map[string]interface{}{ - "boardId": fmt.Sprintf("${{ %s.%s.outputs.boardId }}", trelloToolName, trelloPluginKind), + "boardId": fmt.Sprintf("${{ %s.%s.outputs.boardId }}", trelloName, trelloInstance), } errs := pluginengine.HandleOutputsReferences(smgr, dependantOptions) Expect(len(errs)).To(Equal(1)) @@ -169,8 +169,8 @@ var _ = Describe("Pluginengine", func() { It("should give an error when the referred key doesn't exist", func() { trelloState := statemanager.State{ - InstanceID: "mytrelloboard", Name: "trello", + InstanceID: "mytrelloboard", Options: map[string]interface{}{}, Resource: map[string]interface{}{ "outputs": map[string]interface{}{ @@ -183,14 +183,14 @@ var _ = Describe("Pluginengine", func() { Expect(err).NotTo(HaveOccurred()) dependantOptions := map[string]interface{}{ - "boardId": fmt.Sprintf("${{ %s.%s.outputs.boardId }}", trelloToolName, trelloPluginKind), - "todoListId": fmt.Sprintf("${{ %s.%s.outputs.todoListId }}", trelloToolName, trelloPluginKind), - "someKey": fmt.Sprintf("${{ %s.%s.outputs.keyNotExist }}", trelloToolName, trelloPluginKind), + "boardId": fmt.Sprintf("${{ %s.%s.outputs.boardId }}", trelloName, trelloInstance), + "todoListId": fmt.Sprintf("${{ %s.%s.outputs.todoListId }}", trelloName, trelloInstance), + "someKey": fmt.Sprintf("${{ %s.%s.outputs.keyNotExist }}", trelloName, trelloInstance), } expectResult := map[string]interface{}{ "boardId": expectedBoardId, "todoListId": expectedTodoListId, - "someKey": fmt.Sprintf("${{ %s.%s.outputs.keyNotExist }}", trelloToolName, trelloPluginKind), + "someKey": fmt.Sprintf("${{ %s.%s.outputs.keyNotExist }}", trelloName, trelloInstance), } errs := pluginengine.HandleOutputsReferences(smgr, dependantOptions) Expect(len(errs)).To(Equal(1)) @@ -199,8 +199,8 @@ var _ = Describe("Pluginengine", func() { It("should work for nested maps", func() { trelloState := statemanager.State{ - InstanceID: "mytrelloboard", Name: "trello", + InstanceID: "mytrelloboard", Options: map[string]interface{}{}, Resource: map[string]interface{}{ "outputs": map[string]interface{}{ @@ -213,7 +213,7 @@ var _ = Describe("Pluginengine", func() { dependantOptions := map[string]interface{}{ "outerKey": map[string]interface{}{ - "innerKey": fmt.Sprintf("${{ %s.%s.outputs.boardId }}", trelloToolName, trelloPluginKind), + "innerKey": fmt.Sprintf("${{ %s.%s.outputs.boardId }}", trelloName, trelloInstance), }, } expectResult := map[string]interface{}{ @@ -227,10 +227,10 @@ var _ = Describe("Pluginengine", func() { }) }) -func getTool(name, kind string) *configloader.Tool { +func getTool(name, instance string) *configloader.Tool { return &configloader.Tool{ - InstanceID: name, - Name: kind, + Name: name, + InstanceID: instance, Options: map[string]interface{}{"key": "value"}, } }