-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile.ibi
137 lines (119 loc) · 5.27 KB
/
Makefile.ibi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
## Image Based Installation
IBI_VM_NAME = ibi
IBI_VM_MAC = fa:ba:da:1b:11:b1
IBI_VM_MEMORY = 32Gb
IBI_VM_CPUS = 16
IBI_DISK_SIZE = 120
IBI_DOMAIN ?= example.com
IBI_CLUSTER_NAME ?= other-test-sno
IBI_HOSTNAME ?= $(IBI_VM_NAME)
IBI_INSTALLATION_DISK ?= /dev/vda
NET_NAME ?= default
IBI_WORK_DIR ?= ibi-iso-work-dir
LCA_IMAGE ?= quay.io/openshift-kni/lifecycle-agent-operator:4.14.0
COREOS_INSTALLER = quay.io/coreos/coreos-installer:latest
IB_CLI = ./bin/ib-cli
RHCOS_LIVE_ISO = $(IBI_WORK_DIR)/rhcos-live.x86_64.iso
SSH_PUBLIC_KEY ?= $(HOME)/.ssh/id_rsa.pub
IBI_RHCOS_ISO_PATH = $(LIBVIRT_IMAGE_PATH)/rhcos-$(IBI_VM_NAME).iso
IBI_CONFIG_DIR = ibi-config
IBI_CLUSTER_CONFIG_TEMPLATE = ibi-manifest.template
IBI_CLUSTER_CONFIG_PATH = $(IBI_CONFIG_DIR)/cluster-configuration/manifest.json
IBI_CLUSTER_CONFIG_MANIFESTS = $(IBI_CONFIG_DIR)/cluster-configuration/manifests
# Use kcli - TODO: Use virsh or similar
LIBVIRT_POOL = default
KCLI_IMAGE = quay.io/karmab/kcli
kcli = podman run --net host -i --rm --security-opt label=disable -v $(LIBVIRT_IMAGE_PATH):$(LIBVIRT_IMAGE_PATH) -v $(HOME)/.ssh:/root/.ssh -v $(HOME)/.kcli:/root/.kcli -v /var/run/libvirt:/var/run/libvirt $(KCLI_IMAGE)
$(IB_CLI):
mkdir -p bin
podman run -it -v `pwd`:/data --entrypoint cp $(LCA_IMAGE) /usr/local/bin/ib-cli ./data/bin/
.PHONY: ibi-iso
ibi-iso: $(IB_CLI) credentials/pull-secret.json credentials/backup-secret.json credentials/ssh_public.key
mkdir -p $(IBI_WORK_DIR)
$(IB_CLI) create-iso --installation-disk $(IBI_INSTALLATION_DISK) \
--lca-image $(LCA_IMAGE) \
--seed-image $(SEED_IMAGE) \
--seed-version $(SEED_VERSION) \
--auth-file credentials/backup-secret.json \
--pullsecret-file credentials/pull-secret.json \
--ssh-public-key-file $(SSH_PUBLIC_KEY) \
--dir ./$(IBI_WORK_DIR)
sudo cp ./$(IBI_WORK_DIR)/rhcos-ibi.iso "$(IBI_RHCOS_ISO_PATH)"
sudo chmod a+r "$(IBI_RHCOS_ISO_PATH)"
.PHONY: ibi-iso-clean
ibi-iso-clean: ## Delete ISO
-sudo rm -f $(IBI_RHCOS_ISO_PATH) $(IBI_WORK_DIR)
# Configure dhcp and dns for host
.PHONY: host-net-config
host-net-config:
HOST_IP=$(shell virsh domifaddr ${IBI_VM_NAME} | grep ipv4 | awk -F " " '{print $$4}' | cut -d'/' -f1) \
CLUSTER_NAME=$(IBI_CLUSTER_NAME) \
BASE_DOMAIN=$(IBI_DOMAIN) \
NET_NAME=$(NET_NAME) \
HOST_NAME=$(IBI_VM_NAME) \
HOST_MAC=$(IBI_VM_MAC) \
ibi/host-net-config.sh
.PHONY: ibi-vm
ibi-vm: ## Provision IBI VM
@-mkdir -p $(HOME)/.kcli
$(kcli) create vm \
-P iso="$(IBI_RHCOS_ISO_PATH)" \
-P memory=$(IBI_VM_MEMORY) \
-P numcpus=$(IBI_VM_CPUS) \
-P disks=['{"size": $(IBI_DISK_SIZE), "pool": "$(LIBVIRT_POOL)"}'] \
-P nets=['{"name": "$(NET_NAME)", "mac": "$(IBI_VM_MAC)"}'] \
$(IBI_VM_NAME)
@echo "Waiting for VM to get IP address"
sleep 5
$(MAKE) host-net-config
.PHONY: vm-clean
ibi-vm-clean: ## Delete VM
-@$(kcli) delete vm -y $(IBI_VM_NAME)
.PHONY: logs
ibi-logs: ## Show logs of the IBI installation process
echo "Waiting for $(IBI_VM_NAME) to be accessible"
@until ssh $(SSH_FLAGS) core@$(IBI_VM_NAME) true; do sleep 5; echo -n .; done; echo
ssh $(SSH_FLAGS) core@$(IBI_VM_NAME) sudo journalctl -flu install-rhcos-and-restore-seed.service
.PHONY: ibi-certs
ibi-certs:
@echo "Generating new certificates"
rm -rf ./ibi-certs ./kubeconfig.ibi
./ibi/generate_certs.sh $(IBI_CLUSTER_NAME) $(IBI_DOMAIN)
.PHONY: $(IBI_CLUSTER_CONFIG_PATH)
$(IBI_CLUSTER_CONFIG_PATH): ibi-certs
mkdir -p $(shell dirname $(IBI_CLUSTER_CONFIG_PATH))
rm -rf $@
NODE_IP=$(shell virsh domifaddr ${IBI_VM_NAME} | grep ipv4 | awk -F " " '{print $$4}' | cut -d'/' -f1) \
CLUSTER_ID=$(shell uuidgen) \
VM_NAME=$(IBI_VM_NAME) \
SEED_VERSION=$(SEED_VERSION) \
CLUSTER_NAME=$(IBI_CLUSTER_NAME) \
DOMAIN=$(IBI_DOMAIN) \
HOSTNAME=$(IBI_HOSTNAME) \
LOCALHOST_SIGNER_PRIVATE_KEY="$(shell awk 'NF {sub(/\r/, ""); printf "%s\\n",$$0;}' ibi-certs/localhost-serving-signer-key.pem)" \
SERVICE_NETWORK_SIGNER_PRIVATE_KEY="$(shell awk 'NF {sub(/\r/, ""); printf "%s\\n",$$0;}' ibi-certs/service-network-serving-signer-key.pem)" \
LOADBALANCER_SIGNER_PRIVATE_KEY="$(shell awk 'NF {sub(/\r/, ""); printf "%s\\n",$$0;}' ibi-certs/loadbalancer-serving-signer-key.pem)" \
ADMIN_CA_CERT="$(shell awk 'NF {sub(/\r/, ""); printf "%s\\n",$$0;}' ibi-certs/admin-kubeconfig-signer.crt)" \
INGRESS_CA_KEY="$(shell awk 'NF {sub(/\r/, ""); printf "%s\\n",$$0;}' ibi-certs/ingresskey-ingress-operator-key.pem)" \
envsubst < $(IBI_CLUSTER_CONFIG_TEMPLATE) > $@
.PHONY: $(IBI_CLUSTER_CONFIG_MANIFESTS)
$(IBI_CLUSTER_CONFIG_MANIFESTS):
mkdir -p $(IBI_CLUSTER_CONFIG_MANIFESTS)
.PHONY: ibi-config
ibi-config: $(IBI_CLUSTER_CONFIG_PATH) $(IBI_CLUSTER_CONFIG_MANIFESTS)
.PHONY: ibi-config.iso
ibi-config.iso: ibi-config ## Create ibi-config.iso
mkisofs -o $@ -R -V "cluster-config" $(IBI_CONFIG_DIR)
cp $@ $(LIBVIRT_IMAGE_PATH)
.PHONY: ibi-attach-config.iso
ibi-attach-config.iso: ## Attach ibi-config.iso file to IBI VM
virsh change-media $(IBI_VM_NAME) hdc $(LIBVIRT_IMAGE_PATH)/ibi-config.iso
.PHONY: ibi-reboot
ibi-reboot: ## Reboot ibi VM
virsh reboot $(IBI_VM_NAME)
# Delete generated files
.PHONY: ibi-clean
ibi-clean: ibi-vm-clean
rm -fr credentials ibi-certs ibi-config/certs ibi-config.iso ibi-config/cluster-configuration/manifest.json kubeconfig.ibi ibi-ignition.json rhcos-ibi.iso rhcos-live.x86_64.iso
# So vim treats this file as a makefile
# vim: set filetype=make: