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

Add piped config-data flag #2398

Merged
merged 1 commit into from
Aug 27, 2021
Merged

Add piped config-data flag #2398

merged 1 commit into from
Aug 27, 2021

Conversation

khanhtc1202
Copy link
Member

@khanhtc1202 khanhtc1202 commented Aug 27, 2021

What this PR does / why we need it:

Sample command would look like

$ piped piped --metrics \
--tools-dir=/tmp/piped-bin \
--config-data="`cat .dev/piped-config.yaml`"

or

$ piped piped --metrics \
--tools-dir=/tmp/piped-bin \
--config-data='{"apiVersion": "pipecd.dev/v1beta1", "kind": "Piped",...}'

or

$ piped piped --metrics \
--tools-dir=/tmp/piped-bin \
--config-data="`echo $CONFIG_DATA`"

Which issue(s) this PR fixes:

Fixes #2392

Does this PR introduce a user-facing change?:

Enable Piped to load configuration via command line argument using --config-data flag

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.10%. This pull request does not change code coverage.

@@ -497,6 +499,14 @@ func (p *piped) loadConfig(ctx context.Context) (*config.PipedSpec, error) {
return extract(cfg)
}

if p.configData != "" {
cfg, err := config.DecodeYAML([]byte(p.configData))
Copy link
Member

Choose a reason for hiding this comment

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

As I can see the PR body, it's expected to be JSON. In that case, doesn't it have to use MarsharJSON or something like that?

--config-data='{"apiVersion": "pipecd.dev/v1beta1", "kind": "Piped",...}'

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, we can support a kind of like --config-from-stdin.

Copy link
Member Author

@khanhtc1202 khanhtc1202 Aug 27, 2021

Choose a reason for hiding this comment

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

As I can see the PR body, it's expected to be JSON. In that case, doesn't it have to use MarsharJSON or something like that?

--config-data='{"apiVersion": "pipecd.dev/v1beta1", "kind": "Piped",...}'

Well, the fact is our config.DecodeYAML use yaml.YAMLToJSON which allow both YAML and JSON as it input. So basically we don't need to use MarsharJSON or something like that here. In case this --config-data flag is used, I think users would happier to pass string value in JSON format here rather than just YAML format (as we know, yaml requires tabs/spaces strictly so inline command with YAML format is not a good idea), and in the scope of writing down some samples, I chose JSON as it's easier to write.

ref: https://github.com/pipe-cd/pipe/blob/master/pkg/config/config.go#L217

Copy link
Member Author

Choose a reason for hiding this comment

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

Alternatively, we can support a kind of like --config-from-stdin.

Could you provide samples for that flag, I think this --config-data could handle most of the cases we want already 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Well, the fact is our config.DecodeYAML use yaml.YAMLToJSON which allow both YAML and JSON as it input.

Alright, I didn't even know that 👍

Could you provide samples for that flag,

In that case, --config-from-stdin has no sense. Never mind.

@nakabonne
Copy link
Member

/lgtm

@nghialv
Copy link
Member

nghialv commented Aug 27, 2021

Nice add.
/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by nghialv.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

@pipecd-bot pipecd-bot merged commit 506769a into master Aug 27, 2021
@pipecd-bot pipecd-bot deleted the add-config-data-flag branch August 27, 2021 09:14
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.

Enable Piped to load string config
4 participants