Skip to content

Commit bacf996

Browse files
authored
Add proxy configuration to the generated install-config.yaml (#1341)
1 parent 83f0f4e commit bacf996

11 files changed

+101
-21
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ metallb/frr/
1414
assets/templates/99_master-chronyd-redhat.yaml
1515
assets/templates/99_worker-chronyd-redhat.yaml
1616

17-
pull_secret.json
17+
pull_secret.json

02_configure_host.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ if [[ ! -z "${MIRROR_IMAGES}" || $(env | grep "_LOCAL_IMAGE=") || ! -z "${ENABL
5454
setup_local_registry
5555
fi
5656

57+
# Configure a local proxy to be used for the installation
58+
if [[ ! -z "${INSTALLER_PROXY}" ]]; then
59+
generate_proxy_conf > ${WORKING_DIR}/squid.conf
60+
61+
sudo podman run -d --rm \
62+
--net host \
63+
--volume ${WORKING_DIR}/squid.conf:/etc/squid/squid.conf \
64+
--name ds-squid \
65+
--dns 127.0.0.1 \
66+
quay.io/sameersbn/squid:latest
67+
fi
68+
5769
sudo systemctl enable --now firewalld
5870

5971
# Configure an NTP server for use by the cluster, this is especially
@@ -191,7 +203,7 @@ ANSIBLE_FORCE_COLOR=true ansible-playbook \
191203
-e "{use_firewalld: True}" \
192204
-e "provisioning_interface=$PROVISIONING_NETWORK_NAME" \
193205
-e "baremetal_interface=$BAREMETAL_NETWORK_NAME" \
194-
-e "{provisioning_host_ports: [80, ${LOCAL_REGISTRY_PORT}, 8000]}" \
206+
-e "{provisioning_host_ports: [80, ${LOCAL_REGISTRY_PORT}, 8000, ${INSTALLER_PROXY_PORT}]}" \
195207
-e "vbmc_port_range=$VBMC_BASE_PORT:$VBMC_MAX_PORT" \
196208
-i ${VM_SETUP_PATH}/inventory.ini \
197209
-b -vvv ${VM_SETUP_PATH}/firewall.yml

06_create_cluster.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ source validation.sh
1212

1313
early_deploy_validation
1414

15+
if [[ ! -z "$INSTALLER_PROXY" ]]; then
16+
export HTTP_PROXY=${HTTP_PROXY}
17+
export HTTPS_PROXY=${HTTPS_PROXY}
18+
export NO_PROXY=${NO_PROXY}
19+
fi
20+
1521
# Call openshift-installer to deploy the bootstrap node and masters
1622
create_cluster ${OCP_DIR}
1723

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: default all requirements configure ironic ocp_run install_config clean ocp_cleanup ironic_cleanup host_cleanup cache_cleanup registry_cleanup workingdir_cleanup podman_cleanup bell
1+
.PHONY: default all requirements configure ironic ocp_run install_config clean ocp_cleanup ironic_cleanup host_cleanup cache_cleanup registry_cleanup proxy_cleanup workingdir_cleanup podman_cleanup bell
22
default: requirements configure build_installer ironic install_config ocp_run bell
33

44
all: default
@@ -29,7 +29,7 @@ ocp_run:
2929
gather:
3030
./must_gather.sh
3131

32-
clean: ocp_cleanup ironic_cleanup host_cleanup assisted_deployment_cleanup
32+
clean: ocp_cleanup ironic_cleanup proxy_cleanup host_cleanup assisted_deployment_cleanup
3333

3434
assisted_deployment_cleanup:
3535
./assisted_deployment.sh delete_all
@@ -57,6 +57,9 @@ workingdir_cleanup:
5757
podman_cleanup:
5858
./podman_cleanup.sh
5959

60+
proxy_cleanup:
61+
./proxy_cleanup.sh
62+
6063
bell:
6164
@echo "Done!" $$'\a'
6265

common.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export SSH_PUB_KEY="${SSH_PUB_KEY:-$(cat $HOME/.ssh/id_rsa.pub)}"
6969
# mirror images for installation in restricted network
7070
export MIRROR_IMAGES=${MIRROR_IMAGES:-}
7171

72+
# Setup up a local proxy for installation
73+
export INSTALLER_PROXY=${INSTALLER_PROXY:-}
74+
export INSTALLER_PROXY_PORT=${INSTALLER_PROXY_PORT:-8215}
75+
7276
# Hypervisor details
7377
export REMOTE_LIBVIRT=${REMOTE_LIBVIRT:-0}
7478
export PROVISIONING_HOST_USER=${PROVISIONING_HOST_USER:-$USER}

config_example.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ set -x
272272
# been configured.
273273
# export ADDITIONAL_TRUST_BUNDLE=/path/to/ca_file
274274

275+
# Configures the installer to use a proxy running on the local host
276+
# and blocks all outgoing traffic
277+
# export INSTALLER_PROXY=true
278+
275279
##
276280
## Assisted Deployment
277281
##

network.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ function nth_ip() {
77
python -c "from ansible_collections.ansible.netcommon.plugins.filter import ipaddr; print(ipaddr.nthhost('"$network"', $idx))"
88
}
99

10+
function ipversion(){
11+
if [[ $1 =~ : ]] ; then
12+
echo 6
13+
exit
14+
fi
15+
echo 4
16+
}
17+
18+
function wrap_if_ipv6(){
19+
if [ $(ipversion $1) == 6 ] ; then
20+
echo "[$1]"
21+
exit
22+
fi
23+
echo "$1"
24+
}
1025

1126
export IP_STACK=${IP_STACK:-"v6"}
1227
export HOST_IP_STACK=${HOST_IP_STACK:-${IP_STACK}}
@@ -151,3 +166,19 @@ else
151166
export BOOTSTRAP_PROVISIONING_IP=${BOOTSTRAP_PROVISIONING_IP:-$(nth_ip $PROVISIONING_NETWORK 2)}
152167
export CLUSTER_PROVISIONING_IP=${CLUSTER_PROVISIONING_IP:-$(nth_ip $PROVISIONING_NETWORK 3)}
153168
fi
169+
170+
# Proxy related configuration
171+
if [[ ! -z "$INSTALLER_PROXY" ]]; then
172+
export EXT_SUBNET=${EXTERNAL_SUBNET_V6}
173+
if [[ "$IP_STACK" = "v4" ]]; then
174+
EXT_SUBNET=${EXTERNAL_SUBNET_V4}
175+
fi
176+
177+
HTTP_PROXY=http://$(wrap_if_ipv6 ${PROVISIONING_HOST_EXTERNAL_IP}):${INSTALLER_PROXY_PORT}
178+
HTTPS_PROXY=http://$(wrap_if_ipv6 ${PROVISIONING_HOST_EXTERNAL_IP}):${INSTALLER_PROXY_PORT}
179+
NO_PROXY=${PROVISIONING_NETWORK},9999,${EXT_SUBNET}
180+
181+
if [[ "$PROVISIONING_NETWORK_PROFILE" == "Disabled" ]]; then
182+
NO_PROXY=${EXT_SUBNET},9999
183+
fi
184+
fi

ocp_install_env.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,16 @@ sshKey: |
270270
fips: ${FIPS_MODE:-false}
271271
EOF
272272

273+
if [[ ! -z "$INSTALLER_PROXY" ]]; then
274+
275+
cat >> "${outdir}/install-config.yaml" << EOF
276+
proxy:
277+
httpProxy: ${HTTP_PROXY}
278+
httpsProxy: ${HTTPS_PROXY}
279+
noProxy: ${NO_PROXY}
280+
EOF
281+
fi
282+
273283
cp "${outdir}/install-config.yaml" "${outdir}/install-config.yaml.save"
274284
}
275285

proxy_cleanup.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -x
4+
5+
source logging.sh
6+
source common.sh
7+
source validation.sh
8+
9+
early_cleanup_validation
10+
11+
sudo podman kill ds-squid || true

utils.sh

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,22 +165,6 @@ function create_cluster() {
165165
$OPENSHIFT_INSTALLER --dir "${assets_dir}" --log-level=debug create cluster 2>&1 | grep --line-buffered -v 'password\|X-Auth-Token\|UserData:'
166166
}
167167

168-
function ipversion(){
169-
if [[ $1 =~ : ]] ; then
170-
echo 6
171-
exit
172-
fi
173-
echo 4
174-
}
175-
176-
function wrap_if_ipv6(){
177-
if [ $(ipversion $1) == 6 ] ; then
178-
echo "[$1]"
179-
exit
180-
fi
181-
echo "$1"
182-
}
183-
184168
function network_ip() {
185169
local network
186170
local rc
@@ -584,6 +568,21 @@ function wait_for_crd() {
584568
oc wait --for condition=established --timeout=60s "crd/$1" || exit 1
585569
}
586570
571+
function generate_proxy_conf() {
572+
if [[ "$PROVISIONING_NETWORK_PROFILE" != "Disabled" ]]; then
573+
echo "acl all src ${PROVISIONING_NETWORK}"
574+
fi
575+
576+
cat <<EOF
577+
acl all src ${EXT_SUBNET}
578+
http_access allow all
579+
http_port ${INSTALLER_PROXY_PORT}
580+
debug_options ALL,2
581+
dns_v4_first on
582+
coredump_dir /var/spool/squid
583+
EOF
584+
}
585+
587586
_tmpfiles=
588587
function removetmp(){
589588
[ -n "$_tmpfiles" ] && rm -rf $_tmpfiles || true

vm_setup_vars.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ provisioning_network:
5454
external_network:
5555
- name: "{{ baremetal_network_name }}"
5656
bridge: "{{ baremetal_network_name }}"
57-
forward_mode: "{{ 'bridge' if lookup('env', 'MANAGE_BR_BRIDGE') == 'n' else 'nat' }}"
57+
forward_mode: "{{ 'bridge' if lookup('env', 'MANAGE_BR_BRIDGE') == 'n' else 'nat' if not lookup('env', 'INSTALLER_PROXY') else 'route'}}"
5858
address_v4: "{{ baremetal_network_cidr_v4|nthhost(1)|default('', true) }}"
5959
netmask_v4: "{{ baremetal_network_cidr_v4|ipaddr('netmask') }}"
6060
address_v6: "{{ baremetal_network_cidr_v6|nthhost(1)|default('', true) }}"

0 commit comments

Comments
 (0)