Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Config Logic Enhancement #655

Merged
merged 8 commits into from
Jun 7, 2022

Conversation

daniel-hutao
Copy link
Member

@daniel-hutao daniel-hutao commented Jun 6, 2022

Signed-off-by: Daniel Hu tao.hu@merico.dev

Pre-Checklist

Note: please complete ALL items in the following checklist.

  • I have read through the CONTRIBUTING.md documentation.
  • My code has the necessary comments and documentation (if needed).
  • I have added relevant tests

Description

  • Reorganize configloader package
  • Single config support implemented
  • All docs & yaml updated
  • Quickstart & GitOps workflow tested locally

Related Issues

close #596

related closed pr: #604

New Behavior (screenshots if needed)

See the test below.

Test

1. quickstart with single config

  • quickstart.yaml
---
# tool file path, you can set it to absolute path or relative path.
toolFile: "" # here is a relative path.
# state config, backend can be local or s3
state:
  backend: local
  options:
    stateFile: devstream.state

---
tools:
  - name: github-repo-scaffolding-golang
    instanceID: default
    options:
      owner: daniel-hutao
      repo: go-webapp-devstream-demo
      branch: main
      image_repo: exploitht/go-webapp-devstream-demo
  - name: githubactions-golang
    instanceID: default
    dependsOn: ["github-repo-scaffolding-golang.default"]
    options:
      owner: daniel-hutao
      repo: go-webapp-devstream-demo
      language:
        name: go
        version: "1.17"
      branch: main
      build:
        enable: True
      test:
        enable: True
        coverage:
          enable: True
      docker:
        enable: False
  • apply
2022-06-06 16:12:11 ℹ [INFO]  Apply started.
2022-06-06 16:12:11 ℹ [INFO]  Got Backend from config: local
2022-06-06 16:12:11 ℹ [INFO]  Using dir <.devstream> to store plugins.
2022-06-06 16:12:11 ℹ [INFO]  Using local backend. State file: devstream.state.
2022-06-06 16:12:11 ℹ [INFO]  Tool (github-repo-scaffolding-golang/default) found in config but doesn't exist in the state, will be created.
2022-06-06 16:12:11 ℹ [INFO]  Tool (githubactions-golang/default) found in config but doesn't exist in the state, will be created.
2022-06-06 16:12:11 ℹ [INFO]  Start executing the plan.
2022-06-06 16:12:11 ℹ [INFO]  Changes count: 2.
2022-06-06 16:12:11 ℹ [INFO]  -------------------- [  Processing progress: 1/2.  ] --------------------
2022-06-06 16:12:11 ℹ [INFO]  Processing: (github-repo-scaffolding-golang/default) -> Create ...
2022-06-06 16:12:14 ℹ [INFO]  The repo go-webapp-devstream-demo has been created.
2022-06-06 16:12:26 ✔ [SUCCESS]  Tool (github-repo-scaffolding-golang/default) Create done.
2022-06-06 16:12:26 ℹ [INFO]  -------------------- [  Processing progress: 2/2.  ] --------------------
2022-06-06 16:12:26 ℹ [INFO]  Processing: (githubactions-golang/default) -> Create ...
2022-06-06 16:12:26 ℹ [INFO]  Creating GitHub Actions workflow pr-builder.yml ...
2022-06-06 16:12:27 ✔ [SUCCESS]  Github Actions workflow pr-builder.yml created.
2022-06-06 16:12:27 ℹ [INFO]  Creating GitHub Actions workflow main-builder.yml ...
2022-06-06 16:12:28 ✔ [SUCCESS]  Github Actions workflow main-builder.yml created.
2022-06-06 16:12:28 ✔ [SUCCESS]  Tool (githubactions-golang/default) Create done.
2022-06-06 16:12:28 ℹ [INFO]  -------------------- [  Processing done.  ] --------------------
2022-06-06 16:12:28 ✔ [SUCCESS]  All plugins applied successfully.
2022-06-06 16:12:28 ✔ [SUCCESS]  Apply finished.
  • delete
2022-06-06 16:13:21 ℹ [INFO]  Delete started.
2022-06-06 16:13:21 ℹ [INFO]  Got Backend from config: local
2022-06-06 16:13:21 ℹ [INFO]  Using dir <.devstream> to store plugins.
2022-06-06 16:13:21 ℹ [INFO]  Using local backend. State file: devstream.state.
2022-06-06 16:13:21 ℹ [INFO]  Tool (githubactions-golang/default) will be deleted.
2022-06-06 16:13:21 ℹ [INFO]  Tool (github-repo-scaffolding-golang/default) will be deleted.
2022-06-06 16:13:21 ℹ [INFO]  Start executing the plan.
2022-06-06 16:13:21 ℹ [INFO]  Changes count: 2.
2022-06-06 16:13:21 ℹ [INFO]  -------------------- [  Processing progress: 1/2.  ] --------------------
2022-06-06 16:13:21 ℹ [INFO]  Processing: (githubactions-golang/default) -> Delete ...
2022-06-06 16:13:22 ℹ [INFO]  Deleting GitHub Actions workflow pr-builder.yml ...
2022-06-06 16:13:22 ✔ [SUCCESS]  GitHub Actions workflow pr-builder.yml removed.
2022-06-06 16:13:22 ℹ [INFO]  Deleting GitHub Actions workflow main-builder.yml ...
2022-06-06 16:13:23 ✔ [SUCCESS]  GitHub Actions workflow main-builder.yml removed.
2022-06-06 16:13:23 ℹ [INFO]  Prepare to delete 'githubactions-golang_default' from States.
2022-06-06 16:13:23 ✔ [SUCCESS]  Tool (githubactions-golang/default) delete done.
2022-06-06 16:13:23 ℹ [INFO]  -------------------- [  Processing progress: 2/2.  ] --------------------
2022-06-06 16:13:23 ℹ [INFO]  Processing: (github-repo-scaffolding-golang/default) -> Delete ...
2022-06-06 16:13:24 ✔ [SUCCESS]  GitHub repo go-webapp-devstream-demo removed.
2022-06-06 16:13:24 ℹ [INFO]  Prepare to delete 'github-repo-scaffolding-golang_default' from States.
2022-06-06 16:13:24 ✔ [SUCCESS]  Tool (github-repo-scaffolding-golang/default) delete done.
2022-06-06 16:13:24 ℹ [INFO]  -------------------- [  Processing done.  ] --------------------
2022-06-06 16:13:24 ✔ [SUCCESS]  All plugins deleted successfully.
2022-06-06 16:13:24 ✔ [SUCCESS]  Delete finished.

2. quickstart with 2 config files

  • quickstart.yaml
---
# tool file path, you can set it to absolute path or relative path.
toolFile: "tools-qs.yaml" # here is a relative path.
# state config, backend can be local or s3
state:
  backend: local
  options:
    stateFile: devstream.state
  • tools-qs.yaml
---
tools:
  - name: github-repo-scaffolding-golang
    instanceID: default
    options:
      owner: daniel-hutao
      repo: go-webapp-devstream-demo
      branch: main
      image_repo: exploitht/go-webapp-devstream-demo
  - name: githubactions-golang
    instanceID: default
    dependsOn: ["github-repo-scaffolding-golang.default"]
    options:
      owner: daniel-hutao
      repo: go-webapp-devstream-demo
      language:
        name: go
        version: "1.17"
      branch: main
      build:
        enable: True
      test:
        enable: True
        coverage:
          enable: True
      docker:
        enable: False
  • apply
2022-06-06 16:23:22 ℹ [INFO]  Apply started.
2022-06-06 16:23:22 ℹ [INFO]  Got Backend from config: local
2022-06-06 16:23:22 ℹ [INFO]  Using dir <.devstream> to store plugins.
2022-06-06 16:23:22 ℹ [INFO]  Using local backend. State file: devstream.state.
2022-06-06 16:23:22 ℹ [INFO]  Tool (github-repo-scaffolding-golang/default) found in config but doesn't exist in the state, will be created.
2022-06-06 16:23:22 ℹ [INFO]  Tool (githubactions-golang/default) found in config but doesn't exist in the state, will be created.
2022-06-06 16:23:22 ℹ [INFO]  Start executing the plan.
2022-06-06 16:23:22 ℹ [INFO]  Changes count: 2.
2022-06-06 16:23:22 ℹ [INFO]  -------------------- [  Processing progress: 1/2.  ] --------------------
2022-06-06 16:23:22 ℹ [INFO]  Processing: (github-repo-scaffolding-golang/default) -> Create ...
2022-06-06 16:23:24 ℹ [INFO]  The repo go-webapp-devstream-demo has been created.
2022-06-06 16:23:37 ✔ [SUCCESS]  Tool (github-repo-scaffolding-golang/default) Create done.
2022-06-06 16:23:37 ℹ [INFO]  -------------------- [  Processing progress: 2/2.  ] --------------------
2022-06-06 16:23:37 ℹ [INFO]  Processing: (githubactions-golang/default) -> Create ...
2022-06-06 16:23:37 ℹ [INFO]  Creating GitHub Actions workflow pr-builder.yml ...
2022-06-06 16:23:38 ✔ [SUCCESS]  Github Actions workflow pr-builder.yml created.
2022-06-06 16:23:38 ℹ [INFO]  Creating GitHub Actions workflow main-builder.yml ...
2022-06-06 16:23:39 ✔ [SUCCESS]  Github Actions workflow main-builder.yml created.
2022-06-06 16:23:39 ✔ [SUCCESS]  Tool (githubactions-golang/default) Create done.
2022-06-06 16:23:39 ℹ [INFO]  -------------------- [  Processing done.  ] --------------------
2022-06-06 16:23:39 ✔ [SUCCESS]  All plugins applied successfully.
2022-06-06 16:23:39 ✔ [SUCCESS]  Apply finished.
  • delete
2022-06-06 16:24:02 ℹ [INFO]  Delete started.
2022-06-06 16:24:02 ℹ [INFO]  Got Backend from config: local
2022-06-06 16:24:02 ℹ [INFO]  Using dir <.devstream> to store plugins.
2022-06-06 16:24:02 ℹ [INFO]  Using local backend. State file: devstream.state.
2022-06-06 16:24:02 ℹ [INFO]  Tool (githubactions-golang/default) will be deleted.
2022-06-06 16:24:02 ℹ [INFO]  Tool (github-repo-scaffolding-golang/default) will be deleted.
2022-06-06 16:24:02 ℹ [INFO]  Start executing the plan.
2022-06-06 16:24:02 ℹ [INFO]  Changes count: 2.
2022-06-06 16:24:02 ℹ [INFO]  -------------------- [  Processing progress: 1/2.  ] --------------------
2022-06-06 16:24:02 ℹ [INFO]  Processing: (githubactions-golang/default) -> Delete ...
2022-06-06 16:24:03 ℹ [INFO]  Deleting GitHub Actions workflow pr-builder.yml ...
2022-06-06 16:24:03 ✔ [SUCCESS]  GitHub Actions workflow pr-builder.yml removed.
2022-06-06 16:24:04 ℹ [INFO]  Deleting GitHub Actions workflow main-builder.yml ...
2022-06-06 16:24:05 ✔ [SUCCESS]  GitHub Actions workflow main-builder.yml removed.
2022-06-06 16:24:05 ℹ [INFO]  Prepare to delete 'githubactions-golang_default' from States.
2022-06-06 16:24:05 ✔ [SUCCESS]  Tool (githubactions-golang/default) delete done.
2022-06-06 16:24:05 ℹ [INFO]  -------------------- [  Processing progress: 2/2.  ] --------------------
2022-06-06 16:24:05 ℹ [INFO]  Processing: (github-repo-scaffolding-golang/default) -> Delete ...
2022-06-06 16:24:05 ✔ [SUCCESS]  GitHub repo go-webapp-devstream-demo removed.
2022-06-06 16:24:05 ℹ [INFO]  Prepare to delete 'github-repo-scaffolding-golang_default' from States.
2022-06-06 16:24:05 ✔ [SUCCESS]  Tool (github-repo-scaffolding-golang/default) delete done.
2022-06-06 16:24:05 ℹ [INFO]  -------------------- [  Processing done.  ] --------------------
2022-06-06 16:24:05 ✔ [SUCCESS]  All plugins deleted successfully.
2022-06-06 16:24:05 ✔ [SUCCESS]  Delete finished.

3. gitops with single config file

  • gitops.yaml
---
# core config
varFile: "" # If not empty, use the specified external variables config file
toolFile: "" # If not empty, use the specified external tools config file
state: # state config, backend can be local or s3
  backend: local
  options:
    stateFile: devstream.state

---
# variables config
defaultBranch: main
githubUsername: daniel-hutao
repoName: dtm-test-go
jiraID: merico
jiraUserEmail: tao.hu@merico.dev
jiraProjectKey: DT
dockerhubUsername: exploitht
argocdNameSpace: argocd
argocdDeployTimeout: 10m

