Skip to content

Commit 6a686f6

Browse files
committed
refactor config structure for split k0smotron installations
Signed-off-by: apedriza <[email protected]>
1 parent ee79f00 commit 6a686f6

File tree

126 files changed

+1909
-20045
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+1909
-20045
lines changed

.github/workflows/capi-smoke-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ jobs:
7979
run: |
8080
kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.24/deploy/local-path-storage.yaml
8181
82-
- name: Download install manifest for k0smotron
82+
- name: Download install manifest for k0smotron standalone
8383
uses: actions/download-artifact@v5
8484
with:
85-
name: install-yaml
85+
name: install-standalone-yaml
8686

8787
- name: Run inttest for CAPI with docker provider
8888
run: |

.github/workflows/go.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ jobs:
8080
config.yaml
8181
k0sproject-k0smotron/
8282
83-
- name: Generate install yaml
83+
- name: Generate install yaml for standalone mode
8484
run: |
85-
make release
85+
make release-standalone
8686
87-
- name: Upload install yaml
87+
- name: Upload install-standalone yaml
8888
uses: actions/upload-artifact@v4
8989
with:
90-
name: install-yaml
91-
path: install.yaml
90+
name: install-standalone-yaml
91+
path: install-standalone.yaml
9292

9393
unittest:
9494
name: Unit & Integration tests
@@ -176,7 +176,7 @@ jobs:
176176
- name: Download install manifest for k0smotron
177177
uses: actions/download-artifact@v5
178178
with:
179-
name: install-yaml
179+
name: install-standalone-yaml
180180

181181
- name: Load k0smotron image bundle
182182
run: |
@@ -272,11 +272,6 @@ jobs:
272272
run: |
273273
docker load -i k0smotron-image-bundle.tar
274274
275-
- name: Download install manifest
276-
uses: actions/download-artifact@v5
277-
with:
278-
name: install-yaml
279-
280275
- name: Run e2e test
281276
run: |
282277
make e2e TEST_NAME="${{ matrix.e2e-suite }}"

.github/workflows/publish-docs.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
echo STABLE="$STABLE" >> $GITHUB_OUTPUT
8282
8383
# Ensures the current branch is gh-pages,
84-
# Creates / updates the "install.yaml" file with the corresponding versions
84+
# Creates / updates the "install.yaml" and "install-standalone.yaml" files with the corresponding versions
8585
# Commits if the files were changed
8686
# Finally pushes if there are unpushed commits
8787
- name: Create install files
@@ -94,9 +94,12 @@ jobs:
9494
run: |
9595
STABLE=${{ steps.set_versions.outputs.STABLE }}
9696
make release IMG=quay.io/k0sproject/k0smotron:${STABLE}
97+
make release-standalone IMG=quay.io/k0sproject/k0smotron:${STABLE}
9798
cp install.yaml /tmp/install.yaml
99+
cp install-standalone.yaml /tmp/install-standalone.yaml
98100
git checkout gh-pages
99101
cp /tmp/install.yaml ${STABLE}/install.yaml
100-
git add ${STABLE}/install.yaml && git update-index --refresh
101-
git diff-index --quiet HEAD -- || git commit -m "Update install.yaml to ${STABLE}"
102+
cp /tmp/install-standalone.yaml ${STABLE}/install-standalone.yaml
103+
git add ${STABLE}/install.yaml ${STABLE}/install-standalone.yaml && git update-index --refresh
104+
git diff-index --quiet HEAD -- || git commit -m "Update install.yaml and install-standalone.yaml to ${STABLE}"
102105
git push origin gh-pages

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Generated files
22
install.yaml
3+
install-standalone.yaml
34
bootstrap-components.yaml
45
control-plane-components.yaml
56
infrastructure-components.yaml

Makefile

Lines changed: 68 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -63,33 +63,61 @@ help: ## Display this help.
6363
##@ Development
6464

6565
### CRD manifests (one per API group)
66-
.PHONY: manifests-bootstrap manifests-controlplane manifests-infrastructure manifests-k0smotron
66+
.PHONY: manifests-bootstrap manifests-controlplane manifests-infrastructure manifests-standalone
6767
manifests-bootstrap: $(CONTROLLER_GEN) ## Generate CRDs for bootstrap.cluster.x-k8s.io
68-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook \
69-
paths="./..." \
70-
output:crd:artifacts:config=config/crd/bases/bootstrap
71-
find ./config/crd/bases/bootstrap -type f ! -name "bootstrap*" ! -name "kustomization.yaml" -print0 | xargs -0 rm
68+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true \
69+
paths="./api/bootstrap/v1beta1/..." \
70+
paths=./internal/controller/bootstrap/... \
71+
output:crd:artifacts:config=config/clusterapi/bootstrap/crd/bases \
72+
output:rbac:dir=config/clusterapi/bootstrap/rbac
7273

73-
manifests-controlplane: $(CONTROLLER_GEN) ## Generate CRDs for controlplane.cluster.x-k8s.io
74+
manifests-controlplane: $(CONTROLLER_GEN) ## Generate CRDs for controlplane.cluster.x-k8s.io.
75+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook \
76+
paths="./api/controlplane/v1beta1/..." \
77+
paths=./internal/controller/controlplane/... \
78+
output:crd:artifacts:config=config/clusterapi/controlplane/crd/bases
7479
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook \
75-
paths="./..." \
76-
output:crd:artifacts:config=config/crd/bases/controlplane
77-
find ./config/crd/bases/controlplane -type f ! -name "controlplane*" ! -name "kustomization.yaml" -print0 | xargs -0 rm
80+
paths="./api/controlplane/v1beta1/..." \
81+
paths="./api/k0smotron.io/v1beta1/..." \
82+
paths=./internal/controller/controlplane/... \
83+
paths=./internal/controller/k0smotron.io/... \
84+
output:rbac:dir=config/clusterapi/controlplane/rbac \
85+
output:webhook:dir=config/clusterapi/controlplane/webhook
7886

7987
manifests-infrastructure: $(CONTROLLER_GEN) ## Generate CRDs for infrastructure.cluster.x-k8s.io
80-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook \
81-
paths="./..." \
82-
output:crd:artifacts:config=config/crd/bases/infrastructure
83-
find ./config/crd/bases/infrastructure -type f ! -name "infrastructure*" ! -name "kustomization.yaml" -print0 | xargs -0 rm
88+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true \
89+
paths="./api/infrastructure/v1beta1/..." \
90+
paths=./internal/controller/infrastructure/... \
91+
output:crd:artifacts:config=config/clusterapi/infrastructure/crd/bases \
92+
output:rbac:dir=config/clusterapi/infrastructure/rbac
8493

85-
manifests-k0smotron: $(CONTROLLER_GEN) ## Generate CRDs for k0smotron.io
94+
manifests-standalone: $(CONTROLLER_GEN) ## Generate CRDs for k0smotron.io standalone
8695
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook \
87-
paths="./..." \
88-
output:crd:artifacts:config=config/crd/bases/k0smotron.io
89-
find ./config/crd/bases/k0smotron.io -type f ! -name "k0smotron.io*" ! -name "kustomization.yaml" -print0 | xargs -0 rm
96+
paths="./api/k0smotron.io/v1beta1/..." \
97+
paths=./internal/controller/k0smotron.io/... \
98+
output:crd:artifacts:config=config/standalone/crd/bases \
99+
output:rbac:dir=config/standalone/rbac \
100+
output:webhook:dir=config/standalone/webhook
101+
102+
.PHONY: manifests-capi-integration
103+
manifests-capi-integration: manifests manifests-capi-integration-without-crd
104+
105+
.PHONY: manifests-capi-integration-without-crd
106+
manifests-capi-integration-without-crd: $(CONTROLLER_GEN) # Generate RBAC and webhook manifests for all controllers except CRDs in order to reuse them from each config/clusterapi/{provider}
107+
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook \
108+
paths="./api/bootstrap/v1beta1/..." \
109+
paths=./internal/controller/bootstrap/... \
110+
paths="./api/controlplane/v1beta1/..." \
111+
paths="./api/k0smotron.io/v1beta1/..." \
112+
paths=./internal/controller/controlplane/... \
113+
paths=./internal/controller/k0smotron.io/... \
114+
paths="./api/infrastructure/v1beta1/..." \
115+
paths=./internal/controller/infrastructure/... \
116+
output:rbac:dir=config/clusterapi/all/rbac \
117+
output:webhook:dir=config/clusterapi/all/webhook
90118

91119
.PHONY: manifests
92-
manifests: manifests-bootstrap manifests-controlplane manifests-infrastructure manifests-k0smotron ## Generate all CRD YAMLs per group
120+
manifests: manifests-bootstrap manifests-controlplane manifests-infrastructure manifests-standalone ## Generate all CRD YAMLs per group
93121

94122
### generate
95123
generate_targets += api/k0smotron.io/v1beta1/zz_generated.deepcopy.go
@@ -100,7 +128,7 @@ generate_targets += api/infrastructure/v1beta1/zz_generated.deepcopy.go
100128
$(generate_targets): $(CONTROLLER_GEN)
101129
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
102130

103-
generate: $(generate_targets) clusterapi-manifests ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
131+
generate: $(generate_targets) manifests ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
104132

105133

106134
GO_PKGS=$(shell go list ./...)
@@ -151,10 +179,6 @@ e2e-aws:
151179
build:
152180
go build -o bin/manager cmd/main.go
153181

154-
.PHONY: run
155-
run: manifests generate fmt vet ## Run a controller from your host.
156-
go run ./cmd/main.go
157-
158182
# If you wish built the manager image targeting other platforms you can use the --platform flag.
159183
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
160184
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
@@ -195,49 +219,43 @@ ifndef ignore-not-found
195219
ignore-not-found = false
196220
endif
197221

198-
.PHONY: install
199-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
200-
$(KUSTOMIZE) build config/crd | kubectl create -f -
201-
202-
.PHONY: uninstall
203-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
204-
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
205-
206222
.PHONY: deploy
207223
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
208-
cd config/manager && $(KUSTOMIZE) edit set image k0s/k0smotron=${IMG}
209-
$(KUSTOMIZE) build config/default | kubectl create -f -
224+
cd config/clusterapi/all/manager && $(KUSTOMIZE) edit set image k0s/k0smotron=${IMG}
225+
$(KUSTOMIZE) build config/clusterapi/all | kubectl create -f -
226+
git checkout config/clusterapi/all/manager/kustomization.yaml
210227

211228
.PHONY: undeploy
212229
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
213-
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
230+
$(KUSTOMIZE) build config/clusterapi/all | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
214231

215232
.PHONY: release
216-
release: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
233+
release: manifests-capi-integration kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
234+
cd config/clusterapi/all/manager && $(KUSTOMIZE) edit set image controller=${IMG}
235+
$(KUSTOMIZE) build config/clusterapi/all > install.yaml
236+
git checkout config/clusterapi/all/manager/kustomization.yaml
237+
238+
.PHONY: release-standalone
239+
release-standalone: manifests-standalone kustomize ## Generate install yaml for standalone mode
217240
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
218-
$(KUSTOMIZE) build config/default > install.yaml
241+
$(KUSTOMIZE) build config/standalone > install-standalone.yaml
219242
git checkout config/manager/kustomization.yaml
220243

221-
clusterapi-manifests:
222-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./api/bootstrap/..." output:crd:artifacts:config=config/clusterapi/bootstrap/bases
223-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./api/controlplane/..." output:crd:artifacts:config=config/clusterapi/controlplane/bases
224-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./api/infrastructure/..." output:crd:artifacts:config=config/clusterapi/infrastructure/bases
225-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./api/k0smotron.io/..." output:crd:artifacts:config=config/clusterapi/k0smotron.io/bases
226-
227-
bootstrap-components.yaml: $(CONTROLLER_GEN) clusterapi-manifests kustomize
244+
bootstrap-components.yaml: $(CONTROLLER_GEN) manifests-bootstrap kustomize
228245
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
229246
$(KUSTOMIZE) build config/clusterapi/bootstrap/ > bootstrap-components.yaml
230247
git checkout config/manager/kustomization.yaml
231248

232-
control-plane-components.yaml: $(CONTROLLER_GEN) clusterapi-manifests kustomize
249+
control-plane-components.yaml: $(CONTROLLER_GEN) manifests-controlplane kustomize
233250
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
234251
$(KUSTOMIZE) build config/clusterapi/controlplane/ > control-plane-components.yaml
235252
git checkout config/manager/kustomization.yaml
236253

237-
infrastructure-components.yaml: $(CONTROLLER_GEN) clusterapi-manifests kustomize
254+
infrastructure-components.yaml: $(CONTROLLER_GEN) manifests-infrastructure kustomize
238255
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
239256
$(KUSTOMIZE) build config/clusterapi/infrastructure/ > infrastructure-components.yaml
240257
git checkout config/manager/kustomization.yaml
258+
241259
##@ Build Dependencies
242260

243261
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
@@ -272,23 +290,23 @@ $(CRDOC): Makefile.variables | $(LOCALBIN)
272290

273291
.PHONY: docs-generate-bootstrap docs-generate-controlplane docs-generate-infrastructure docs-generate-k0smotron docs-generate-reference
274292
docs-generate-bootstrap: $(CRDOC) ## Generate docs for bootstrap CRDs
275-
$(CRDOC) --resources config/crd/bases/bootstrap --output docs/resource-reference/bootstrap.cluster.x-k8s.io-v1beta1.md
293+
$(CRDOC) --resources config/clusterapi/bootstrap/crd/bases --output docs/resource-reference/bootstrap.cluster.x-k8s.io-v1beta1.md
276294

277295
docs-generate-controlplane: $(CRDOC) ## Generate docs for controlplane CRDs
278-
$(CRDOC) --resources config/crd/bases/controlplane --output docs/resource-reference/controlplane.cluster.x-k8s.io-v1beta1.md
296+
$(CRDOC) --resources config/clusterapi/controlplane/crd/bases --output docs/resource-reference/controlplane.cluster.x-k8s.io-v1beta1.md
279297

280298
docs-generate-infrastructure: $(CRDOC) ## Generate docs for infrastructure CRDs
281-
$(CRDOC) --resources config/crd/bases/infrastructure --output docs/resource-reference/infrastructure.cluster.x-k8s.io-v1beta1.md
299+
$(CRDOC) --resources config/clusterapi/infrastructure/crd/bases --output docs/resource-reference/infrastructure.cluster.x-k8s.io-v1beta1.md
282300

283301
docs-generate-k0smotron: $(CRDOC) ## Generate docs for k0smotron CRDs
284-
$(CRDOC) --resources config/crd/bases/k0smotron.io --output docs/resource-reference/k0smotron.io-v1beta1.md
302+
$(CRDOC) --resources config/standalone/crd/bases --output docs/resource-reference/k0smotron.io-v1beta1.md
285303

286304
# Generate docs for all CRDs apis
287305
docs-generate-reference: docs-generate-bootstrap docs-generate-controlplane docs-generate-infrastructure docs-generate-k0smotron
288306

289307
## Generate all code, manifests, documentation, and release artifacts
290308
.PHONY: generate-all
291-
generate-all: clean generate manifests clusterapi-manifests docs-generate-reference release
309+
generate-all: clean generate docs-generate-reference release
292310

293311
.PHONY: $(smoketests)
294312
$(smoketests): release k0smotron-image-bundle.tar

cmd/main.go

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"k8s.io/client-go/kubernetes"
3535
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3636
_ "k8s.io/client-go/plugin/pkg/client/auth"
37+
"k8s.io/client-go/rest"
3738
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3839
"sigs.k8s.io/cluster-api/util/flags"
3940
ctrl "sigs.k8s.io/controller-runtime"
@@ -42,6 +43,7 @@ import (
4243
capictrl "sigs.k8s.io/controller-runtime/pkg/controller"
4344
"sigs.k8s.io/controller-runtime/pkg/healthz"
4445
"sigs.k8s.io/controller-runtime/pkg/log/zap"
46+
"sigs.k8s.io/controller-runtime/pkg/manager"
4547
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
4648
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
4749

@@ -70,10 +72,13 @@ var (
7072
)
7173

7274
const (
73-
allControllers = "all"
75+
allControllers = "all"
76+
// CAPI controllers flags
7477
bootstrapController = "bootstrap"
7578
controlPlaneController = "control-plane"
7679
infrastructureController = "infrastructure"
80+
// Standalone controller flag
81+
standaloneController = "standalone"
7782
)
7883

7984
func init() {
@@ -273,32 +278,8 @@ func main() {
273278
}
274279

275280
if isControllerEnabled(controlPlaneController) {
276-
_ = mgr.AddReadyzCheck("webhook-check", mgr.GetWebhookServer().StartedChecker())
277-
if err = (&controller.ClusterReconciler{
278-
Client: mgr.GetClient(),
279-
Scheme: mgr.GetScheme(),
280-
ClientSet: clientSet,
281-
RESTConfig: restConfig,
282-
Recorder: mgr.GetEventRecorderFor("cluster-reconciler"),
283-
}).SetupWithManager(mgr, ctrlOptions); err != nil {
284-
setupLog.Error(err, "unable to create controller", "controller", "K0smotronCluster")
285-
os.Exit(1)
286-
}
287-
288-
if err = controller.SetupK0sControlPlaneWebhookWithManager(mgr); err != nil {
289-
setupLog.Error(err, "unable to create webhook", "webhook", "k0smotron.Cluster")
290-
os.Exit(1)
291-
}
292-
293-
if err = (&controller.JoinTokenRequestReconciler{
294-
Client: mgr.GetClient(),
295-
Scheme: mgr.GetScheme(),
296-
ClientSet: clientSet,
297-
RESTConfig: restConfig,
298-
}).SetupWithManager(mgr, ctrlOptions); err != nil {
299-
setupLog.Error(err, "unable to create controller", "controller", "JoinTokenRequest")
300-
os.Exit(1)
301-
}
281+
// If 'control-plane' CAPI controller is explicitly enabled, it means also standalone controllers must be enabled
282+
setStandaloneControllers(mgr, clientSet, restConfig, ctrlOptions)
302283

303284
if runCAPIControllers {
304285
if err = (&controlplane.K0smotronController{
@@ -332,6 +313,9 @@ func main() {
332313
os.Exit(1)
333314
}
334315
}
316+
} else if isControllerEnabled(standaloneController) {
317+
// If 'standalone' controller is explicitly enabled, run only standalone controllers.
318+
setStandaloneControllers(mgr, clientSet, restConfig, ctrlOptions)
335319
}
336320

337321
if isControllerEnabled(infrastructureController) && runCAPIControllers {
@@ -387,3 +371,32 @@ func main() {
387371
func isControllerEnabled(controllerName string) bool {
388372
return enabledControllers[controllerName]
389373
}
374+
375+
func setStandaloneControllers(mgr manager.Manager, clientSet *kubernetes.Clientset, restConfig *rest.Config, opts capictrl.Options) {
376+
_ = mgr.AddReadyzCheck("webhook-check", mgr.GetWebhookServer().StartedChecker())
377+
if err := (&controller.ClusterReconciler{
378+
Client: mgr.GetClient(),
379+
Scheme: mgr.GetScheme(),
380+
ClientSet: clientSet,
381+
RESTConfig: restConfig,
382+
Recorder: mgr.GetEventRecorderFor("cluster-reconciler"),
383+
}).SetupWithManager(mgr, opts); err != nil {
384+
setupLog.Error(err, "unable to create controller", "controller", "K0smotronCluster")
385+
os.Exit(1)
386+
}
387+
388+
if err := controller.SetupK0sControlPlaneWebhookWithManager(mgr); err != nil {
389+
setupLog.Error(err, "unable to create webhook", "webhook", "k0smotron.Cluster")
390+
os.Exit(1)
391+
}
392+
393+
if err := (&controller.JoinTokenRequestReconciler{
394+
Client: mgr.GetClient(),
395+
Scheme: mgr.GetScheme(),
396+
ClientSet: clientSet,
397+
RESTConfig: restConfig,
398+
}).SetupWithManager(mgr, opts); err != nil {
399+
setupLog.Error(err, "unable to create controller", "controller", "JoinTokenRequest")
400+
os.Exit(1)
401+
}
402+
}

0 commit comments

Comments
 (0)