Fix/eliminate default filter 11822#13136
Fix/eliminate default filter 11822#13136AdeshDeshmukh wants to merge 3 commits intokubernetes-sigs:masterfrom
Conversation
This PR adds documentation explaining best practices for managing Kubespray custom configurations in a separate git repository with minimal files. Resolves issue 10645
Define defaults in roles/defaults/main.yml instead of using the | d() filter throughout task files. - Add node_labels default to roles/kubernetes/node-label/defaults/main.yml - Add kubeadm_patch_default_type to roles/kubernetes/kubeadm_common/defaults/main.yml - Update node-label task to use node_labels directly without filter - Update kubeadm_common task to use kubeadm_patch_default_type variable - Change | d(None) to | default(None) in download.yml for consistency Closes kubernetes-sigs#11822 Signed-off-by: AdeshDeshmukh <adeshkd123@gmail.com>
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions 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-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: AdeshDeshmukh The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @AdeshDeshmukh. 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 Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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-sigs/prow repository. |
VannTen
left a comment
There was a problem hiding this comment.
Some comments.
The docs updates looks unrelated ? They seem to stand on their own, so maybe split them off in another PR ?
| kubeadm_patches: [] | ||
| # Default patch type for kubeadm patches when not explicitly specified | ||
| kubeadm_patch_default_type: strategic | ||
|
|
There was a problem hiding this comment.
This one can stays as a inline default.
The patches themselves are user-definable, but adding an additional knob would only save one line par patch and add some unpredictability ; better to keep the hardcoded default patch type for this.
| {{ etcd_binary_checksum if (etcd_deployment_type == 'host') | ||
| else etcd_digest_checksum | d(None) }} | ||
| else etcd_digest_checksum | default(None) }} | ||
| url: "{{ etcd_download_url }}" |
There was a problem hiding this comment.
While default is more explicit than d, please revert this one, the history churn isn't worth it.
There was a problem hiding this comment.
Pull request overview
This PR aims to reduce repeated inline default/d() filters in Kubespray roles by moving defaults into role defaults/ files, and it also adds documentation for a “minimal inventory” workflow.
Changes:
- Introduces a
node_labelsdefault in thenode-labelrole and simplifies the task loop accordingly. - Updates various download checksum templating expressions in
kubespray_defaults. - Adds a new “Minimal Inventory Guide” doc and links it from Getting Started + sidebar.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| roles/kubespray_defaults/defaults/main/download.yml | Changes checksum templating for many container downloads (None fallback handling). |
| roles/kubernetes/node-label/tasks/main.yml | Removes inline {} default and is defined check for node_labels. |
| roles/kubernetes/node-label/defaults/main.yml | Adds node_labels: {} default and documentation comment/examples. |
| roles/kubernetes/kubeadm_common/defaults/main.yml | Touches defaults file (but does not currently add the described new default). |
| docs/getting_started/minimal-inventory.md | Adds a new guide describing a minimal inventory + submodule workflow. |
| docs/getting_started/getting-started.md | Adds a link to the Minimal Inventory guide. |
| docs/_sidebar.md | Adds Minimal Inventory page to the docs sidebar. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| repo: "{{ cilium_image_repo }}" | ||
| tag: "{{ cilium_image_tag }}" | ||
| checksum: "{{ cilium_digest_checksum | default(None) }}" | ||
| checksum: "{{ cilium_digest_checksum | d(None) }}" |
There was a problem hiding this comment.
The PR description says this change should normalize | d(None) to | default(None) for Ansible best practices, but this file currently uses the d(None) alias. If the goal is consistency/readability, consider switching back to default(None) (or update the PR description if d() is intentional).
| # Node labels to be applied to nodes | ||
| # Format: dictionary of key=value pairs |
There was a problem hiding this comment.
This defaults file is missing the YAML document start marker (---). With the repo’s .yamllint config extending the default rules, document-start is enforced and this file will fail linting unless it begins with ---.
| --- | ||
| kubeadm_patches_dir: "{{ kube_config_dir }}/patches" | ||
| kubeadm_patches: [] | ||
|
|
There was a problem hiding this comment.
The PR description mentions introducing a kubeadm_patch_default_type: strategic default to avoid hardcoding | d('strategic') in tasks, but this variable isn’t defined here. As a result, the tasks still rely on an inline default filter. Add the variable (and then update the task to use it) to complete the refactor.
|
|
||
| ```bash | ||
| cd kubespray | ||
| ansible-playbook -i ../inventory/mycluster cluster.yml -b -v |
There was a problem hiding this comment.
The multi-line ansible-playbook example splits the command across two lines without a line-continuation (\). Copy/pasting this will execute --private-key=... as a separate command and fail; keep it on one line or add \ at the end of the first line.
| ansible-playbook -i ../inventory/mycluster cluster.yml -b -v | |
| ansible-playbook -i ../inventory/mycluster cluster.yml -b -v \ |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
This PR refactors how default values are handled across several roles in kubespray.
Currently, multiple task files use the
| d(default_value)filter inline, resulting in the same defaults being repeated throughout the codebase. This PR moves those defaults to their respectivedefaults/main.ymlfiles, making defaults easier to maintain and override from inventory.Specifically:
node_labels: {}in node-label role defaults instead of using| d({})in the taskkubeadm_patch_default_type: strategicin kubeadm_common role defaults instead of hardcoding| d('strategic')in the task| d(None)to| default(None)in download.yml for consistency with Ansible best practicesThis improves code readability and ensures each default is defined in a single location.
Which issue(s) this PR fixes:
Fixes #11822
Special notes for your reviewer:
This is an incremental change as suggested in the issue. Some uses of
| d()remain where they handle Ansible built-in variable fallbacks (e.g.,ansible_hostvsansible_ssh_hostin bastion-ssh-config) or conditional stat checks.Does this PR introduce a user-facing change?:
NONE