---
# plugins config
tools:
  - name: github-repo-scaffolding-golang
    instanceID: default
    options:
      owner: [[ githubUsername ]]
      org: ""
      repo: [[ repoName ]]
      branch: [[ defaultBranch ]]
      image_repo: [[ dockerhubUsername ]]/[[ repoName ]]
  - name: jira-github-integ
    instanceID: default
    dependsOn: [ "github-repo-scaffolding-golang.default" ]
    options:
      owner: [[ githubUsername ]]
      repo: [[ repoName ]]
      jiraBaseUrl: https://[[ jiraID ]].atlassian.net
      jiraUserEmail: [[ jiraUserEmail ]]
      jiraProjectKey: [[ jiraProjectKey ]]
      branch: main
  - name: githubactions-golang
    instanceID: default
    dependsOn: [ "github-repo-scaffolding-golang.default" ]
    options:
      owner: ${{github-repo-scaffolding-golang.default.outputs.owner}}
      org: ""
      repo: ${{github-repo-scaffolding-golang.default.outputs.repo}}
      language:
        name: go
        version: "1.17"
      branch: [[ defaultBranch ]]
      build:
        enable: True
        command: "go build ./..."
      test:
        enable: True
        command: "go test ./..."
        coverage:
          enable: True
          profile: "-race -covermode=atomic"
          output: "coverage.out"
      docker:
        enable: True
        registry:
          type: dockerhub
          username: [[ dockerhubUsername ]]
          repository: ${{github-repo-scaffolding-golang.default.outputs.repo}}
  - name: argocd
    instanceID: default
    options:
      create_namespace: true
      repo:
        name: argo
        url: https://argoproj.github.io/argo-helm
      chart:
        chart_name: argo/argo-cd
        release_name: argocd
        namespace: [[ argocdNameSpace ]]
        wait: true
        timeout: [[ argocdDeployTimeout ]]
        upgradeCRDs: true
  - name: argocdapp
    instanceID: default
    dependsOn: ["argocd.default", "github-repo-scaffolding-golang.default"]
    options:
      app:
        name: ${{github-repo-scaffolding-golang.default.outputs.repo}}
        namespace: [[ argocdNameSpace ]]
      destination:
        server: https://kubernetes.default.svc
        namespace: default
      source:
        valuefile: values.yaml
        path: helm/${{github-repo-scaffolding-golang.default.outputs.repo}}
        repoURL: ${{github-repo-scaffolding-golang.default.outputs.repoURL}}
  • apply
2022-06-06 16:32:55 ℹ [INFO]  Apply started.
2022-06-06 16:32:55 ℹ [INFO]  Got Backend from config: local
2022-06-06 16:32:55 ℹ [INFO]  Using dir <.devstream> to store plugins.
2022-06-06 16:32:56 ℹ [INFO]  Using local backend. State file: devstream.state.
2022-06-06 16:32:56 ℹ [INFO]  Tool (github-repo-scaffolding-golang/default) found in config but doesn't exist in the state, will be created.
2022-06-06 16:32:56 ℹ [INFO]  Tool (argocd/default) found in config but doesn't exist in the state, will be created.
2022-06-06 16:32:56 ℹ [INFO]  Tool (jira-github-integ/default) found in config but doesn't exist in the state, will be created.
2022-06-06 16:32:56 ℹ [INFO]  Tool (githubactions-golang/default) found in config but doesn't exist in the state, will be created.
2022-06-06 16:32:56 ℹ [INFO]  Tool (argocdapp/default) found in config but doesn't exist in the state, will be created.
2022-06-06 16:32:56 ℹ [INFO]  Start executing the plan.
2022-06-06 16:32:56 ℹ [INFO]  Changes count: 5.
2022-06-06 16:32:56 ℹ [INFO]  -------------------- [  Processing progress: 1/5.  ] --------------------
2022-06-06 16:32:56 ℹ [INFO]  Processing: (github-repo-scaffolding-golang/default) -> Create ...
2022-06-06 16:32:58 ℹ [INFO]  The repo dtm-test-go has been created.
2022-06-06 16:33:11 ✔ [SUCCESS]  Tool (github-repo-scaffolding-golang/default) Create done.
2022-06-06 16:33:11 ℹ [INFO]  -------------------- [  Processing progress: 2/5.  ] --------------------
2022-06-06 16:33:11 ℹ [INFO]  Processing: (argocd/default) -> Create ...
2022-06-06 16:33:13 ℹ [INFO]  Creating or updating helm chart ...
2022/06/06 16:33:15 creating 1 resource(s)
2022/06/06 16:33:15 creating 1 resource(s)
2022/06/06 16:33:15 creating 1 resource(s)
2022/06/06 16:33:15 creating 1 resource(s)
2022/06/06 16:33:15 Clearing discovery cache
2022/06/06 16:33:15 beginning wait for 4 resources with timeout of 1m0s
2022/06/06 16:33:21 creating 43 resource(s)
2022/06/06 16:33:21 beginning wait for 43 resources with timeout of 10m0s
2022/06/06 16:33:21 Deployment is not ready: argocd/argocd-applicationset-controller. 0 out of 1 expected pods are ready
... 
2022/06/06 16:35:51 Deployment is not ready: argocd/argocd-dex-server. 0 out of 1 expected pods are ready
2022/06/06 16:35:53 Deployment is not ready: argocd/argocd-dex-server. 0 out of 1 expected pods are ready
2022/06/06 16:35:56 release installed successfully: argocd/argo-cd-4.8.2
2022-06-06 16:35:56 ✔ [SUCCESS]  Tool (argocd/default) Create done.
2022-06-06 16:35:56 ℹ [INFO]  -------------------- [  Processing progress: 3/5.  ] --------------------
2022-06-06 16:35:56 ℹ [INFO]  Processing: (jira-github-integ/default) -> Create ...
2022-06-06 16:35:58 ℹ [INFO]  Creating GitHub Actions workflow jira-github-integ.yml ...
2022-06-06 16:35:59 ✔ [SUCCESS]  Github Actions workflow jira-github-integ.yml created.
2022-06-06 16:36:01 ✔ [SUCCESS]  Tool (jira-github-integ/default) Create done.
2022-06-06 16:36:01 ℹ [INFO]  -------------------- [  Processing progress: 4/5.  ] --------------------
2022-06-06 16:36:01 ℹ [INFO]  Processing: (githubactions-golang/default) -> Create ...
2022-06-06 16:36:02 ℹ [INFO]  Creating GitHub Actions workflow pr-builder.yml ...
2022-06-06 16:36:03 ✔ [SUCCESS]  Github Actions workflow pr-builder.yml created.
2022-06-06 16:36:03 ℹ [INFO]  Creating GitHub Actions workflow main-builder.yml ...
2022-06-06 16:36:04 ✔ [SUCCESS]  Github Actions workflow main-builder.yml created.
2022-06-06 16:36:04 ✔ [SUCCESS]  Tool (githubactions-golang/default) Create done.
2022-06-06 16:36:04 ℹ [INFO]  -------------------- [  Processing progress: 5/5.  ] --------------------
2022-06-06 16:36:04 ℹ [INFO]  Processing: (argocdapp/default) -> Create ...
2022-06-06 16:36:05 ℹ [INFO]  application.argoproj.io/dtm-test-go created
2022-06-06 16:36:05 ✔ [SUCCESS]  Tool (argocdapp/default) Create done.
2022-06-06 16:36:05 ℹ [INFO]  -------------------- [  Processing done.  ] --------------------
2022-06-06 16:36:05 ✔ [SUCCESS]  All plugins applied successfully.
2022-06-06 16:36:05 ✔ [SUCCESS]  Apply finished.
  • delete
2022-06-06 16:36:42 ℹ [INFO]  Delete started.
2022-06-06 16:36:42 ℹ [INFO]  Got Backend from config: local
2022-06-06 16:36:42 ℹ [INFO]  Using dir <.devstream> to store plugins.
2022-06-06 16:36:42 ℹ [INFO]  Using local backend. State file: devstream.state.
2022-06-06 16:36:42 ℹ [INFO]  Tool (jira-github-integ/default) will be deleted.
2022-06-06 16:36:42 ℹ [INFO]  Tool (githubactions-golang/default) will be deleted.
2022-06-06 16:36:42 ℹ [INFO]  Tool (argocdapp/default) will be deleted.
2022-06-06 16:36:42 ℹ [INFO]  Tool (github-repo-scaffolding-golang/default) will be deleted.
2022-06-06 16:36:42 ℹ [INFO]  Tool (argocd/default) will be deleted.
2022-06-06 16:36:42 ℹ [INFO]  Start executing the plan.
2022-06-06 16:36:42 ℹ [INFO]  Changes count: 5.
2022-06-06 16:36:42 ℹ [INFO]  -------------------- [  Processing progress: 1/5.  ] --------------------
2022-06-06 16:36:42 ℹ [INFO]  Processing: (jira-github-integ/default) -> Delete ...
2022-06-06 16:36:43 ℹ [INFO]  Deleting GitHub Actions workflow jira-github-integ.yml ...
2022-06-06 16:36:43 ✔ [SUCCESS]  GitHub Actions workflow jira-github-integ.yml removed.
2022-06-06 16:36:43 ℹ [INFO]  Prepare to delete 'jira-github-integ_default' from States.
2022-06-06 16:36:43 ✔ [SUCCESS]  Tool (jira-github-integ/default) delete done.
2022-06-06 16:36:43 ℹ [INFO]  -------------------- [  Processing progress: 2/5.  ] --------------------
2022-06-06 16:36:43 ℹ [INFO]  Processing: (githubactions-golang/default) -> Delete ...
2022-06-06 16:36:45 ℹ [INFO]  Deleting GitHub Actions workflow pr-builder.yml ...
2022-06-06 16:36:45 ✔ [SUCCESS]  GitHub Actions workflow pr-builder.yml removed.
2022-06-06 16:36:46 ℹ [INFO]  Deleting GitHub Actions workflow main-builder.yml ...
2022-06-06 16:36:46 ✔ [SUCCESS]  GitHub Actions workflow main-builder.yml removed.
2022-06-06 16:36:46 ℹ [INFO]  Prepare to delete 'githubactions-golang_default' from States.
2022-06-06 16:36:46 ✔ [SUCCESS]  Tool (githubactions-golang/default) delete done.
2022-06-06 16:36:46 ℹ [INFO]  -------------------- [  Processing progress: 3/5.  ] --------------------
2022-06-06 16:36:46 ℹ [INFO]  Processing: (argocdapp/default) -> Delete ...
2022-06-06 16:36:48 ℹ [INFO]  application.argoproj.io "dtm-test-go" deleted
2022-06-06 16:36:48 ℹ [INFO]  Prepare to delete 'argocdapp_default' from States.
2022-06-06 16:36:48 ✔ [SUCCESS]  Tool (argocdapp/default) delete done.
2022-06-06 16:36:48 ℹ [INFO]  -------------------- [  Processing progress: 4/5.  ] --------------------
2022-06-06 16:36:48 ℹ [INFO]  Processing: (github-repo-scaffolding-golang/default) -> Delete ...
2022-06-06 16:36:48 ✔ [SUCCESS]  GitHub repo dtm-test-go removed.
2022-06-06 16:36:48 ℹ [INFO]  Prepare to delete 'github-repo-scaffolding-golang_default' from States.
2022-06-06 16:36:48 ✔ [SUCCESS]  Tool (github-repo-scaffolding-golang/default) delete done.
2022-06-06 16:36:48 ℹ [INFO]  -------------------- [  Processing progress: 5/5.  ] --------------------
2022-06-06 16:36:48 ℹ [INFO]  Processing: (argocd/default) -> Delete ...
2022-06-06 16:36:50 ℹ [INFO]  Uninstalling argocd helm chart.
2022/06/06 16:36:50 uninstall: Deleting argocd
2022/06/06 16:36:51 Starting delete for "argocd-dex-server" Service
2022/06/06 16:36:51 Starting delete for "argocd-repo-server" Service
2022/06/06 16:36:51 Starting delete for "argocd-server" Service
2022/06/06 16:36:51 Starting delete for "argocd-applicationset-controller" Service
2022/06/06 16:36:51 Starting delete for "argocd-redis" Service
2022/06/06 16:36:51 Starting delete for "argocd-application-controller" Service
2022/06/06 16:36:51 Starting delete for "argocd-application-controller" StatefulSet
2022/06/06 16:36:51 Starting delete for "argocd-applicationset-controller" Deployment
2022/06/06 16:36:51 Starting delete for "argocd-server" Deployment
2022/06/06 16:36:51 Starting delete for "argocd-redis" Deployment
2022/06/06 16:36:51 Starting delete for "argocd-notifications-controller" Deployment
2022/06/06 16:36:51 Starting delete for "argocd-dex-server" Deployment
2022/06/06 16:36:51 Starting delete for "argocd-repo-server" Deployment
2022/06/06 16:36:52 Starting delete for "argocd-dex-server" RoleBinding
2022/06/06 16:36:52 Starting delete for "argocd-applicationset-controller" RoleBinding
2022/06/06 16:36:52 Starting delete for "argocd-repo-server" RoleBinding
2022/06/06 16:36:52 Starting delete for "argocd-server" RoleBinding
2022/06/06 16:36:52 Starting delete for "argocd-application-controller" RoleBinding
2022/06/06 16:36:52 Starting delete for "argocd-notifications-controller" RoleBinding
2022/06/06 16:36:52 Starting delete for "argocd-dex-server" Role
2022/06/06 16:36:52 Starting delete for "argocd-repo-server" Role
2022/06/06 16:36:52 Starting delete for "argocd-server" Role
2022/06/06 16:36:52 Starting delete for "argocd-notifications-controller" Role
2022/06/06 16:36:52 Starting delete for "argocd-applicationset-controller" Role
2022/06/06 16:36:52 Starting delete for "argocd-application-controller" Role
2022/06/06 16:36:52 Starting delete for "argocd-server" ClusterRoleBinding
2022/06/06 16:36:52 Starting delete for "argocd-application-controller" ClusterRoleBinding
2022/06/06 16:36:52 Starting delete for "argocd-server" ClusterRole
2022/06/06 16:36:52 Starting delete for "argocd-application-controller" ClusterRole
2022/06/06 16:36:52 Starting delete for "argocd-gpg-keys-cm" ConfigMap
2022/06/06 16:36:52 Starting delete for "argocd-rbac-cm" ConfigMap
2022/06/06 16:36:52 Starting delete for "argocd-ssh-known-hosts-cm" ConfigMap
2022/06/06 16:36:52 Starting delete for "argocd-tls-certs-cm" ConfigMap
2022/06/06 16:36:52 Starting delete for "argocd-cm" ConfigMap
2022/06/06 16:36:52 Starting delete for "argocd-notifications-controller-cm" ConfigMap
2022/06/06 16:36:52 Starting delete for "argocd-notifications-controller-secret" Secret
2022/06/06 16:36:52 Starting delete for "argocd-secret" Secret
2022/06/06 16:36:52 Starting delete for "argocd-dex-server" ServiceAccount
2022/06/06 16:36:52 Starting delete for "argocd-repo-server" ServiceAccount
2022/06/06 16:36:52 Starting delete for "argocd-notifications-controller" ServiceAccount
2022/06/06 16:36:52 Starting delete for "argocd-application-controller" ServiceAccount
2022/06/06 16:36:52 Starting delete for "argocd-applicationset-controller" ServiceAccount
2022/06/06 16:36:52 Starting delete for "argocd-server" ServiceAccount
2022/06/06 16:36:52 purge requested for argocd
2022/06/06 16:36:52 release uninstalled, response: &{0x1400027e000 }
2022-06-06 16:36:52 ℹ [INFO]  Prepare to delete 'argocd_default' from States.
2022-06-06 16:36:52 ✔ [SUCCESS]  Tool (argocd/default) delete done.
2022-06-06 16:36:52 ℹ [INFO]  -------------------- [  Processing done.  ] --------------------
2022-06-06 16:36:52 ✔ [SUCCESS]  All plugins deleted successfully.
2022-06-06 16:36:52 ✔ [SUCCESS]  Delete finished.

