Skip to content

Commit

Permalink
[improvement] Add new flavors (#325)
Browse files Browse the repository at this point in the history
* Add new flavors
  • Loading branch information
amold1 authored May 23, 2024
1 parent 0d9640b commit 843fc27
Show file tree
Hide file tree
Showing 47 changed files with 1,034 additions and 198 deletions.
34 changes: 26 additions & 8 deletions hack/generate-flavors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,35 @@ set -euo pipefail

REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
FLAVORS_DIR="${REPO_ROOT}/templates/flavors"
SUPPORTED_DISTROS=(
"rke2"
"k3s"
"kubeadm"
)
SUPPORTED_CLUSTERCLASSES=(
"clusterclass-kubeadm"
)

for name in $(find "${FLAVORS_DIR}/"* -maxdepth 0 -type d -print0 | xargs -0 -I {} basename {} | grep -v base | grep -v clusterclass-base ); do
for clusterclass in ${SUPPORTED_CLUSTERCLASSES[@]}; do
# 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
echo "****** Generating clusterclass-${clusterclass} flavor ******"
kustomize build "${FLAVORS_DIR}/${clusterclass}" > "${REPO_ROOT}/templates/${clusterclass}.yaml"
cp "${FLAVORS_DIR}/${clusterclass}/cluster-template.yaml" "${REPO_ROOT}/templates/cluster-template-${clusterclass}.yaml"
done


for distro in ${SUPPORTED_DISTROS[@]}; do
for name in $(find "${FLAVORS_DIR}/${distro}/"* -maxdepth 0 -type d -print0 | xargs -0 -I {} basename {}); do
if [[ ${name} == "default" ]]; then
echo "****** Generating ${distro} flavor ******"
kustomize build "${FLAVORS_DIR}/${distro}/${name}" > "${REPO_ROOT}/templates/cluster-template-${distro}.yaml"
else
echo "****** Generating ${distro}-${name} flavor ******"
kustomize build "${FLAVORS_DIR}/${distro}/${name}" > "${REPO_ROOT}/templates/cluster-template-${distro}-${name}.yaml"
fi
done
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"
mv "${REPO_ROOT}/templates/cluster-template-kubeadm.yaml" "${REPO_ROOT}/templates/cluster-template.yaml"
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ data:
toPorts:
- ports:
- port: "6443"
- port: "2379"
- port: "2380"
---
apiVersion: addons.cluster.x-k8s.io/v1beta1
kind: ClusterResourceSet
Expand Down
12 changes: 0 additions & 12 deletions templates/flavors/README.md

This file was deleted.

4 changes: 2 additions & 2 deletions templates/flavors/clusterclass-kubeadm/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resources:
- clusterClass.yaml
- kubeadmControlPlaneTemplate.yaml
- linodeClusterTemplate.yaml
- ../default
- ../kubeadm/default

transformers:
- replacementTransformer.yaml
Expand Down Expand Up @@ -47,4 +47,4 @@ patches:
patch: |-
kind: KubeadmConfigTemplate
metadata:
name: kubeadm-worker
name: kubeadm-worker
42 changes: 0 additions & 42 deletions templates/flavors/default/kustomization.yaml

This file was deleted.

51 changes: 0 additions & 51 deletions templates/flavors/k3s/ciliumNetworkPolicies.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../default
- ../../addons/cluster-autoscaler
- ../../../addons/cluster-autoscaler

patches:
- target:
group: cluster.x-k8s.io
version: v1beta1
kind: Cluster
patch: |-
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: ${CLUSTER_NAME}
labels:
cluster-autoscaler: "true"
- target:
group: cluster.x-k8s.io
version: v1beta1
Expand All @@ -27,3 +18,14 @@ patches:
annotations:
cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: ${WORKER_MACHINE_MIN:-"1"}
cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: ${WORKER_MACHINE_MAX:-"10"}
- target:
group: cluster.x-k8s.io
version: v1beta1
kind: Cluster
patch: |-
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: ${CLUSTER_NAME}
labels:
cluster-autoscaler: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ spec:
nodeName: '{{ ds.meta_data.label }}'
preK3sCommands:
- |
mkdir -p /etc/rancher/k3s/config.yaml.d/
echo "node-ip: $(ip a s eth1 |grep 'inet ' |cut -d' ' -f6|cut -d/ -f1)" >> /etc/rancher/k3s/config.yaml.d/capi-config.yaml
- sed -i '/swap/d' /etc/fstab
- swapoff -a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
- ../../../infra
- k3sControlPlane.yaml
- k3sConfigTemplate.yaml
- ciliumNetworkPolicies.yaml
- secret.yaml
- ../../../addons/cilium-network-policies
patches:
- target:
group: cluster.x-k8s.io
Expand Down
File renamed without changes.
77 changes: 77 additions & 0 deletions templates/flavors/k3s/dual-stack/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../vpcless

patches:
- target:
group: cluster.x-k8s.io
version: v1beta1
kind: Cluster
patch: |-
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: ${CLUSTER_NAME}
spec:
clusterNetwork:
pods:
cidrBlocks:
- 10.192.0.0/10
- fd02::/80
services:
cidrBlocks:
- 10.96.0.0/12
- fd03::/108
- target:
group: controlplane.cluster.x-k8s.io
version: v1beta1
kind: KThreesControlPlane
patch: |-
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KThreesControlPlane
metadata:
name: ${CLUSTER_NAME}-control-plane
spec:
kthreesConfigSpec:
serverConfig:
kubeControllerManagerArgs:
- "node-cidr-mask-size-ipv6=96"
clusterCidr: "10.192.0.0/10,fd02::/80"
serviceCidr: "10.96.0.0/12,fd03::/108"
- target:
kind: HelmChartProxy
name: .*-cilium
patch: |-
- op: replace
path: /spec/valuesTemplate
value: |
bgpControlPlane:
enabled: true
ipv6:
enabled: true
ipam:
mode: kubernetes
k8s:
requireIPv4PodCIDR: true
hubble:
relay:
enabled: true
ui:
enabled: true
- target:
group: controlplane.cluster.x-k8s.io
version: v1beta1
kind: KThreesControlPlane
patch: |-
- op: replace
path: /spec/kthreesConfigSpec/preK3sCommands
value:
- |
mkdir -p /etc/rancher/k3s/config.yaml.d/
echo -n "kubelet-arg: \"--node-ip=" >> /etc/rancher/k3s/config.yaml.d/capi-config.yaml
echo -n "$(ip a s eth0 |grep -E 'inet ' |cut -d' ' -f6|cut -d/ -f1 | grep -E '192.168')" >> /etc/rancher/k3s/config.yaml.d/capi-config.yaml
echo ",$(ip a s eth0 |grep -E 'inet6 ' |cut -d' ' -f6|cut -d/ -f1 | grep -vE 'fe80')\"" >> /etc/rancher/k3s/config.yaml.d/capi-config.yaml
- sed -i '/swap/d' /etc/fstab
- swapoff -a
- hostnamectl set-hostname '{{ ds.meta_data.label }}' && hostname -F /etc/hostname
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../default
- ../../addons/etcd-backup-restore
- ../../../addons/etcd-backup-restore
patches:
- target:
group: cluster.x-k8s.io
Expand Down
Loading

0 comments on commit 843fc27

Please sign in to comment.