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

calico_pool_blocksize must be cast as well in assertion when defined #8321

Conversation

emiran-orange
Copy link
Contributor

What type of PR is this?
/kind bug

What this PR does / why we need it:
When calico default pool already exists and calico_pool_blocksize is defined in inventory, the assertion on blocksize equality wrongly fails because a string cast is missing

Which issue(s) this PR fixes:
None that I know of

Special notes for your reviewer:
N/A

Does this PR introduce a user-facing change?:
None

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 20, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @emiran-orange. 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 20, 2021
Copy link
Contributor

@cristicalin cristicalin left a comment

Choose a reason for hiding this comment

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

/ok-to-test

@@ -53,7 +53,7 @@
- name: "Check if inventory match current cluster configuration"
assert:
that:
- calico_pool_conf.spec.blockSize|string == (calico_pool_blocksize | default(kube_network_node_prefix | string))
- calico_pool_conf.spec.blockSize|string == (calico_pool_blocksize | default(kube_network_node_prefix) | string)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't these be compared as int instead of string ?

Copy link
Contributor Author

@emiran-orange emiran-orange Dec 20, 2021

Choose a reason for hiding this comment

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

Well, #8120 changed the comparison format from int to string.
To answer your question, if so, the referenced PR should be reverted and mine changed so that calico_pool_conf.spec.blockSize is cast as int as both kube_network_node_prefix and calico_pool_blocksize are int

Copy link
Contributor Author

@emiran-orange emiran-orange Dec 20, 2021

Choose a reason for hiding this comment

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

To answer your question, if so, the referenced PR should be reverted and mine changed so that..

Actually, I take back what I posted in my last comment, if so, the referenced PR should be reverted and mine deleted.

I took a look at #8119. I think the issue is a false positive as ansible key/val parser there does not do typing and passing -e kube_network_node_prefix=26 will make kube_network_node_prefix be a string whereas it is expected t be an int (in inventory)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cristicalin What do you think ?

Copy link
Contributor

@cristicalin cristicalin Dec 20, 2021

Choose a reason for hiding this comment

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

You can always do the right thing ™️ in this PR and fix both the order and they type cast.
I have to admit that #8120 dropped off my radar after the premature merge.

PS: everything you pass to ansible via -e var=value ends up as a string, to pass different types like int or bool you have to use the json syntax like -e '{bool_var: True, my_int_var: 23}'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cristicalin
My point wasn't not to pass the parameter but to pass it the right way:
-e '{"kube_network_node_prefix": 26}' instead of -e kube_network_node_prefix=26

Copy link
Contributor

Choose a reason for hiding this comment

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

There are valid situations where you cannot control the type ansible assigns to this variable, especially if you embed kubespray as part of a larger project and call cluster.yml with include_playbook and your variables are calculated or extracted from some other data source.

It is a good practice to ensure types a properly set when variables are compared to avoid issues propagating silently. As was the case with the original PR #8120 this should be fixed by setting the proper types when comparing the variables since at least kube_network_node_prefix is user supplied input and all user input should be sanitized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fine by me. So my PR stands, it defaults calico_pool_blocksize to kube_network_node_prefix and then applies type cast.
LGTY?

Copy link
Contributor

Choose a reason for hiding this comment

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

As said above, I think the typecast should be to int instead of string but the change in logic is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I misunderstood your point enforcing int type. That should fixed now

@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 Dec 20, 2021
@emiran-orange emiran-orange changed the title calico_pool_blocksize must be cast as string in assertion when defined calico_pool_blocksize must be cast as well in assertion when defined Dec 22, 2021
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 22, 2021
Copy link
Contributor

@oomichi oomichi left a comment

Choose a reason for hiding this comment

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

/lgtm

@@ -53,7 +53,7 @@
- name: "Check if inventory match current cluster configuration"
assert:
that:
- calico_pool_conf.spec.blockSize|string == (calico_pool_blocksize | default(kube_network_node_prefix | string))
- calico_pool_conf.spec.blockSize|int == (calico_pool_blocksize | default(kube_network_node_prefix) | int)
Copy link
Contributor

Choose a reason for hiding this comment

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

calico_pool_conf.spec.blockSize is an integer as the following, the change itself seems good for me.

# calicoctl.sh get ipPool default-pool -o json
{
...
  },
  "spec": {
    "cidr": "10.233.64.0/18",
    "vxlanMode": "Always",
    "ipipMode": "Never",
    "natOutgoing": true,
    "blockSize": 24,
    "nodeSelector": "all()"
  }
}

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 22, 2021
Copy link
Member

@floryut floryut left a comment

Choose a reason for hiding this comment

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

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: emiran-orange, floryut

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 merged commit 2b5c185 into kubernetes-sigs:master Dec 23, 2021
@floryut floryut mentioned this pull request Dec 23, 2021
sakuraiyuta pushed a commit to sakuraiyuta/kubespray that referenced this pull request Apr 16, 2022
…ubernetes-sigs#8321)

* calico_pool_blocksize must be cast as string in assertion when defined

* Cast as int rather than string
LuckySB pushed a commit to southbridgeio/kubespray that referenced this pull request Jun 29, 2023
…ubernetes-sigs#8321)

* calico_pool_blocksize must be cast as string in assertion when defined

* Cast as int rather than string
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. kind/bug Categorizes issue or PR as related to a bug. 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/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants