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

How to factorize code between kops and cluster api? #16540

Open
remyleone opened this issue May 7, 2024 · 2 comments
Open

How to factorize code between kops and cluster api? #16540

remyleone opened this issue May 7, 2024 · 2 comments
Assignees
Labels
kind/feature Categorizes issue or PR as related to a new feature. kind/office-hours

Comments

@remyleone
Copy link
Contributor

/kind feature

1. Describe IN DETAIL the feature/behavior/change you would like to see.

I would like to have documentation about how to have reusable components between kops and cluster api controller. For those both tools there is a lot of overlap in the preparation of a cluster. Is there any documentation/recommendation about how to reuse code between those two projects?

2. Feel free to provide a design supporting your feature request.

I would like to have documentation about the core functions/interfaces that would need to be documented to permit maximum reusability between kops and cluster api.

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label May 7, 2024
@remyleone remyleone changed the title How to factorize code between kops and cluster api How to factorize code between kops and cluster api? May 7, 2024
@hakman
Copy link
Member

hakman commented May 8, 2024

/assign @justinsb
/kind office-hours

@justinsb
Copy link
Member

This is a great question. I don't think we have a "do it this way" answer, but here's my suggestion....

There are broadly two levels in the code; in kOps we have the tasks and the model layer. I think the tasks layer is essentially trying to create a declarative/idempotent abstraction of the cloud provider's RESTful APIs, and the model layer is translating kOps to those tasks.

I think the tasks layer is the best opportunity for reuse. The cloud-provider code would benefit from it, cluster-api would benefit from it, and tasks would also benefit from it. I also work on KCC , which is a set of operators for managing cloud resources on GCP (and AWS has ACK, Azure has ASO), those also map pretty naturally to the tasks layer.

This doesn't necessarily mean reuse of the task layer directly (though it would be an interesting refactor to try once we've done the 1.30 beta and can do big refactors on the main branch). At its most basic it could be copy-and-paste reuse and then we can see whether it is worthwhile doing the bigger refactor.

The idea though is that generally the work to add kOps / cluster-api / cloud-provider support can be split into the work to "translate" those APIs to the cloud-provider APIs, and then the work to drive those cloud-provider APIs in a way compatible with the Kubernetes reconciliation/declarative model. Because the "mapping" involves a different source API, it's always going to be hard to reuse, but the "reconciliation" layer has the same "target" and the same representation (the output of the mapping), so should be much easier to reproduce. My theory is that the reconciliation layer is also more time consuming to implement and generally where there are more bugs, but that is only a hypothesis.

The Kubernetes operator layer is an interesting additional opportunity. I don't know if anyone has tried building cluster-api / cloud-provider support on top of operators; I'm pretty sure nobody has for kOps because it would need some tricks to fake client.Client. But I do think that is possible, so if you wanted to investigate that I'd be very interested in exploring that with you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. kind/office-hours
Projects
None yet
Development

No branches or pull requests

4 participants