Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/capi-smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ jobs:
run: |
kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.24/deploy/local-path-storage.yaml

- name: Download install manifest for k0smotron
- name: Download install manifest for k0smotron standalone
uses: actions/download-artifact@v5
with:
name: install-yaml
name: install-standalone-yaml

- name: Run inttest for CAPI with docker provider
run: |
Expand Down
17 changes: 6 additions & 11 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ jobs:
config.yaml
k0sproject-k0smotron/

- name: Generate install yaml
- name: Generate install yaml for standalone mode
run: |
make release
make release-standalone

- name: Upload install yaml
- name: Upload install-standalone yaml
uses: actions/upload-artifact@v4
with:
name: install-yaml
path: install.yaml
name: install-standalone-yaml
path: install-standalone.yaml

unittest:
name: Unit & Integration tests
Expand Down Expand Up @@ -176,7 +176,7 @@ jobs:
- name: Download install manifest for k0smotron
uses: actions/download-artifact@v5
with:
name: install-yaml
name: install-standalone-yaml

- name: Load k0smotron image bundle
run: |
Expand Down Expand Up @@ -272,11 +272,6 @@ jobs:
run: |
docker load -i k0smotron-image-bundle.tar

- name: Download install manifest
uses: actions/download-artifact@v5
with:
name: install-yaml

- name: Run e2e test
run: |
make e2e TEST_NAME="${{ matrix.e2e-suite }}"
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
echo STABLE="$STABLE" >> $GITHUB_OUTPUT

# Ensures the current branch is gh-pages,
# Creates / updates the "install.yaml" file with the corresponding versions
# Creates / updates the "install.yaml" and "install-standalone.yaml" files with the corresponding versions
# Commits if the files were changed
# Finally pushes if there are unpushed commits
- name: Create install files
Expand All @@ -94,9 +94,12 @@ jobs:
run: |
STABLE=${{ steps.set_versions.outputs.STABLE }}
make release IMG=quay.io/k0sproject/k0smotron:${STABLE}
make release-standalone IMG=quay.io/k0sproject/k0smotron:${STABLE}
cp install.yaml /tmp/install.yaml
cp install-standalone.yaml /tmp/install-standalone.yaml
git checkout gh-pages
cp /tmp/install.yaml ${STABLE}/install.yaml
git add ${STABLE}/install.yaml && git update-index --refresh
git diff-index --quiet HEAD -- || git commit -m "Update install.yaml to ${STABLE}"
cp /tmp/install-standalone.yaml ${STABLE}/install-standalone.yaml
git add ${STABLE}/install.yaml ${STABLE}/install-standalone.yaml && git update-index --refresh
git diff-index --quiet HEAD -- || git commit -m "Update install.yaml and install-standalone.yaml to ${STABLE}"
git push origin gh-pages
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated files
install.yaml
install-standalone.yaml
bootstrap-components.yaml
control-plane-components.yaml
infrastructure-components.yaml
Expand Down
118 changes: 68 additions & 50 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,61 @@ help: ## Display this help.
##@ Development

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

manifests-controlplane: $(CONTROLLER_GEN) ## Generate CRDs for controlplane.cluster.x-k8s.io
manifests-controlplane: $(CONTROLLER_GEN) ## Generate CRDs for controlplane.cluster.x-k8s.io.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook \
paths="./api/controlplane/v1beta1/..." \
paths=./internal/controller/controlplane/... \
output:crd:artifacts:config=config/clusterapi/controlplane/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook \
paths="./..." \
output:crd:artifacts:config=config/crd/bases/controlplane
find ./config/crd/bases/controlplane -type f ! -name "controlplane*" ! -name "kustomization.yaml" -print0 | xargs -0 rm
paths="./api/controlplane/v1beta1/..." \
paths="./api/k0smotron.io/v1beta1/..." \
paths=./internal/controller/controlplane/... \
paths=./internal/controller/k0smotron.io/... \
output:rbac:dir=config/clusterapi/controlplane/rbac \
output:webhook:dir=config/clusterapi/controlplane/webhook

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

manifests-k0smotron: $(CONTROLLER_GEN) ## Generate CRDs for k0smotron.io
manifests-standalone: $(CONTROLLER_GEN) ## Generate CRDs for k0smotron.io standalone
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook \
paths="./..." \
output:crd:artifacts:config=config/crd/bases/k0smotron.io
find ./config/crd/bases/k0smotron.io -type f ! -name "k0smotron.io*" ! -name "kustomization.yaml" -print0 | xargs -0 rm
paths="./api/k0smotron.io/v1beta1/..." \
paths=./internal/controller/k0smotron.io/... \
output:crd:artifacts:config=config/standalone/crd/bases \
output:rbac:dir=config/standalone/rbac \
output:webhook:dir=config/standalone/webhook

.PHONY: manifests-capi-integration
manifests-capi-integration: manifests manifests-capi-integration-without-crd

.PHONY: manifests-capi-integration-without-crd
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}
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook \
paths="./api/bootstrap/v1beta1/..." \
paths=./internal/controller/bootstrap/... \
paths="./api/controlplane/v1beta1/..." \
paths="./api/k0smotron.io/v1beta1/..." \
paths=./internal/controller/controlplane/... \
paths=./internal/controller/k0smotron.io/... \
paths="./api/infrastructure/v1beta1/..." \
paths=./internal/controller/infrastructure/... \
output:rbac:dir=config/clusterapi/all/rbac \
output:webhook:dir=config/clusterapi/all/webhook

.PHONY: manifests
manifests: manifests-bootstrap manifests-controlplane manifests-infrastructure manifests-k0smotron ## Generate all CRD YAMLs per group
manifests: manifests-bootstrap manifests-controlplane manifests-infrastructure manifests-standalone ## Generate all CRD YAMLs per group

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

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


GO_PKGS=$(shell go list ./...)
Expand Down Expand Up @@ -151,10 +179,6 @@ e2e-aws:
build:
go build -o bin/manager cmd/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/main.go

# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
Expand Down Expand Up @@ -195,49 +219,43 @@ ifndef ignore-not-found
ignore-not-found = false
endif

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl create -f -

.PHONY: uninstall
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.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image k0s/k0smotron=${IMG}
$(KUSTOMIZE) build config/default | kubectl create -f -
cd config/clusterapi/all/manager && $(KUSTOMIZE) edit set image k0s/k0smotron=${IMG}
$(KUSTOMIZE) build config/clusterapi/all | kubectl create -f -
git checkout config/clusterapi/all/manager/kustomization.yaml

.PHONY: undeploy
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.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
$(KUSTOMIZE) build config/clusterapi/all | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: release
release: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
release: manifests-capi-integration kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/clusterapi/all/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/clusterapi/all > install.yaml
git checkout config/clusterapi/all/manager/kustomization.yaml

.PHONY: release-standalone
release-standalone: manifests-standalone kustomize ## Generate install yaml for standalone mode
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default > install.yaml
$(KUSTOMIZE) build config/standalone > install-standalone.yaml
git checkout config/manager/kustomization.yaml

clusterapi-manifests:
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./api/bootstrap/..." output:crd:artifacts:config=config/clusterapi/bootstrap/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./api/controlplane/..." output:crd:artifacts:config=config/clusterapi/controlplane/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./api/infrastructure/..." output:crd:artifacts:config=config/clusterapi/infrastructure/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./api/k0smotron.io/..." output:crd:artifacts:config=config/clusterapi/k0smotron.io/bases

bootstrap-components.yaml: $(CONTROLLER_GEN) clusterapi-manifests kustomize
bootstrap-components.yaml: $(CONTROLLER_GEN) manifests-bootstrap kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/clusterapi/bootstrap/ > bootstrap-components.yaml
git checkout config/manager/kustomization.yaml

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

infrastructure-components.yaml: $(CONTROLLER_GEN) clusterapi-manifests kustomize
infrastructure-components.yaml: $(CONTROLLER_GEN) manifests-infrastructure kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/clusterapi/infrastructure/ > infrastructure-components.yaml
git checkout config/manager/kustomization.yaml

##@ Build Dependencies

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

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

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

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

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

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

## Generate all code, manifests, documentation, and release artifacts
.PHONY: generate-all
generate-all: clean generate manifests clusterapi-manifests docs-generate-reference release
generate-all: clean generate docs-generate-reference release

.PHONY: $(smoketests)
$(smoketests): release k0smotron-image-bundle.tar
Expand Down
67 changes: 40 additions & 27 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"k8s.io/client-go/kubernetes"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/flags"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -42,6 +43,7 @@ import (
capictrl "sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

Expand Down Expand Up @@ -70,10 +72,13 @@ var (
)

const (
allControllers = "all"
allControllers = "all"
// CAPI controllers flags
bootstrapController = "bootstrap"
controlPlaneController = "control-plane"
infrastructureController = "infrastructure"
// Standalone controller flag
standaloneController = "standalone"
)

func init() {
Expand Down Expand Up @@ -273,32 +278,8 @@ func main() {
}

if isControllerEnabled(controlPlaneController) {
_ = mgr.AddReadyzCheck("webhook-check", mgr.GetWebhookServer().StartedChecker())
if err = (&controller.ClusterReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ClientSet: clientSet,
RESTConfig: restConfig,
Recorder: mgr.GetEventRecorderFor("cluster-reconciler"),
}).SetupWithManager(mgr, ctrlOptions); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "K0smotronCluster")
os.Exit(1)
}

if err = controller.SetupK0sControlPlaneWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "k0smotron.Cluster")
os.Exit(1)
}

if err = (&controller.JoinTokenRequestReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ClientSet: clientSet,
RESTConfig: restConfig,
}).SetupWithManager(mgr, ctrlOptions); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "JoinTokenRequest")
os.Exit(1)
}
// If 'control-plane' CAPI controller is explicitly enabled, it means also standalone controllers must be enabled
setStandaloneControllers(mgr, clientSet, restConfig, ctrlOptions)

if runCAPIControllers {
if err = (&controlplane.K0smotronController{
Expand Down Expand Up @@ -332,6 +313,9 @@ func main() {
os.Exit(1)
}
}
} else if isControllerEnabled(standaloneController) {
// If 'standalone' controller is explicitly enabled, run only standalone controllers.
setStandaloneControllers(mgr, clientSet, restConfig, ctrlOptions)
}

if isControllerEnabled(infrastructureController) && runCAPIControllers {
Expand Down Expand Up @@ -387,3 +371,32 @@ func main() {
func isControllerEnabled(controllerName string) bool {
return enabledControllers[controllerName]
}

func setStandaloneControllers(mgr manager.Manager, clientSet *kubernetes.Clientset, restConfig *rest.Config, opts capictrl.Options) {
_ = mgr.AddReadyzCheck("webhook-check", mgr.GetWebhookServer().StartedChecker())
if err := (&controller.ClusterReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ClientSet: clientSet,
RESTConfig: restConfig,
Recorder: mgr.GetEventRecorderFor("cluster-reconciler"),
}).SetupWithManager(mgr, opts); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "K0smotronCluster")
os.Exit(1)
}

if err := controller.SetupK0sControlPlaneWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "k0smotron.Cluster")
os.Exit(1)
}

if err := (&controller.JoinTokenRequestReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ClientSet: clientSet,
RESTConfig: restConfig,
}).SetupWithManager(mgr, opts); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "JoinTokenRequest")
os.Exit(1)
}
}
Loading
Loading