Skip to content

Commit c43745f

Browse files
committed
add Makefile for managing Talos environments
Signed-off-by: zhangzujian <[email protected]>
1 parent 26aa33b commit c43745f

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ SHELL = /bin/bash
33
include build.mk
44
include ut.mk
55
include kind.mk
6+
include talos.mk
67
include e2e.mk
78

89
REGISTRY = kubeovn

talos.mk

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Makefile for managing Talos environment
2+
3+
TALOS_REGISTRY_MIRROR_NAME ?= talos-registry-mirror
4+
TALOS_REGISTRY_MIRROR_HOST ?= 10.5.0.1
5+
TALOS_REGISTRY_MIRROR_PORT ?= 6000
6+
TALOS_REGISTRY_MIRROR = $(TALOS_REGISTRY_MIRROR_HOST):$(TALOS_REGISTRY_MIRROR_PORT)
7+
TALOS_REGISTRY_MIRROR_URL = http://$(TALOS_REGISTRY_MIRROR)
8+
9+
TALOS_CLUSTER_NAME ?= talos
10+
11+
.PHONY: talos-registry-mirror
12+
talos-registry-mirror:
13+
@if [ -z $$(docker ps -a -q -f name="^$(TALOS_REGISTRY_MIRROR_NAME)$$") ]; then \
14+
echo ">>> Creating Talos registry mirror..."; \
15+
docker run -d -p $(TALOS_REGISTRY_MIRROR_PORT):5000 --restart=always --name $(TALOS_REGISTRY_MIRROR_NAME) registry:2; \
16+
echo ">>> Talos registry mirror created."; \
17+
else \
18+
echo ">>> Talos registry mirror already exists."; \
19+
fi
20+
21+
.PHONY: talos-prepare-images
22+
talos-prepare-images: talos-registry-mirror
23+
@echo ">>> Preparing Talos images..."
24+
@for image in $$(talosctl image default | grep -v flannel); do \
25+
if [ -z $$(docker images -q $$image) ]; then \
26+
echo ">>>> Pulling $$image..."; \
27+
docker pull $$image; \
28+
else \
29+
echo ">>>> Image $$image already exists."; \
30+
fi; \
31+
echo ">>>>> Tagging $$image..."; \
32+
img=$$(echo $$image | sed -E 's#^[^/]+/#127.0.0.1:$(TALOS_REGISTRY_MIRROR_PORT)/#'); \
33+
docker tag $$image $$img; \
34+
echo ">>>>> Pushing $$img to registry mirror..."; \
35+
docker push $$img; \
36+
done
37+
38+
.PHONY: talos-init
39+
talos-init: talos-clean talos-prepare-images
40+
@echo ">>> Creating Talos cluster..."
41+
@talosctl cluster create --name $(TALOS_CLUSTER_NAME) \
42+
--registry-mirror docker.io=$(TALOS_REGISTRY_MIRROR_URL) \
43+
--registry-mirror gcr.io=$(TALOS_REGISTRY_MIRROR_URL) \
44+
--registry-mirror ghcr.io=$(TALOS_REGISTRY_MIRROR_URL) \
45+
--registry-mirror registry.k8s.io=$(TALOS_REGISTRY_MIRROR_URL) \
46+
--config-patch @yamls/talos-cluster-patch.yaml \
47+
--skip-k8s-node-readiness-check
48+
@echo ">>> Talos cluster created."
49+
@echo ">>> Downloading kubeconfig..."
50+
@talosctl kubeconfig -f --cluster $(TALOS_CLUSTER_NAME) -n $(TALOS_CLUSTER_NAME)-controlplane-1
51+
@echo ">>> Talos kubeconfig downloaded."
52+
@echo ">>> Getting all nodes..."
53+
@kubectl get nodes -o wide
54+
@echo ">>> Getting all pods..."
55+
@kubectl get pods -A -o wide
56+
57+
.PHONY: talos-clean
58+
talos-clean:
59+
@echo ">>> Deleting Talos cluster..."
60+
@talosctl cluster destroy --name $(TALOS_CLUSTER_NAME)
61+
@echo ">>> Talos cluster deleted."
62+
63+
.PHONY: talos-install
64+
talos-install: untaint-control-plane
65+
@echo ">>> Installing Kube-OVN with version $(VERSION)..."
66+
@echo ">>>>> Tagging Kube-OVN image..."
67+
@docker tag $(REGISTRY)/kube-ovn:$(VERSION) 127.0.0.1:$(TALOS_REGISTRY_MIRROR_PORT)/$(REGISTRY)/kube-ovn:$(VERSION)
68+
@echo ">>>>> Pushing Kube-OVN image..."
69+
@docker push 127.0.0.1:$(TALOS_REGISTRY_MIRROR_PORT)/$(REGISTRY)/kube-ovn:$(VERSION)
70+
@echo ">>>>> Updating node labels..."
71+
@kubectl label node --overwrite -l node-role.kubernetes.io/control-plane kube-ovn/role=master
72+
@kubectl label node --overwrite -l ovn.kubernetes.io/ovs_dp_type!=userspace ovn.kubernetes.io/ovs_dp_type=kernel
73+
@echo ">>>>> Installing Kube-OVN..."
74+
@helm install kubeovn ./charts/kube-ovn --wait \
75+
--set global.images.kubeovn.tag=$(VERSION) \
76+
--set OPENVSWITCH_DIR=/var/lib/openvswitch \
77+
--set OVN_DIR=/var/lib/ovn \
78+
--set DISABLE_MODULES_MANAGEMENT=true \
79+
--set networking.NET_STACK=ipv4 \
80+
--set networking.ENABLE_SSL=$(shell echo $${ENABLE_SSL:-false}) \
81+
--set func.SECURE_SERVING=$(shell echo $${SECURE_SERVING:-false}) \
82+
--set func.ENABLE_BIND_LOCAL_IP=$(shell echo $${ENABLE_BIND_LOCAL_IP:-true}) \
83+
--set func.ENABLE_ANP=$(shell echo $${ENABLE_ANP:-false}) \
84+
--set func.ENABLE_IC=$(shell kubectl get node --show-labels | grep -qw "ovn.kubernetes.io/ic-gw" && echo true || echo false)

yamls/talos-cluster-patch.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cluster:
2+
network:
3+
cni:
4+
name: none

0 commit comments

Comments
 (0)