forked from eranco74/bootstrap-in-place-poc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
185 lines (145 loc) · 5.96 KB
/
Makefile
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# Disable built-in rules
MAKEFLAGS += --no-builtin-rules
SNO_DIR = .
########################
# User variables
########################
checkenv:
ifndef PULL_SECRET
$(error PULL_SECRET must be defined)
endif
INSTALLATION_DISK ?= /dev/vda
RELEASE_IMAGE ?= quay.io/openshift-release-dev/ocp-release:4.8.0-fc.7-x86_64
########################
INSTALLER_WORKDIR = sno-workdir
INSTALLER_BIN = bin/openshift-install
LIVE_ISO_IGNITION_NAME = bootstrap-in-place-for-live-iso.ign
BIP_LIVE_ISO_IGNITION = $(INSTALLER_WORKDIR)/$(LIVE_ISO_IGNITION_NAME)
LIBVIRT_ISO_PATH = /var/lib/libvirt/images
INSTALLER_ISO_PATH = $(SNO_DIR)/installer-image.iso
INSTALLER_ISO_PATH_SNO = $(SNO_DIR)/installer-SNO-image.iso
INSTALLER_ISO_PATH_SNO_IN_LIBVIRT = $(LIBVIRT_ISO_PATH)/installer-SNO-image.iso
MACHINE_NETWORK ?= 192.168.126.0/24
CLUSTER_NETWORK ?= 10.128.0.0/14
CLUSTER_SVC_NETWORK ?= 172.30.0.0/16
INSTALL_CONFIG_TEMPLATE = $(SNO_DIR)/install-config.yaml.template
INSTALL_CONFIG = $(SNO_DIR)/install-config.yaml
INSTALL_CONFIG_IN_WORKDIR = $(INSTALLER_WORKDIR)/install-config.yaml
NET_CONFIG_TEMPLATE = $(SNO_DIR)/net.xml.template
NET_CONFIG = $(SNO_DIR)/net.xml
NET_NAME = test-net
VM_NAME = sno-test
VOL_NAME = $(VM_NAME).qcow2
SSH_KEY_DIR = $(SNO_DIR)/ssh-key
SSH_KEY_PUB_PATH = $(SSH_KEY_DIR)/key.pub
SSH_KEY_PRIV_PATH = $(SSH_KEY_DIR)/key
SSH_FLAGS = -o IdentityFile=$(SSH_KEY_PRIV_PATH) \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no
HOST_IP = 192.168.126.10
SSH_HOST = core@$(HOST_IP)
$(SSH_KEY_DIR):
@echo Creating SSH key dir
mkdir $@
$(SSH_KEY_PRIV_PATH): $(SSH_KEY_DIR)
@echo "No private key $@ found, generating a private-public pair"
# -N "" means no password
ssh-keygen -f $@ -N ""
chmod 400 $@
$(SSH_KEY_PUB_PATH): $(SSH_KEY_PRIV_PATH)
.PHONY: gather checkenv clean destroy-libvirt start-iso network ssh
# $(INSTALL_CONFIG) is also PHONY to force the makefile to regenerate it with new env vars
.PHONY: $(INSTALL_CONFIG)
# $(INSTALLER_WORKDIR) is also PHONY because "installer create single-node-ignition-config" doesn't regenerate
# if some of the files in the folder already exist
.PHONY: $(INSTALLER_WORKDIR)
.SILENT: destroy-libvirt
clean: destroy-libvirt
rm -rf $(INSTALLER_WORKDIR)
rm -rf registry-config.json
$(SNO_DIR)/bm-dell-clean.sh || true
destroy-libvirt:
echo "Destroying previous libvirt resources"
NET_NAME=$(NET_NAME) \
VM_NAME=$(VM_NAME) \
VOL_NAME=$(VOL_NAME) \
$(SNO_DIR)/virt-delete-sno.sh || true
# Render the install config from the template with the correct pull secret and SSH key
$(INSTALL_CONFIG): $(INSTALL_CONFIG_TEMPLATE) checkenv $(SSH_KEY_PUB_PATH)
sed -e 's/YOUR_PULL_SECRET/$(PULL_SECRET)/' \
-e 's|YOUR_SSH_KEY|$(shell cat $(SSH_KEY_PUB_PATH))|' \
-e 's|INSTALLATION_DISK|$(INSTALLATION_DISK)|' \
-e 's|CLUSTER_NETWORK|$(CLUSTER_NETWORK)|' \
-e 's|MACHINE_NETWORK|$(MACHINE_NETWORK)|' \
-e 's|CLUSTER_SVC_NETWORK|$(CLUSTER_SVC_NETWORK)|' \
$(INSTALL_CONFIG_TEMPLATE) > $(INSTALL_CONFIG)
# Render the libvirt net config file with the network name and host IP
$(NET_CONFIG): $(NET_CONFIG_TEMPLATE)
sed -e 's/REPLACE_NET_NAME/$(NET_NAME)/' \
-e 's/REPLACE_HOST_IP/$(HOST_IP)/' \
$(NET_CONFIG_TEMPLATE) > $@
network: destroy-libvirt $(NET_CONFIG)
NET_XML=$(NET_CONFIG) $(SNO_DIR)/virt-create-net.sh
# Create a working directory for the openshift-installer `--dir` parameter
$(INSTALLER_WORKDIR):
@echo Overwriting previous working directory $@
rm -rf $@
mkdir $@
# The openshift-installer expects the install config file to be in its working directory
$(INSTALL_CONFIG_IN_WORKDIR): $(INSTALLER_WORKDIR) $(INSTALL_CONFIG)
cp $(INSTALL_CONFIG) $@
# Original CoreOS ISO
$(INSTALLER_ISO_PATH):
$(SNO_DIR)/download_live_iso.sh $@
# Get the openshift-installer from the release image
$(INSTALLER_BIN): registry-config.json
oc adm release extract --registry-config=registry-config.json --command=openshift-install --to ./bin $(RELEASE_IMAGE)
.PHONY: registry-config.json
registry-config.json:
jq -n '$(PULL_SECRET)' > registry-config.json
# Allow user to define custom manifests in ./manifests/*.yaml
$(INSTALLER_WORKDIR)/manifests: $(INSTALL_CONFIG_IN_WORKDIR) $(INSTALLER_BIN) $(SNO_DIR)/manifests
RELEASE_IMAGE=$(RELEASE_IMAGE) \
INSTALLER_BIN=$(INSTALLER_BIN) \
INSTALLER_WORKDIR=$(INSTALLER_WORKDIR) \
$(SNO_DIR)/manifests.sh
@echo Copying user manifests...
$(shell echo 'cp -v $(SNO_DIR)/manifests/*.yaml $(INSTALLER_WORKDIR)/manifests/ || true')
# Use the openshift-installer to generate BiP Live ISO ignition file
$(BIP_LIVE_ISO_IGNITION): $(INSTALLER_WORKDIR)/manifests
RELEASE_IMAGE=$(RELEASE_IMAGE) \
INSTALLER_BIN=$(INSTALLER_BIN) \
INSTALLER_WORKDIR=$(INSTALLER_WORKDIR) \
$(SNO_DIR)/generate.sh
# Embed the ignition file in the CoreOS ISO
$(INSTALLER_ISO_PATH_SNO): $(BIP_LIVE_ISO_IGNITION) $(INSTALLER_ISO_PATH)
# openshift-install will not overwrite existing ISOs, so we delete it beforehand
rm -f $@
ISO_PATH=$(INSTALLER_ISO_PATH) \
IGNITION_PATH=$(BIP_LIVE_ISO_IGNITION) \
OUTPUT_PATH=$@ \
$(SNO_DIR)/embed.sh
$(INSTALLER_ISO_PATH_SNO_IN_LIBVIRT): $(INSTALLER_ISO_PATH_SNO)
sudo cp $< $@
sudo chown qemu:qemu $@
# Destroy previously created VMs/Networks and create a VM/Network with an ISO containing the BiP embedded ignition file
start-iso: $(INSTALLER_ISO_PATH_SNO_IN_LIBVIRT) network
RHCOS_ISO=$(INSTALLER_ISO_PATH_SNO_IN_LIBVIRT) \
VM_NAME=$(VM_NAME) \
NET_NAME=$(NET_NAME) \
$(SNO_DIR)/virt-install-sno-iso-ign.sh
ssh: $(SSH_KEY_PRIV_PATH)
ssh $(SSH_FLAGS) $(SSH_HOST)
dump_ignition:
@[ ! -f $(BIP_LIVE_ISO_IGNITION) ] && echo $(BIP_LIVE_ISO_IGNITION) does not exist && exit 1 || true
@echo Dumping ignition into ./ign-root/
rm -rf ./ign-root/
python3 $(SNO_DIR)/ignition_dump.py $(BIP_LIVE_ISO_IGNITION)
gather:
@echo Gathering logs...
@echo If this fails, try killing running SSH agent instances. Installer will prefer those \
over your explicitly provided key file
$(INSTALLER_BIN) gather bootstrap \
--bootstrap $(HOST_IP) \
--master $(HOST_IP) \
--key $(SSH_KEY_PRIV_PATH)