Skip to content

Commit

Permalink
refactor kubeadm and clusterclass flavor to use inline configuration (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
eljohnson92 authored Apr 30, 2024
1 parent 2ca0f3f commit 182c7f9
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 159 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ kubeconfig*
docs/book
release/*
templates/cluster-template*.yaml
infrastructure-linode/*
infrastructure-*-linode/*
4 changes: 4 additions & 0 deletions hack/manifests/kubeadm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ kind: ControlPlaneProvider
metadata:
name: kubeadm
namespace: kubeadm-control-plane-system
spec:
manager:
featureGates:
ClusterTopology: true
4 changes: 0 additions & 4 deletions templates/common-init-files/kustomization.yaml

This file was deleted.

44 changes: 0 additions & 44 deletions templates/common-init-files/secret.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions templates/flavors/clusterclass-base/kustomization.yaml

This file was deleted.

This file was deleted.

This file was deleted.

80 changes: 80 additions & 0 deletions templates/flavors/clusterclass-kubeadm/deleteTransformer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
# Delete LinodeCluster after values are copied to LinodeClusterTemplate
apiVersion: builtin
kind: PatchTransformer
metadata:
name: LinodeCluster-patch-delete
patch: |-
$patch: delete
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeCluster
metadata:
name: ${CLUSTER_NAME}
---
# Delete Cluster from ../base
apiVersion: builtin
kind: PatchTransformer
metadata:
name: patch-delete-cluster
patch: |-
$patch: delete
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: ${CLUSTER_NAME}
---
# Delete kubeadmControlPlane after values are copied to KubeadmControlPlaneTemplate
apiVersion: builtin
kind: PatchTransformer
metadata:
name: kubeadm-patch-delete
patch: |-
$patch: delete
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlane
metadata:
name: ${CLUSTER_NAME}-control-plane
---
# delete machineDeployment from ../base
apiVersion: builtin
kind: PatchTransformer
metadata:
name: patch-delete-machineDeployment
patch: |-
$patch: delete
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
metadata:
name: ${CLUSTER_NAME}-md-0
---
# delete extra fields from kubeadmControlPlaneTemplate
apiVersion: builtin
kind: PatchTransformer
metadata:
name: patch-delete-KubeadmControlPlaneTemplate
target:
kind: KubeadmControlPlaneTemplate
patch: |-
- op: remove
path: /spec/template/spec/machineTemplate
value:
- op: remove
path: /spec/template/spec/replicas
value:
- op: remove
path: /spec/template/spec/version
value:
#patch: |-
# $patch: delete
# apiVersion: controlplane.cluster.x-k8s.io/v1beta1
# kind: KubeadmControlPlaneTemplate
# metadata:
# name: kubeadm-control-plane
# spec:
# machineTemplate:
# infrastructureRef:
# apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
# kind: LinodeMachineTemplate
# name: ${CLUSTER_NAME}-control-plane
# replicas: ${CONTROL_PLANE_MACHINE_COUNT}
# version: ${KUBERNETES_VERSION}
39 changes: 0 additions & 39 deletions templates/flavors/clusterclass-kubeadm/kubeadmConfigTemplate.yaml

This file was deleted.

51 changes: 45 additions & 6 deletions templates/flavors/clusterclass-kubeadm/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,48 @@ kind: Kustomization
resources:
- clusterClass.yaml
- kubeadmControlPlaneTemplate.yaml
- kubeadmConfigTemplate.yaml
- ../clusterclass-base
- ../../common-init-files
- ../../addons/cilium
- ../../addons/provider-linode
- ../../addons/cluster-resource-set
- linodeClusterTemplate.yaml
- ../default

transformers:
- replacementTransformer.yaml
- deleteTransformer.yaml

patches:

- target:
group: infrastructure.cluster.x-k8s.io
version: v1alpha1
kind: LinodeMachineTemplate
name: .*md-0
options:
allowNameChange: true
patch: |-
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeMachineTemplate
metadata:
name: kubeadm-worker
- target:
group: infrastructure.cluster.x-k8s.io
version: v1alpha1
kind: LinodeMachineTemplate
name: .*control-plane
options:
allowNameChange: true
patch: |-
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeMachineTemplate
metadata:
name: kubeadm-control-plane
- target:
group: bootstrap.cluster.x-k8s.io
version: v1beta1
kind: KubeadmConfigTemplate
options:
allowNameChange: true
patch: |-
kind: KubeadmConfigTemplate
metadata:
name: kubeadm-worker
30 changes: 30 additions & 0 deletions templates/flavors/clusterclass-kubeadm/replacementTransformer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
apiVersion: builtin
kind: ReplacementTransformer
metadata:
name: linode-cluster-replace
replacements:
- source:
kind: LinodeCluster
fieldPath: spec
targets:
- select:
kind: LinodeClusterTemplate
fieldPaths:
- spec.template.spec
---
apiVersion: builtin
kind: ReplacementTransformer
metadata:
name: kubeadm-controlplane-replace
replacements:
- source:
kind: KubeadmControlPlane
name: ${CLUSTER_NAME}-control-plane
fieldPath: spec
targets:
- select:
kind: KubeadmControlPlaneTemplate
name: kubeadm-control-plane
fieldPaths:
- spec.template.spec
53 changes: 37 additions & 16 deletions templates/flavors/default/kubeadmConfigTemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,46 @@ spec:
spec:
files:
- path: /etc/containerd/config.toml
contentFrom:
secret:
name: common-init-files
key: containerd-config.toml
content: |
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
- path: /etc/modules-load.d/k8s.conf
contentFrom:
secret:
name: common-init-files
key: k8s-modules.conf
content: |
overlay
br_netfilter
- path: /etc/sysctl.d/k8s.conf
contentFrom:
secret:
name: common-init-files
key: sysctl-k8s.conf
content: |
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1
- path: /kubeadm-pre-init.sh
contentFrom:
secret:
name: common-init-files
key: kubeadm-pre-init.sh
content: |
#!/bin/bash
set -euo pipefail
export DEBIAN_FRONTEND=noninteractive
mkdir -p -m 755 /etc/apt/keyrings
PATCH_VERSION=$${1#[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
if [ -d "/sys/class/net/eth1" ]; then
IPADDR=$(ip a s eth1 |grep 'inet ' |cut -d' ' -f6|cut -d/ -f1)
sed -i "s/kubeletExtraArgs:/kubeletExtraArgs:\n node-ip: $IPADDR/g" /run/kubeadm/kubeadm.yaml
fi
permissions: "0500"
preKubeadmCommands:
- /kubeadm-pre-init.sh ${KUBERNETES_VERSION}
Expand Down
Loading

0 comments on commit 182c7f9

Please sign in to comment.