4. gitops with 3 config files

  • gitops.yaml
---
# core config
varFile: "variables-gitops.yaml" # If not empty, use the specified external variables config file
toolFile: "tools-gitops.yaml" # If not empty, use the specified external tools config file
state: # state config, backend can be local or s3
  backend: local
  options:
    stateFile: devstream.state
  • variables-gitops.yaml
defaultBranch: main
githubUsername: daniel-hutao
repoName: dtm-test-go
jiraID: merico
jiraUserEmail: tao.hu@merico.dev
jiraProjectKey: DT
dockerhubUsername: exploitht
argocdNameSpace: argocd
argocdDeployTimeout: 10m
  • tools-gitops.yaml
tools:
- name: github-repo-scaffolding-golang
  instanceID: default
  options:
    owner: [[ githubUsername ]]
    org: ""
    repo: [[ repoName ]]
    branch: [[ defaultBranch ]]
    image_repo: [[ dockerhubUsername ]]/[[ repoName ]]
- name: jira-github-integ
  instanceID: default
  dependsOn: [ "github-repo-scaffolding-golang.default" ]
  options:
    owner: [[ githubUsername ]]
    repo: [[ repoName ]]
    jiraBaseUrl: https://[[ jiraID ]].atlassian.net
    jiraUserEmail: [[ jiraUserEmail ]]
    jiraProjectKey: [[ jiraProjectKey ]]
    branch: main
- name: githubactions-golang
  instanceID: default
  dependsOn: [ "github-repo-scaffolding-golang.default" ]
  options:
    owner: ${{github-repo-scaffolding-golang.default.outputs.owner}}
    org: ""
    repo: ${{github-repo-scaffolding-golang.default.outputs.repo}}
    language:
      name: go
      version: "1.17"
    branch: [[ defaultBranch ]]
    build:
      enable: True
      command: "go build ./..."
    test:
      enable: True
      command: "go test ./..."
      coverage:
        enable: True
        profile: "-race -covermode=atomic"
        output: "coverage.out"
    docker:
      enable: True
      registry:
        type: dockerhub
        username: [[ dockerhubUsername ]]
        repository: ${{github-repo-scaffolding-golang.default.outputs.repo}}
- name: argocd
  instanceID: default
  options:
    create_namespace: true
    repo:
      name: argo
      url: https://argoproj.github.io/argo-helm
    chart:
      chart_name: argo/argo-cd
      release_name: argocd
      namespace: [[ argocdNameSpace ]]
      wait: true
      timeout: [[ argocdDeployTimeout ]]
      upgradeCRDs: true
- name: argocdapp
  instanceID: default
  dependsOn: ["argocd.default", "github-repo-scaffolding-golang.default"]
  options:
    app:
      name: ${{github-repo-scaffolding-golang.default.outputs.repo}}
      namespace: [[ argocdNameSpace ]]
    destination:
      server: https://kubernetes.default.svc
      namespace: default
    source:
      valuefile: values.yaml
      path: helm/${{github-repo-scaffolding-golang.default.outputs.repo}}
      repoURL: ${{github-repo-scaffolding-golang.default.outputs.repoURL}}
  • apply
2022-06-06 16:37:57 ℹ [INFO]  Apply started.
2022-06-06 16:37:57 ℹ [INFO]  Got Backend from config: local
2022-06-06 16:37:57 ℹ [INFO]  Using dir <.devstream> to store plugins.
2022-06-06 16:37:57 ℹ [INFO]  Using local backend. State file: devstream.state.
2022-06-06 16:37:57 ℹ [INFO]  Tool (github-repo-scaffolding-golang/default) found in config but doesn't exist in the state, will be created.
2022-06-06 16:37:57 ℹ [INFO]  Tool (argocd/default) found in config but doesn't exist in the state, will be created.
2022-06-06 16:37:57 ℹ [INFO]  Tool (jira-github-integ/default) found in config but doesn't exist in the state, will be created.
2022-06-06 16:37:57 ℹ [INFO]  Tool (githubactions-golang/default) found in config but doesn't exist in the state, will be created.
2022-06-06 16:37:57 ℹ [INFO]  Tool (argocdapp/default) found in config but doesn't exist in the state, will be created.
2022-06-06 16:37:57 ℹ [INFO]  Start executing the plan.
2022-06-06 16:37:57 ℹ [INFO]  Changes count: 5.
2022-06-06 16:37:57 ℹ [INFO]  -------------------- [  Processing progress: 1/5.  ] --------------------
2022-06-06 16:37:57 ℹ [INFO]  Processing: (github-repo-scaffolding-golang/default) -> Create ...
2022-06-06 16:38:00 ℹ [INFO]  The repo dtm-test-go has been created.
2022-06-06 16:38:12 ✔ [SUCCESS]  Tool (github-repo-scaffolding-golang/default) Create done.
2022-06-06 16:38:12 ℹ [INFO]  -------------------- [  Processing progress: 2/5.  ] --------------------
2022-06-06 16:38:12 ℹ [INFO]  Processing: (argocd/default) -> Create ...
2022-06-06 16:38:14 ℹ [INFO]  Creating or updating helm chart ...
2022/06/06 16:38:15 creating 1 resource(s)
2022/06/06 16:38:15 CRD applications.argoproj.io is already present. Skipping.
2022/06/06 16:38:16 creating 1 resource(s)
2022/06/06 16:38:16 CRD applicationsets.argoproj.io is already present. Skipping.
2022/06/06 16:38:16 creating 1 resource(s)
2022/06/06 16:38:16 CRD argocdextensions.argoproj.io is already present. Skipping.
2022/06/06 16:38:16 creating 1 resource(s)
2022/06/06 16:38:16 CRD appprojects.argoproj.io is already present. Skipping.
2022/06/06 16:38:18 creating 43 resource(s)
2022/06/06 16:38:18 beginning wait for 43 resources with timeout of 10m0s
2022/06/06 16:38:19 Deployment is not ready: argocd/argocd-applicationset-controller. 0 out of 1 expected pods are ready
2022/06/06 16:38:21 Deployment is not ready: argocd/argocd-applicationset-controller. 0 out of 1 expected pods are ready
2022/06/06 16:38:23 Deployment is not ready: argocd/argocd-applicationset-controller. 0 out of 1 expected pods are ready
2022/06/06 16:38:25 Deployment is not ready: argocd/argocd-repo-server. 0 out of 1 expected pods are ready
2022/06/06 16:38:27 Deployment is not ready: argocd/argocd-repo-server. 0 out of 1 expected pods are ready
2022/06/06 16:38:29 Deployment is not ready: argocd/argocd-repo-server. 0 out of 1 expected pods are ready
2022/06/06 16:38:31 Deployment is not ready: argocd/argocd-repo-server. 0 out of 1 expected pods are ready
2022/06/06 16:38:33 Deployment is not ready: argocd/argocd-repo-server. 0 out of 1 expected pods are ready
2022/06/06 16:38:35 Deployment is not ready: argocd/argocd-repo-server. 0 out of 1 expected pods are ready
2022/06/06 16:38:37 Deployment is not ready: argocd/argocd-repo-server. 0 out of 1 expected pods are ready
2022/06/06 16:38:39 release installed successfully: argocd/argo-cd-4.8.2
2022-06-06 16:38:39 ✔ [SUCCESS]  Tool (argocd/default) Create done.
2022-06-06 16:38:39 ℹ [INFO]  -------------------- [  Processing progress: 3/5.  ] --------------------
2022-06-06 16:38:39 ℹ [INFO]  Processing: (jira-github-integ/default) -> Create ...
2022-06-06 16:38:40 ℹ [INFO]  Creating GitHub Actions workflow jira-github-integ.yml ...
2022-06-06 16:38:40 ✔ [SUCCESS]  Github Actions workflow jira-github-integ.yml created.
2022-06-06 16:38:42 ✔ [SUCCESS]  Tool (jira-github-integ/default) Create done.
2022-06-06 16:38:42 ℹ [INFO]  -------------------- [  Processing progress: 4/5.  ] --------------------
2022-06-06 16:38:42 ℹ [INFO]  Processing: (githubactions-golang/default) -> Create ...
2022-06-06 16:38:44 ℹ [INFO]  Creating GitHub Actions workflow pr-builder.yml ...
2022-06-06 16:38:44 ✔ [SUCCESS]  Github Actions workflow pr-builder.yml created.
2022-06-06 16:38:45 ℹ [INFO]  Creating GitHub Actions workflow main-builder.yml ...
2022-06-06 16:38:45 ✔ [SUCCESS]  Github Actions workflow main-builder.yml created.
2022-06-06 16:38:45 ✔ [SUCCESS]  Tool (githubactions-golang/default) Create done.
2022-06-06 16:38:45 ℹ [INFO]  -------------------- [  Processing progress: 5/5.  ] --------------------
2022-06-06 16:38:45 ℹ [INFO]  Processing: (argocdapp/default) -> Create ...
2022-06-06 16:38:46 ℹ [INFO]  application.argoproj.io/dtm-test-go created
2022-06-06 16:38:46 ✔ [SUCCESS]  Tool (argocdapp/default) Create done.
2022-06-06 16:38:46 ℹ [INFO]  -------------------- [  Processing done.  ] --------------------
2022-06-06 16:38:46 ✔ [SUCCESS]  All plugins applied successfully.
2022-06-06 16:38:46 ✔ [SUCCESS]  Apply finished.
  • delete
2022-06-06 16:40:10 ℹ [INFO]  Delete started.
2022-06-06 16:40:10 ℹ [INFO]  Got Backend from config: local
2022-06-06 16:40:10 ℹ [INFO]  Using dir <.devstream> to store plugins.
2022-06-06 16:40:10 ℹ [INFO]  Using local backend. State file: devstream.state.
2022-06-06 16:40:10 ℹ [INFO]  Tool (jira-github-integ/default) will be deleted.
2022-06-06 16:40:10 ℹ [INFO]  Tool (githubactions-golang/default) will be deleted.
2022-06-06 16:40:10 ℹ [INFO]  Tool (argocdapp/default) will be deleted.
2022-06-06 16:40:10 ℹ [INFO]  Tool (github-repo-scaffolding-golang/default) will be deleted.
2022-06-06 16:40:10 ℹ [INFO]  Tool (argocd/default) will be deleted.
2022-06-06 16:40:10 ℹ [INFO]  Start executing the plan.
2022-06-06 16:40:10 ℹ [INFO]  Changes count: 5.
2022-06-06 16:40:10 ℹ [INFO]  -------------------- [  Processing progress: 1/5.  ] --------------------
2022-06-06 16:40:10 ℹ [INFO]  Processing: (jira-github-integ/default) -> Delete ...
2022-06-06 16:40:11 ℹ [INFO]  Deleting GitHub Actions workflow jira-github-integ.yml ...
2022-06-06 16:40:12 ✔ [SUCCESS]  GitHub Actions workflow jira-github-integ.yml removed.
2022-06-06 16:40:12 ℹ [INFO]  Prepare to delete 'jira-github-integ_default' from States.
2022-06-06 16:40:12 ✔ [SUCCESS]  Tool (jira-github-integ/default) delete done.
2022-06-06 16:40:12 ℹ [INFO]  -------------------- [  Processing progress: 2/5.  ] --------------------
2022-06-06 16:40:12 ℹ [INFO]  Processing: (githubactions-golang/default) -> Delete ...
2022-06-06 16:40:13 ℹ [INFO]  Deleting GitHub Actions workflow pr-builder.yml ...
2022-06-06 16:40:14 ✔ [SUCCESS]  GitHub Actions workflow pr-builder.yml removed.
2022-06-06 16:40:14 ℹ [INFO]  Deleting GitHub Actions workflow main-builder.yml ...
2022-06-06 16:40:15 ✔ [SUCCESS]  GitHub Actions workflow main-builder.yml removed.
2022-06-06 16:40:15 ℹ [INFO]  Prepare to delete 'githubactions-golang_default' from States.
2022-06-06 16:40:15 ✔ [SUCCESS]  Tool (githubactions-golang/default) delete done.
2022-06-06 16:40:15 ℹ [INFO]  -------------------- [  Processing progress: 3/5.  ] --------------------
2022-06-06 16:40:15 ℹ [INFO]  Processing: (argocdapp/default) -> Delete ...
2022-06-06 16:40:16 ℹ [INFO]  application.argoproj.io "dtm-test-go" deleted
2022-06-06 16:40:16 ℹ [INFO]  Prepare to delete 'argocdapp_default' from States.
2022-06-06 16:40:16 ✔ [SUCCESS]  Tool (argocdapp/default) delete done.
2022-06-06 16:40:16 ℹ [INFO]  -------------------- [  Processing progress: 4/5.  ] --------------------
2022-06-06 16:40:16 ℹ [INFO]  Processing: (github-repo-scaffolding-golang/default) -> Delete ...
2022-06-06 16:40:17 ✔ [SUCCESS]  GitHub repo dtm-test-go removed.
2022-06-06 16:40:17 ℹ [INFO]  Prepare to delete 'github-repo-scaffolding-golang_default' from States.
2022-06-06 16:40:17 ✔ [SUCCESS]  Tool (github-repo-scaffolding-golang/default) delete done.
2022-06-06 16:40:17 ℹ [INFO]  -------------------- [  Processing progress: 5/5.  ] --------------------
2022-06-06 16:40:17 ℹ [INFO]  Processing: (argocd/default) -> Delete ...
2022-06-06 16:40:19 ℹ [INFO]  Uninstalling argocd helm chart.
2022/06/06 16:40:19 uninstall: Deleting argocd
2022/06/06 16:40:20 Starting delete for "argocd-redis" Service
2022/06/06 16:40:20 Starting delete for "argocd-application-controller" Service
2022/06/06 16:40:20 Starting delete for "argocd-server" Service
2022/06/06 16:40:20 Starting delete for "argocd-repo-server" Service
2022/06/06 16:40:20 Starting delete for "argocd-dex-server" Service
2022/06/06 16:40:20 Starting delete for "argocd-applicationset-controller" Service
2022/06/06 16:40:20 Starting delete for "argocd-application-controller" StatefulSet
2022/06/06 16:40:20 Starting delete for "argocd-redis" Deployment
2022/06/06 16:40:20 Starting delete for "argocd-applicationset-controller" Deployment
2022/06/06 16:40:20 Starting delete for "argocd-notifications-controller" Deployment
2022/06/06 16:40:20 Starting delete for "argocd-dex-server" Deployment
2022/06/06 16:40:20 Starting delete for "argocd-server" Deployment
2022/06/06 16:40:20 Starting delete for "argocd-repo-server" Deployment
2022/06/06 16:40:20 Starting delete for "argocd-dex-server" RoleBinding
2022/06/06 16:40:20 Starting delete for "argocd-applicationset-controller" RoleBinding
2022/06/06 16:40:20 Starting delete for "argocd-application-controller" RoleBinding
2022/06/06 16:40:20 Starting delete for "argocd-repo-server" RoleBinding
2022/06/06 16:40:20 Starting delete for "argocd-notifications-controller" RoleBinding
2022/06/06 16:40:20 Starting delete for "argocd-server" RoleBinding
2022/06/06 16:40:21 Starting delete for "argocd-dex-server" Role
2022/06/06 16:40:21 Starting delete for "argocd-applicationset-controller" Role
2022/06/06 16:40:21 Starting delete for "argocd-repo-server" Role
2022/06/06 16:40:21 Starting delete for "argocd-application-controller" Role
2022/06/06 16:40:21 Starting delete for "argocd-server" Role
2022/06/06 16:40:21 Starting delete for "argocd-notifications-controller" Role
2022/06/06 16:40:21 Starting delete for "argocd-server" ClusterRoleBinding
2022/06/06 16:40:21 Starting delete for "argocd-application-controller" ClusterRoleBinding
2022/06/06 16:40:21 Starting delete for "argocd-server" ClusterRole
2022/06/06 16:40:21 Starting delete for "argocd-application-controller" ClusterRole
2022/06/06 16:40:21 Starting delete for "argocd-gpg-keys-cm" ConfigMap
2022/06/06 16:40:21 Starting delete for "argocd-ssh-known-hosts-cm" ConfigMap
2022/06/06 16:40:21 Starting delete for "argocd-rbac-cm" ConfigMap
2022/06/06 16:40:21 Starting delete for "argocd-cm" ConfigMap
2022/06/06 16:40:21 Starting delete for "argocd-notifications-controller-cm" ConfigMap
2022/06/06 16:40:21 Starting delete for "argocd-tls-certs-cm" ConfigMap
2022/06/06 16:40:21 Starting delete for "argocd-notifications-controller-secret" Secret
2022/06/06 16:40:21 Starting delete for "argocd-secret" Secret
2022/06/06 16:40:21 Starting delete for "argocd-dex-server" ServiceAccount
2022/06/06 16:40:21 Starting delete for "argocd-applicationset-controller" ServiceAccount
2022/06/06 16:40:21 Starting delete for "argocd-application-controller" ServiceAccount
2022/06/06 16:40:21 Starting delete for "argocd-repo-server" ServiceAccount
2022/06/06 16:40:21 Starting delete for "argocd-server" ServiceAccount
2022/06/06 16:40:21 Starting delete for "argocd-notifications-controller" ServiceAccount
2022/06/06 16:40:21 purge requested for argocd
2022/06/06 16:40:21 release uninstalled, response: &{0x140000f1570 }
2022-06-06 16:40:21 ℹ [INFO]  Prepare to delete 'argocd_default' from States.
2022-06-06 16:40:21 ✔ [SUCCESS]  Tool (argocd/default) delete done.
2022-06-06 16:40:21 ℹ [INFO]  -------------------- [  Processing done.  ] --------------------
2022-06-06 16:40:21 ✔ [SUCCESS]  All plugins deleted successfully.
2022-06-06 16:40:21 ✔ [SUCCESS]  Delete finished.

Signed-off-by: Daniel Hu <tao.hu@merico.dev>
Signed-off-by: Daniel Hu <tao.hu@merico.dev>
Signed-off-by: Daniel Hu <tao.hu@merico.dev>
Signed-off-by: Daniel Hu <tao.hu@merico.dev>
Signed-off-by: Daniel Hu <tao.hu@merico.dev>
Signed-off-by: Daniel Hu <tao.hu@merico.dev>
Signed-off-by: Daniel Hu <tao.hu@merico.dev>
@daniel-hutao daniel-hutao marked this pull request as ready for review June 6, 2022 09:23
@daniel-hutao daniel-hutao changed the title wip: Feat: Config Logic Enhancement Feat: Config Logic Enhancement Jun 6, 2022
@daniel-hutao daniel-hutao added enhancement New feature or request refactor refactor labels Jun 6, 2022
internal/pkg/configloader/config.go Outdated Show resolved Hide resolved
internal/pkg/configloader/config.go Outdated Show resolved Hide resolved
internal/pkg/configloader/coreconfig.go Outdated Show resolved Hide resolved
internal/pkg/configloader/coreconfig.go Outdated Show resolved Hide resolved
internal/pkg/configloader/toolconfig.go Outdated Show resolved Hide resolved
internal/pkg/configloader/config.go Show resolved Hide resolved
internal/pkg/configloader/config.go Outdated Show resolved Hide resolved
Signed-off-by: Daniel Hu <tao.hu@merico.dev>
@daniel-hutao daniel-hutao requested a review from aFlyBird0 June 6, 2022 15:03
@daniel-hutao
Copy link
Member Author

@aFlyBird0 Thanks for your very detailed code review work, I've made the appropriate changes and retested locally to make certain no new bugs were introduced. Please take a review again at this pr.

Comment on lines +29 to +43
func LoadConfig(configFileName string) (*Config, error) {
// 1. read the original config file
originalConfigFileBytes, err := loadOriginalConfigFile(configFileName)
if err != nil {
log.Error(err)
log.Info("Maybe the default file doesn't exist or you forgot to pass your config file to the \"-f\" option?")
log.Info("See \"dtm help\" for more information.")
return nil, err
}
log.Debugf("Original general config: \n%s\n", string(configFileBytes))

var gConfig ConfigFile
err = yaml.Unmarshal(configFileBytes, &gConfig)
// 2. split original config
coreConfigBytes, variablesConfigBytes, toolsConfigBytes, err := SplitConfigFileBytes(originalConfigFileBytes)
if err != nil {
log.Error("Please verify the format of your general config file.")
log.Errorf("Reading general config file failed. %s.", err)
return nil, err
}

errs := validateConfigFile(&gConfig)
if len(errs) != 0 {
for _, e := range errs {
log.Errorf("Config file validation failed: %s.", e)
}
return nil, nil
}
return renderConfigs(coreConfigBytes, variablesConfigBytes, toolsConfigBytes)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elegant and simple!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

state:
---
# core config
varFile: "" # If not empty, use the specified external variables config file
Copy link
Member

@aFlyBird0 aFlyBird0 Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should tell user that toolFile should be not empty when varFile is not empty. In docs or this yaml file. We can also do it later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here is not that toolFile must be non-empty if varFile is not empty, but that if toolFile exists and var is used inside, varFile needs to exist. If toolFile and toolConfig does not exist, it does not matter whether varFile exists or not. We can "educate" the user later in one of the documents.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here is not that toolFile must be non-empty if varFile is not empty, but that if toolFile exists and var is used inside, varFile needs to exist. If toolFile and toolConfig does not exist, it does not matter whether varFile exists or not. We can "educate" the user later in one of the documents.

Got it, thank you for explanation.

Comment on lines +185 to +206
func SplitConfigFileBytes(fileBytes []byte) (coreConfig []byte, varConfig []byte, toolConfig []byte, err error) {
splitBytes := bytes.Split(bytes.TrimPrefix(fileBytes, []byte("---")), []byte("---"))

switch len(splitBytes) {
case 1:
coreConfig = splitBytes[0]
case 2:
coreConfig = splitBytes[0]
toolConfig = splitBytes[1]
case 3:
coreConfig = splitBytes[0]
varConfig = splitBytes[1]
toolConfig = splitBytes[2]
default:
err = fmt.Errorf("invalid config format")
}

if len(coreConfig) == 0 {
err = fmt.Errorf("core config is empty")
}

return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nice practice to use default value! It's very "Go"!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🍀 Proposal: dtm Configuration Enhancement: Single Profile Support
3 participants