Skip to content

feat(atc): support named var. - #4777

Merged
vito merged 8 commits into
concourse:masterfrom
evanchaoli:named_var_source
Dec 12, 2019
Merged

vito merged 8 commits into
concourse:masterfrom
evanchaoli:named_var_source

Conversation

@evanchaoli

@evanchaoli evanchaoli commented Nov 18, 2019 •

Copy link
Copy Markdown
Contributor

Existing Issue

This is a a follow-up enhancement of PR #4600, and complies with RFC Conourse/RFC#39.

Why do we need this PR?

This PR makes pipeline var_source fully functional.

Changes proposed in this pull request

Basically this change is neat.

  • The key part is to add a new struct namedSecrets. It extract var_source name from secretPath, then checks var_source and forward real Get to the underlying secrets.
  • VarSourcePool will always returns namedSecrets with original secrets wrapped in it.
  • The regexp is updated in template.go to accept named var like ((vs:var)).
  • Unit tests and testflight have been updated.

Contributor Checklist

Are the following items included as part of this PR? Please delete checkbox items that don't apply.

Reviewer Checklist

This section is intended for the core maintainers only, to track review progress. Please do not
fill out this section.

  • Code reviewed
  • Tests reviewed
  • Documentation reviewed
  • Release notes reviewed
  • PR acceptance performed
  • New config flags added? Ensure that they are added to the BOSH
    and Helm packaging; otherwise, ignored for the integration tests (for example, if they are Garden configs that are not displayed in the --help text).

@evanchaoli

evanchaoli commented Nov 18, 2019 •

Copy link
Copy Markdown
Contributor Author

My test pipeline:

var_sources:
- name: dev-vault
  type: vault
  config:
    url: http://192.168.1.12:8200
    path_prefix: concourse
    skip_team_path: true
    client_token: ((my-vault-token))

- name: vs-dummy
  type: dummy
  config:
    vars:
      clone-pass: ((dev-vault:test.pass))

resource_types:
- name: rt-tiny
  type: registry-image
  source:
    repository: evanli/tiny2
    tag: v2

resources:
- name: tiny
  type: rt-tiny
  check_every: 2m
  source:
    key: ((dev-vault:hello))

jobs:
- name: test
  public: true
  plan:
  - get: tiny
    params:
      other_key: ((dev-vault:test.pass))

  - task: task-should-succeed
    config:
      platform: linux
      image_resource:
        type: registry-image
        source: {repository: busybox}
      run:
        path: sh
        args:
         - -exc
         - |
           echo The pass is ((dev-vault:test.pass)) and clone-pass is ((vs-dummy:clone-pass))

  - task: task-should-fail
    config:
      platform: linux
      image_resource:
        type: registry-image
        source: {repository: busybox}
      run:
        path: sh
        args:
         - -exc
         - |
           echo The name is ((test.pass))

Where the first task use var_source name with the vars, which should pass; and the second task uses var names without var_source name, then it will look for vars from the system vault, and will not find, then fail.

The UI screen shot proves the test passed:

named_var_source2

@evanchaoli
evanchaoli force-pushed the named_var_source branch 4 times, most recently from 112b168 to 9b946f5 Compare November 18, 2019 05:20
@taylorsilva

Copy link
Copy Markdown
Member

Did you mean to reference issue #4579 instead of #4580?

@evanchaoli

Copy link
Copy Markdown
Contributor Author

@tylorsilva sorry for the confusion. I think 4580 was added by auto completion. I didn’t notice that, just removed that.

@evanchaoli

Copy link
Copy Markdown
Contributor Author

@vito Can you please review this? It’s ready for review.

@vito vito self-assigned this Nov 22, 2019
@evanchaoli
evanchaoli force-pushed the named_var_source branch 2 times, most recently from d1fda8c to 20e1990 Compare November 25, 2019 15:09
@evanchaoli

Copy link
Copy Markdown
Contributor Author

I added a new config skip_team_path to Vault, so that in var_sources, secret lookup may skip team paths. This behavior complies with RFC var_sources.

@evanchaoli

evanchaoli commented Nov 29, 2019 •

Copy link
Copy Markdown
Contributor Author

@vito I communicated with some of our users this week, and they felt that allowing a var_source to refer to previous var_sources would be helpful, which is same as what you have proposed in RFC: var_sources. So I just added a new commit to support that, as you can see, the code is actually very simple.

The only restriction is, if var_source B refer to var_source A, then A must be defined before B. Though we can add some code to eliminate the restriction by ordering var_sources by dependencies, but I think it's fair to require a var_source to be defined before using it.

edit: During my test, I finally realized that we have to order var_sources at runtime. Because if we just swap order of var_sources in YAML, fly set-pipeline will not detect diff, so that not able to update pipeline. I just added one more commit that orders var_sources by dependency, so that var_sources order in YAML will no longer be a problem. The commit also enhanced var_source related error a little bit.

@evanchaoli evanchaoli mentioned this pull request Nov 29, 2019
@evanchaoli
evanchaoli force-pushed the named_var_source branch 5 times, most recently from f967b63 to f6f0529 Compare December 6, 2019 01:18
@evanchaoli

Copy link
Copy Markdown
Contributor Author

Just rebased and resolved conflicts.

@vito vito added this to the v5.8.0 milestone Dec 6, 2019

@vito vito left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry for the wait! This looks great so far. Left some suggestions inline. And I think the skipTeamPath stuff should probably be split out.

We'll try to get this in for v5.8 but we're already overdue so we might end up shipping without it. No rush, we can always just ship again. v5.8 can be set_pipeline, v5.9 can be var_sources. 🙂

If the feedback makes sense let me know if you think you can make the changes in time! We can push out the release for a bit more.

Comment thread atc/config.go Resolved
Comment thread atc/config_test.go Resolved
Comment thread atc/config.go Resolved
Comment thread atc/configvalidate/validate_test.go Resolved
Comment thread atc/creds/pool.go Resolved
Comment thread atc/creds/vault/manager.go Resolved
Comment thread atc/db/pipeline.go Resolved
…hat, secret lookup will skip paths of team/ and team/pipeline/."

This reverts commit a15ee7e.

Signed-off-by: Chao Li <[email protected]>
@evanchaoli

Copy link
Copy Markdown
Contributor Author

@vito I have just addressed all review comments:

  • Removed creds.NamedSecrets and anded vars.NamedVariables.
  • Restored pool.go, so that pool.go is not touched in this PR. With vars.NamedVariables, pool doesn't need to realize var source name at all.
  • Added test cases to config validate.
  • Reverted skipTeamPath.

I hope var source to be included in 5.8, because our users are waiting for that, I don't want them to wait the other month for 5.9. Also, I plan to work on input_vars, based on code of this PR, input_var should be easy to implement.

My roadmap is to contribute "input_vars" and "OPA integration" to 5.9, I have submitted RFCs for both of them. "OPA integration" is an urgent feature for us, actually I have finished coding but haven't submitted a PR yet. "input_vars" is not urgent, but very nice to have, that will somewhat change the way of creating pipelines, reducing development effort of tasks and resource types.

vito
vito previously approved these changes Dec 11, 2019

@vito vito left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My only feedback is a tiny refactor so I think this is good to go. 👍 Will leave this open until we're closer to v5.8 in case you want to sneak it in.

Thanks a bunch!

Comment thread vars/named_vars.go Resolved
Comment thread atc/db/pipeline.go Resolved
@vito

vito commented Dec 11, 2019

Copy link
Copy Markdown
Contributor

Looks like testflight is failing. Here are some relevant logs:

web_1     | {"timestamp":"2019-12-11T17:51:26.763230340Z","level":"debug","source":"atc","message":"atc.pipelines.radar.scan-resource.interval-runner.tick.found-existing-credential-manager","data":{"pipeline":"tf-pipeline-4-5a94a3bd-e9d4-4343-6453-6ee8ddabdf3c","resource":"resource-using-vars","session":"16.55.27.1.1","team":"testflight"}}
web_1     | {"timestamp":"2019-12-11T17:51:26.763466054Z","level":"error","source":"atc","message":"atc.pipelines.radar.scan-resource.interval-runner.tick.failed-to-evaluate-resource-source","data":{"error":"undefined vars: vs:initial_version_var, vs:some_numeric_var","pipeline":"tf-pipeline-4-5a94a3bd-e9d4-4343-6453-6ee8ddabdf3c","resource":"resource-using-vars","session":"16.55.27.1.1","team":"testflight"}}
web_1     | {"timestamp":"2019-12-11T17:51:26.765630634Z","level":"error","source":"atc","message":"atc.pipelines.radar.failed-to-run-scan-resource","data":{"error":"undefined vars: vs:initial_version_var, vs:some_numeric_var","pipeline":"tf-pipeline-4-5a94a3bd-e9d4-4343-6453-6ee8ddabdf3c","session":"16.55","team":"testflight"}}

@evanchaoli

Copy link
Copy Markdown
Contributor Author

Looks like testflight is failing. Here are some relevant logs:

@vito Thank the testflight for catching the bug. The bug was introduced yesterday when I changed to NamedVariable, which was only hit when there was a single var_source defined in a pipeline. While both my local tests and unit tests used multiple var_sources, so the bug was not caught.

I have fixed the bug, and enhanced the unit tests to cover both single var_source and multiple var_sources cases.

BTW, why are we no longer able to see build logs? Looks like the pipelines are not exposed to public now.

@vito vito left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sneaky midnight review! Noticed one more tiny thing I think we should fix.

We're in the midst of re-paving our CI stack, so for now the URL of our CI is https://nci.concourse-ci.org. I'm able to view the PR builds anonymously at least but it looks like we need to expose a few other pipelines that have been moved over, if it's those you were looking for. We'll switch the DNS back to ci.concourse-ci.org once we're completely switched over.

Comment thread vars/named_vars.go Resolved
@evanchaoli

Copy link
Copy Markdown
Contributor Author

Sneaky midnight review! Noticed one more tiny thing I think we should fix.

We're in the midst of re-paving our CI stack, so for now the URL of our CI is https://nci.concourse-ci.org. I'm able to view the PR builds anonymously at least but it looks like we need to expose a few other pipelines that have been moved over, if it's those you were looking for. We'll switch the DNS back to ci.concourse-ci.org once we're completely switched over.

Thanks for working so late. I just realized that I can see build logs now.

@vito vito left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good to go - thanks a bunch!

I'm working on docs for var_sources today - we'll get it in v5.8.

@vito
vito merged commit c678087 into concourse:master Dec 12, 2019
@jamieklassen jamieklassen mentioned this pull request Dec 16, 2019
20 tasks done
@evanchaoli
evanchaoli deleted the named_var_source branch December 17, 2019 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants