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

Allow missing keys in templates by default #39486

Merged

Conversation

ncdc
Copy link
Member

@ncdc ncdc commented Jan 5, 2017

Switch to allowing missing keys in jsonpath templates by default.

Add support for allowing/disallowing missing keys in go templates
(default=allow).

Add --allow-missing-template-keys flag to control this behavior (default=true /
allow missing keys).

Fixes #37991

@kubernetes/sig-cli-misc @kubernetes/api-reviewers @smarterclayton @fabianofranz @liggitt @pwittrock

@ncdc ncdc added the sig/cli Categorizes an issue or PR as relevant to SIG CLI. label Jan 5, 2017
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 5, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@ncdc
Copy link
Member Author

ncdc commented Jan 5, 2017

Will add test-cmd tests if this looks good

@@ -2527,6 +2531,14 @@ func NewTemplatePrinter(tmpl []byte) (*TemplatePrinter, error) {
}, nil
}

func (p *TemplatePrinter) AllowMissingKeys(allow bool) {
Copy link
Member Author

@ncdc ncdc Jan 5, 2017

Choose a reason for hiding this comment

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

I can take this bit out if we want to just apply this to the jsonpath printer for starters, as it is a slight behavior change (allow sets missingkey to zero instead of default). Or I could have allow set missingkey to default to retain the current behavior.

@k8s-ci-robot
Copy link
Contributor

Jenkins Bazel Build failed for commit b89cf0f. Full PR test history.

The magic incantation to run this job again is @k8s-bot bazel test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-github-robot k8s-github-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. release-note-label-needed labels Jan 5, 2017
@ncdc
Copy link
Member Author

ncdc commented Jan 5, 2017

Working on fixing compilation failures and some switches that I missed. Updates coming real soon.

@ncdc ncdc force-pushed the allow-missing-keys-in-templates branch from b89cf0f to e6a49a4 Compare January 5, 2017 21:16
@ncdc ncdc added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jan 5, 2017
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. release-note-label-needed labels Jan 5, 2017
@ncdc
Copy link
Member Author

ncdc commented Jan 5, 2017

@soltysh fyi

@ncdc ncdc force-pushed the allow-missing-keys-in-templates branch from e6a49a4 to 9d556b3 Compare January 5, 2017 21:46
@k8s-ci-robot
Copy link
Contributor

Jenkins Kubemark GCE e2e failed for commit e6a49a4e5d6f5149cae9a40e3b8fc2ec51742b51. Full PR test history.

The magic incantation to run this job again is @k8s-bot kubemark e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot
Copy link
Contributor

Jenkins verification failed for commit 9d556b3ef5ab81c33de89989aaf53b217f4b52e8. Full PR test history.

The magic incantation to run this job again is @k8s-bot verify test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot
Copy link
Contributor

Jenkins kops AWS e2e failed for commit 9d556b3ef5ab81c33de89989aaf53b217f4b52e8. Full PR test history.

The magic incantation to run this job again is @k8s-bot kops aws e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@ncdc ncdc force-pushed the allow-missing-keys-in-templates branch from 9d556b3 to f079e3e Compare January 6, 2017 01:11
@smarterclayton
Copy link
Contributor

Looks good to me, want some opinions on naming (argument was not to use "--strict" because that's too generic) from sig cli.

@ncdc
Copy link
Member Author

ncdc commented Jan 6, 2017

@k8s-bot test this

@k8s-ci-robot
Copy link
Contributor

Jenkins unit/integration failed for commit f079e3ebcd62c55b307b9071ed4e457607dfba7d. Full PR test history.

The magic incantation to run this job again is @k8s-bot unit test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot
Copy link
Contributor

Jenkins GCI GCE e2e failed for commit f079e3ebcd62c55b307b9071ed4e457607dfba7d. Full PR test history.

The magic incantation to run this job again is @k8s-bot gci gce e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@ncdc
Copy link
Member Author

ncdc commented Jan 6, 2017

@k8s-bot gci gce e2e test this

@k8s-bot unit test this issue #39510

@fabianofranz
Copy link
Contributor

I'd like --output-strict-templates or something else with the --output-* prefix so it's "grouped" with its context. I think the flag description must also mention it only applies to some kind(s) of --output=. Other options: --strict-missing-keys, --allow-missing-keys, --strict-template-errors, --skip-template-errors, --abort-template-errors.

@soltysh
Copy link
Contributor

soltysh commented Jan 9, 2017

LGTM, +1 for --allow-missing-keys

@ncdc
Copy link
Member Author

ncdc commented Jan 9, 2017

I'm not crazy about --output-strict-templates because it sounds like it's a directive saying that the command needs to output strict templates, as opposed to saying that the template input is parsed in strict mode. I do like --allow-missing-keys but maybe to be explicit it should be --allow-missing-template-keys?

@soltysh
Copy link
Contributor

soltysh commented Jan 9, 2017

I am still struggling with readability vs brevity for this, so either of --allow-missing-keys or --allow-missing-template-keys works fine with me.

@ncdc
Copy link
Member Author

ncdc commented Jan 9, 2017 via email

@fabianofranz
Copy link
Contributor

Assuming that the default will be to allow missing keys, I would err on the side of readability for the flag's name.

I agree, this is not something to be used too often so readability > brevity. Update the PR and let's get this in.

@soltysh
Copy link
Contributor

soltysh commented Jan 9, 2017

Yes!

Switch to allowing missing keys in jsonpath templates by default.

Add support for allowing/disallowing missing keys in go templates
(default=allow).

Add --allow-missing-template-keys flag to control this behavior
(default=true / allow missing keys).
@ncdc ncdc force-pushed the allow-missing-keys-in-templates branch from f079e3e to 80c5cd8 Compare January 9, 2017 15:39
@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 9, 2017
if err != nil {
return nil, false, fmt.Errorf("error parsing template %s, %v\n", formatArgument, err)
}
templatePrinter.AllowMissingKeys(allowMissingTemplateKeys)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about extending NewTemplatePrinter with that new flag since we're passing it every time we use it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Follow-up?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure.

@soltysh
Copy link
Contributor

soltysh commented Jan 9, 2017

Neat, otherwise LGTM.

@fabianofranz fabianofranz added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 9, 2017
@fabianofranz
Copy link
Contributor

LGTM

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 39486, 37288, 39477, 39455, 39542)

@k8s-github-robot k8s-github-robot merged commit 9ef9630 into kubernetes:master Jan 10, 2017
@ncdc
Copy link
Member Author

ncdc commented Jan 12, 2017

Do we want to cherrypick this to 1.5?

@soltysh
Copy link
Contributor

soltysh commented Jan 12, 2017

I say - yes.

@k8s-cherrypick-bot
Copy link

Removing label cherrypick-candidate because no release milestone was set. This is an invalid state and thus this PR is not being considered for cherry-pick to any release branch. Please add an appropriate release milestone and then re-add the label.

@ncdc ncdc added this to the v1.5 milestone Jan 12, 2017
@saad-ali saad-ali added the cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. label Jan 20, 2017
k8s-github-robot pushed a commit that referenced this pull request Jan 20, 2017
…39895-#39038-upstream-release-1.5

Automatic merge from submit-queue

Automated cherry pick of #39486 #39895 #39038

Cherry pick of #39486 #39895 #39038 on release-1.5.

#39486: Allow missing keys in templates by default
#39895: Fix expected error text
#39038: Fix kubectl get -f <file> -o <nondefault printer>
@ncdc ncdc deleted the allow-missing-keys-in-templates branch February 13, 2017 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants