Skip to content
Draft
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 @@ -75,15 +75,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 @@ -171,7 +171,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 @@ -265,11 +265,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: |
export TEST_NAME=Test$(echo "${{ matrix.e2e-suite }}" | awk -F'-' '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)}1' OFS='')
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
9 changes: 8 additions & 1 deletion .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 All @@ -25,6 +26,9 @@ __debug_bin*
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# VSCode
.vscode/

# Kubernetes Generated files - skip generated files, except for vendored files

!vendor/**/zz_generated.*
Expand All @@ -39,4 +43,7 @@ __debug_bin*
_artifacts

# E2E test templates
e2e/data/infrastructure-docker/**/cluster-template*.yaml
e2e/data/infrastructure-docker/**/cluster-template*.yaml

# Dev environment files
.tiltbuild/
122 changes: 76 additions & 46 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,50 @@ help: ## Display this help.
### CRD manifests (one per API group)
.PHONY: manifests-bootstrap manifests-controlplane manifests-infrastructure manifests-k0smotron
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 \
output:rbac:dir=config/clusterapi/bootstrap/rbac

manifests-controlplane: $(CONTROLLER_GEN) ## Generate CRDs for controlplane.cluster.x-k8s.io
$(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:crd:artifacts:config=config/clusterapi/controlplane/crd \
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 \
paths="./api/infrastructure/v1beta1/..." \
paths=./internal/controller/infrastructure/... \
output:crd:artifacts:config=config/clusterapi/infrastructure/crd \
output:rbac:dir=config/clusterapi/infrastructure/rbac

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/infrastructure
find ./config/crd/bases/infrastructure -type f ! -name "infrastructure*" ! -name "kustomization.yaml" -print0 | xargs -0 rm
paths="./api/k0smotron.io/v1beta1/..." \
paths=./internal/controller/k0smotron.io/... \
output:crd:artifacts:config=config/standalone/crd \
output:rbac:dir=config/standalone/rbac \
output:webhook:dir=config/standalone/webhook

manifests-k0smotron: $(CONTROLLER_GEN) ## Generate CRDs for k0smotron.io
manifests-capi-integration: $(CONTROLLER_GEN)
$(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/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:crd:artifacts:config=config/clusterapi/all/crd/bases \
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
Expand All @@ -99,7 +121,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 @@ -187,47 +209,55 @@ endif

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl create -f -
$(KUSTOMIZE) build config/clusterapi/all/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 -
$(KUSTOMIZE) build config/clusterapi/all/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: tilt-standalone-env
tilt-standalone-env:
$(MAKE) release-standalone IMG=k0smotron-controller-manager
tilt up $(if $(DEBUG),-- --debug)

.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.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default > install.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
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
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/standalone/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/standalone > install-standalone.yaml
git checkout config/standalone/manager/kustomization.yaml

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

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

infrastructure-components.yaml: $(CONTROLLER_GEN) clusterapi-manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
infrastructure-components.yaml: $(CONTROLLER_GEN) manifests-infrastructure kustomize
cd config/clusterapi/infrastructure/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/clusterapi/infrastructure/ > infrastructure-components.yaml
git checkout config/manager/kustomization.yaml
git checkout config/clusterapi/infrastructure/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 @@ -262,23 +292,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 --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 --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 --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 --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 Expand Up @@ -330,7 +360,7 @@ kind-deploy-capi:

.PHONY: kind-deploy-k0smotron
kind-deploy-k0smotron: release k0smotron-image-bundle.tar
kind load image-archive k0smotron-image-bundle.tar --name k0smotron
kind load image-archive k0smotron-image-bundle.tar
kubectl apply --server-side=true -f install.yaml
kubectl rollout restart -n k0smotron deployment/k0smotron-controller-manager

Expand Down
96 changes: 96 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# -*- mode: Python -*-

config.define_bool("debug")
cfg = config.parse()
debug = cfg.get('debug', False)

print("Debug mode is", debug)

# Deploy cert-manager if not already present.
# This is required for the k0smotron webhook to function correctly.
local('kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.18.2/cert-manager.yaml')
# wait for the service to become available
local('kubectl wait --for=condition=available deployment/cert-manager deployment/cert-manager-cainjector deployment/cert-manager-webhook -n cert-manager --timeout=300s')


# including 'all=N -l' in gcflags disables optimizations and inlining, making it easier to debug the code.
compile_cmd = 'CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -gcflags "all=-N -l" -o .tiltbuild/bin/manager cmd/main.go'

k0smotron_deployment_name = 'k0smotron-controller-manager'

local_resource(
"k0smotron_binary",
compile_cmd,
deps=[
'cmd',
'api/k0smotron.io',
'internal/controller/k0smotron.io',
'internal/controller/util',
'internal/exec',
'internal/util',
'go.mod',
'go.sum',
],
ignore=['**/*_test.go'])

dockerfile_contents = """
# Tilt image
FROM golang:1.24.6 as tilt-helper
# Install delve. Note this should be kept in step with the Go release minor version.
RUN go install github.com/go-delve/delve/cmd/[email protected]

FROM golang:1.24.6 as tilt
WORKDIR /
COPY --from=tilt-helper /go/bin/dlv .
COPY manager .
"""

# We build development image with delve installed and the binary compiled without optimizations and inlining.
# The controller image is only built once the '.tiltbuild/bin/manager' binary is built by the local_resource
# above.
docker_build(
ref = k0smotron_deployment_name,
context = ".tiltbuild/bin/",
dockerfile_contents = dockerfile_contents,
only = "manager")

standalone_install_path = './install-standalone.yaml'
dlv_command = ["/dlv", "exec", "./manager", "--headless", "--listen=:30000", "--api-version=2", "--accept-multiclient"]

# Modify the install-standalone.yaml to use the development image with delve and remove the securityContext
# that prevents the container from running as root, which is required for a good integration with Tilt.
objects = read_yaml_stream(standalone_install_path)
for o in objects:
if o['kind'] == 'Deployment' and o['metadata']['name'] == k0smotron_deployment_name:
# Use the development image with delve installed.
o['spec']['template']['spec']['securityContext'] = None

# If debug mode is enabled, wrap the controller manager command with dlv.
if debug:
# If container manager is 'manager', change its command to wrap with dlv.
for c in o['spec']['template']['spec']['containers']:
if c['name'] == 'manager':
if len(c['args']) > 0:
# Append the original args after a '--' to the dlv command.
dlv_command.append('--')
for arg in c['args']:
dlv_command.append(arg)
c['args'] = []

c['command'] = dlv_command

# Increase container memory limit to 512Mi.
if 'resources' not in c:
c['resources'] = {}
if 'limits' not in c['resources']:
c['resources']['limits'] = {}
c['resources']['limits']['memory'] = '512Mi'

# Remove liveness and readiness probes to avoid interfering with the debugger.
c['livenessProbe'] = None
c['readinessProbe'] = None

k8s_yaml(encode_yaml_stream(objects))

# workload name is the name of the k0smotron controller manager deployment.
k8s_resource(k0smotron_deployment_name, port_forwards='30000:30000', resource_deps=['k0smotron_binary'])
Loading