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

Preserve scalar types when using the replacement filter #4494

Merged

Conversation

lack
Copy link
Contributor

@lack lack commented Feb 25, 2022

Erasing the scalar type tag leads to unfortunate circumstances, in that
the resulting yaml code is valid yaml, but will not meet the object
spec.

For example, using the replacement transformer to take a port number as
a string from a ConfigMap and set a Pod port would previously end up
with:

  • port: "8080"
    when the spec requires that this is not a string:
  • port: 8080

Signed-off-by: Jim Ramsay i.am@jimramsay.com

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 25, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @lack!

It looks like this is your first PR to kubernetes-sigs/kustomize 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kustomize has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 25, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @lack. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 25, 2022
@natasha41575
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 4, 2022
- select:
kind: Pod
fieldPaths:
- spec.containers.0.ports.0.port
Copy link
Contributor

Choose a reason for hiding this comment

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

Question, what happens in the scenario that this path does not yet exist and we have to create it? e.g.

replacements:
- source:
    kind: ConfigMap
    name: config
    fieldPath: data.PORT
  targets:
  - select:
      kind: Pod
    fieldPaths:
    - spec.containers.0.ports.0.port
    options:
      create: true

Would you mind adding a test for this case? No need to fix the behavior in this PR if it does something undesirable - but it would be good to just have the test as a record of the behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea!

Current behavior would be to create it with the source type (since Kustomize doesn't know what the target type is if it didn't already parse it)

Will add!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added. Though it did expose another problem in the replacement code: Apparently the "create" option doesn't deal well with appending to arrays or creating intermediate maps or arrays.

I'll log separate issues about those.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out intermediate maps are fine. Intermediate arrays are complicated. Following up on that in #4507

@lack
Copy link
Contributor Author

lack commented Mar 8, 2022

Maybe I'll add an explicit test for boolean conversion as well as int?

@natasha41575
Copy link
Contributor

Maybe I'll add an explicit test for boolean conversion as well as int?

Yes please! Thank you. Once that is done I'll do another pass and we can get this PR in.

Erasing the scalar type tag leads to unfortunate circumstances, in that
the resulting yaml code is valid yaml, but will not meet the object
spec.

For example, using the replacement transformer to take a port number as
a string from a ConfigMap and set a Pod port would previously end up
with:
 - containerPort: "8080"
when the spec requires that this is not a string:
 - containerPort: 8080

Added unit tests for conversion to and from integers and booleans, plus
creation from string and creation from integer.

The creation behavior needs some refinement in a future PR.

Signed-off-by: Jim Ramsay <i.am@jimramsay.com>
@lack lack force-pushed the replacement/string-int-autoconvert branch from c00ed07 to cb80659 Compare March 9, 2022 11:42
@lack
Copy link
Contributor Author

lack commented Mar 9, 2022

Okay! Latest change adds unit tests for conversion to/from boolean as well.

@lack
Copy link
Contributor Author

lack commented Mar 11, 2022

@natasha41575 ^^ Ready to go, I think!

@natasha41575
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 16, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lack, natasha41575

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 16, 2022
@k8s-ci-robot k8s-ci-robot merged commit 3ae5aa9 into kubernetes-sigs:master Mar 16, 2022
@lack
Copy link
Contributor Author

lack commented Mar 17, 2022

Fixes #4479

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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

3 participants