From c572de19683191d1451c64ba6c5dcb1eb380fa49 Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Thu, 16 May 2024 14:52:00 -0400 Subject: [PATCH] use kustomize transformers --- docs/src/topics/flavors/cilium-bgp-lb.md | 3 +- .../cilium-bgp-lb/kubeadmConfigTemplate.yaml | 57 --------------- .../flavors/cilium-bgp-lb/kustomization.yaml | 70 +++++++++++++++++++ .../cilium-bgp-lb/linodeMachineTemplate.yaml | 12 ---- .../cilium-bgp-lb/machineDeployment.yaml | 13 ---- 5 files changed, 71 insertions(+), 84 deletions(-) diff --git a/docs/src/topics/flavors/cilium-bgp-lb.md b/docs/src/topics/flavors/cilium-bgp-lb.md index 5eff6af2d..89e819f85 100644 --- a/docs/src/topics/flavors/cilium-bgp-lb.md +++ b/docs/src/topics/flavors/cilium-bgp-lb.md @@ -47,10 +47,9 @@ Linode networking and API limitations: ## Usage -1. (Optional) Set up environment variables +1. (Optional) Set up environment variable ```sh # Optional - export LINODE_BGP_PEER_MACHINE_TYPE=g6-standard-2 export BGP_PEER_MACHINE_COUNT=2 ``` diff --git a/templates/flavors/cilium-bgp-lb/kubeadmConfigTemplate.yaml b/templates/flavors/cilium-bgp-lb/kubeadmConfigTemplate.yaml index 711008695..2159ad300 100644 --- a/templates/flavors/cilium-bgp-lb/kubeadmConfigTemplate.yaml +++ b/templates/flavors/cilium-bgp-lb/kubeadmConfigTemplate.yaml @@ -3,60 +3,3 @@ apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 kind: KubeadmConfigTemplate metadata: name: ${CLUSTER_NAME}-md-bgp -spec: - template: - spec: - files: - - path: /etc/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 - content: | - overlay - br_netfilter - - path: /etc/sysctl.d/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 - 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} - - sed -i '/swap/d' /etc/fstab - - swapoff -a - - hostnamectl set-hostname '{{ ds.meta_data.label }}' && hostname -F /etc/hostname - joinConfiguration: - nodeRegistration: - kubeletExtraArgs: - cloud-provider: external - node-labels: cilium-bgp-peering="true" - name: '{{ ds.meta_data.label }}' diff --git a/templates/flavors/cilium-bgp-lb/kustomization.yaml b/templates/flavors/cilium-bgp-lb/kustomization.yaml index dbac851d0..a58f8d327 100644 --- a/templates/flavors/cilium-bgp-lb/kustomization.yaml +++ b/templates/flavors/cilium-bgp-lb/kustomization.yaml @@ -27,3 +27,73 @@ patches: env: - name: LINODE_URL value: https://api.linode.com/v4beta +transformers: +- | + apiVersion: builtin + kind: ReplacementTransformer + metadata: + name: clone-bgp + replacements: + - source: + kind: KubeadmConfigTemplate + name: ${CLUSTER_NAME}-md-0 + fieldPath: .spec + targets: + - select: + kind: KubeadmConfigTemplate + name: ${CLUSTER_NAME}-md-bgp + fieldPaths: + - .spec + options: + create: true + - source: + kind: LinodeMachineTemplate + name: ${CLUSTER_NAME}-md-0 + fieldPath: .spec + targets: + - select: + kind: LinodeMachineTemplate + name: ${CLUSTER_NAME}-md-bgp + fieldPaths: + - .spec + options: + create: true + - source: + kind: MachineDeployment + name: ${CLUSTER_NAME}-md-0 + fieldPath: .spec.template + targets: + - select: + kind: MachineDeployment + name: ${CLUSTER_NAME}-md-bgp + fieldPaths: + - .spec.template + options: + create: true +- |- + apiVersion: builtin + kind: PatchTransformer + metadata: + name: patch-kubeadmconfig + patch: |- + - op: add + path: /spec/template/spec/joinConfiguration/nodeRegistration/kubeletExtraArgs/node-labels + value: cilium-bgp-peering="true" + target: + kind: KubeadmConfigTemplate + name: .*-md-bgp +- |- + apiVersion: builtin + kind: PatchTransformer + metadata: + name: patch-machinedeployment + patch: |- + - op: replace + path: /spec/template/spec/bootstrap/configRef/name + value: ${CLUSTER_NAME}-md-bgp + - op: replace + path: /spec/template/spec/infrastructureRef/name + value: ${CLUSTER_NAME}-md-bgp + target: + kind: MachineDeployment + name: .*-md-bgp diff --git a/templates/flavors/cilium-bgp-lb/linodeMachineTemplate.yaml b/templates/flavors/cilium-bgp-lb/linodeMachineTemplate.yaml index 1e8b5e49f..943988db0 100644 --- a/templates/flavors/cilium-bgp-lb/linodeMachineTemplate.yaml +++ b/templates/flavors/cilium-bgp-lb/linodeMachineTemplate.yaml @@ -2,15 +2,3 @@ apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeMachineTemplate metadata: name: ${CLUSTER_NAME}-md-bgp -spec: - template: - spec: - image: ${LINODE_OS:="linode/ubuntu22.04"} - type: ${LINODE_BGP_PEER_MACHINE_TYPE:=${LINODE_MACHINE_TYPE}} - region: ${LINODE_REGION} - interfaces: - - purpose: public - primary: true - authorizedKeys: - # uncomment to include your ssh key in linode provisioning - # - ${LINODE_SSH_PUBKEY:=""} diff --git a/templates/flavors/cilium-bgp-lb/machineDeployment.yaml b/templates/flavors/cilium-bgp-lb/machineDeployment.yaml index b1993e95f..c63ba0d89 100644 --- a/templates/flavors/cilium-bgp-lb/machineDeployment.yaml +++ b/templates/flavors/cilium-bgp-lb/machineDeployment.yaml @@ -6,16 +6,3 @@ metadata: spec: clusterName: ${CLUSTER_NAME} replicas: ${BGP_PEER_MACHINE_COUNT:=2} - template: - spec: - clusterName: ${CLUSTER_NAME} - version: "${KUBERNETES_VERSION}" - bootstrap: - configRef: - name: ${CLUSTER_NAME}-md-bgp - apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 - kind: KubeadmConfigTemplate - infrastructureRef: - name: ${CLUSTER_NAME}-md-bgp - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeMachineTemplate