Skip to content

Fix/eliminate default filter 11822#13136

Open
AdeshDeshmukh wants to merge 3 commits intokubernetes-sigs:masterfrom
AdeshDeshmukh:fix/eliminate-default-filter-11822
Open

Fix/eliminate default filter 11822#13136
AdeshDeshmukh wants to merge 3 commits intokubernetes-sigs:masterfrom
AdeshDeshmukh:fix/eliminate-default-filter-11822

Conversation

@AdeshDeshmukh
Copy link
Copy Markdown

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 respective defaults/main.yml files, making defaults easier to maintain and override from inventory.

Specifically:

  • Defines node_labels: {} in node-label role defaults instead of using | d({}) in the task
  • Defines kubeadm_patch_default_type: strategic in kubeadm_common role defaults instead of hardcoding | d('strategic') in the task
  • Normalizes | d(None) to | default(None) in download.yml for consistency with Ansible best practices

This 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_host vs ansible_ssh_host in bastion-ssh-config) or conditional stat checks.

Does this PR introduce a user-facing change?:

NONE

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>
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

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.

Details

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 31, 2026
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Mar 31, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot requested review from mzaian and yankay March 31, 2026 13:17
@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Mar 31, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: AdeshDeshmukh
Once this PR has been reviewed and has the lgtm label, please assign mzaian for approval. For more information see the Code Review Process.

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

Details 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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 31, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

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 /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.

Details

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 31, 2026
Copy link
Copy Markdown
Contributor

@VannTen VannTen left a comment

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 }}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

While default is more explicit than d, please revert this one, the history churn isn't worth it.

Copilot AI review requested due to automatic review settings April 3, 2026 13:37
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_labels default in the node-label role 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) }}"
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +2
# Node labels to be applied to nodes
# Format: dictionary of key=value pairs
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

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 ---.

Copilot uses AI. Check for mistakes.
Comment on lines 1 to +4
---
kubeadm_patches_dir: "{{ kube_config_dir }}/patches"
kubeadm_patches: []

Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.

```bash
cd kubespray
ansible-playbook -i ../inventory/mycluster cluster.yml -b -v
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
ansible-playbook -i ../inventory/mycluster cluster.yml -b -v
ansible-playbook -i ../inventory/mycluster cluster.yml -b -v \

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. needs-ok-to-test Indicates a PR that requires an org member to verify it 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.

eliminate all instances of default filter in roles => var should have a default defined only once

4 participants