Skip to content

Commit

Permalink
change dev setup to use ignition in KubeadmControlPlane (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
defo89 authored Jul 31, 2024
1 parent 522787a commit 60b5416
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 119 deletions.
40 changes: 32 additions & 8 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,27 @@ settings = {
"cert_manager_version": "v1.14.4",
"kubernetes_version": "v1.29.4",
"metal_image": "ghcr.io/ironcore-dev/metal-operator-controller-manager:latest",
"extra_args": {
"new_args": {
"metal": [
"--health-probe-bind-address=:8081",
"--metrics-bind-address=127.0.0.1:8080",
"--leader-elect",
"--probe-image=ghcr.io/ironcore-dev/metalprobe:latest",
"--probe-os-image=ghcr.io/ironcore-dev/os-images/gardenlinux:1443",
"--registry-url=http://0.0.0.0:30010"
],
"kubeadm-controlplane": [
"--leader-elect",
"--diagnostics-address=:8443",
"--insecure-diagnostics=false",
"--feature-gates=MachinePool=false,KubeadmBootstrapFormatIgnition=true",
],
"kubeadm-bootstrap": [
"--leader-elect",
"--diagnostics-address=:8443",
"--insecure-diagnostics=false",
"--feature-gates=MachinePool=false,KubeadmBootstrapFormatIgnition=true",
"--bootstrap-token-ttl=15m"
]
}
}
Expand Down Expand Up @@ -67,6 +80,17 @@ def deploy_capi():
if kb_extra_args:
patch_args_with_extra_args("capi-kubeadm-bootstrap-system", "capi-kubeadm-bootstrap-controller-manager", kb_extra_args)

if settings.get("new_args"):
new_args = settings.get("new_args")
if new_args.get("kubeadm-controlplane"):
kcp_new_args = new_args.get("kubeadm-controlplane")
if kcp_new_args:
replace_args_with_new_args("capi-kubeadm-control-plane-system", "capi-kubeadm-control-plane-controller-manager", kcp_new_args)
if new_args.get("kubeadm-bootstrap"):
kb_new_args = new_args.get("kubeadm-bootstrap")
if kb_new_args:
replace_args_with_new_args("capi-kubeadm-bootstrap-system", "capi-kubeadm-bootstrap-controller-manager", kb_new_args)

# deploy metal-operator
def deploy_metal():
version = settings.get("metal_version")
Expand All @@ -75,13 +99,13 @@ def deploy_metal():
cmd = "{} build {} | {} | {} apply -f -".format(kustomize_cmd, metal_uri, envsubst_cmd, kubectl_cmd)
local(cmd, quiet=True)

if settings.get("extra_args"):
extra_args = settings.get("extra_args")
if extra_args.get("metal"):
metal_extra_args = extra_args.get("metal")
if metal_extra_args:
if settings.get("new_args"):
new_args = settings.get("new_args")
if new_args.get("metal"):
metal_new_args = new_args.get("metal")
if metal_new_args:
for namespace in ["metal-operator-system"]:
replace_args_with_extra_args(namespace, "metal-operator-controller-manager", metal_extra_args)
replace_args_with_new_args(namespace, "metal-operator-controller-manager", metal_new_args)

patch_image("metal-operator-system", "metal-operator-controller-manager", image)

Expand All @@ -106,7 +130,7 @@ def patch_args_with_extra_args(namespace, name, extra_args):
}]
local("kubectl patch deployment {} -n {} --type json -p='{}'".format(name, namespace, str(encode_json(patch)).replace("\n", "")))

def replace_args_with_extra_args(namespace, name, extra_args):
def replace_args_with_new_args(namespace, name, extra_args):
patch = [{
"op": "replace",
"path": "/spec/template/spec/containers/0/args",
Expand Down
137 changes: 26 additions & 111 deletions templates/test/cluster_v1beta1_kubeadmcontrolplane.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,121 +10,36 @@ spec:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
name: metalmachinetemplate-sample-control-plane
kubeadmConfigSpec:
users:
- name: root
sshAuthorizedKeys: [foo]
files:
- content: |
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
name: kube-vip
namespace: kube-system
spec:
containers:
- args:
- manager
env:
- name: cp_enable
value: "true"
- name: vip_interface
value: eth0
- name: address
value: foo
- name: port
value: "6443"
- name: vip_arp
value: "true"
- name: vip_leaderelection
value: "true"
- name: vip_leaseduration
value: "15"
- name: vip_renewdeadline
value: "10"
- name: vip_retryperiod
value: "2"
image: ghcr.io/kube-vip/kube-vip:v0.7.1
imagePullPolicy: IfNotPresent
name: kube-vip
resources: {}
securityContext:
capabilities:
add:
- NET_ADMIN
- NET_RAW
volumeMounts:
- mountPath: /etc/kubernetes/admin.conf
name: kubeconfig
hostAliases:
- hostnames:
- localhost
- kubernetes
ip: 127.0.0.1
hostNetwork: true
volumes:
- hostPath:
path: /etc/kubernetes/admin.conf
type: FileOrCreate
name: kubeconfig
status: {}
owner: root:root
path: /etc/kubernetes/manifests/kube-vip.yaml
- path: /etc/kube-vip-prepare.sh
content: |
#!/bin/bash
# Copyright 2020 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
# Configure the workaround required for kubeadm init with kube-vip:
# xref: https://github.com/kube-vip/kube-vip/issues/684
# Nothing to do for kubernetes < v1.29
KUBEADM_MINOR="$(kubeadm version -o short | cut -d '.' -f 2)"
if [[ "$KUBEADM_MINOR" -lt "29" ]]; then
exit 0
fi
IS_KUBEADM_INIT="false"
# cloud-init kubeadm init
if [[ -f /run/kubeadm/kubeadm.yaml ]]; then
IS_KUBEADM_INIT="true"
fi
# ignition kubeadm init
if [[ -f /etc/kubeadm.sh ]] && grep -q -e "kubeadm init" /etc/kubeadm.sh; then
IS_KUBEADM_INIT="true"
fi
if [[ "$IS_KUBEADM_INIT" == "true" ]]; then
sed -i 's#path: /etc/kubernetes/admin.conf#path: /etc/kubernetes/super-admin.conf#' \
/etc/kubernetes/manifests/kube-vip.yaml
fi
owner: root:root
permissions: "0700"
preKubeadmCommands:
- /etc/kube-vip-prepare.sh
initConfiguration:
nodeRegistration:
name: $${METAL_HOSTNAME}
kubeletExtraArgs:
provider-id: "foo"
cloud-provider: external
clusterConfiguration:
apiServer:
extraArgs:
cloud-provider: external
controllerManager:
extraArgs:
cloud-provider: external
joinConfiguration:
nodeRegistration:
name: $${METAL_HOSTNAME}
kubeletExtraArgs:
provider-id: "foo"
cloud-provider: external
format: ignition
ignition:
containerLinuxConfig:
additionalConfig: |-
files:
- path: /opt/testdir/testfile
filesystem: root
mode: 0644
contents:
inline: |
[TEST]
test=1
preKubeadmCommands:
- envsubst < /etc/kubeadm.yml > /etc/kubeadm.yml.tmp
- mv /etc/kubeadm.yml.tmp /etc/kubeadm.yml
version: 1.29.4

0 comments on commit 60b5416

Please sign in to comment.