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

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion roles/network_plugin/calico/tasks/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

- calico_pool_conf.spec.cidr == (calico_pool_cidr | default(kube_pods_subnet))
- not calico_pool_conf.spec.ipipMode is defined or calico_pool_conf.spec.ipipMode == calico_ipip_mode
- not calico_pool_conf.spec.vxlanMode is defined or calico_pool_conf.spec.vxlanMode == calico_vxlan_mode
Expand Down