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

Adds support for Ansible collections #9582

Merged
merged 1 commit into from
Mar 27, 2023

Conversation

luksi1
Copy link
Contributor

@luksi1 luksi1 commented Dec 15, 2022

What type of PR is this?

/kind feature

What this PR does / why we need it:

Collections are a modern way for Ansible to handle projects like this, allowing downstream users to patch into kubespray's code. This change allows for example a downstream user to simply install a Kubernetes cluster with something like this:

- name: Install Kubernetes
  ansible.builtin.import_playbook: kubernetes_sigs.kubespray.cluster

Which issue(s) this PR fixes:

Fixes #9048

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

This would cause a change to the repository's structure, meaning downstream users would either need to change their code to point to the playbooks directory or use the ansible.builtin.import_playbook module

Add support for Ansible collections in Kubespray (⚠️ See notes !)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 15, 2022
@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 Dec 15, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @luksi1. 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Dec 15, 2022
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 9, 2023
@luksi1 luksi1 force-pushed the issue_9048 branch 2 times, most recently from b54144c to ccf8c8c Compare January 9, 2023 11:21
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jan 9, 2023
@luksi1 luksi1 force-pushed the issue_9048 branch 2 times, most recently from 021ba50 to 1a7f708 Compare January 11, 2023 07:17
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 11, 2023
@luksi1 luksi1 force-pushed the issue_9048 branch 2 times, most recently from f6ff021 to ede4218 Compare January 17, 2023 09:46
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 21, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 27, 2023
@luksi1 luksi1 force-pushed the issue_9048 branch 10 times, most recently from 9bdc69b to bdf9ad3 Compare March 3, 2023 17:58
@luksi1 luksi1 force-pushed the issue_9048 branch 3 times, most recently from aedd841 to 2bcf169 Compare March 15, 2023 09:32
@luksi1
Copy link
Contributor Author

luksi1 commented Mar 15, 2023

Sorry, for the late reply @floryut. Yes, there's some problems that popped up with syntax checking that I need to resolve.

@luksi1 luksi1 force-pushed the issue_9048 branch 14 times, most recently from 7dfef09 to 613f26f Compare March 20, 2023 09:22
@luksi1
Copy link
Contributor Author

luksi1 commented Mar 21, 2023

@floryut, I think this is good-to-go. Sorry, for the delay. I made a last minute change in tests/ansible.cfg as the syntax checks were not able to find the roles directory. I do not believe though this should cause any problems.

@floryut
Copy link
Member

floryut commented Mar 21, 2023

@luksi1 Thank you 👍
Can someone take a look at this one ?

@@ -0,0 +1,357 @@
#!/usr/bin/python
Copy link
Member

Choose a reason for hiding this comment

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

I don't see this as removed elsewhere are we supposed to have two versions of this now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, the answer is yes. We would have to maintain a duplicate of this since an Ansible collection structure places libraries under plugins, see here, while an Ansible playbook structure
places libraries under library, see here.

The idea of this first iteration is to retain the structure as-is, so users could either use the repository as an Ansible collection, by simply pointing their requirements.txt directly at the Kubespray's repository, or download it and use it the same as before. And this seemed like the easiest way forward.

Copy link
Member

Choose a reason for hiding this comment

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

Random guess but did you try to see if a symlink works here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would probably work, but before I start changing anything, do we want to go down this path? Symlinks will probably work fine on Linux distributions, and should work out-of-the-box when cloning (not tested), but I believe that symlinks in Windows require admin rights to access mklink functions plus enabling core.symlinks functionality when cloning, which might result in some confusion for users running Ansible from Windows. There might even be some additional edge cases that I'm not familiar with. Are we comfortable with this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That settles it :) I'll see if I can't get the collection working with a symlink instead of duplicating the library. Thanks for the feedback.

Choose a reason for hiding this comment

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

Btw. how about using #!/usr/bin/env bash everywhere or at least in all new places introduced with this PR? This way operating systems like NixOS are supported, too. Using env is the best way when going for maximum portability. https://www.gnu.org/software/coreutils/manual/html_node/env-invocation.html

Copy link
Member

Choose a reason for hiding this comment

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

Since CI is failing I am guessing you might try the other way around (moving the file to the new location and symlink from old to new).

@michel-zimmer AFAICS there is only one file in this PR with this https://github.com/kubernetes-sigs/kubespray/blob/46dc09ca7647213230a0d869b13e150ae650c2b4/tests/scripts/check_galaxy_version.sh, feel free to send a PR for cleaning up those across the repo though!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MrFreezeex, good suggestion! Worked like a charm! Let me know if there's any other concerns regarding this PR.

@MrFreezeex
Copy link
Member

Thanks for modernizing Kubespray with collection support :D @luksi1
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 27, 2023
@k8s-ci-robot k8s-ci-robot merged commit acbf44a into kubernetes-sigs:master Mar 27, 2023
@yankay yankay mentioned this pull request May 15, 2023
pedro-peter pushed a commit to pedro-peter/kubespray that referenced this pull request May 8, 2024
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide Kubespray as an Ansible collection
6 participants