forked from eranco74/ib-orchestrate-vm
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile.ibi
159 lines (135 loc) · 5.95 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
## Image Based Installation
IBI_VM_NAME ?= ibi
IBI_VM_IP ?= 192.168.127.74
IBI_VM_NETWORK ?= 192.168.127.0/24
IBI_VM_MAC ?= fa:ba:da:1b:11:b1
IBI_VM_RAM_MB ?= $(RAM_MB)
IBI_VM_CPUS ?= $(CPU_CORE)
IBI_DISK_SIZE ?= $(DISK_GB)
IBI_NET_NAME ?= $(NET_TARGET_NAME)
IBI_DOMAIN ?= $(NET_TARGET_DOMAIN)
IBI_CLUSTER_NAME ?= $(IBI_VM_NAME)
IBI_HOSTNAME ?= $(IBI_VM_NAME)
IBI_INSTALLATION_DISK ?= /dev/vda
IBI_WORK_DIR ?= ibi-iso-work-dir
IBI_INSTALL_CONFIG ?= $(IBI_WORK_DIR)/install-config.yaml
IBI_KUBECONFIG = $(IBI_WORK_DIR)/auth/kubeconfig
OPENSHIFT_INSTALLER_RELEASE_IMAGE ?= quay.io/openshift-release-dev/ocp-release:4.17.0-ec.3-x86_64
OPENSHIFT_INSTALLER_BIN ?= bin/openshift-install
# Used to populate releaseRegistry in imagebased-config.yaml
IBI_RELEASE_REGISTRY ?= quay.io
IBI_RELEASE_IMAGE ?= $(DEFAULT_RELEASE_IMAGE)
IBI_INSTALLATION_CONFIG_TEMPLATE = image-based-installation-config-template.yaml
IBI_CONFIG_TEMPLATE = image-based-config-template.yaml
ifdef DHCP
IBI_CONFIG_TEMPLATE = image-based-config-template-dhcp.yaml
endif
ifeq ($(PRECACHE_MODE),directory)
IBI_EXTRA_PARTITION_START ?= use_directory
else
IBI_EXTRA_PARTITION_START ?= -40G
endif
IBI_RHCOS_ISO_PATH = $(LIBVIRT_IMAGE_PATH)/rhcos-$(IBI_VM_NAME).iso
.PHONY: ibi
ibi: ibi-iso ibi-vm ibi-logs imagebasedconfig.iso ibi-attach-config.iso ibi-reboot wait-for-ibi
$(OPENSHIFT_INSTALLER_BIN): credentials/pull-secret.json
ifeq ("$(wildcard $(OPENSHIFT_INSTALLER_BIN))","") # do not run this target if the openshift-install binary is already present
oc adm release extract --registry-config=credentials/pull-secret.json --command=openshift-install --to $(dir $(OPENSHIFT_INSTALLER_BIN)) $(OPENSHIFT_INSTALLER_RELEASE_IMAGE)
endif
.PHONY: ibi-iso
ibi-iso: $(SSH_KEY_PRIV_PATH) $(OPENSHIFT_INSTALLER_BIN) credentials/pull-secret.json image-based-installation-config.yaml ## Create ISO to be used in IBI
mkdir -p $(IBI_WORK_DIR)
OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE=$(IBI_RELEASE_IMAGE) $(OPENSHIFT_INSTALLER_BIN) image-based create image --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:
-sudo rm -rf $(IBI_RHCOS_ISO_PATH) $(IBI_WORK_DIR)
# Configure dhcp and dns for host
.PHONY: host-net-config
host-net-config:
HOST_IP=$(IBI_VM_IP) \
CLUSTER_NAME=$(IBI_CLUSTER_NAME) \
BASE_DOMAIN=$(IBI_DOMAIN) \
NET_NAME=$(IBI_NET_NAME) \
HOST_NAME=$(IBI_VM_NAME) \
HOST_MAC=$(IBI_VM_MAC) \
$(SNO_DIR)/host-net-config.sh
.PHONY: ibi-vm
ibi-vm: target-network host-net-config ## Provision IBI VM
RHCOS_ISO=$(IBI_RHCOS_ISO_PATH) \
VM_NAME=$(IBI_VM_NAME) \
NET_NAME=$(IBI_NET_NAME) \
DISK_GB=$(IBI_DISK_SIZE) \
CPU_CORE=$(IBI_VM_CPUS) \
HOST_MAC=$(IBI_VM_MAC) \
RAM_MB=$(IBI_VM_RAM_MB) \
$(SNO_DIR)/virt-install-sno-iso-ign.sh
.PHONY: ibi-vm-remove
ibi-vm-remove: VM_NAME=$(IBI_VM_NAME)
ibi-vm-remove: vm-remove ## Remove IBI VM and the storage associated with it
.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_IP) true; do sleep 5; echo -n .; done; echo
ssh $(SSH_FLAGS) core@$(IBI_VM_IP) "sudo journalctl -flu install-rhcos-and-restore-seed.service | stdbuf -o0 -e0 awk '{print \$$0 } /Finished SNO Image-based Installation./ { exit }'"
.PHONY: image-based-installation-config.yaml
image-based-installation-config.yaml: $(SSH_KEY_PRIV_PATH) ## Create image-based-installation-config.yaml
$(info Creating IBI image-based-installation-config.yaml)
@mkdir -p $(IBI_WORK_DIR)
@< $(IBI_INSTALLATION_CONFIG_TEMPLATE) \
SEED_IMAGE=$(SEED_IMAGE) \
SEED_VERSION=$(SEED_VERSION) \
PULL_SECRET='$(PULL_SECRET)' \
INSTALLATION_DISK=$(IBI_INSTALLATION_DISK) \
SSH_KEY='$(shell cat $(SSH_KEY))' \
envsubst > $(IBI_WORK_DIR)/image-based-installation-config.yaml
.PHONY: ibi-install-config
ibi-install-config: $(SSH_KEY_PRIV_PATH)
$(info Creating IBI install-config.yaml)
@mkdir -p $(IBI_WORK_DIR)
@# CLUSTER_NETWORK and CLUSTER_SVC_NETWORK are ommited because they are not used (the ones from the seed image are used)
@INSTALLER_WORKDIR=../$(IBI_WORK_DIR) \
PULL_SECRET='$(PULL_SECRET)' \
SSH_KEY=$(SSH_KEY) \
INSTALLATION_DISK=$(IBI_INSTALLATION_DISK) \
CLUSTER_NAME=$(IBI_CLUSTER_NAME) \
BASE_DOMAIN=$(IBI_DOMAIN) \
MACHINE_NETWORK=$(IBI_VM_NETWORK) \
make -C $(SNO_DIR) ../$(IBI_WORK_DIR)/install-config.yaml
.PHONY: ibi-imagebased-config
ibi-imagebased-config:
$(info Creating IBI image-based-config.yaml)
@mkdir -p $(IBI_WORK_DIR)
@< $(IBI_CONFIG_TEMPLATE) \
VM_NAME=$(IBI_VM_NAME) \
HOST_IP=$(IBI_VM_IP) \
HOST_MAC=$(IBI_VM_MAC) \
HOST_ROUTE=$(shell $(virsh) net-dumpxml $(IBI_NET_NAME) | grep '<ip ' | xargs -n1 | grep address | cut -d = -f 2) \
RELEASE_REGISTRY=$(IBI_RELEASE_REGISTRY) \
envsubst > $(IBI_WORK_DIR)/image-based-config.yaml
.PHONY: imagebasedconfig.iso
imagebasedconfig.iso: RELEASE_VERSION=$(SEED_VERSION)
imagebasedconfig.iso: $(IBI_WORK_DIR)/imagebasedconfig.iso ## Create imagebasedconfig.iso using openshift-installer
.PHONY: $(IBI_WORK_DIR)/imagebasedconfig.iso
$(IBI_WORK_DIR)/imagebasedconfig.iso: RELEASE_VERSION=$(SEED_VERSION)
$(IBI_WORK_DIR)/imagebasedconfig.iso: $(OPENSHIFT_INSTALLER_BIN) ibi-install-config ibi-imagebased-config
$(OPENSHIFT_INSTALLER_BIN) image-based create config-image --dir $(IBI_WORK_DIR)
sudo cp $@ $(LIBVIRT_IMAGE_PATH)
.PHONY: ibi-attach-config.iso
ibi-attach-config.iso: ## Attach imagebasedconfig.iso file to IBI VM
$(virsh) change-media $(IBI_VM_NAME) --config sda $(LIBVIRT_IMAGE_PATH)/imagebasedconfig.iso
.PHONY: ibi-reboot
ibi-reboot: ## Reboot ibi VM
$(virsh) reboot $(IBI_VM_NAME)
.PHONY: wait-for-ibi
wait-for-ibi: SNO_KUBECONFIG=$(IBI_KUBECONFIG)
wait-for-ibi: wait-for-install-complete ## Wait for IBI cluster to be healthy
.PHONY: ibi-reboot-wait
ibi-reboot-wait: ibi-reboot wait-for-ibi
# Delete generated files
.PHONY: ibi-clean
ibi-clean: ibi-vm-remove
rm -fr credentials $(IBI_WORK_DIR)
# So vim treats this file as a makefile
# vim: set filetype=make: