From 16cede322ff7e1f927dad0bb75035acb8447324f Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Fri, 9 Feb 2024 13:02:14 -0500 Subject: [PATCH 01/12] start adding flavors enable cluster topology feature gate for Tilt --- Tiltfile | 2 +- templates/cluster-template-clusterclass.yaml | 157 ++++++++++++++++++ templates/flavors/base/cluster-template.yaml | 94 +++++++++++ templates/flavors/base/kustomization.yaml | 5 + .../flavors/clusterclass/clusterclass.yaml | 41 +++++ .../clusterclass/kubeadm-config-template.yaml | 37 +++++ .../kubeadm-controlplane-template.yaml | 49 ++++++ .../clusterclass/linode-cluster-template.yaml | 8 + .../linode-machine-controlplane-template.yaml | 12 ++ .../linode-machine-worker-template.yaml | 12 ++ templates/flavors/default/kustomization.yaml | 4 + .../flavors/default/machine-deployment.yaml | 73 ++++++++ 12 files changed, 493 insertions(+), 1 deletion(-) create mode 100644 templates/cluster-template-clusterclass.yaml create mode 100644 templates/flavors/base/cluster-template.yaml create mode 100644 templates/flavors/base/kustomization.yaml create mode 100644 templates/flavors/clusterclass/clusterclass.yaml create mode 100644 templates/flavors/clusterclass/kubeadm-config-template.yaml create mode 100644 templates/flavors/clusterclass/kubeadm-controlplane-template.yaml create mode 100644 templates/flavors/clusterclass/linode-cluster-template.yaml create mode 100644 templates/flavors/clusterclass/linode-machine-controlplane-template.yaml create mode 100644 templates/flavors/clusterclass/linode-machine-worker-template.yaml create mode 100644 templates/flavors/default/kustomization.yaml create mode 100644 templates/flavors/default/machine-deployment.yaml diff --git a/Tiltfile b/Tiltfile index dd82106ed..7aeebb361 100644 --- a/Tiltfile +++ b/Tiltfile @@ -9,7 +9,7 @@ docker_build( local_resource( 'capi-controller-manager', - cmd='EXP_CLUSTER_RESOURCE_SET=true clusterctl init --addon helm', + cmd='EXP_CLUSTER_RESOURCE_SET=true CLUSTER_TOPOLOGY=true clusterctl init --addon helm', ) manager_yaml = decode_yaml_stream(kustomize("config/default")) diff --git a/templates/cluster-template-clusterclass.yaml b/templates/cluster-template-clusterclass.yaml new file mode 100644 index 000000000..a7a0b154f --- /dev/null +++ b/templates/cluster-template-clusterclass.yaml @@ -0,0 +1,157 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: ClusterClass +metadata: + name: ${CLUSTER_CLASS_NAME} +spec: + controlPlane: + ref: + apiVersion: controlplane.cluster.x-k8s.io/v1beta1 + kind: KubeadmControlPlaneTemplate + name: ${CLUSTER_NAME} + machineInfrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + name: ${CLUSTER_NAME}-control-plane + infrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeClusterTemplate + name: ${CLUSTER_NAME} + workers: + machineDeployments: + - class: ${CLUSTER_NAME}-worker + template: + bootstrap: + ref: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 + kind: KubeadmConfigTemplate + name: ${CLUSTER_NAME} + infrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + name: ${CLUSTER_NAME}-worker +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeClusterTemplate +metadata: + name: ${CLUSTER_NAME}-linode-cluster +spec: + template: + spec: + region: ${LINODE_REGION} +--- +kind: LinodeMachineTemplate +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +metadata: + name: ${CLUSTER_NAME}-control-plane +spec: + template: + spec: + image: ${LINODE_OS} + type: ${LINODE_CONTROL_PLANE_MACHINE_TYPE} + region: ${LINODE_REGION} + authorizedKeys: + - ${LINODE_SSH_KEY} +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeMachineTemplate +metadata: + name: ${CLUSTER_NAME}-worker +spec: + template: + spec: + image: ${LINODE_OS} + type: ${LINODE_MACHINE_TYPE} + region: ${LINODE_REGION} + authorizedKeys: + - ${LINODE_SSH_KEY} +--- +kind: KubeadmControlPlaneTemplate +apiVersion: controlplane.cluster.x-k8s.io/v1beta1 +metadata: + name: ${CLUSTER_NAME}-control-plane +spec: + template: + spec: + kubeadmConfigSpec: + files: + - path: /etc/containerd/config.toml + contentFrom: + secret: + name: common-init-files + key: containerd-config.toml + - path: /etc/modules-load.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: k8s-modules.conf + - path: /etc/sysctl.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: sysctl-k8s.conf + - path: /kubeadm-pre-init.sh + contentFrom: + secret: + name: common-init-files + key: kubeadm-pre-init.sh + permissions: "0500" + preKubeadmCommands: + - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + clusterConfiguration: + apiServer: + extraArgs: + cloud-provider: external + timeoutForControlPlane: 20m + initConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: external + provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + name: '{{ ds.meta_data.label }}' + joinConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: external + provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + name: '{{ ds.meta_data.label }}' +--- +apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 +kind: KubeadmConfigTemplate +metadata: + name: ${CLUSTER_NAME}-worker +spec: + template: + spec: + files: + - path: /etc/containerd/config.toml + contentFrom: + secret: + name: common-init-files + key: containerd-config.toml + - path: /etc/modules-load.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: k8s-modules.conf + - path: /etc/sysctl.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: sysctl-k8s.conf + - path: /kubeadm-pre-init.sh + contentFrom: + secret: + name: common-init-files + key: kubeadm-pre-init.sh + permissions: "0500" + preKubeadmCommands: + - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + joinConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: external + provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + name: '{{ ds.meta_data.label }}' diff --git a/templates/flavors/base/cluster-template.yaml b/templates/flavors/base/cluster-template.yaml new file mode 100644 index 000000000..64bd2d83c --- /dev/null +++ b/templates/flavors/base/cluster-template.yaml @@ -0,0 +1,94 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: ${CLUSTER_NAME} + labels: + cni: cilium +spec: + clusterNetwork: + pods: + cidrBlocks: + - 192.168.128.0/17 + controlPlaneRef: + apiVersion: controlplane.cluster.x-k8s.io/v1beta1 + kind: KubeadmControlPlane + name: ${CLUSTER_NAME}-control-plane + infrastructureRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeCluster + name: ${CLUSTER_NAME} +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeCluster +metadata: + name: ${CLUSTER_NAME} +spec: + region: ${LINODE_REGION} +--- +kind: KubeadmControlPlane +apiVersion: controlplane.cluster.x-k8s.io/v1beta1 +metadata: + name: ${CLUSTER_NAME}-control-plane +spec: + replicas: ${CONTROL_PLANE_MACHINE_COUNT} + machineTemplate: + infrastructureRef: + kind: LinodeMachineTemplate + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + name: ${CLUSTER_NAME}-control-plane + kubeadmConfigSpec: + files: + - path: /etc/containerd/config.toml + contentFrom: + secret: + name: common-init-files + key: containerd-config.toml + - path: /etc/modules-load.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: k8s-modules.conf + - path: /etc/sysctl.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: sysctl-k8s.conf + - path: /kubeadm-pre-init.sh + contentFrom: + secret: + name: common-init-files + key: kubeadm-pre-init.sh + permissions: "0500" + preKubeadmCommands: + - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + clusterConfiguration: + apiServer: + extraArgs: + cloud-provider: external + timeoutForControlPlane: 20m + initConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: external + provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + name: '{{ ds.meta_data.label }}' + joinConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: external + provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + name: '{{ ds.meta_data.label }}' + version: "${KUBERNETES_VERSION}" +--- +kind: LinodeMachineTemplate +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +metadata: + name: ${CLUSTER_NAME}-control-plane +spec: + template: + spec: + image: ${LINODE_OS} + type: ${LINODE_CONTROL_PLANE_MACHINE_TYPE} + region: ${LINODE_REGION} + authorizedKeys: + - ${LINODE_SSH_KEY} diff --git a/templates/flavors/base/kustomization.yaml b/templates/flavors/base/kustomization.yaml new file mode 100644 index 000000000..5e058e123 --- /dev/null +++ b/templates/flavors/base/kustomization.yaml @@ -0,0 +1,5 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: default +resources: + - cluster-template.yaml diff --git a/templates/flavors/clusterclass/clusterclass.yaml b/templates/flavors/clusterclass/clusterclass.yaml new file mode 100644 index 000000000..f624972f3 --- /dev/null +++ b/templates/flavors/clusterclass/clusterclass.yaml @@ -0,0 +1,41 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: ClusterClass +metadata: + name: ${CLUSTER_CLASS_NAME} +spec: + controlPlane: + ref: + apiVersion: controlplane.cluster.x-k8s.io/v1beta1 + kind: KubeadmControlPlaneTemplate + name: ${CLUSTER_NAME} + machineInfrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + name: ${CLUSTER_NAME}-control-plane + infrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeClusterTemplate + name: ${CLUSTER_NAME} + workers: + machineDeployments: + - class: ${CLUSTER_NAME}-worker + template: + bootstrap: + ref: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 + kind: KubeadmConfigTemplate + name: ${CLUSTER_NAME} + infrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + name: ${CLUSTER_NAME}-worker + patches: + - definitions: + - jsonPatches: + - op: add + path: /spec/template/spec/kubeadmConfigSpec/clusterConfiguration/controllerManager/extraArgs/cluster-name + valueFrom: + variable: builtin.cluster.name diff --git a/templates/flavors/clusterclass/kubeadm-config-template.yaml b/templates/flavors/clusterclass/kubeadm-config-template.yaml new file mode 100644 index 000000000..867a1ad66 --- /dev/null +++ b/templates/flavors/clusterclass/kubeadm-config-template.yaml @@ -0,0 +1,37 @@ +apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 +kind: KubeadmConfigTemplate +metadata: + name: ${CLUSTER_NAME}-worker +spec: + template: + spec: + files: + - path: /etc/containerd/config.toml + contentFrom: + secret: + name: common-init-files + key: containerd-config.toml + - path: /etc/modules-load.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: k8s-modules.conf + - path: /etc/sysctl.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: sysctl-k8s.conf + - path: /kubeadm-pre-init.sh + contentFrom: + secret: + name: common-init-files + key: kubeadm-pre-init.sh + permissions: "0500" + preKubeadmCommands: + - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + joinConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: external + provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + name: '{{ ds.meta_data.label }}' diff --git a/templates/flavors/clusterclass/kubeadm-controlplane-template.yaml b/templates/flavors/clusterclass/kubeadm-controlplane-template.yaml new file mode 100644 index 000000000..a095d03f2 --- /dev/null +++ b/templates/flavors/clusterclass/kubeadm-controlplane-template.yaml @@ -0,0 +1,49 @@ +kind: KubeadmControlPlaneTemplate +apiVersion: controlplane.cluster.x-k8s.io/v1beta1 +metadata: + name: ${CLUSTER_NAME}-control-plane +spec: + template: + spec: + kubeadmConfigSpec: + files: + - path: /etc/containerd/config.toml + contentFrom: + secret: + name: common-init-files + key: containerd-config.toml + - path: /etc/modules-load.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: k8s-modules.conf + - path: /etc/sysctl.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: sysctl-k8s.conf + - path: /kubeadm-pre-init.sh + contentFrom: + secret: + name: common-init-files + key: kubeadm-pre-init.sh + permissions: "0500" + preKubeadmCommands: + - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + clusterConfiguration: + apiServer: + extraArgs: + cloud-provider: external + timeoutForControlPlane: 20m + initConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: external + provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + name: '{{ ds.meta_data.label }}' + joinConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: external + provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + name: '{{ ds.meta_data.label }}' diff --git a/templates/flavors/clusterclass/linode-cluster-template.yaml b/templates/flavors/clusterclass/linode-cluster-template.yaml new file mode 100644 index 000000000..d3ddc4a66 --- /dev/null +++ b/templates/flavors/clusterclass/linode-cluster-template.yaml @@ -0,0 +1,8 @@ +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeClusterTemplate +metadata: + name: ${CLUSTER_NAME}-linode-cluster +spec: + template: + spec: + region: ${LINODE_REGION} diff --git a/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml b/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml new file mode 100644 index 000000000..3ea3543fc --- /dev/null +++ b/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml @@ -0,0 +1,12 @@ +kind: LinodeMachineTemplate +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +metadata: + name: ${CLUSTER_NAME}-control-plane +spec: + template: + spec: + image: ${LINODE_OS} + type: ${LINODE_CONTROL_PLANE_MACHINE_TYPE} + region: ${LINODE_REGION} + authorizedKeys: + - ${LINODE_SSH_KEY} diff --git a/templates/flavors/clusterclass/linode-machine-worker-template.yaml b/templates/flavors/clusterclass/linode-machine-worker-template.yaml new file mode 100644 index 000000000..7bd30862d --- /dev/null +++ b/templates/flavors/clusterclass/linode-machine-worker-template.yaml @@ -0,0 +1,12 @@ +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeMachineTemplate +metadata: + name: ${CLUSTER_NAME}-worker +spec: + template: + spec: + image: ${LINODE_OS} + type: ${LINODE_MACHINE_TYPE} + region: ${LINODE_REGION} + authorizedKeys: + - ${LINODE_SSH_KEY} diff --git a/templates/flavors/default/kustomization.yaml b/templates/flavors/default/kustomization.yaml new file mode 100644 index 000000000..64f1b8bc5 --- /dev/null +++ b/templates/flavors/default/kustomization.yaml @@ -0,0 +1,4 @@ +namespace: default +resources: + - ../base + - machine-deployment.yaml diff --git a/templates/flavors/default/machine-deployment.yaml b/templates/flavors/default/machine-deployment.yaml new file mode 100644 index 000000000..cda7f50be --- /dev/null +++ b/templates/flavors/default/machine-deployment.yaml @@ -0,0 +1,73 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: MachineDeployment +metadata: + name: ${CLUSTER_NAME}-md-0 +spec: + clusterName: ${CLUSTER_NAME} + replicas: ${WORKER_MACHINE_COUNT} + selector: + matchLabels: + template: + spec: + clusterName: ${CLUSTER_NAME} + version: "${KUBERNETES_VERSION}" + bootstrap: + configRef: + name: ${CLUSTER_NAME}-md-0 + apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 + kind: KubeadmConfigTemplate + infrastructureRef: + name: ${CLUSTER_NAME}-md-0 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeMachineTemplate +metadata: + name: ${CLUSTER_NAME}-md-0 +spec: + template: + spec: + image: ${LINODE_OS} + type: ${LINODE_MACHINE_TYPE} + region: ${LINODE_REGION} + authorizedKeys: + - ${LINODE_SSH_KEY} +--- +apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 +kind: KubeadmConfigTemplate +metadata: + name: ${CLUSTER_NAME}-md-0 +spec: + template: + spec: + files: + - path: /etc/containerd/config.toml + contentFrom: + secret: + name: common-init-files + key: containerd-config.toml + - path: /etc/modules-load.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: k8s-modules.conf + - path: /etc/sysctl.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: sysctl-k8s.conf + - path: /kubeadm-pre-init.sh + contentFrom: + secret: + name: common-init-files + key: kubeadm-pre-init.sh + permissions: "0500" + preKubeadmCommands: + - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + joinConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: external + provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + name: '{{ ds.meta_data.label }}' From d5087ccd61b257352687b81dbf3d93d0d132ca01 Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Fri, 9 Feb 2024 16:18:20 -0500 Subject: [PATCH 02/12] need common init files --- .../common-init-files/kustomization.yaml | 3 ++ templates/common-init-files/secret.yaml | 38 +++++++++++++++++++ .../flavors/clusterclass/kustomization.yaml | 9 +++++ templates/flavors/default/kustomization.yaml | 1 + 4 files changed, 51 insertions(+) create mode 100644 templates/common-init-files/kustomization.yaml create mode 100644 templates/common-init-files/secret.yaml create mode 100644 templates/flavors/clusterclass/kustomization.yaml diff --git a/templates/common-init-files/kustomization.yaml b/templates/common-init-files/kustomization.yaml new file mode 100644 index 000000000..82ec21000 --- /dev/null +++ b/templates/common-init-files/kustomization.yaml @@ -0,0 +1,3 @@ +namespace: default +resources: + - secret.yaml diff --git a/templates/common-init-files/secret.yaml b/templates/common-init-files/secret.yaml new file mode 100644 index 000000000..879f13471 --- /dev/null +++ b/templates/common-init-files/secret.yaml @@ -0,0 +1,38 @@ +apiVersion: v1 +kind: Secret +metadata: + name: common-init-files +stringData: + containerd-config.toml: | + version = 2 + imports = ["/etc/containerd/conf.d/*.toml"] + [plugins] + [plugins."io.containerd.grpc.v1.cri"] + sandbox_image = "registry.k8s.io/pause:3.9" + [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc] + runtime_type = "io.containerd.runc.v2" + [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options] + SystemdCgroup = true + k8s-modules.conf: | + overlay + br_netfilter + sysctl-k8s.conf: | + net.bridge.bridge-nf-call-iptables = 1 + net.bridge.bridge-nf-call-ip6tables = 1 + net.ipv4.ip_forward = 1 + kubeadm-pre-init.sh: | + #!/bin/bash + export DEBIAN_FRONTEND=noninteractive + hostnamectl set-hostname "$1" && hostname -F /etc/hostname + mkdir -p -m 755 /etc/apt/keyrings + VERSION=${2%.*} + curl -fsSL "https://pkgs.k8s.io/core:/stable:/v$VERSION/deb/Release.key" | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg + echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v$VERSION/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list + apt-get update -y + apt-get install -y kubelet=$2* kubeadm=$2* kubectl=$2* containerd + apt-mark hold kubelet kubeadm kubectl containerd + modprobe overlay + modprobe br_netfilter + sysctl --system + sed -i '/swap/d' /etc/fstab + swapoff -a diff --git a/templates/flavors/clusterclass/kustomization.yaml b/templates/flavors/clusterclass/kustomization.yaml new file mode 100644 index 000000000..071ba9ed5 --- /dev/null +++ b/templates/flavors/clusterclass/kustomization.yaml @@ -0,0 +1,9 @@ +namespace: default +resources: + - clusterclass.yaml + - linode-cluster-template.yaml + - linode-machine-controlplane-template.yaml + - linode-machine-worker-template.yaml + - kubeadm-controlplane-template.yaml + - kubeadm-config-template.yaml + - ../../common-init-files diff --git a/templates/flavors/default/kustomization.yaml b/templates/flavors/default/kustomization.yaml index 64f1b8bc5..19473ad29 100644 --- a/templates/flavors/default/kustomization.yaml +++ b/templates/flavors/default/kustomization.yaml @@ -2,3 +2,4 @@ namespace: default resources: - ../base - machine-deployment.yaml + - ../../common-init-files From 73fe0d002a1d1423b647a68681011fda1eac642f Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Tue, 20 Feb 2024 16:25:22 -0500 Subject: [PATCH 03/12] updates for cluster class support --- .gitignore | 2 + Makefile | 4 + hack/generate-flavors.sh | 13 + templates/addons/cilium/cilium.yaml | 21 ++ templates/addons/cilium/kustomization.yaml | 4 + .../cluster-resource-set/kustomization.yaml | 5 + .../addons/cluster-resource-set/secret.yaml | 29 ++ .../kustomization.yaml | 4 + .../linode-bs-csi.yaml} | 0 .../addons/provider-linode/kustomization.yaml | 4 + .../addons/provider-linode/linode-ccm.yaml | 21 ++ templates/cluster-template-clusterclass.yaml | 157 ---------- templates/cluster-template.yaml | 288 ------------------ templates/common-init-files/secret.yaml | 8 +- templates/flavors/base/cluster-template.yaml | 17 +- templates/flavors/base/kustomization.yaml | 1 - templates/flavors/clusterclass/cluster.yaml | 15 + .../flavors/clusterclass/clusterclass.yaml | 18 +- .../clusterclass/kubeadm-config-template.yaml | 6 +- .../kubeadm-controlplane-template.yaml | 10 +- .../flavors/clusterclass/kustomization.yaml | 4 +- .../clusterclass/linode-cluster-template.yaml | 2 +- .../linode-machine-controlplane-template.yaml | 6 +- .../linode-machine-worker-template.yaml | 5 +- templates/flavors/default/kustomization.yaml | 4 +- .../flavors/default/machine-deployment.yaml | 5 +- 26 files changed, 175 insertions(+), 478 deletions(-) create mode 100755 hack/generate-flavors.sh create mode 100644 templates/addons/cilium/cilium.yaml create mode 100644 templates/addons/cilium/kustomization.yaml create mode 100644 templates/addons/cluster-resource-set/kustomization.yaml create mode 100644 templates/addons/cluster-resource-set/secret.yaml create mode 100644 templates/addons/linode-blockstorage-csi-driver/kustomization.yaml rename templates/addons/{linode-blockstorage-csi-driver-helm.yaml => linode-blockstorage-csi-driver/linode-bs-csi.yaml} (100%) create mode 100644 templates/addons/provider-linode/kustomization.yaml create mode 100644 templates/addons/provider-linode/linode-ccm.yaml delete mode 100644 templates/cluster-template-clusterclass.yaml delete mode 100644 templates/cluster-template.yaml create mode 100644 templates/flavors/clusterclass/cluster.yaml diff --git a/.gitignore b/.gitignore index 37ee674bd..dbd2a29c3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ kubeconfig* .devbox/* docs/book release/* +templates/cluster-template*.yaml +infrastructure-linode/* diff --git a/Makefile b/Makefile index fbbd06fda..4a124dfb8 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,10 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." +.PHONY: generate-flavors ## Generate template flavors. +generate-flavors: $(KUSTOMIZE) + ./hack/generate-flavors.sh + ## -------------------------------------- ## Development ## -------------------------------------- diff --git a/hack/generate-flavors.sh b/hack/generate-flavors.sh new file mode 100755 index 000000000..dfbc726a4 --- /dev/null +++ b/hack/generate-flavors.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -euo pipefail + +REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. +FLAVORS_DIR="${REPO_ROOT}/templates/flavors" + +for name in $(find "${FLAVORS_DIR}/"* -maxdepth 0 -type d -print0 | xargs -0 -I {} basename {} | grep -v base); do + kustomize build "${FLAVORS_DIR}/${name}" > "${REPO_ROOT}/templates/cluster-template-${name}.yaml" +done + +# move the default template to the default file expected by clusterctl +mv "${REPO_ROOT}/templates/cluster-template-default.yaml" "${REPO_ROOT}/templates/cluster-template.yaml" diff --git a/templates/addons/cilium/cilium.yaml b/templates/addons/cilium/cilium.yaml new file mode 100644 index 000000000..338ab35d6 --- /dev/null +++ b/templates/addons/cilium/cilium.yaml @@ -0,0 +1,21 @@ +apiVersion: addons.cluster.x-k8s.io/v1alpha1 +kind: HelmChartProxy +metadata: + name: cilium +spec: + clusterSelector: + matchLabels: + cni: cilium + repoURL: https://helm.cilium.io/ + chartName: cilium + version: ${CILIUM_VERSION:=1.15.0} + options: + waitForJobs: true + wait: true + timeout: 5m + valuesTemplate: | + hubble: + relay: + enabled: true + ui: + enabled: true diff --git a/templates/addons/cilium/kustomization.yaml b/templates/addons/cilium/kustomization.yaml new file mode 100644 index 000000000..07edafad1 --- /dev/null +++ b/templates/addons/cilium/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - cilium.yaml diff --git a/templates/addons/cluster-resource-set/kustomization.yaml b/templates/addons/cluster-resource-set/kustomization.yaml new file mode 100644 index 000000000..97a816adb --- /dev/null +++ b/templates/addons/cluster-resource-set/kustomization.yaml @@ -0,0 +1,5 @@ + +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - secret.yaml diff --git a/templates/addons/cluster-resource-set/secret.yaml b/templates/addons/cluster-resource-set/secret.yaml new file mode 100644 index 000000000..554fc1ea9 --- /dev/null +++ b/templates/addons/cluster-resource-set/secret.yaml @@ -0,0 +1,29 @@ +apiVersion: v1 +kind: Secret +type: addons.cluster.x-k8s.io/resource-set +metadata: + name: linode-${CLUSTER_NAME}-crs-0 +stringData: + linode-token-region.yaml: |- + kind: Secret + apiVersion: v1 + metadata: + name: linode-token-region + namespace: kube-system + stringData: + apiToken: ${LINODE_TOKEN} + region: ${LINODE_REGION} +--- +apiVersion: addons.cluster.x-k8s.io/v1beta1 +kind: ClusterResourceSet +metadata: + name: ${CLUSTER_NAME}-crs-0 +spec: + clusterSelector: + matchLabels: + crs: ${CLUSTER_NAME}-crs + resources: + - kind: Secret + name: linode-${CLUSTER_NAME}-crs-0 + strategy: ApplyOnce +--- diff --git a/templates/addons/linode-blockstorage-csi-driver/kustomization.yaml b/templates/addons/linode-blockstorage-csi-driver/kustomization.yaml new file mode 100644 index 000000000..02d14e4ac --- /dev/null +++ b/templates/addons/linode-blockstorage-csi-driver/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - linode-bs-csi.yaml diff --git a/templates/addons/linode-blockstorage-csi-driver-helm.yaml b/templates/addons/linode-blockstorage-csi-driver/linode-bs-csi.yaml similarity index 100% rename from templates/addons/linode-blockstorage-csi-driver-helm.yaml rename to templates/addons/linode-blockstorage-csi-driver/linode-bs-csi.yaml diff --git a/templates/addons/provider-linode/kustomization.yaml b/templates/addons/provider-linode/kustomization.yaml new file mode 100644 index 000000000..8adc23586 --- /dev/null +++ b/templates/addons/provider-linode/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - linode-ccm.yaml diff --git a/templates/addons/provider-linode/linode-ccm.yaml b/templates/addons/provider-linode/linode-ccm.yaml new file mode 100644 index 000000000..dd2839fa4 --- /dev/null +++ b/templates/addons/provider-linode/linode-ccm.yaml @@ -0,0 +1,21 @@ +apiVersion: addons.cluster.x-k8s.io/v1alpha1 +kind: HelmChartProxy +metadata: + name: linode-cloud-controller-manager +spec: + clusterSelector: + matchLabels: + ccm: linode + repoURL: https://linode.github.io/linode-cloud-controller-manager/ + chartName: ccm-linode + namespace: kube-system + version: ${LINODE_CCM_VERSION:=v0.3.24} + options: + waitForJobs: true + wait: true + timeout: 5m + valuesTemplate: | + secretRef: + name: "linode-token-region" + image: + pullPolicy: IfNotPresent diff --git a/templates/cluster-template-clusterclass.yaml b/templates/cluster-template-clusterclass.yaml deleted file mode 100644 index a7a0b154f..000000000 --- a/templates/cluster-template-clusterclass.yaml +++ /dev/null @@ -1,157 +0,0 @@ -apiVersion: cluster.x-k8s.io/v1beta1 -kind: ClusterClass -metadata: - name: ${CLUSTER_CLASS_NAME} -spec: - controlPlane: - ref: - apiVersion: controlplane.cluster.x-k8s.io/v1beta1 - kind: KubeadmControlPlaneTemplate - name: ${CLUSTER_NAME} - machineInfrastructure: - ref: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeMachineTemplate - name: ${CLUSTER_NAME}-control-plane - infrastructure: - ref: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeClusterTemplate - name: ${CLUSTER_NAME} - workers: - machineDeployments: - - class: ${CLUSTER_NAME}-worker - template: - bootstrap: - ref: - apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 - kind: KubeadmConfigTemplate - name: ${CLUSTER_NAME} - infrastructure: - ref: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeMachineTemplate - name: ${CLUSTER_NAME}-worker ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeClusterTemplate -metadata: - name: ${CLUSTER_NAME}-linode-cluster -spec: - template: - spec: - region: ${LINODE_REGION} ---- -kind: LinodeMachineTemplate -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -metadata: - name: ${CLUSTER_NAME}-control-plane -spec: - template: - spec: - image: ${LINODE_OS} - type: ${LINODE_CONTROL_PLANE_MACHINE_TYPE} - region: ${LINODE_REGION} - authorizedKeys: - - ${LINODE_SSH_KEY} ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeMachineTemplate -metadata: - name: ${CLUSTER_NAME}-worker -spec: - template: - spec: - image: ${LINODE_OS} - type: ${LINODE_MACHINE_TYPE} - region: ${LINODE_REGION} - authorizedKeys: - - ${LINODE_SSH_KEY} ---- -kind: KubeadmControlPlaneTemplate -apiVersion: controlplane.cluster.x-k8s.io/v1beta1 -metadata: - name: ${CLUSTER_NAME}-control-plane -spec: - template: - spec: - kubeadmConfigSpec: - files: - - path: /etc/containerd/config.toml - contentFrom: - secret: - name: common-init-files - key: containerd-config.toml - - path: /etc/modules-load.d/k8s.conf - contentFrom: - secret: - name: common-init-files - key: k8s-modules.conf - - path: /etc/sysctl.d/k8s.conf - contentFrom: - secret: - name: common-init-files - key: sysctl-k8s.conf - - path: /kubeadm-pre-init.sh - contentFrom: - secret: - name: common-init-files - key: kubeadm-pre-init.sh - permissions: "0500" - preKubeadmCommands: - - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" - clusterConfiguration: - apiServer: - extraArgs: - cloud-provider: external - timeoutForControlPlane: 20m - initConfiguration: - nodeRegistration: - kubeletExtraArgs: - cloud-provider: external - provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' - name: '{{ ds.meta_data.label }}' - joinConfiguration: - nodeRegistration: - kubeletExtraArgs: - cloud-provider: external - provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' - name: '{{ ds.meta_data.label }}' ---- -apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 -kind: KubeadmConfigTemplate -metadata: - name: ${CLUSTER_NAME}-worker -spec: - template: - spec: - files: - - path: /etc/containerd/config.toml - contentFrom: - secret: - name: common-init-files - key: containerd-config.toml - - path: /etc/modules-load.d/k8s.conf - contentFrom: - secret: - name: common-init-files - key: k8s-modules.conf - - path: /etc/sysctl.d/k8s.conf - contentFrom: - secret: - name: common-init-files - key: sysctl-k8s.conf - - path: /kubeadm-pre-init.sh - contentFrom: - secret: - name: common-init-files - key: kubeadm-pre-init.sh - permissions: "0500" - preKubeadmCommands: - - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" - joinConfiguration: - nodeRegistration: - kubeletExtraArgs: - cloud-provider: external - provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' - name: '{{ ds.meta_data.label }}' diff --git a/templates/cluster-template.yaml b/templates/cluster-template.yaml deleted file mode 100644 index 706bffb92..000000000 --- a/templates/cluster-template.yaml +++ /dev/null @@ -1,288 +0,0 @@ -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Cluster -metadata: - name: ${CLUSTER_NAME} - labels: - cni: cilium - ccm: linode - crs: ${CLUSTER_NAME}-crs -spec: - clusterNetwork: - pods: - cidrBlocks: - - 192.168.128.0/17 - controlPlaneRef: - apiVersion: controlplane.cluster.x-k8s.io/v1beta1 - kind: KubeadmControlPlane - name: ${CLUSTER_NAME}-control-plane - infrastructureRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeCluster - name: ${CLUSTER_NAME} ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeCluster -metadata: - name: ${CLUSTER_NAME} -spec: - region: ${LINODE_REGION} ---- -kind: KubeadmControlPlane -apiVersion: controlplane.cluster.x-k8s.io/v1beta1 -metadata: - name: ${CLUSTER_NAME}-control-plane -spec: - replicas: ${CONTROL_PLANE_MACHINE_COUNT} - machineTemplate: - infrastructureRef: - kind: LinodeMachineTemplate - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - name: ${CLUSTER_NAME}-control-plane - kubeadmConfigSpec: - files: - - path: /etc/containerd/config.toml - contentFrom: - secret: - name: common-init-files - key: containerd-config.toml - - path: /etc/modules-load.d/k8s.conf - contentFrom: - secret: - name: common-init-files - key: k8s-modules.conf - - path: /etc/sysctl.d/k8s.conf - contentFrom: - secret: - name: common-init-files - key: sysctl-k8s.conf - - path: /kubeadm-pre-init.sh - contentFrom: - secret: - name: common-init-files - key: kubeadm-pre-init.sh - permissions: "0500" - preKubeadmCommands: - - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' ${KUBERNETES_VERSION} - clusterConfiguration: - apiServer: - extraArgs: - cloud-provider: external - controllerManager: - extraArgs: - cloud-provider: external - initConfiguration: - nodeRegistration: - kubeletExtraArgs: - cloud-provider: external - provider-id: 'linode://{{ ds.meta_data.id }}' - name: '{{ ds.meta_data.label }}' - joinConfiguration: - nodeRegistration: - kubeletExtraArgs: - cloud-provider: external - provider-id: 'linode://{{ ds.meta_data.id }}' - name: '{{ ds.meta_data.label }}' - version: "${KUBERNETES_VERSION}" ---- -kind: LinodeMachineTemplate -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -metadata: - name: ${CLUSTER_NAME}-control-plane -spec: - template: - spec: - image: ${LINODE_OS:="linode/ubuntu22.04"} - type: ${LINODE_CONTROL_PLANE_MACHINE_TYPE} - region: ${LINODE_REGION} - authorizedKeys: - # uncomment to include your ssh key in linode provisioning - # - ${LINODE_SSH_PUBKEY:=""} ---- -apiVersion: cluster.x-k8s.io/v1beta1 -kind: MachineDeployment -metadata: - name: ${CLUSTER_NAME}-md-0 -spec: - clusterName: ${CLUSTER_NAME} - replicas: ${WORKER_MACHINE_COUNT} - selector: - matchLabels: - template: - spec: - clusterName: ${CLUSTER_NAME} - version: "${KUBERNETES_VERSION}" - bootstrap: - configRef: - name: ${CLUSTER_NAME}-md-0 - apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 - kind: KubeadmConfigTemplate - infrastructureRef: - name: ${CLUSTER_NAME}-md-0 - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeMachineTemplate ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeMachineTemplate -metadata: - name: ${CLUSTER_NAME}-md-0 -spec: - template: - spec: - image: ${LINODE_OS:="linode/ubuntu22.04"} - type: ${LINODE_MACHINE_TYPE} - region: ${LINODE_REGION} - authorizedKeys: - # uncomment to include your ssh key in linode provisioning - # - ${LINODE_SSH_PUBKEY:=""} ---- -apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 -kind: KubeadmConfigTemplate -metadata: - name: ${CLUSTER_NAME}-md-0 -spec: - template: - spec: - files: - - path: /etc/containerd/config.toml - contentFrom: - secret: - name: common-init-files - key: containerd-config.toml - - path: /etc/modules-load.d/k8s.conf - contentFrom: - secret: - name: common-init-files - key: k8s-modules.conf - - path: /etc/sysctl.d/k8s.conf - contentFrom: - secret: - name: common-init-files - key: sysctl-k8s.conf - - path: /kubeadm-pre-init.sh - contentFrom: - secret: - name: common-init-files - key: kubeadm-pre-init.sh - permissions: "0500" - preKubeadmCommands: - - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' ${KUBERNETES_VERSION} - joinConfiguration: - nodeRegistration: - kubeletExtraArgs: - cloud-provider: external - provider-id: 'linode://{{ ds.meta_data.id }}' - name: '{{ ds.meta_data.label }}' ---- -apiVersion: v1 -kind: Secret -metadata: - name: common-init-files -stringData: - containerd-config.toml: | - version = 2 - imports = ["/etc/containerd/conf.d/*.toml"] - [plugins] - [plugins."io.containerd.grpc.v1.cri"] - sandbox_image = "registry.k8s.io/pause:3.9" - [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc] - runtime_type = "io.containerd.runc.v2" - [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options] - SystemdCgroup = true - k8s-modules.conf: | - overlay - br_netfilter - sysctl-k8s.conf: | - net.bridge.bridge-nf-call-iptables = 1 - net.bridge.bridge-nf-call-ip6tables = 1 - net.ipv4.ip_forward = 1 - kubeadm-pre-init.sh: | - #!/bin/bash - set -euo pipefail - export DEBIAN_FRONTEND=noninteractive - hostnamectl set-hostname "$1" && hostname -F /etc/hostname - mkdir -p -m 755 /etc/apt/keyrings - PATCH_VERSION=$${2#[v]} - VERSION=$${PATCH_VERSION%.*} - curl -fsSL "https://pkgs.k8s.io/core:/stable:/v$VERSION/deb/Release.key" | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg - echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v$VERSION/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list - apt-get update -y - apt-get install -y kubelet=$PATCH_VERSION* kubeadm=$PATCH_VERSION* kubectl=$PATCH_VERSION* containerd - apt-mark hold kubelet kubeadm kubectl containerd - modprobe overlay - modprobe br_netfilter - sysctl --system - sed -i '/swap/d' /etc/fstab - swapoff -a ---- -apiVersion: v1 -kind: Secret -type: addons.cluster.x-k8s.io/resource-set -metadata: - name: linode-${CLUSTER_NAME}-crs-0 -stringData: - linode-token-region.yaml: |- - kind: Secret - apiVersion: v1 - metadata: - name: linode-token-region - namespace: kube-system - stringData: - apiToken: ${LINODE_TOKEN} - region: ${LINODE_REGION} ---- -apiVersion: addons.cluster.x-k8s.io/v1beta1 -kind: ClusterResourceSet -metadata: - name: ${CLUSTER_NAME}-crs-0 -spec: - clusterSelector: - matchLabels: - crs: ${CLUSTER_NAME}-crs - resources: - - kind: Secret - name: linode-${CLUSTER_NAME}-crs-0 - strategy: ApplyOnce ---- -apiVersion: addons.cluster.x-k8s.io/v1alpha1 -kind: HelmChartProxy -metadata: - name: cilium -spec: - clusterSelector: - matchLabels: - cni: cilium - repoURL: https://helm.cilium.io/ - chartName: cilium - version: 1.15.0 - options: - waitForJobs: true - wait: true - timeout: 5m - valuesTemplate: | - hubble: - relay: - enabled: true - ui: - enabled: true ---- -apiVersion: addons.cluster.x-k8s.io/v1alpha1 -kind: HelmChartProxy -metadata: - name: linode-cloud-controller-manager -spec: - clusterSelector: - matchLabels: - ccm: linode - repoURL: https://linode.github.io/linode-cloud-controller-manager/ - chartName: ccm-linode - namespace: kube-system - version: v0.3.24 - options: - waitForJobs: true - wait: true - timeout: 5m - valuesTemplate: | - secretRef: - name: "linode-token-region" - image: - pullPolicy: IfNotPresent diff --git a/templates/common-init-files/secret.yaml b/templates/common-init-files/secret.yaml index 879f13471..860f3a9ec 100644 --- a/templates/common-init-files/secret.yaml +++ b/templates/common-init-files/secret.yaml @@ -22,17 +22,19 @@ stringData: net.ipv4.ip_forward = 1 kubeadm-pre-init.sh: | #!/bin/bash + set -euo pipefail export DEBIAN_FRONTEND=noninteractive hostnamectl set-hostname "$1" && hostname -F /etc/hostname mkdir -p -m 755 /etc/apt/keyrings - VERSION=${2%.*} + PATCH_VERSION=$${2#[v]} + VERSION=$${PATCH_VERSION%.*} curl -fsSL "https://pkgs.k8s.io/core:/stable:/v$VERSION/deb/Release.key" | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v$VERSION/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list apt-get update -y - apt-get install -y kubelet=$2* kubeadm=$2* kubectl=$2* containerd + apt-get install -y kubelet=$PATCH_VERSION* kubeadm=$PATCH_VERSION* kubectl=$PATCH_VERSION* containerd apt-mark hold kubelet kubeadm kubectl containerd modprobe overlay modprobe br_netfilter sysctl --system sed -i '/swap/d' /etc/fstab - swapoff -a + swapoff -a \ No newline at end of file diff --git a/templates/flavors/base/cluster-template.yaml b/templates/flavors/base/cluster-template.yaml index 64bd2d83c..0c9fa6a14 100644 --- a/templates/flavors/base/cluster-template.yaml +++ b/templates/flavors/base/cluster-template.yaml @@ -4,11 +4,13 @@ metadata: name: ${CLUSTER_NAME} labels: cni: cilium + ccm: linode + crs: ${CLUSTER_NAME}-crs spec: clusterNetwork: pods: cidrBlocks: - - 192.168.128.0/17 + - 192.168.128.0/17 controlPlaneRef: apiVersion: controlplane.cluster.x-k8s.io/v1beta1 kind: KubeadmControlPlane @@ -65,18 +67,20 @@ spec: apiServer: extraArgs: cloud-provider: external - timeoutForControlPlane: 20m + controllerManager: + extraArgs: + cloud-provider: external initConfiguration: nodeRegistration: kubeletExtraArgs: cloud-provider: external - provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + provider-id: 'linode://{{ ds.meta_data.id }}' name: '{{ ds.meta_data.label }}' joinConfiguration: nodeRegistration: kubeletExtraArgs: cloud-provider: external - provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + provider-id: 'linode://{{ ds.meta_data.id }}' name: '{{ ds.meta_data.label }}' version: "${KUBERNETES_VERSION}" --- @@ -87,8 +91,9 @@ metadata: spec: template: spec: - image: ${LINODE_OS} + image: ${LINODE_OS:="linode/ubuntu22.04"} type: ${LINODE_CONTROL_PLANE_MACHINE_TYPE} region: ${LINODE_REGION} authorizedKeys: - - ${LINODE_SSH_KEY} + # uncomment to include your ssh key in linode provisioning + # - ${LINODE_SSH_PUBKEY:=""} diff --git a/templates/flavors/base/kustomization.yaml b/templates/flavors/base/kustomization.yaml index 5e058e123..d5709d2ab 100644 --- a/templates/flavors/base/kustomization.yaml +++ b/templates/flavors/base/kustomization.yaml @@ -1,5 +1,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization -namespace: default resources: - cluster-template.yaml diff --git a/templates/flavors/clusterclass/cluster.yaml b/templates/flavors/clusterclass/cluster.yaml new file mode 100644 index 000000000..3646361ea --- /dev/null +++ b/templates/flavors/clusterclass/cluster.yaml @@ -0,0 +1,15 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: ${CLUSTER_NAME} +spec: + topology: + class: ${CLUSTER_CLASS_NAME} + version: ${KUBERNETES_VERSION} + controlPlane: + replicas: ${CONTROL_PLANE_MACHINE_COUNT} + workers: + machineDeployments: + - class: default-worker + name: md-0 + replicas: ${WORKER_MACHINE_COUNT} diff --git a/templates/flavors/clusterclass/clusterclass.yaml b/templates/flavors/clusterclass/clusterclass.yaml index f624972f3..90cc1d18f 100644 --- a/templates/flavors/clusterclass/clusterclass.yaml +++ b/templates/flavors/clusterclass/clusterclass.yaml @@ -7,31 +7,31 @@ spec: ref: apiVersion: controlplane.cluster.x-k8s.io/v1beta1 kind: KubeadmControlPlaneTemplate - name: ${CLUSTER_NAME} + name: ${CLUSTER_CLASS_NAME}-control-plane machineInfrastructure: ref: apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeMachineTemplate - name: ${CLUSTER_NAME}-control-plane + name: ${CLUSTER_CLASS_NAME}-control-plane infrastructure: ref: apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeClusterTemplate - name: ${CLUSTER_NAME} + name: ${CLUSTER_CLASS_NAME} workers: machineDeployments: - - class: ${CLUSTER_NAME}-worker + - class: default-worker template: bootstrap: ref: apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 kind: KubeadmConfigTemplate - name: ${CLUSTER_NAME} + name: ${CLUSTER_CLASS_NAME}-worker infrastructure: ref: apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeMachineTemplate - name: ${CLUSTER_NAME}-worker + name: ${CLUSTER_CLASS_NAME}-worker patches: - definitions: - jsonPatches: @@ -39,3 +39,9 @@ spec: path: /spec/template/spec/kubeadmConfigSpec/clusterConfiguration/controllerManager/extraArgs/cluster-name valueFrom: variable: builtin.cluster.name + selector: + apiVersion: controlplane.cluster.x-k8s.io/v1beta1 + kind: KubeadmControlPlaneTemplate + matchResources: + controlPlane: true + name: controlPlane diff --git a/templates/flavors/clusterclass/kubeadm-config-template.yaml b/templates/flavors/clusterclass/kubeadm-config-template.yaml index 867a1ad66..15383acb6 100644 --- a/templates/flavors/clusterclass/kubeadm-config-template.yaml +++ b/templates/flavors/clusterclass/kubeadm-config-template.yaml @@ -1,7 +1,7 @@ apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 kind: KubeadmConfigTemplate metadata: - name: ${CLUSTER_NAME}-worker + name: ${CLUSTER_CLASS_NAME}-worker spec: template: spec: @@ -28,10 +28,10 @@ spec: key: kubeadm-pre-init.sh permissions: "0500" preKubeadmCommands: - - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' ${KUBERNETES_VERSION} joinConfiguration: nodeRegistration: kubeletExtraArgs: cloud-provider: external - provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + provider-id: 'linode://{{ ds.meta_data.id }}' name: '{{ ds.meta_data.label }}' diff --git a/templates/flavors/clusterclass/kubeadm-controlplane-template.yaml b/templates/flavors/clusterclass/kubeadm-controlplane-template.yaml index a095d03f2..8914ef664 100644 --- a/templates/flavors/clusterclass/kubeadm-controlplane-template.yaml +++ b/templates/flavors/clusterclass/kubeadm-controlplane-template.yaml @@ -1,7 +1,7 @@ kind: KubeadmControlPlaneTemplate apiVersion: controlplane.cluster.x-k8s.io/v1beta1 metadata: - name: ${CLUSTER_NAME}-control-plane + name: ${CLUSTER_CLASS_NAME}-control-plane spec: template: spec: @@ -34,16 +34,18 @@ spec: apiServer: extraArgs: cloud-provider: external - timeoutForControlPlane: 20m + controllerManager: + extraArgs: + cloud-provider: external initConfiguration: nodeRegistration: kubeletExtraArgs: cloud-provider: external - provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + provider-id: 'linode://{{ ds.meta_data.id }}' name: '{{ ds.meta_data.label }}' joinConfiguration: nodeRegistration: kubeletExtraArgs: cloud-provider: external - provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + provider-id: 'linode://{{ ds.meta_data.id }}' name: '{{ ds.meta_data.label }}' diff --git a/templates/flavors/clusterclass/kustomization.yaml b/templates/flavors/clusterclass/kustomization.yaml index 071ba9ed5..3ead4f48f 100644 --- a/templates/flavors/clusterclass/kustomization.yaml +++ b/templates/flavors/clusterclass/kustomization.yaml @@ -1,4 +1,3 @@ -namespace: default resources: - clusterclass.yaml - linode-cluster-template.yaml @@ -7,3 +6,6 @@ resources: - kubeadm-controlplane-template.yaml - kubeadm-config-template.yaml - ../../common-init-files + - ../../addons/cilium + - ../../addons/provider-linode + - ../../addons/cluster-resource-set diff --git a/templates/flavors/clusterclass/linode-cluster-template.yaml b/templates/flavors/clusterclass/linode-cluster-template.yaml index d3ddc4a66..2c4e5db3f 100644 --- a/templates/flavors/clusterclass/linode-cluster-template.yaml +++ b/templates/flavors/clusterclass/linode-cluster-template.yaml @@ -1,7 +1,7 @@ apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeClusterTemplate metadata: - name: ${CLUSTER_NAME}-linode-cluster + name: ${CLUSTER_CLASS_NAME} spec: template: spec: diff --git a/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml b/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml index 3ea3543fc..10a77dd90 100644 --- a/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml +++ b/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml @@ -1,12 +1,12 @@ kind: LinodeMachineTemplate apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 metadata: - name: ${CLUSTER_NAME}-control-plane + name: ${CLUSTER_CLASS_NAME}-control-plane spec: template: spec: image: ${LINODE_OS} type: ${LINODE_CONTROL_PLANE_MACHINE_TYPE} region: ${LINODE_REGION} - authorizedKeys: - - ${LINODE_SSH_KEY} + # uncomment to include your ssh key in linode provisioning + # - ${LINODE_SSH_PUBKEY:=""} diff --git a/templates/flavors/clusterclass/linode-machine-worker-template.yaml b/templates/flavors/clusterclass/linode-machine-worker-template.yaml index 7bd30862d..c15f16797 100644 --- a/templates/flavors/clusterclass/linode-machine-worker-template.yaml +++ b/templates/flavors/clusterclass/linode-machine-worker-template.yaml @@ -1,7 +1,7 @@ apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeMachineTemplate metadata: - name: ${CLUSTER_NAME}-worker + name: ${CLUSTER_CLASS_NAME}-worker spec: template: spec: @@ -9,4 +9,5 @@ spec: type: ${LINODE_MACHINE_TYPE} region: ${LINODE_REGION} authorizedKeys: - - ${LINODE_SSH_KEY} + # uncomment to include your ssh key in linode provisioning + # - ${LINODE_SSH_PUBKEY:=""} diff --git a/templates/flavors/default/kustomization.yaml b/templates/flavors/default/kustomization.yaml index 19473ad29..a02873200 100644 --- a/templates/flavors/default/kustomization.yaml +++ b/templates/flavors/default/kustomization.yaml @@ -1,5 +1,7 @@ -namespace: default resources: - ../base - machine-deployment.yaml - ../../common-init-files + - ../../addons/cilium + - ../../addons/provider-linode + - ../../addons/cluster-resource-set diff --git a/templates/flavors/default/machine-deployment.yaml b/templates/flavors/default/machine-deployment.yaml index cda7f50be..10220cbbc 100644 --- a/templates/flavors/default/machine-deployment.yaml +++ b/templates/flavors/default/machine-deployment.yaml @@ -32,7 +32,8 @@ spec: type: ${LINODE_MACHINE_TYPE} region: ${LINODE_REGION} authorizedKeys: - - ${LINODE_SSH_KEY} + # uncomment to include your ssh key in linode provisioning + # - ${LINODE_SSH_PUBKEY:=""} --- apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 kind: KubeadmConfigTemplate @@ -69,5 +70,5 @@ spec: nodeRegistration: kubeletExtraArgs: cloud-provider: external - provider-id: 'linode:///{{ ds.meta_data.region }}/{{ ds.meta_data.id }}' + provider-id: 'linode://{{ ds.meta_data.id }}' name: '{{ ds.meta_data.label }}' From 1db63219e6f9d9b59392ee09c397a652c33b5489 Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Wed, 21 Feb 2024 14:27:42 -0500 Subject: [PATCH 04/12] generate flavors as part of release --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4a124dfb8..725514f5d 100644 --- a/Makefile +++ b/Makefile @@ -206,7 +206,8 @@ release: $(KUSTOMIZE) mkdir -p $(RELEASE_DIR)/ $(MAKE) set-manifest-image MANIFEST_IMG=$(REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG) $(KUSTOMIZE) build config/default > $(RELEASE_DIR)/infrastructure-components.yaml - cp templates/cluster-template* $(RELEASE_DIR)/ + $(MAKE) generate-flavors + mv templates/cluster-template* $(RELEASE_DIR)/ cp metadata.yaml $(RELEASE_DIR)/metadata.yaml ## -------------------------------------- From 2820372bbca250e36d2eca44b7eb270a4864bebc Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Wed, 21 Feb 2024 14:58:01 -0500 Subject: [PATCH 05/12] make local release --- Makefile | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 725514f5d..04ccdaa99 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ REGISTRY ?= docker.io/linode IMAGE_NAME ?= cluster-api-provider-linode CONTROLLER_IMAGE ?= $(REGISTRY)/$(IMAGE_NAME) -TAG ?= dev # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = 1.28.0 OS=$(shell uname -s | tr '[:upper:]' '[:lower:]') @@ -12,7 +11,7 @@ ARCH_SHORT := amd64 else ifeq ($(ARCH_SHORT),aarch64) ARCH_SHORT := arm64 endif -VERSION ?= $(shell git describe --tags --dirty=-dev) +VERSION ?= $(shell git describe --always --dirty=-dev) BUILD_ARGS := --build-arg VERSION=$(VERSION) # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) @@ -139,20 +138,16 @@ _e2etest: manifests generate _e2etest-infra build: manifests generate fmt vet ## Build manager binary. go build -ldflags="-X github.com/linode/cluster-api-provider-linode/version.version=$(VERSION)" -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 to build 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/ .PHONY: docker-build docker-build: ## Build docker image with the manager. - $(CONTAINER_TOOL) build $(BUILD_ARGS) . -t $(CONTROLLER_IMAGE):$(TAG) + $(CONTAINER_TOOL) build $(BUILD_ARGS) . -t $(CONTROLLER_IMAGE):$(VERSION) .PHONY: docker-push docker-push: ## Push docker image with the manager. - $(CONTAINER_TOOL) push $(CONTROLLER_IMAGE):$(TAG) + $(CONTAINER_TOOL) push $(CONTROLLER_IMAGE):$(VERSION) # PLATFORMS defines the target platforms for the manager image be built to provide support to multiple # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: @@ -167,7 +162,7 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross - $(CONTAINER_TOOL) buildx create --name project-v3-builder $(CONTAINER_TOOL) buildx use project-v3-builder - - $(CONTAINER_TOOL) buildx build $(BUILD_ARGS) --push --platform=$(PLATFORMS) --tag $(CONTROLLER_IMAGE):$(TAG) -f Dockerfile.cross . + - $(CONTAINER_TOOL) buildx build $(BUILD_ARGS) --push --platform=$(PLATFORMS) --tag $(CONTROLLER_IMAGE):$(VERSION) -f Dockerfile.cross . - $(CONTAINER_TOOL) buildx rm project-v3-builder rm Dockerfile.cross @@ -194,21 +189,24 @@ tilt-cluster: ctlptl tilt kind clusterctl ##@ Release: RELEASE_DIR ?= release -RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null) .PHONY: set-manifest-image set-manifest-image: ## Update kustomize image patch file for default resource. sed -i'' -e 's@image: .*@image: '"${MANIFEST_IMG}:${MANIFEST_TAG}"'@' ./config/default/manager_image_patch.yaml .PHONY: release -release: $(KUSTOMIZE) - rm -rf $(RELEASE_DIR) +release: $(KUSTOMIZE) clean-release mkdir -p $(RELEASE_DIR)/ - $(MAKE) set-manifest-image MANIFEST_IMG=$(REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG) + $(MAKE) set-manifest-image MANIFEST_IMG=$(REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(VERSION) $(KUSTOMIZE) build config/default > $(RELEASE_DIR)/infrastructure-components.yaml $(MAKE) generate-flavors mv templates/cluster-template* $(RELEASE_DIR)/ cp metadata.yaml $(RELEASE_DIR)/metadata.yaml + $(MAKE) clean-release-git + +.PHONY: local-release +local-release: + RELEASE_DIR=infrastructure-linode/0.0.0 $(MAKE) release ## -------------------------------------- ## Cleanup @@ -220,6 +218,14 @@ release: $(KUSTOMIZE) clean: rm -rf $(LOCALBIN) +.PHONY: clean-release-git +clean-release-git: ## Restores the git files usually modified during a release + git restore config/default/*manager_image_patch.yaml + +.PHONY: clean-release +clean-release: clean-release-git + rm -rf $(RELEASE_DIR) + ## -------------------------------------- ## Build Dependencies ## -------------------------------------- From 7ca5c6ae018a9439ece11b698a961a7a283f89d8 Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Wed, 21 Feb 2024 15:34:28 -0500 Subject: [PATCH 06/12] restructure and update development docs --- docs/src/developers/development.md | 99 ++++++++++++++++++------------ 1 file changed, 59 insertions(+), 40 deletions(-) diff --git a/docs/src/developers/development.md b/docs/src/developers/development.md index ab5cb2317..6f8b9dca1 100644 --- a/docs/src/developers/development.md +++ b/docs/src/developers/development.md @@ -7,12 +7,10 @@ - [Setting up](#setting-up) - [Base requirements](#base-requirements) - [Clone the source code](#clone-the-source-code) + - [Enable git hooks](#enable-git-hooks) + - [Set up devbox](#recommended-set-up-devbox) - [Get familiar with basic concepts](#get-familiar-with-basic-concepts) - [Developing](#developing) - - [Enable git hooks](#enable-git-hooks) - - [Setting up the environment](#setting-up-the-environment) - - [Using devbox](#using-devbox) - - [Tilt Requirements](#tilt-requirements) - [Using Tilt](#using-tilt) - [Deploying a workload cluster](#deploying-a-workload-cluster) - [Customizing the cluster deployment](#customizing-the-cluster-deployment) @@ -27,6 +25,11 @@ ### Base requirements +```admonish warning +Ensure you have your `LINODE_TOKEN` set as outlined in the +[getting started prerequisites](../topics/getting-started.md#Prerequisites) section. +``` + There are no requirements since development dependencies are fetched as needed via the make targets, but a recommendation is to [install Devbox](https://jetpack.io/devbox/docs/installing_devbox/) @@ -38,22 +41,6 @@ git clone https://github.com/linode/cluster-api-provider-linode cd cluster-api-provider-linode ``` -### Get familiar with basic concepts - -This provider is based on the [Cluster API project](https://github.com/kubernetes-sigs/cluster-api). -It's recommended to familiarize yourself with Cluster API resources, concepts, and conventions -outlined in the [Cluster API Book](https://cluster-api.sigs.k8s.io/). - -## Developing - -This repository uses [Go Modules](https://github.com/golang/go/wiki/Modules) -to track and vendor dependencies. - -To pin a new dependency, run: -```bash -go get @ -``` - ### Enable git hooks To enable automatic code validation on code push, execute the following commands: @@ -68,18 +55,9 @@ If you would like to temporarily disable git hook, set `SKIP_GIT_PUSH_HOOK` valu SKIP_GIT_PUSH_HOOK=1 git push ``` -### Setting up the environment - -```admonish warning -Ensure you have your `LINODE_TOKEN` set as outlined in the -[getting started prerequisites](../topics/getting-started.md#Prerequisites) section. -``` - -All development dependencies should be taken care of via Devbox and/or make target dependencies. - -#### Using devbox +### [Recommended] Set up devbox -1. Install dependent packages in your project +1. Install dependent packages in your project ```shell devbox install ``` @@ -93,10 +71,27 @@ All development dependencies should be taken care of via Devbox and/or make targ devbox shell ``` -From this point you can use the devbox shell like a regular shell. +From this point you can use the devbox shell like a regular shell. The rest of the guide assumes a devbox shell is used, but the make target dependencies will install any missing dependencies if needed when running -outside of a devbox shell. +outside a devbox shell. + +### Get familiar with basic concepts + +This provider is based on the [Cluster API project](https://github.com/kubernetes-sigs/cluster-api). +It's recommended to familiarize yourself with Cluster API resources, concepts, and conventions +outlined in the [Cluster API Book](https://cluster-api.sigs.k8s.io/). + +## Developing + +This repository uses [Go Modules](https://github.com/golang/go/wiki/Modules) +to track and vendor dependencies. + +To pin a new dependency, run: +```bash +go get @ +``` + ### Using tilt To build a kind cluster and start Tilt, simply run: @@ -117,6 +112,34 @@ kind delete cluster --name tilt After your kind management cluster is up and running with Tilt, you should be ready to deploy your first cluster. +#### Generating the cluster templates + +For local development, templates should be generated via: + +``` +make local-release +``` + +This creates `infrastructure-linode/0.0.0/` with all the cluster templates: + +```bash +infrastructure-linode/0.0.0 +├── cluster-template-clusterclass.yaml +├── cluster-template.yaml +├── infrastructure-components.yaml +└── metadata.yaml +``` + +This can then be used with `clusterctl` by adding the following to `~/.clusterctl/cluster-api.yaml` +(assuming the repo exists in the `$HOME` directory): + +``` +providers: + - name: linode + url: ${HOME}/cluster-api-provider-linode/infrastructure-linode/0.0.0/infrastructure-components.yaml + type: InfrastructureProvider +``` + #### Customizing the cluster deployment Here is a list of required configuration parameters: @@ -137,24 +160,20 @@ export LINODE_MACHINE_TYPE=g6-standard-2 You can also use `clusterctl generate` to see which variables need to be set: ``` -clusterctl generate cluster $CLUSTER_NAME --from ./templates/cluster-template.yaml --list-variables +clusterctl generate cluster $CLUSTER_NAME --infrastructure linode:0.0.0 [--flavor ] --list-variables ``` ~~~ -```admonish warning -Please note the templates require the use of `clusterctl generate` to substitute the environment variables properly. -``` - #### Creating the workload cluster Once you have all the necessary environment variables set, -you can deploy a workload cluster with the following command: +you can deploy a workload cluster with the default flavor: ```shell clusterctl generate cluster $CLUSTER_NAME \ --kubernetes-version v1.29.1 \ - --from templates/cluster-template.yaml \ + --infrastructure linode:0.0.0 \ | kubectl apply -f - ``` From f959fe160b00f10396c0fb59cfe4d3bbe837cbaf Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Wed, 21 Feb 2024 15:47:57 -0500 Subject: [PATCH 07/12] add README for flavors dir --- templates/flavors/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 templates/flavors/README.md diff --git a/templates/flavors/README.md b/templates/flavors/README.md new file mode 100644 index 000000000..c297af5a1 --- /dev/null +++ b/templates/flavors/README.md @@ -0,0 +1,20 @@ +# Flavors + +In `clusterctl` the infrastructure provider authors can provide different types +of cluster templates referred to as "flavors". You can use the `--flavor` flag +to specify which flavor to use for a cluster, e.g: + +```shell +clusterctl generate cluster test-cluster --flavor clusterclass +``` + +To use the default flavor, omit the `--flavor` flag. + +See the [`clusterctl` flavors docs](https://cluster-api.sigs.k8s.io/clusterctl/commands/generate-cluster.html#flavors) for more information. + +This directory contains each of the flavors for CAPL. Each directory besides `base` will be used to +create a flavor by running `kustomize build` on the directory. The name of the directory will be +appended to the end of the cluster-template.yaml, e.g cluster-template-{directory-name}.yaml. That +flavor can be used by specifying `--flavor {directory-name}`. + +To generate all CAPL flavors, run `make generate-flavors`. From 92ee44a2a7fbb37801fe158244380f46acb30a34 Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Wed, 21 Feb 2024 17:00:26 -0500 Subject: [PATCH 08/12] make the LINODE_OS optional --- .../clusterclass/linode-machine-controlplane-template.yaml | 2 +- .../flavors/clusterclass/linode-machine-worker-template.yaml | 2 +- templates/flavors/default/machine-deployment.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml b/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml index 10a77dd90..b8061980f 100644 --- a/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml +++ b/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml @@ -5,7 +5,7 @@ metadata: spec: template: spec: - image: ${LINODE_OS} + image: ${LINODE_OS:="linode/ubuntu22.04"} type: ${LINODE_CONTROL_PLANE_MACHINE_TYPE} region: ${LINODE_REGION} # uncomment to include your ssh key in linode provisioning diff --git a/templates/flavors/clusterclass/linode-machine-worker-template.yaml b/templates/flavors/clusterclass/linode-machine-worker-template.yaml index c15f16797..682ae9ddf 100644 --- a/templates/flavors/clusterclass/linode-machine-worker-template.yaml +++ b/templates/flavors/clusterclass/linode-machine-worker-template.yaml @@ -5,7 +5,7 @@ metadata: spec: template: spec: - image: ${LINODE_OS} + image: ${LINODE_OS:="linode/ubuntu22.04"} type: ${LINODE_MACHINE_TYPE} region: ${LINODE_REGION} authorizedKeys: diff --git a/templates/flavors/default/machine-deployment.yaml b/templates/flavors/default/machine-deployment.yaml index 10220cbbc..22065cb52 100644 --- a/templates/flavors/default/machine-deployment.yaml +++ b/templates/flavors/default/machine-deployment.yaml @@ -28,7 +28,7 @@ metadata: spec: template: spec: - image: ${LINODE_OS} + image: ${LINODE_OS:="linode/ubuntu22.04"} type: ${LINODE_MACHINE_TYPE} region: ${LINODE_REGION} authorizedKeys: From 8a863cffbade9d42d3aa29bd4ef4e950bd536512 Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Thu, 22 Feb 2024 13:15:16 -0500 Subject: [PATCH 09/12] add vars on clusterclass --- templates/flavors/clusterclass/cluster.yaml | 15 +++ .../flavors/clusterclass/clusterclass.yaml | 121 ++++++++++++++++-- .../clusterclass/linode-cluster-template.yaml | 3 +- .../linode-machine-controlplane-template.yaml | 11 +- .../linode-machine-worker-template.yaml | 12 +- 5 files changed, 138 insertions(+), 24 deletions(-) diff --git a/templates/flavors/clusterclass/cluster.yaml b/templates/flavors/clusterclass/cluster.yaml index 3646361ea..c79f24360 100644 --- a/templates/flavors/clusterclass/cluster.yaml +++ b/templates/flavors/clusterclass/cluster.yaml @@ -2,10 +2,25 @@ apiVersion: cluster.x-k8s.io/v1beta1 kind: Cluster metadata: name: ${CLUSTER_NAME} + labels: + cni: cilium + ccm: linode + crs: ${CLUSTER_NAME}-crs spec: + clusterNetwork: + pods: + cidrBlocks: + - 192.168.128.0/17 topology: class: ${CLUSTER_CLASS_NAME} version: ${KUBERNETES_VERSION} + variables: + - name: region + value: ${LINODE_REGION} + - name: controlPlaneMachineType + value: ${LINODE_CONTROL_PLANE_MACHINE_TYPE} + - name: workerMachineType + value: ${LINODE_MACHINE_TYPE} controlPlane: replicas: ${CONTROL_PLANE_MACHINE_COUNT} workers: diff --git a/templates/flavors/clusterclass/clusterclass.yaml b/templates/flavors/clusterclass/clusterclass.yaml index 90cc1d18f..a3471e089 100644 --- a/templates/flavors/clusterclass/clusterclass.yaml +++ b/templates/flavors/clusterclass/clusterclass.yaml @@ -32,16 +32,113 @@ spec: apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeMachineTemplate name: ${CLUSTER_CLASS_NAME}-worker + variables: + - name: region + required: true + schema: + openAPIV3Schema: + type: string + default: us-ord + - name: controlPlaneMachineType + required: true + schema: + openAPIV3Schema: + type: string + default: g6-standard-2 + - name: workerMachineType + required: true + schema: + openAPIV3Schema: + type: string + default: g6-standard-2 + - name: osImage + required: true + schema: + openAPIV3Schema: + type: string + default: linode/ubuntu22.04 patches: - - definitions: - - jsonPatches: - - op: add - path: /spec/template/spec/kubeadmConfigSpec/clusterConfiguration/controllerManager/extraArgs/cluster-name - valueFrom: - variable: builtin.cluster.name - selector: - apiVersion: controlplane.cluster.x-k8s.io/v1beta1 - kind: KubeadmControlPlaneTemplate - matchResources: - controlPlane: true - name: controlPlane + - name: region + definitions: + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeClusterTemplate + matchResources: + infrastructureCluster: true + jsonPatches: + - op: add + path: /spec/template/spec/region + valueFrom: + variable: region + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + matchResources: + controlPlane: true + jsonPatches: + - op: replace + path: /spec/template/spec/region + valueFrom: + variable: region + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + matchResources: + machineDeploymentClass: + names: + - default-worker + jsonPatches: + - op: replace + path: /spec/template/spec/region + valueFrom: + variable: region + - name: controlPlaneMachineType + definitions: + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + matchResources: + controlPlane: true + jsonPatches: + - op: replace + path: /spec/template/spec/type + valueFrom: + variable: controlPlaneMachineType + - name: workerMachineType + definitions: + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + matchResources: + machineDeploymentClass: + names: + - default-worker + jsonPatches: + - op: replace + path: /spec/template/spec/type + valueFrom: + variable: workerMachineType + - name: osImage + definitions: + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + matchResources: + machineDeploymentClass: + names: + - default-worker + jsonPatches: + - op: replace + path: /spec/template/spec/image + valueFrom: + variable: osImage + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + matchResources: + controlPlane: true + jsonPatches: + - op: replace + path: /spec/template/spec/image + valueFrom: + variable: osImage diff --git a/templates/flavors/clusterclass/linode-cluster-template.yaml b/templates/flavors/clusterclass/linode-cluster-template.yaml index 2c4e5db3f..c531a786f 100644 --- a/templates/flavors/clusterclass/linode-cluster-template.yaml +++ b/templates/flavors/clusterclass/linode-cluster-template.yaml @@ -5,4 +5,5 @@ metadata: spec: template: spec: - region: ${LINODE_REGION} + # region is a required field (OpenAPI schema). + region: REPLACEME diff --git a/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml b/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml index b8061980f..ee3c7a987 100644 --- a/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml +++ b/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml @@ -5,8 +5,9 @@ metadata: spec: template: spec: - image: ${LINODE_OS:="linode/ubuntu22.04"} - type: ${LINODE_CONTROL_PLANE_MACHINE_TYPE} - region: ${LINODE_REGION} - # uncomment to include your ssh key in linode provisioning - # - ${LINODE_SSH_PUBKEY:=""} + # image is a required field (OpenAPI schema). + image: REPLACEME + # type is a required field (OpenAPI schema). + type: REPLACEME + # region is a required field (OpenAPI schema). + region: REPLACEME diff --git a/templates/flavors/clusterclass/linode-machine-worker-template.yaml b/templates/flavors/clusterclass/linode-machine-worker-template.yaml index 682ae9ddf..cb78836b8 100644 --- a/templates/flavors/clusterclass/linode-machine-worker-template.yaml +++ b/templates/flavors/clusterclass/linode-machine-worker-template.yaml @@ -5,9 +5,9 @@ metadata: spec: template: spec: - image: ${LINODE_OS:="linode/ubuntu22.04"} - type: ${LINODE_MACHINE_TYPE} - region: ${LINODE_REGION} - authorizedKeys: - # uncomment to include your ssh key in linode provisioning - # - ${LINODE_SSH_PUBKEY:=""} + # image is a required field (OpenAPI schema). + image: REPLACEME + # type is a required field (OpenAPI schema). + type: REPLACEME + # region is a required field (OpenAPI schema). + region: REPLACEME From 495627c4fc992b8ab006ae79f04b97aeab02c030 Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Thu, 22 Feb 2024 13:59:49 -0500 Subject: [PATCH 10/12] update docs for clusterclass --- docs/src/developers/development.md | 58 ++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/docs/src/developers/development.md b/docs/src/developers/development.md index 6f8b9dca1..f5b9e6d08 100644 --- a/docs/src/developers/development.md +++ b/docs/src/developers/development.md @@ -15,6 +15,8 @@ - [Deploying a workload cluster](#deploying-a-workload-cluster) - [Customizing the cluster deployment](#customizing-the-cluster-deployment) - [Creating the workload cluster](#creating-the-workload-cluster) + - [Using the default flavor](#using-the-default-flavor) + - [Using ClusterClass (alpha)](#using-clusterclass) - [Cleaning up the workload cluster](#cleaning-up-the-workload-cluster) - [Automated Testing](#automated-testing) - [E2E Testing](#e2e-testing) @@ -36,7 +38,7 @@ needed via the make targets, but a recommendation is to ### Clone the source code -```shell +```sh git clone https://github.com/linode/cluster-api-provider-linode cd cluster-api-provider-linode ``` @@ -45,20 +47,20 @@ cd cluster-api-provider-linode To enable automatic code validation on code push, execute the following commands: -```bash +```sh PATH="$PWD/bin:$PATH" make husky && husky install ``` If you would like to temporarily disable git hook, set `SKIP_GIT_PUSH_HOOK` value: -```bash +```sh SKIP_GIT_PUSH_HOOK=1 git push ``` ### [Recommended] Set up devbox 1. Install dependent packages in your project - ```shell + ```sh devbox install ``` @@ -67,7 +69,7 @@ SKIP_GIT_PUSH_HOOK=1 git push ``` 2. Use devbox environment - ```shell + ```sh devbox shell ``` @@ -88,14 +90,14 @@ This repository uses [Go Modules](https://github.com/golang/go/wiki/Modules) to track and vendor dependencies. To pin a new dependency, run: -```bash +```sh go get @ ``` ### Using tilt To build a kind cluster and start Tilt, simply run: -```shell +```sh make tilt-cluster ``` @@ -104,7 +106,7 @@ Once your kind management cluster is up and running, you can To tear down the tilt-cluster, run -```shell +```sh kind delete cluster --name tilt ``` @@ -116,13 +118,13 @@ After your kind management cluster is up and running with Tilt, you should be re For local development, templates should be generated via: -``` +```sh make local-release ``` This creates `infrastructure-linode/0.0.0/` with all the cluster templates: -```bash +```sh infrastructure-linode/0.0.0 ├── cluster-template-clusterclass.yaml ├── cluster-template.yaml @@ -144,7 +146,7 @@ providers: Here is a list of required configuration parameters: -```bash +```sh # Cluster settings export CLUSTER_NAME=capl-cluster export KUBERNETES_VERSION=v1.29.1 @@ -167,10 +169,12 @@ clusterctl generate cluster $CLUSTER_NAME --infrastructure linode:0.0.0 [--flavo #### Creating the workload cluster +##### Using the default flavor + Once you have all the necessary environment variables set, you can deploy a workload cluster with the default flavor: -```shell +```sh clusterctl generate cluster $CLUSTER_NAME \ --kubernetes-version v1.29.1 \ --infrastructure linode:0.0.0 \ @@ -180,6 +184,32 @@ clusterctl generate cluster $CLUSTER_NAME \ This will provision the cluster with the CNI defaulted to [cilium](../topics/addons.md#cilium) and the [linode-ccm](../topics/addons.md#ccm) installed. +##### Using ClusterClass (alpha) + +~~~admonish success title="" +ClusterClass experimental feature is enabled by default in the KIND management cluster +created via `make tilt-cluster` +~~~ + +You can use the `clusterclass` flavor to create a workload cluster as well, assuming the +management cluster has the [ClusterTopology feature gate set](https://cluster-api.sigs.k8s.io/tasks/experimental-features/cluster-class/): + +```sh +# Create the ClusterClass and templates +clusterctl generate cluster $CLUSTER_NAME \ + --kubernetes-version v1.29.1 \ + --infrastructure linode:0.0.0 \ + --flavor clusterclass \ + | kubectl apply -f - + +# Create the actual Cluster that uses the ClusterClass +clusterctl generate cluster $CLUSTER_NAME \ + --kubernetes-version v1.29.1 \ + --infrastructure linode:0.0.0 \ + --from ./templates/flavors/clusterclass/cluster.yaml \ + | kubectl apply -f - +``` + ```admonish question title="" For any issues, please refer to the [troubleshooting guide](../topics/troubleshooting.md). ``` @@ -188,7 +218,7 @@ For any issues, please refer to the [troubleshooting guide](../topics/troublesho To delete the cluster, simply run: -```bash +```sh kubectl delete cluster $CLUSTER_NAME ``` @@ -201,7 +231,7 @@ For any issues, please refer to the [troubleshooting guide](../topics/troublesho #### E2E Testing To run E2E locally run: -```bash +```sh make e2etest ``` From 671c9f4fd602c212ff4d27cf31901aace4137f3c Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Thu, 22 Feb 2024 14:04:33 -0500 Subject: [PATCH 11/12] install cilium in kube-system NS on provisioned clusters --- templates/addons/cilium/cilium.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/addons/cilium/cilium.yaml b/templates/addons/cilium/cilium.yaml index 338ab35d6..5eb267d1d 100644 --- a/templates/addons/cilium/cilium.yaml +++ b/templates/addons/cilium/cilium.yaml @@ -8,6 +8,7 @@ spec: cni: cilium repoURL: https://helm.cilium.io/ chartName: cilium + namespace: kube-system version: ${CILIUM_VERSION:=1.15.0} options: waitForJobs: true From f73f81a6ecb5b8af67623f9aca9a50e876608e57 Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Fri, 23 Feb 2024 10:40:23 -0500 Subject: [PATCH 12/12] address review comments --- Makefile | 30 ++++++++++++------- docs/src/developers/development.md | 12 ++------ hack/generate-flavors.sh | 9 +++++- templates/common-init-files/secret.yaml | 3 +- .../cluster-template.yaml} | 2 +- .../clusterclass.yaml | 12 ++++---- .../kubeadm-config-template.yaml | 2 +- .../kubeadm-controlplane-template.yaml | 2 +- .../kustomization.yaml | 0 .../linode-cluster-template.yaml | 2 +- .../linode-machine-controlplane-template.yaml | 2 +- .../linode-machine-worker-template.yaml | 2 +- 12 files changed, 44 insertions(+), 34 deletions(-) rename templates/flavors/{clusterclass/cluster.yaml => clusterclass-kubeadm/cluster-template.yaml} (95%) rename templates/flavors/{clusterclass => clusterclass-kubeadm}/clusterclass.yaml (94%) rename templates/flavors/{clusterclass => clusterclass-kubeadm}/kubeadm-config-template.yaml (96%) rename templates/flavors/{clusterclass => clusterclass-kubeadm}/kubeadm-controlplane-template.yaml (97%) rename templates/flavors/{clusterclass => clusterclass-kubeadm}/kustomization.yaml (100%) rename templates/flavors/{clusterclass => clusterclass-kubeadm}/linode-cluster-template.yaml (86%) rename templates/flavors/{clusterclass => clusterclass-kubeadm}/linode-machine-controlplane-template.yaml (88%) rename templates/flavors/{clusterclass => clusterclass-kubeadm}/linode-machine-worker-template.yaml (90%) diff --git a/Makefile b/Makefile index 04ccdaa99..b0b3a7cd1 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ ARCH_SHORT := amd64 else ifeq ($(ARCH_SHORT),aarch64) ARCH_SHORT := arm64 endif -VERSION ?= $(shell git describe --always --dirty=-dev) +VERSION ?= $(shell git describe --always --tag --dirty=-dev) BUILD_ARGS := --build-arg VERSION=$(VERSION) # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) @@ -190,23 +190,33 @@ tilt-cluster: ctlptl tilt kind clusterctl RELEASE_DIR ?= release +.PHONY: release +release: $(KUSTOMIZE) clean-release set-manifest-image release-manifests generate-flavors release-templates release-metadata clean-release-git + +$(RELEASE_DIR): + mkdir -p $(RELEASE_DIR)/ + +.PHONY: release-metadata +release-metadata: $(RELEASE_DIR) + cp metadata.yaml $(RELEASE_DIR)/metadata.yaml + +.PHONY: release-templates +release-templates: $(RELEASE_DIR) + mv templates/cluster-template* $(RELEASE_DIR)/ + mv templates/clusterclass* $(RELEASE_DIR)/ + .PHONY: set-manifest-image set-manifest-image: ## Update kustomize image patch file for default resource. - sed -i'' -e 's@image: .*@image: '"${MANIFEST_IMG}:${MANIFEST_TAG}"'@' ./config/default/manager_image_patch.yaml + sed -i'' -e 's@image: .*@image: '"$(REGISTRY)/$(IMAGE_NAME):$(VERSION)"'@' ./config/default/manager_image_patch.yaml -.PHONY: release -release: $(KUSTOMIZE) clean-release - mkdir -p $(RELEASE_DIR)/ - $(MAKE) set-manifest-image MANIFEST_IMG=$(REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(VERSION) +.PHONY: release-manifests +release-manifests: $(KUSTOMIZE) $(RELEASE_DIR) $(KUSTOMIZE) build config/default > $(RELEASE_DIR)/infrastructure-components.yaml - $(MAKE) generate-flavors - mv templates/cluster-template* $(RELEASE_DIR)/ - cp metadata.yaml $(RELEASE_DIR)/metadata.yaml - $(MAKE) clean-release-git .PHONY: local-release local-release: RELEASE_DIR=infrastructure-linode/0.0.0 $(MAKE) release + $(MAKE) clean-release-git ## -------------------------------------- ## Cleanup diff --git a/docs/src/developers/development.md b/docs/src/developers/development.md index f5b9e6d08..5ef40a54e 100644 --- a/docs/src/developers/development.md +++ b/docs/src/developers/development.md @@ -126,7 +126,7 @@ This creates `infrastructure-linode/0.0.0/` with all the cluster templates: ```sh infrastructure-linode/0.0.0 -├── cluster-template-clusterclass.yaml +├── cluster-template-kubeadm-clusterclass.yaml ├── cluster-template.yaml ├── infrastructure-components.yaml └── metadata.yaml @@ -195,18 +195,10 @@ You can use the `clusterclass` flavor to create a workload cluster as well, assu management cluster has the [ClusterTopology feature gate set](https://cluster-api.sigs.k8s.io/tasks/experimental-features/cluster-class/): ```sh -# Create the ClusterClass and templates clusterctl generate cluster $CLUSTER_NAME \ --kubernetes-version v1.29.1 \ --infrastructure linode:0.0.0 \ - --flavor clusterclass \ - | kubectl apply -f - - -# Create the actual Cluster that uses the ClusterClass -clusterctl generate cluster $CLUSTER_NAME \ - --kubernetes-version v1.29.1 \ - --infrastructure linode:0.0.0 \ - --from ./templates/flavors/clusterclass/cluster.yaml \ + --flavor kubeadm-clusterclass \ | kubectl apply -f - ``` diff --git a/hack/generate-flavors.sh b/hack/generate-flavors.sh index dfbc726a4..38c7c25f0 100755 --- a/hack/generate-flavors.sh +++ b/hack/generate-flavors.sh @@ -6,7 +6,14 @@ REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. FLAVORS_DIR="${REPO_ROOT}/templates/flavors" for name in $(find "${FLAVORS_DIR}/"* -maxdepth 0 -type d -print0 | xargs -0 -I {} basename {} | grep -v base); do - kustomize build "${FLAVORS_DIR}/${name}" > "${REPO_ROOT}/templates/cluster-template-${name}.yaml" + # clusterctl expects clusterclass not have the "cluster-template" prefix + # except for the actual cluster template using the clusterclass + if [[ "$name" == clusterclass* ]]; then + kustomize build "${FLAVORS_DIR}/${name}" > "${REPO_ROOT}/templates/${name}.yaml" + cp "${FLAVORS_DIR}/${name}/cluster-template.yaml" "${REPO_ROOT}/templates/cluster-template-${name}.yaml" + else + kustomize build "${FLAVORS_DIR}/${name}" > "${REPO_ROOT}/templates/cluster-template-${name}.yaml" + fi done # move the default template to the default file expected by clusterctl diff --git a/templates/common-init-files/secret.yaml b/templates/common-init-files/secret.yaml index 860f3a9ec..e2b3a7827 100644 --- a/templates/common-init-files/secret.yaml +++ b/templates/common-init-files/secret.yaml @@ -37,4 +37,5 @@ stringData: modprobe br_netfilter sysctl --system sed -i '/swap/d' /etc/fstab - swapoff -a \ No newline at end of file + swapoff -a + diff --git a/templates/flavors/clusterclass/cluster.yaml b/templates/flavors/clusterclass-kubeadm/cluster-template.yaml similarity index 95% rename from templates/flavors/clusterclass/cluster.yaml rename to templates/flavors/clusterclass-kubeadm/cluster-template.yaml index c79f24360..4aef17cef 100644 --- a/templates/flavors/clusterclass/cluster.yaml +++ b/templates/flavors/clusterclass-kubeadm/cluster-template.yaml @@ -12,7 +12,7 @@ spec: cidrBlocks: - 192.168.128.0/17 topology: - class: ${CLUSTER_CLASS_NAME} + class: kubeadm version: ${KUBERNETES_VERSION} variables: - name: region diff --git a/templates/flavors/clusterclass/clusterclass.yaml b/templates/flavors/clusterclass-kubeadm/clusterclass.yaml similarity index 94% rename from templates/flavors/clusterclass/clusterclass.yaml rename to templates/flavors/clusterclass-kubeadm/clusterclass.yaml index a3471e089..68bdd2339 100644 --- a/templates/flavors/clusterclass/clusterclass.yaml +++ b/templates/flavors/clusterclass-kubeadm/clusterclass.yaml @@ -1,23 +1,23 @@ apiVersion: cluster.x-k8s.io/v1beta1 kind: ClusterClass metadata: - name: ${CLUSTER_CLASS_NAME} + name: kubeadm spec: controlPlane: ref: apiVersion: controlplane.cluster.x-k8s.io/v1beta1 kind: KubeadmControlPlaneTemplate - name: ${CLUSTER_CLASS_NAME}-control-plane + name: kubeadm-control-plane machineInfrastructure: ref: apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeMachineTemplate - name: ${CLUSTER_CLASS_NAME}-control-plane + name: kubeadm-control-plane infrastructure: ref: apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeClusterTemplate - name: ${CLUSTER_CLASS_NAME} + name: kubeadm workers: machineDeployments: - class: default-worker @@ -26,12 +26,12 @@ spec: ref: apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 kind: KubeadmConfigTemplate - name: ${CLUSTER_CLASS_NAME}-worker + name: kubeadm-worker infrastructure: ref: apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeMachineTemplate - name: ${CLUSTER_CLASS_NAME}-worker + name: kubeadm-worker variables: - name: region required: true diff --git a/templates/flavors/clusterclass/kubeadm-config-template.yaml b/templates/flavors/clusterclass-kubeadm/kubeadm-config-template.yaml similarity index 96% rename from templates/flavors/clusterclass/kubeadm-config-template.yaml rename to templates/flavors/clusterclass-kubeadm/kubeadm-config-template.yaml index 15383acb6..c19aa3002 100644 --- a/templates/flavors/clusterclass/kubeadm-config-template.yaml +++ b/templates/flavors/clusterclass-kubeadm/kubeadm-config-template.yaml @@ -1,7 +1,7 @@ apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 kind: KubeadmConfigTemplate metadata: - name: ${CLUSTER_CLASS_NAME}-worker + name: kubeadm-worker spec: template: spec: diff --git a/templates/flavors/clusterclass/kubeadm-controlplane-template.yaml b/templates/flavors/clusterclass-kubeadm/kubeadm-controlplane-template.yaml similarity index 97% rename from templates/flavors/clusterclass/kubeadm-controlplane-template.yaml rename to templates/flavors/clusterclass-kubeadm/kubeadm-controlplane-template.yaml index 8914ef664..6f3f72dee 100644 --- a/templates/flavors/clusterclass/kubeadm-controlplane-template.yaml +++ b/templates/flavors/clusterclass-kubeadm/kubeadm-controlplane-template.yaml @@ -1,7 +1,7 @@ kind: KubeadmControlPlaneTemplate apiVersion: controlplane.cluster.x-k8s.io/v1beta1 metadata: - name: ${CLUSTER_CLASS_NAME}-control-plane + name: kubeadm-control-plane spec: template: spec: diff --git a/templates/flavors/clusterclass/kustomization.yaml b/templates/flavors/clusterclass-kubeadm/kustomization.yaml similarity index 100% rename from templates/flavors/clusterclass/kustomization.yaml rename to templates/flavors/clusterclass-kubeadm/kustomization.yaml diff --git a/templates/flavors/clusterclass/linode-cluster-template.yaml b/templates/flavors/clusterclass-kubeadm/linode-cluster-template.yaml similarity index 86% rename from templates/flavors/clusterclass/linode-cluster-template.yaml rename to templates/flavors/clusterclass-kubeadm/linode-cluster-template.yaml index c531a786f..1e3f6d74e 100644 --- a/templates/flavors/clusterclass/linode-cluster-template.yaml +++ b/templates/flavors/clusterclass-kubeadm/linode-cluster-template.yaml @@ -1,7 +1,7 @@ apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeClusterTemplate metadata: - name: ${CLUSTER_CLASS_NAME} + name: kubeadm spec: template: spec: diff --git a/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml b/templates/flavors/clusterclass-kubeadm/linode-machine-controlplane-template.yaml similarity index 88% rename from templates/flavors/clusterclass/linode-machine-controlplane-template.yaml rename to templates/flavors/clusterclass-kubeadm/linode-machine-controlplane-template.yaml index ee3c7a987..89666c070 100644 --- a/templates/flavors/clusterclass/linode-machine-controlplane-template.yaml +++ b/templates/flavors/clusterclass-kubeadm/linode-machine-controlplane-template.yaml @@ -1,7 +1,7 @@ kind: LinodeMachineTemplate apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 metadata: - name: ${CLUSTER_CLASS_NAME}-control-plane + name: kubeadm-control-plane spec: template: spec: diff --git a/templates/flavors/clusterclass/linode-machine-worker-template.yaml b/templates/flavors/clusterclass-kubeadm/linode-machine-worker-template.yaml similarity index 90% rename from templates/flavors/clusterclass/linode-machine-worker-template.yaml rename to templates/flavors/clusterclass-kubeadm/linode-machine-worker-template.yaml index cb78836b8..10da62b09 100644 --- a/templates/flavors/clusterclass/linode-machine-worker-template.yaml +++ b/templates/flavors/clusterclass-kubeadm/linode-machine-worker-template.yaml @@ -1,7 +1,7 @@ apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeMachineTemplate metadata: - name: ${CLUSTER_CLASS_NAME}-worker + name: kubeadm-worker spec: template: spec: