Skip to content

Commit 4ea9d3f

Browse files
authored
feat: create K3s baseline cluster template (#62)
1 parent 8e06265 commit 4ea9d3f

File tree

7 files changed

+132
-12
lines changed

7 files changed

+132
-12
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.2
1+
2.1.3-dev
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"name": "baseline-k3s",
3+
"version": "v0.0.1",
4+
"kubernetesVersion": "v1.32.4+k3s1",
5+
"description": "Baseline Cluster Template for k3s",
6+
"controlplaneprovidertype": "k3s",
7+
"infraprovidertype": "intel",
8+
"clusterconfiguration": {
9+
"kind": "KThreesControlPlaneTemplate",
10+
"apiVersion": "controlplane.cluster.x-k8s.io/v1beta1",
11+
"metadata": {
12+
"labels": {
13+
"cpumanager": "true"
14+
}
15+
},
16+
"spec": {
17+
"template": {
18+
"spec": {
19+
"files": [
20+
{
21+
"path": "/var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl",
22+
"content": "version = 2\n\n[plugins.\\\"io.containerd.internal.v1.opt\\\"]\n path = \\\"/var/lib/rancher/k3s/agent/containerd\\\"\n\n[plugins.\\\"io.containerd.grpc.v1.cri\\\"]\n stream_server_address = \\\"127.0.0.1\\\"\n stream_server_port = \\\"10010\\\"\n enable_selinux = false\n enable_unprivileged_ports = true\n enable_unprivileged_icmp = true\n sandbox_image = \\\"index.docker.io/rancher/mirrored-pause:3.6\\\"\n disable_apparmor = true\n\n[plugins.\\\"io.containerd.grpc.v1.cri\\\".containerd]\n snapshotter = \\\"overlayfs\\\"\n disable_snapshot_annotations = true\n\n[plugins.\\\"io.containerd.grpc.v1.cri\\\".containerd.runtimes.runc]\n runtime_type = \\\"io.containerd.runc.v2\\\"\n\n[plugins.\\\"io.containerd.grpc.v1.cri\\\".containerd.runtimes.runc.options]\n SystemdCgroup = true\n\n[plugins.\\\"io.containerd.grpc.v1.cri\\\".registry]\n config_path = \\\"/var/lib/rancher/k3s/agent/etc/containerd/certs.d\\\"\n\n[plugins.\\\"io.containerd.grpc.v1.cri\\\".containerd.runtimes.kata-qemu]\n runtime_type = \\\"io.containerd.kata-qemu.v2\\\"\n runtime_path = \\\"/opt/kata/bin/containerd-shim-kata-v2\\\"\n privileged_without_host_devices = true\n pod_annotations = [\\\"io.katacontainers.*\\\"]\n\n[plugins.\\\"io.containerd.grpc.v1.cri\\\".containerd.runtimes.kata-qemu.options]\n ConfigPath = \\\"/opt/kata/share/defaults/kata-containers/configuration-qemu.toml\\\""
23+
}
24+
],
25+
"agentConfig": {
26+
"kubelet": {
27+
"extraArgs": [
28+
"--topology-manager-policy=best-effort",
29+
"--cpu-manager-policy=static",
30+
"--reserved-cpus=1",
31+
"--max-pods=250",
32+
"--tls-cipher-suites=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"
33+
]
34+
}
35+
},
36+
"preK3sCommands": [
37+
"mkdir -p /etc/systemd/system/k3s-server.service.d",
38+
"echo '[Service]\nEnvironmentFile=/etc/environment' > /etc/systemd/system/k3s-server.service.d/override.conf",
39+
"make -p /var/lib/kubelet/static-pods",
40+
"sed -i '/kubelet-arg:/a\\- pod-manifest-path=/var/lib/kubelet/static-pods' /etc/rancher/k3s/config.yaml"
41+
],
42+
"postK3sCommands": [
43+
"kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.29.3/manifests/calico.yaml"
44+
],
45+
"privateRegistriesConfig": {},
46+
"serverConfig": {
47+
"cni": "calico",
48+
"cniMultusEnable": true,
49+
"disableComponents": {
50+
"kubernetesComponents": [
51+
"cloudController"
52+
]
53+
},
54+
"kubeApiServer": {
55+
"extraArgs": [
56+
"--feature-gates=PortForwardWebsockets=true",
57+
"--tls-cipher-suites=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"
58+
]
59+
},
60+
"kubeControllerManager": {
61+
"extraArgs": null
62+
},
63+
"kubeScheduler": {
64+
"extraArgs": null
65+
},
66+
"etcd": {
67+
"exposeMetrics": false,
68+
"backupConfig": {
69+
"retention": "5",
70+
"scheduleCron": "0 */5 * * *"
71+
},
72+
"customConfig": {
73+
"extraArgs": [
74+
"cipher-suites=[TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384]"
75+
]
76+
}
77+
}
78+
},
79+
"nodeDrainTimeout": "2m",
80+
"rolloutStrategy": {
81+
"type": "RollingUpdate",
82+
"rollingUpdate": {
83+
"maxSurge": 1
84+
}
85+
}
86+
}
87+
}
88+
}
89+
},
90+
"clusterNetwork": {
91+
"pods": {
92+
"cidrBlocks": [
93+
"10.45.0.0/16"
94+
]
95+
},
96+
"services": {
97+
"cidrBlocks": [
98+
"10.46.0.0/16"
99+
]
100+
}
101+
},
102+
"cluster-labels": {
103+
"default-extension": "baseline"
104+
}
105+
}

deployment/charts/cluster-manager/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ type: application
1616
# This is the chart version. This version number should be incremented each time you make changes
1717
# to the chart and its templates, including the app version.
1818
# Versions are expected to follow Semantic Versioning (https://semver.org/)
19-
version: 2.1.2
20-
appVersion: 2.1.2
19+
version: 2.1.3-dev
20+
appVersion: 2.1.3-dev
2121
annotations: {}

deployment/charts/cluster-template-crd/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ apiVersion: v2
66
name: cluster-template-crd
77
description: A Helm chart for the ClusterTemplate CRD
88
type: application
9-
version: 2.1.2
10-
appVersion: 2.1.2
9+
version: 2.1.3-dev
10+
appVersion: 2.1.3-dev
1111
annotations: {}

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ replace github.com/google/cel-go => github.com/google/cel-go v0.22.1
99

1010
require (
1111
github.com/cenkalti/backoff/v4 v4.3.0
12-
github.com/getkin/kin-openapi v0.128.0
12+
github.com/getkin/kin-openapi v0.131.0
1313
github.com/go-logr/logr v1.4.2
1414
github.com/golang-jwt/jwt/v5 v5.2.2
1515
github.com/google/go-cmp v0.7.0
@@ -40,6 +40,8 @@ require (
4040
require (
4141
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
4242
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 // indirect
43+
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 // indirect
44+
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect
4345
github.com/speakeasy-api/openapi-overlay v0.9.0 // indirect
4446
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
4547
)
@@ -115,9 +117,9 @@ require (
115117
github.com/hashicorp/hcl/v2 v2.23.0 // indirect
116118
github.com/hashicorp/vault/api v1.16.0 // indirect
117119
github.com/inconshreveable/mousetrap v1.1.0 // indirect
118-
github.com/invopop/yaml v0.3.1 // indirect
119120
github.com/josharian/intern v1.0.0 // indirect
120121
github.com/json-iterator/go v1.1.12 // indirect
122+
github.com/k3s-io/cluster-api-k3s v0.2.1
121123
github.com/klauspost/compress v1.18.0 // indirect
122124
github.com/labstack/echo-contrib v0.17.3 // indirect
123125
github.com/labstack/echo/v4 v4.13.3 // indirect

go.sum

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/
533533
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
534534
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
535535
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
536-
github.com/getkin/kin-openapi v0.128.0 h1:jqq3D9vC9pPq1dGcOCv7yOp1DaEe7c/T1vzcLbITSp4=
537-
github.com/getkin/kin-openapi v0.128.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM=
536+
github.com/getkin/kin-openapi v0.131.0 h1:NO2UeHnFKRYhZ8wg6Nyh5Cq7dHk4suQQr72a4pMrDxE=
537+
github.com/getkin/kin-openapi v0.131.0/go.mod h1:3OlG51PCYNsPByuiMB0t4fjnNlIDnaEDsjiKUV8nL58=
538538
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
539539
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
540540
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
@@ -730,8 +730,6 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
730730
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
731731
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
732732
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
733-
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
734-
github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA=
735733
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
736734
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
737735
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
@@ -747,6 +745,8 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm
747745
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
748746
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
749747
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
748+
github.com/k3s-io/cluster-api-k3s v0.2.1 h1:2Szv/27vCRxWFzOI+xyYvAHBhVhFPhIBReIQk6E3VPU=
749+
github.com/k3s-io/cluster-api-k3s v0.2.1/go.mod h1:ZdxgoSyAUwpMHbLHVOkaGBWM1+Uhd5xhQp4zDNGFllg=
750750
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
751751
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
752752
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
@@ -824,11 +824,16 @@ github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 h1:ykgG34472DWey7TSjd8vIfNykXgjOg
824824
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1/go.mod h1:N5+lY1tiTDV3V1BeHtOxeWXHoPVeApvsvjJqegfoaz8=
825825
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
826826
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
827+
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 h1:G7ERwszslrBzRxj//JalHPu/3yz+De2J+4aLtSRlHiY=
828+
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037/go.mod h1:2bpvgLBZEtENV5scfDFEtB/5+1M4hkQhDQrccEJ/qGw=
829+
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 h1:bQx3WeLcUWy+RletIKwUIt4x3t8n2SxavmoclizMb8c=
830+
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90/go.mod h1:y5+oSEHCPT/DGrS++Wc/479ERge0zTFxaF8PbGKcg2o=
827831
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
828832
github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
829833
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
830-
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
831834
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
835+
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
836+
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
832837
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
833838
github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU=
834839
github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk=

internal/webhook/v1alpha1/clustertemplate_webhook.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"sigs.k8s.io/controller-runtime/pkg/webhook"
1818
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
1919

20+
kthreescpv1beta2 "github.com/k3s-io/cluster-api-k3s/controlplane/api/v1beta2"
2021
"github.com/open-edge-platform/cluster-manager/v2/api/v1alpha1"
2122
clusterv1alpha1 "github.com/open-edge-platform/cluster-manager/v2/api/v1alpha1"
2223
"github.com/open-edge-platform/cluster-manager/v2/pkg/api"
@@ -66,6 +67,13 @@ func (v *ClusterTemplateCustomValidator) ValidateCreate(ctx context.Context, obj
6667
slog.Error("invalid RKE2ControlPlaneTemplate", "error", err)
6768
return nil, fmt.Errorf("failed to convert cluster configuration: %w", err)
6869
}
70+
case api.K3s:
71+
kthreesControlPlaneTemplate := &kthreescpv1beta2.KThreesControlPlaneTemplate{}
72+
err := json.Unmarshal([]byte(clustertemplate.Spec.ClusterConfiguration), &kthreesControlPlaneTemplate)
73+
if err != nil {
74+
slog.Error("invalid KThreesControlPlaneTemplate", "error", err)
75+
return nil, fmt.Errorf("failed to convert cluster configuration: %w", err)
76+
}
6977
default:
7078
return nil, fmt.Errorf("invalid control plane provider type: %s", clustertemplate.Spec.ControlPlaneProviderType)
7179
}

0 commit comments

Comments
 (0)