Skip to content

Commit 7a5ae0c

Browse files
authored
Add flavor to run Gardener in the mini-lab (#202)
1 parent 1ca3690 commit 7a5ae0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1009
-650
lines changed

.github/workflows/integration.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
flavors:
2222
- name: cumulus
2323
- name: sonic
24+
- name: gardener
2425

2526
steps:
2627
- name: Gain back workspace permissions # https://github.com/actions/checkout/issues/211

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ requirements.yaml
1212
.extra_vars.yaml
1313
sonic-vs.img
1414
*.bak
15+
.ansible
16+
files/certs/*.pem
17+
files/certs/**/*.pem
18+
files/certs/**/*.crt

Makefile

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ else ifeq ($(MINI_LAB_FLAVOR),capms)
3434
LAB_MACHINES=machine01,machine02,machine03
3535
LAB_TOPOLOGY=mini-lab.capms.yaml
3636
VRF=Vrf20
37+
else ifeq ($(MINI_LAB_FLAVOR),gardener)
38+
GARDENER_ENABLED=true
39+
# usually gardener restricts the maximum version for k8s:
40+
K8S_VERSION=1.30.8
41+
LAB_MACHINES=machine01,machine02
42+
LAB_TOPOLOGY=mini-lab.sonic.yaml
43+
VRF=Vrf20
3744
else
3845
$(error Unknown flavor $(MINI_LAB_FLAVOR))
3946
endif
@@ -50,7 +57,7 @@ else
5057
endif
5158

5259
.PHONY: up
53-
up: env control-plane-bake partition-bake
60+
up: env gen-certs control-plane-bake partition-bake
5461
@chmod 600 files/ssh/id_rsa
5562
docker compose up --remove-orphans --force-recreate control-plane partition
5663
@$(MAKE) --no-print-directory start-machines
@@ -67,6 +74,21 @@ restart: down up
6774
.PHONY: down
6875
down: cleanup
6976

77+
.PHONY: gen-certs
78+
gen-certs:
79+
@if ! [ -f "files/certs/ca.pem" ]; then \
80+
echo "certificate generation required, running cfssl container"; \
81+
docker run --rm \
82+
--user $$(id -u):$$(id -g) \
83+
--entrypoint bash \
84+
-v ${PWD}:/work \
85+
cfssl/cfssl /work/scripts/roll_certs.sh; fi
86+
87+
.PHONY: roll-certs
88+
roll-certs:
89+
rm files/certs/ca.pem
90+
$(MAKE) gen-certs
91+
7092
.PHONY: control-plane
7193
control-plane: control-plane-bake env
7294
docker compose up --remove-orphans --force-recreate control-plane
@@ -272,3 +294,20 @@ dev-env:
272294
@echo "export METALCTL_API_URL=http://api.172.17.0.1.nip.io:8080/metal"
273295
@echo "export METALCTL_HMAC=metal-admin"
274296
@echo "export KUBECONFIG=$(KUBECONFIG)"
297+
298+
## Gardener integration
299+
300+
.PHONY: fetch-virtual-kubeconfig
301+
fetch-virtual-kubeconfig:
302+
kubectl config unset users.virtual-garden
303+
kubectl config unset contexts.virtual-garden
304+
kubectl config unset clusters.virtual-garden
305+
kubectl get secret -n garden garden-kubeconfig-for-admin -o jsonpath='{.data.kubeconfig}' | base64 -d > .virtual-kubeconfig
306+
kubectl --kubeconfig=.virtual-kubeconfig config rename-context garden virtual-garden
307+
sed -i 's/name: garden/name: virtual-garden/g' .virtual-kubeconfig
308+
sed -i 's/name: admin/name: virtual-garden/g' .virtual-kubeconfig
309+
kubectl --kubeconfig=.virtual-kubeconfig config set contexts.virtual-garden.cluster virtual-garden
310+
kubectl --kubeconfig=.virtual-kubeconfig config set contexts.virtual-garden.user virtual-garden
311+
KUBECONFIG=$$KUBECONFIG:.virtual-kubeconfig kubectl config view --flatten > .merged-kubeconfig
312+
rm .virtual-kubeconfig
313+
mv .merged-kubeconfig .kubeconfig

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ docker compose run --rm metalctl machine rm 00000000-0000-0000-0000-000000000001
196196

197197
There are two versions, or flavors, of the mini-lab environment which differ in regards to the NOS running on the leaves:
198198

199-
- `cumulus` -- runs 2 Cumulus switches.
200-
- `sonic` -- runs 2 SONiC switches
199+
- `cumulus`: runs 2 Cumulus switches.
200+
- `sonic`: runs 2 SONiC switches
201+
- `capms`: runs the SONiC flavor but with three instead of two machines (this is used for [cluster-provider-metal-stack](https://github.com/metal-stack/cluster-api-provider-metal-stack) in order to have dedicated hosts for control plane / worker / firewall)
202+
- `gardener`: installs the [Gardener](https://gardener.cloud) in the mini-lab
201203

202204
In order to start specific flavor, you can define the flavor as follows:
203205

compose.yaml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ services:
1919
- CI=${CI}
2020
- DOCKER_HUB_USER=${DOCKER_HUB_USER}
2121
- DOCKER_HUB_TOKEN=${DOCKER_HUB_TOKEN}
22+
- GARDENER_ENABLED=${GARDENER_ENABLED:-}
2223
network_mode: host
2324
working_dir: /mini-lab
24-
dns:
25-
- 172.17.0.1
26-
- 1.1.1.1
27-
- 1.0.0.1
2825
entrypoint:
2926
- /bin/bash
3027
- -ce
@@ -55,10 +52,6 @@ services:
5552
- DOCKER_HUB_TOKEN=${DOCKER_HUB_TOKEN}
5653
network_mode: host
5754
working_dir: /mini-lab
58-
dns:
59-
- 172.17.0.1
60-
- 1.1.1.1
61-
- 1.0.0.1
6255
entrypoint:
6356
- /bin/bash
6457
- -ce
@@ -82,8 +75,4 @@ services:
8275
- ./files/ignition.json:/tmp/ignition.json
8376
- ./files/rules.yaml:/tmp/rules.yaml
8477
network_mode: host
85-
dns:
86-
- 172.17.0.1
87-
- 1.1.1.1
88-
- 1.0.0.1
8978
command: --version

deploy_control_plane.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
hosts: control-plane
44
connection: local
55
gather_facts: false
6-
vars:
7-
setup_yaml:
8-
- url: https://raw.githubusercontent.com/metal-stack/releases/{{ metal_stack_release_version }}/release.yaml
9-
meta_var: metal_stack_release
106
roles:
117
- name: ansible-common
128
tags: always
@@ -26,3 +22,7 @@
2622
tags: auditing
2723
- name: metal-roles/control-plane/roles/metal
2824
tags: metal
25+
26+
- name: deploy gardener
27+
import_playbook: deploy_gardener.yaml
28+
when: gardener_enabled

deploy_gardener.yaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
- name: deploy gardener
3+
hosts: control-plane
4+
connection: local
5+
gather_facts: false
6+
pre_tasks:
7+
- name: Fake Gardener metal shoot
8+
k8s:
9+
definition:
10+
apiVersion: v1
11+
kind: ConfigMap
12+
metadata:
13+
name: shoot-info
14+
namespace: kube-system
15+
data:
16+
nodeNetwork: 172.18.0.0/16
17+
podNetwork: 10.244.0.0/24
18+
serviceNetwork: 10.96.0.0/16
19+
20+
- name: Create garden namespace
21+
k8s:
22+
definition:
23+
apiVersion: v1
24+
kind: Namespace
25+
metadata:
26+
name: garden
27+
28+
# our current state in metal-roles/gardener does not support network policies from gardenlet <-> virtual garden
29+
# this should be possible to resolve when we use the Gardener Operator
30+
- name: Deploy allow all network policy
31+
k8s:
32+
definition: "{{ lookup('file', 'netpol-allow-all.yaml') }}"
33+
namespace: garden
34+
apply: yes
35+
roles:
36+
- name: ansible-common
37+
tags: always
38+
- name: minio
39+
- name: powerdns
40+
tags: powerdns
41+
- name: metal-roles/control-plane/roles/gardener
42+
tags: gardener
43+
vars:
44+
metal_control_plane_host_provider: metal
45+
46+
post_tasks:
47+
# gardener exposes the istio ingress gateway through service type load balancer
48+
# we can fake the exposal by patching the status field, which is also what's
49+
# done in the gardener local environment
50+
- name: Wait for istio ingress gateway service
51+
kubernetes.core.k8s_info:
52+
api_version: v1
53+
kind: Service
54+
name: istio-ingressgateway
55+
namespace: istio-ingress
56+
register: result
57+
until: result.resources
58+
retries: 30
59+
delay: 10
60+
61+
- name: Patch ingress status of istio ingress gateway to allow seed to get ready
62+
patch_service_status_k8s:
63+
name: istio-ingressgateway
64+
namespace: istio-ingress
65+
body:
66+
status:
67+
loadBalancer:
68+
ingress:
69+
- ip: "172.17.0.1"
70+
71+
- name: Wait until seed is ready
72+
kubernetes.core.k8s_info:
73+
api_version: "core.gardener.cloud/v1beta1"
74+
kind: Seed
75+
name: "{{ metal_control_plane_stage_name }}"
76+
kubeconfig: "{{ gardener_kube_apiserver_kubeconfig_path }}"
77+
wait: yes
78+
wait_condition:
79+
reason: GardenletReady
80+
status: "True"
81+
type: GardenletReady
82+
wait_timeout: 300

deploy_partition.yaml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@
2929
command: tar xf /root/jessie-apt-transport-fix.tar.gz
3030
- name: install apt-transport
3131
shell: dpkg -i /root/https-deps/*.deb && apt-get install -fy
32+
- name: use own repo mirrors (old ones are 404)
33+
copy:
34+
dest: /etc/apt/sources.list
35+
content: |
36+
deb https://cumulus-3.apt.metal-stack.io/cumulus CumulusLinux-3 main
37+
deb-src https://cumulus-3.apt.metal-stack.io/cumulus CumulusLinux-3 main
38+
39+
deb https://cumulus-3.apt.metal-stack.io/cumulus-updates CumulusLinux-3-updates main
40+
deb-src https://cumulus-3.apt.metal-stack.io/cumulus-updates CumulusLinux-3-updates main
41+
42+
deb https://cumulus-3.apt.metal-stack.io/cumulus-security-updates CumulusLinux-3-security-updates main
43+
deb-src https://cumulus-3.apt.metal-stack.io/cumulus-security-updates CumulusLinux-3-security-updates main
44+
- name: set resolv.conf
45+
shell: rm /etc/resolv.conf && echo 'nameserver 8.8.8.8' > /etc/resolv.conf
46+
- name: use own repo key
47+
shell: curl -fsSL https://cumulus-3.apt.metal-stack.io/cumulus-3-repo.gpg | apt-key add -
3248
roles:
3349
- name: cumulus
3450
tags: cumulus
@@ -37,10 +53,6 @@
3753

3854
- name: Deploy dhcp server and pixiecore on leaf01
3955
hosts: leaf01
40-
vars:
41-
setup_yaml:
42-
- url: https://raw.githubusercontent.com/metal-stack/releases/{{ metal_stack_release_version }}/release.yaml
43-
meta_var: metal_stack_release
4456
roles:
4557
- name: ansible-common
4658
tags: always
@@ -51,10 +63,6 @@
5163

5264
- name: Deploy metal-core
5365
hosts: leaves
54-
vars:
55-
setup_yaml:
56-
- url: https://raw.githubusercontent.com/metal-stack/releases/{{ metal_stack_release_version }}/release.yaml
57-
meta_var: metal_stack_release
5866
roles:
5967
- name: ansible-common
6068
tags: always
@@ -65,10 +73,6 @@
6573
hosts: localhost
6674
connection: local
6775
gather_facts: no
68-
vars:
69-
setup_yaml:
70-
- url: https://raw.githubusercontent.com/metal-stack/releases/{{ metal_stack_release_version }}/release.yaml
71-
meta_var: metal_stack_release
7276
roles:
7377
- name: ansible-common
7478
tags: always

files/certs/ca-csr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
"C": "DE",
1111
"L": "Munich",
12-
"O": "Metal-Stack",
12+
"O": "metal-stack",
1313
"OU": "DevOps",
1414
"ST": "Bavaria"
1515
}

files/certs/ca-key.pem

Lines changed: 0 additions & 51 deletions
This file was deleted.

files/certs/ca.pem

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"CN": "client",
3+
"hosts": [""],
4+
"key": {
5+
"algo": "ecdsa",
6+
"size": 256
7+
},
8+
"names": [
9+
{
10+
"C": "DE",
11+
"L": "Munich",
12+
"O": "metal-stack",
13+
"OU": "DevOps",
14+
"ST": "Bavaria"
15+
}
16+
]
17+
}

0 commit comments

Comments
 (0)