|
@@ -2,36 +2,38 @@
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
-# Create SSH key for GCE
|
|
|
-if [ ! -f "{{ gce_ssh_private_key }}" ]; then
|
|
|
- ssh-keygen -t rsa -f "{{ gce_ssh_private_key }}" -C gce-provision-cloud-user -N ''
|
|
|
- ssh-add "{{ gce_ssh_private_key }}" || true
|
|
|
-fi
|
|
|
+if [[ -n "{{ openshift_gcp_ssh_private_key }}" ]]; then
|
|
|
+ # Create SSH key for GCE
|
|
|
+ if [ ! -f "{{ openshift_gcp_ssh_private_key }}" ]; then
|
|
|
+ ssh-keygen -t rsa -f "{{ openshift_gcp_ssh_private_key }}" -C gce-provision-cloud-user -N ''
|
|
|
+ ssh-add "{{ openshift_gcp_ssh_private_key }}" || true
|
|
|
+ fi
|
|
|
|
|
|
-# Check if the ~/.ssh/google_compute_engine.pub key is in the project metadata, and if not, add it there
|
|
|
-pub_key=$(cut -d ' ' -f 2 < "{{ gce_ssh_private_key }}.pub")
|
|
|
-key_tmp_file='/tmp/ocp-gce-keys'
|
|
|
-if ! gcloud --project "{{ gce_project_id }}" compute project-info describe | grep -q "$pub_key"; then
|
|
|
- if gcloud --project "{{ gce_project_id }}" compute project-info describe | grep -q ssh-rsa; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute project-info describe | grep ssh-rsa | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/value: //' > "$key_tmp_file"
|
|
|
+ # Check if the ~/.ssh/google_compute_engine.pub key is in the project metadata, and if not, add it there
|
|
|
+ pub_key=$(cut -d ' ' -f 2 < "{{ openshift_gcp_ssh_private_key }}.pub")
|
|
|
+ key_tmp_file='/tmp/ocp-gce-keys'
|
|
|
+ if ! gcloud --project "{{ openshift_gcp_project }}" compute project-info describe | grep -q "$pub_key"; then
|
|
|
+ if gcloud --project "{{ openshift_gcp_project }}" compute project-info describe | grep -q ssh-rsa; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute project-info describe | grep ssh-rsa | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/value: //' > "$key_tmp_file"
|
|
|
+ fi
|
|
|
+ echo -n 'cloud-user:' >> "$key_tmp_file"
|
|
|
+ cat "{{ openshift_gcp_ssh_private_key }}.pub" >> "$key_tmp_file"
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute project-info add-metadata --metadata-from-file "sshKeys=${key_tmp_file}"
|
|
|
+ rm -f "$key_tmp_file"
|
|
|
fi
|
|
|
- echo -n 'cloud-user:' >> "$key_tmp_file"
|
|
|
- cat "{{ gce_ssh_private_key }}.pub" >> "$key_tmp_file"
|
|
|
- gcloud --project "{{ gce_project_id }}" compute project-info add-metadata --metadata-from-file "sshKeys=${key_tmp_file}"
|
|
|
- rm -f "$key_tmp_file"
|
|
|
fi
|
|
|
|
|
|
metadata=""
|
|
|
-if [[ -n "{{ provision_gce_startup_script_file }}" ]]; then
|
|
|
- if [[ ! -f "{{ provision_gce_startup_script_file }}" ]]; then
|
|
|
- echo "Startup script file missing at {{ provision_gce_startup_script_file }} from=$(pwd)"
|
|
|
+if [[ -n "{{ openshift_gcp_startup_script_file }}" ]]; then
|
|
|
+ if [[ ! -f "{{ openshift_gcp_startup_script_file }}" ]]; then
|
|
|
+ echo "Startup script file missing at {{ openshift_gcp_startup_script_file }} from=$(pwd)"
|
|
|
exit 1
|
|
|
fi
|
|
|
- metadata+="--metadata-from-file=startup-script={{ provision_gce_startup_script_file }}"
|
|
|
+ metadata+="--metadata-from-file=startup-script={{ openshift_gcp_startup_script_file }}"
|
|
|
fi
|
|
|
-if [[ -n "{{ provision_gce_user_data_file }}" ]]; then
|
|
|
- if [[ ! -f "{{ provision_gce_user_data_file }}" ]]; then
|
|
|
- echo "User data file missing at {{ provision_gce_user_data_file }}"
|
|
|
+if [[ -n "{{ openshift_gcp_user_data_file }}" ]]; then
|
|
|
+ if [[ ! -f "{{ openshift_gcp_user_data_file }}" ]]; then
|
|
|
+ echo "User data file missing at {{ openshift_gcp_user_data_file }}"
|
|
|
exit 1
|
|
|
fi
|
|
|
if [[ -n "${metadata}" ]]; then
|
|
@@ -39,14 +41,14 @@ if [[ -n "{{ provision_gce_user_data_file }}" ]]; then
|
|
|
else
|
|
|
metadata="--metadata-from-file="
|
|
|
fi
|
|
|
- metadata+="user-data={{ provision_gce_user_data_file }}"
|
|
|
+ metadata+="user-data={{ openshift_gcp_user_data_file }}"
|
|
|
fi
|
|
|
|
|
|
# Select image or image family
|
|
|
-image="{{ provision_gce_registered_image }}"
|
|
|
-if ! gcloud --project "{{ gce_project_id }}" compute images describe "${image}" &>/dev/null; then
|
|
|
- if ! gcloud --project "{{ gce_project_id }}" compute images describe-from-family "${image}" &>/dev/null; then
|
|
|
- echo "No compute image or image-family found, create an image named '{{ provision_gce_registered_image }}' to continue'"
|
|
|
+image="{{ openshift_gcp_image }}"
|
|
|
+if ! gcloud --project "{{ openshift_gcp_project }}" compute images describe "${image}" &>/dev/null; then
|
|
|
+ if ! gcloud --project "{{ openshift_gcp_project }}" compute images describe-from-family "${image}" &>/dev/null; then
|
|
|
+ echo "No compute image or image-family found, create an image named '{{ openshift_gcp_image }}' to continue'"
|
|
|
exit 1
|
|
|
fi
|
|
|
image="family/${image}"
|
|
@@ -54,19 +56,19 @@ fi
|
|
|
|
|
|
### PROVISION THE INFRASTRUCTURE ###
|
|
|
|
|
|
-dns_zone="{{ dns_managed_zone | default(provision_prefix + 'managed-zone') }}"
|
|
|
+dns_zone="{{ dns_managed_zone | default(openshift_gcp_prefix + 'managed-zone') }}"
|
|
|
|
|
|
# Check the DNS managed zone in Google Cloud DNS, create it if it doesn't exist and exit after printing NS servers
|
|
|
-if ! gcloud --project "{{ gce_project_id }}" dns managed-zones describe "${dns_zone}" &>/dev/null; then
|
|
|
+if ! gcloud --project "{{ openshift_gcp_project }}" dns managed-zones describe "${dns_zone}" &>/dev/null; then
|
|
|
echo "DNS zone '${dns_zone}' doesn't exist. Must be configured prior to running this script"
|
|
|
exit 1
|
|
|
fi
|
|
|
|
|
|
# Create network
|
|
|
-if ! gcloud --project "{{ gce_project_id }}" compute networks describe "{{ gce_network_name }}" &>/dev/null; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute networks create "{{ gce_network_name }}" --mode "auto"
|
|
|
+if ! gcloud --project "{{ openshift_gcp_project }}" compute networks describe "{{ openshift_gcp_network_name }}" &>/dev/null; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute networks create "{{ openshift_gcp_network_name }}" --mode "auto"
|
|
|
else
|
|
|
- echo "Network '{{ gce_network_name }}' already exists"
|
|
|
+ echo "Network '{{ openshift_gcp_network_name }}' already exists"
|
|
|
fi
|
|
|
|
|
|
# Firewall rules in a form:
|
|
@@ -87,56 +89,56 @@ declare -A FW_RULES=(
|
|
|
['infra-node-external']="--allow tcp:80,tcp:443,tcp:1936${range} --target-tags ocp-infra-node"
|
|
|
)
|
|
|
for rule in "${!FW_RULES[@]}"; do
|
|
|
- ( if ! gcloud --project "{{ gce_project_id }}" compute firewall-rules describe "{{ provision_prefix }}$rule" &>/dev/null; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute firewall-rules create "{{ provision_prefix }}$rule" --network "{{ gce_network_name }}" ${FW_RULES[$rule]}
|
|
|
+ ( if ! gcloud --project "{{ openshift_gcp_project }}" compute firewall-rules describe "{{ openshift_gcp_prefix }}$rule" &>/dev/null; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute firewall-rules create "{{ openshift_gcp_prefix }}$rule" --network "{{ openshift_gcp_network_name }}" ${FW_RULES[$rule]}
|
|
|
else
|
|
|
- echo "Firewall rule '{{ provision_prefix }}${rule}' already exists"
|
|
|
+ echo "Firewall rule '{{ openshift_gcp_prefix }}${rule}' already exists"
|
|
|
fi ) &
|
|
|
done
|
|
|
|
|
|
|
|
|
# Master IP
|
|
|
-( if ! gcloud --project "{{ gce_project_id }}" compute addresses describe "{{ provision_prefix }}master-ssl-lb-ip" --global &>/dev/null; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute addresses create "{{ provision_prefix }}master-ssl-lb-ip" --global
|
|
|
+( if ! gcloud --project "{{ openshift_gcp_project }}" compute addresses describe "{{ openshift_gcp_prefix }}master-ssl-lb-ip" --global &>/dev/null; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute addresses create "{{ openshift_gcp_prefix }}master-ssl-lb-ip" --global
|
|
|
else
|
|
|
- echo "IP '{{ provision_prefix }}master-ssl-lb-ip' already exists"
|
|
|
+ echo "IP '{{ openshift_gcp_prefix }}master-ssl-lb-ip' already exists"
|
|
|
fi ) &
|
|
|
|
|
|
# Internal master IP
|
|
|
-( if ! gcloud --project "{{ gce_project_id }}" compute addresses describe "{{ provision_prefix }}master-network-lb-ip" --region "{{ gce_region_name }}" &>/dev/null; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute addresses create "{{ provision_prefix }}master-network-lb-ip" --region "{{ gce_region_name }}"
|
|
|
+( if ! gcloud --project "{{ openshift_gcp_project }}" compute addresses describe "{{ openshift_gcp_prefix }}master-network-lb-ip" --region "{{ openshift_gcp_region }}" &>/dev/null; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute addresses create "{{ openshift_gcp_prefix }}master-network-lb-ip" --region "{{ openshift_gcp_region }}"
|
|
|
else
|
|
|
- echo "IP '{{ provision_prefix }}master-network-lb-ip' already exists"
|
|
|
+ echo "IP '{{ openshift_gcp_prefix }}master-network-lb-ip' already exists"
|
|
|
fi ) &
|
|
|
|
|
|
# Router IP
|
|
|
-( if ! gcloud --project "{{ gce_project_id }}" compute addresses describe "{{ provision_prefix }}router-network-lb-ip" --region "{{ gce_region_name }}" &>/dev/null; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute addresses create "{{ provision_prefix }}router-network-lb-ip" --region "{{ gce_region_name }}"
|
|
|
+( if ! gcloud --project "{{ openshift_gcp_project }}" compute addresses describe "{{ openshift_gcp_prefix }}router-network-lb-ip" --region "{{ openshift_gcp_region }}" &>/dev/null; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute addresses create "{{ openshift_gcp_prefix }}router-network-lb-ip" --region "{{ openshift_gcp_region }}"
|
|
|
else
|
|
|
- echo "IP '{{ provision_prefix }}router-network-lb-ip' already exists"
|
|
|
+ echo "IP '{{ openshift_gcp_prefix }}router-network-lb-ip' already exists"
|
|
|
fi ) &
|
|
|
|
|
|
|
|
|
-{% for node_group in provision_gce_node_groups %}
|
|
|
+{% for node_group in openshift_gcp_node_group_config %}
|
|
|
# configure {{ node_group.name }}
|
|
|
(
|
|
|
- if ! gcloud --project "{{ gce_project_id }}" compute instance-templates describe "{{ provision_prefix }}instance-template-{{ node_group.name }}" &>/dev/null; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute instance-templates create "{{ provision_prefix }}instance-template-{{ node_group.name }}" \
|
|
|
- --machine-type "{{ node_group.machine_type }}" --network "{{ gce_network_name }}" \
|
|
|
- --tags "{{ provision_prefix }}ocp,ocp,{{ node_group.tags }}" \
|
|
|
+ if ! gcloud --project "{{ openshift_gcp_project }}" compute instance-templates describe "{{ openshift_gcp_prefix }}instance-template-{{ node_group.name }}" &>/dev/null; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute instance-templates create "{{ openshift_gcp_prefix }}instance-template-{{ node_group.name }}" \
|
|
|
+ --machine-type "{{ node_group.machine_type }}" --network "{{ openshift_gcp_network_name }}" \
|
|
|
+ --tags "{{ openshift_gcp_prefix }}ocp,ocp,{{ node_group.tags }}" \
|
|
|
--boot-disk-size "{{ node_group.boot_disk_size }}" --boot-disk-type "pd-ssd" \
|
|
|
--scopes "logging-write,monitoring-write,useraccounts-ro,service-control,service-management,storage-ro,compute-rw" \
|
|
|
--image "${image}" ${metadata}
|
|
|
else
|
|
|
- echo "Instance template '{{ provision_prefix }}instance-template-{{ node_group.name }}' already exists"
|
|
|
+ echo "Instance template '{{ openshift_gcp_prefix }}instance-template-{{ node_group.name }}' already exists"
|
|
|
fi
|
|
|
|
|
|
# Create instance group
|
|
|
- if ! gcloud --project "{{ gce_project_id }}" compute instance-groups managed describe "{{ provision_prefix }}ig-{{ node_group.suffix }}" --zone "{{ gce_zone_name }}" &>/dev/null; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute instance-groups managed create "{{ provision_prefix }}ig-{{ node_group.suffix }}" \
|
|
|
- --zone "{{ gce_zone_name }}" --template "{{ provision_prefix }}instance-template-{{ node_group.name }}" --size "{{ node_group.scale }}"
|
|
|
+ if ! gcloud --project "{{ openshift_gcp_project }}" compute instance-groups managed describe "{{ openshift_gcp_prefix }}ig-{{ node_group.suffix }}" --zone "{{ openshift_gcp_zone }}" &>/dev/null; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute instance-groups managed create "{{ openshift_gcp_prefix }}ig-{{ node_group.suffix }}" \
|
|
|
+ --zone "{{ openshift_gcp_zone }}" --template "{{ openshift_gcp_prefix }}instance-template-{{ node_group.name }}" --size "{{ node_group.scale }}"
|
|
|
else
|
|
|
- echo "Instance group '{{ provision_prefix }}ig-{{ node_group.suffix }}' already exists"
|
|
|
+ echo "Instance group '{{ openshift_gcp_prefix }}ig-{{ node_group.suffix }}' already exists"
|
|
|
fi
|
|
|
) &
|
|
|
{% endfor %}
|
|
@@ -147,36 +149,36 @@ for i in `jobs -p`; do wait $i; done
|
|
|
# Configure the master external LB rules
|
|
|
(
|
|
|
# Master health check
|
|
|
-if ! gcloud --project "{{ gce_project_id }}" compute health-checks describe "{{ provision_prefix }}master-ssl-lb-health-check" &>/dev/null; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute health-checks create https "{{ provision_prefix }}master-ssl-lb-health-check" --port "{{ internal_console_port }}" --request-path "/healthz"
|
|
|
+if ! gcloud --project "{{ openshift_gcp_project }}" compute health-checks describe "{{ openshift_gcp_prefix }}master-ssl-lb-health-check" &>/dev/null; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute health-checks create https "{{ openshift_gcp_prefix }}master-ssl-lb-health-check" --port "{{ internal_console_port }}" --request-path "/healthz"
|
|
|
else
|
|
|
- echo "Health check '{{ provision_prefix }}master-ssl-lb-health-check' already exists"
|
|
|
+ echo "Health check '{{ openshift_gcp_prefix }}master-ssl-lb-health-check' already exists"
|
|
|
fi
|
|
|
|
|
|
-gcloud --project "{{ gce_project_id }}" compute instance-groups managed set-named-ports "{{ provision_prefix }}ig-m" \
|
|
|
- --zone "{{ gce_zone_name }}" --named-ports "{{ provision_prefix }}port-name-master:{{ internal_console_port }}"
|
|
|
+gcloud --project "{{ openshift_gcp_project }}" compute instance-groups managed set-named-ports "{{ openshift_gcp_prefix }}ig-m" \
|
|
|
+ --zone "{{ openshift_gcp_zone }}" --named-ports "{{ openshift_gcp_prefix }}port-name-master:{{ internal_console_port }}"
|
|
|
|
|
|
# Master backend service
|
|
|
-if ! gcloud --project "{{ gce_project_id }}" compute backend-services describe "{{ provision_prefix }}master-ssl-lb-backend" --global &>/dev/null; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute backend-services create "{{ provision_prefix }}master-ssl-lb-backend" --health-checks "{{ provision_prefix }}master-ssl-lb-health-check" --port-name "{{ provision_prefix }}port-name-master" --protocol "TCP" --global --timeout="{{ provision_gce_master_https_timeout | default('2m') }}"
|
|
|
- gcloud --project "{{ gce_project_id }}" compute backend-services add-backend "{{ provision_prefix }}master-ssl-lb-backend" --instance-group "{{ provision_prefix }}ig-m" --global --instance-group-zone "{{ gce_zone_name }}"
|
|
|
+if ! gcloud --project "{{ openshift_gcp_project }}" compute backend-services describe "{{ openshift_gcp_prefix }}master-ssl-lb-backend" --global &>/dev/null; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute backend-services create "{{ openshift_gcp_prefix }}master-ssl-lb-backend" --health-checks "{{ openshift_gcp_prefix }}master-ssl-lb-health-check" --port-name "{{ openshift_gcp_prefix }}port-name-master" --protocol "TCP" --global --timeout="{{ openshift_gcp_master_lb_timeout }}"
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute backend-services add-backend "{{ openshift_gcp_prefix }}master-ssl-lb-backend" --instance-group "{{ openshift_gcp_prefix }}ig-m" --global --instance-group-zone "{{ openshift_gcp_zone }}"
|
|
|
else
|
|
|
- echo "Backend service '{{ provision_prefix }}master-ssl-lb-backend' already exists"
|
|
|
+ echo "Backend service '{{ openshift_gcp_prefix }}master-ssl-lb-backend' already exists"
|
|
|
fi
|
|
|
|
|
|
# Master tcp proxy target
|
|
|
-if ! gcloud --project "{{ gce_project_id }}" compute target-tcp-proxies describe "{{ provision_prefix }}master-ssl-lb-target" &>/dev/null; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute target-tcp-proxies create "{{ provision_prefix }}master-ssl-lb-target" --backend-service "{{ provision_prefix }}master-ssl-lb-backend"
|
|
|
+if ! gcloud --project "{{ openshift_gcp_project }}" compute target-tcp-proxies describe "{{ openshift_gcp_prefix }}master-ssl-lb-target" &>/dev/null; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute target-tcp-proxies create "{{ openshift_gcp_prefix }}master-ssl-lb-target" --backend-service "{{ openshift_gcp_prefix }}master-ssl-lb-backend"
|
|
|
else
|
|
|
- echo "Proxy target '{{ provision_prefix }}master-ssl-lb-target' already exists"
|
|
|
+ echo "Proxy target '{{ openshift_gcp_prefix }}master-ssl-lb-target' already exists"
|
|
|
fi
|
|
|
|
|
|
# Master forwarding rule
|
|
|
-if ! gcloud --project "{{ gce_project_id }}" compute forwarding-rules describe "{{ provision_prefix }}master-ssl-lb-rule" --global &>/dev/null; then
|
|
|
- IP=$(gcloud --project "{{ gce_project_id }}" compute addresses describe "{{ provision_prefix }}master-ssl-lb-ip" --global --format='value(address)')
|
|
|
- gcloud --project "{{ gce_project_id }}" compute forwarding-rules create "{{ provision_prefix }}master-ssl-lb-rule" --address "$IP" --global --ports "{{ console_port }}" --target-tcp-proxy "{{ provision_prefix }}master-ssl-lb-target"
|
|
|
+if ! gcloud --project "{{ openshift_gcp_project }}" compute forwarding-rules describe "{{ openshift_gcp_prefix }}master-ssl-lb-rule" --global &>/dev/null; then
|
|
|
+ IP=$(gcloud --project "{{ openshift_gcp_project }}" compute addresses describe "{{ openshift_gcp_prefix }}master-ssl-lb-ip" --global --format='value(address)')
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute forwarding-rules create "{{ openshift_gcp_prefix }}master-ssl-lb-rule" --address "$IP" --global --ports "{{ console_port }}" --target-tcp-proxy "{{ openshift_gcp_prefix }}master-ssl-lb-target"
|
|
|
else
|
|
|
- echo "Forwarding rule '{{ provision_prefix }}master-ssl-lb-rule' already exists"
|
|
|
+ echo "Forwarding rule '{{ openshift_gcp_prefix }}master-ssl-lb-rule' already exists"
|
|
|
fi
|
|
|
) &
|
|
|
|
|
@@ -184,25 +186,25 @@ fi
|
|
|
# Configure the master internal LB rules
|
|
|
(
|
|
|
# Internal master health check
|
|
|
-if ! gcloud --project "{{ gce_project_id }}" compute http-health-checks describe "{{ provision_prefix }}master-network-lb-health-check" &>/dev/null; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute http-health-checks create "{{ provision_prefix }}master-network-lb-health-check" --port "8080" --request-path "/healthz"
|
|
|
+if ! gcloud --project "{{ openshift_gcp_project }}" compute http-health-checks describe "{{ openshift_gcp_prefix }}master-network-lb-health-check" &>/dev/null; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute http-health-checks create "{{ openshift_gcp_prefix }}master-network-lb-health-check" --port "8080" --request-path "/healthz"
|
|
|
else
|
|
|
- echo "Health check '{{ provision_prefix }}master-network-lb-health-check' already exists"
|
|
|
+ echo "Health check '{{ openshift_gcp_prefix }}master-network-lb-health-check' already exists"
|
|
|
fi
|
|
|
|
|
|
# Internal master target pool
|
|
|
-if ! gcloud --project "{{ gce_project_id }}" compute target-pools describe "{{ provision_prefix }}master-network-lb-pool" --region "{{ gce_region_name }}" &>/dev/null; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute target-pools create "{{ provision_prefix }}master-network-lb-pool" --http-health-check "{{ provision_prefix }}master-network-lb-health-check" --region "{{ gce_region_name }}"
|
|
|
+if ! gcloud --project "{{ openshift_gcp_project }}" compute target-pools describe "{{ openshift_gcp_prefix }}master-network-lb-pool" --region "{{ openshift_gcp_region }}" &>/dev/null; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute target-pools create "{{ openshift_gcp_prefix }}master-network-lb-pool" --http-health-check "{{ openshift_gcp_prefix }}master-network-lb-health-check" --region "{{ openshift_gcp_region }}"
|
|
|
else
|
|
|
- echo "Target pool '{{ provision_prefix }}master-network-lb-pool' already exists"
|
|
|
+ echo "Target pool '{{ openshift_gcp_prefix }}master-network-lb-pool' already exists"
|
|
|
fi
|
|
|
|
|
|
# Internal master forwarding rule
|
|
|
-if ! gcloud --project "{{ gce_project_id }}" compute forwarding-rules describe "{{ provision_prefix }}master-network-lb-rule" --region "{{ gce_region_name }}" &>/dev/null; then
|
|
|
- IP=$(gcloud --project "{{ gce_project_id }}" compute addresses describe "{{ provision_prefix }}master-network-lb-ip" --region "{{ gce_region_name }}" --format='value(address)')
|
|
|
- gcloud --project "{{ gce_project_id }}" compute forwarding-rules create "{{ provision_prefix }}master-network-lb-rule" --address "$IP" --region "{{ gce_region_name }}" --target-pool "{{ provision_prefix }}master-network-lb-pool"
|
|
|
+if ! gcloud --project "{{ openshift_gcp_project }}" compute forwarding-rules describe "{{ openshift_gcp_prefix }}master-network-lb-rule" --region "{{ openshift_gcp_region }}" &>/dev/null; then
|
|
|
+ IP=$(gcloud --project "{{ openshift_gcp_project }}" compute addresses describe "{{ openshift_gcp_prefix }}master-network-lb-ip" --region "{{ openshift_gcp_region }}" --format='value(address)')
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute forwarding-rules create "{{ openshift_gcp_prefix }}master-network-lb-rule" --address "$IP" --region "{{ openshift_gcp_region }}" --target-pool "{{ openshift_gcp_prefix }}master-network-lb-pool"
|
|
|
else
|
|
|
- echo "Forwarding rule '{{ provision_prefix }}master-network-lb-rule' already exists"
|
|
|
+ echo "Forwarding rule '{{ openshift_gcp_prefix }}master-network-lb-rule' already exists"
|
|
|
fi
|
|
|
) &
|
|
|
|
|
@@ -210,25 +212,25 @@ fi
|
|
|
# Configure the infra node rules
|
|
|
(
|
|
|
# Router health check
|
|
|
-if ! gcloud --project "{{ gce_project_id }}" compute http-health-checks describe "{{ provision_prefix }}router-network-lb-health-check" &>/dev/null; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute http-health-checks create "{{ provision_prefix }}router-network-lb-health-check" --port "1936" --request-path "/healthz"
|
|
|
+if ! gcloud --project "{{ openshift_gcp_project }}" compute http-health-checks describe "{{ openshift_gcp_prefix }}router-network-lb-health-check" &>/dev/null; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute http-health-checks create "{{ openshift_gcp_prefix }}router-network-lb-health-check" --port "1936" --request-path "/healthz"
|
|
|
else
|
|
|
- echo "Health check '{{ provision_prefix }}router-network-lb-health-check' already exists"
|
|
|
+ echo "Health check '{{ openshift_gcp_prefix }}router-network-lb-health-check' already exists"
|
|
|
fi
|
|
|
|
|
|
# Router target pool
|
|
|
-if ! gcloud --project "{{ gce_project_id }}" compute target-pools describe "{{ provision_prefix }}router-network-lb-pool" --region "{{ gce_region_name }}" &>/dev/null; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute target-pools create "{{ provision_prefix }}router-network-lb-pool" --http-health-check "{{ provision_prefix }}router-network-lb-health-check" --region "{{ gce_region_name }}"
|
|
|
+if ! gcloud --project "{{ openshift_gcp_project }}" compute target-pools describe "{{ openshift_gcp_prefix }}router-network-lb-pool" --region "{{ openshift_gcp_region }}" &>/dev/null; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute target-pools create "{{ openshift_gcp_prefix }}router-network-lb-pool" --http-health-check "{{ openshift_gcp_prefix }}router-network-lb-health-check" --region "{{ openshift_gcp_region }}"
|
|
|
else
|
|
|
- echo "Target pool '{{ provision_prefix }}router-network-lb-pool' already exists"
|
|
|
+ echo "Target pool '{{ openshift_gcp_prefix }}router-network-lb-pool' already exists"
|
|
|
fi
|
|
|
|
|
|
# Router forwarding rule
|
|
|
-if ! gcloud --project "{{ gce_project_id }}" compute forwarding-rules describe "{{ provision_prefix }}router-network-lb-rule" --region "{{ gce_region_name }}" &>/dev/null; then
|
|
|
- IP=$(gcloud --project "{{ gce_project_id }}" compute addresses describe "{{ provision_prefix }}router-network-lb-ip" --region "{{ gce_region_name }}" --format='value(address)')
|
|
|
- gcloud --project "{{ gce_project_id }}" compute forwarding-rules create "{{ provision_prefix }}router-network-lb-rule" --address "$IP" --region "{{ gce_region_name }}" --target-pool "{{ provision_prefix }}router-network-lb-pool"
|
|
|
+if ! gcloud --project "{{ openshift_gcp_project }}" compute forwarding-rules describe "{{ openshift_gcp_prefix }}router-network-lb-rule" --region "{{ openshift_gcp_region }}" &>/dev/null; then
|
|
|
+ IP=$(gcloud --project "{{ openshift_gcp_project }}" compute addresses describe "{{ openshift_gcp_prefix }}router-network-lb-ip" --region "{{ openshift_gcp_region }}" --format='value(address)')
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute forwarding-rules create "{{ openshift_gcp_prefix }}router-network-lb-rule" --address "$IP" --region "{{ openshift_gcp_region }}" --target-pool "{{ openshift_gcp_prefix }}router-network-lb-pool"
|
|
|
else
|
|
|
- echo "Forwarding rule '{{ provision_prefix }}router-network-lb-rule' already exists"
|
|
|
+ echo "Forwarding rule '{{ openshift_gcp_prefix }}router-network-lb-rule' already exists"
|
|
|
fi
|
|
|
) &
|
|
|
|
|
@@ -236,11 +238,11 @@ for i in `jobs -p`; do wait $i; done
|
|
|
|
|
|
# set the target pools
|
|
|
(
|
|
|
-if [[ "ig-m" == "{{ provision_gce_router_network_instance_group }}" ]]; then
|
|
|
- gcloud --project "{{ gce_project_id }}" compute instance-groups managed set-target-pools "{{ provision_prefix }}ig-m" --target-pools "{{ provision_prefix }}master-network-lb-pool,{{ provision_prefix }}router-network-lb-pool" --zone "{{ gce_zone_name }}"
|
|
|
+if [[ "ig-m" == "{{ openshift_gcp_infra_network_instance_group }}" ]]; then
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute instance-groups managed set-target-pools "{{ openshift_gcp_prefix }}ig-m" --target-pools "{{ openshift_gcp_prefix }}master-network-lb-pool,{{ openshift_gcp_prefix }}router-network-lb-pool" --zone "{{ openshift_gcp_zone }}"
|
|
|
else
|
|
|
- gcloud --project "{{ gce_project_id }}" compute instance-groups managed set-target-pools "{{ provision_prefix }}ig-m" --target-pools "{{ provision_prefix }}master-network-lb-pool" --zone "{{ gce_zone_name }}"
|
|
|
- gcloud --project "{{ gce_project_id }}" compute instance-groups managed set-target-pools "{{ provision_prefix }}{{ provision_gce_router_network_instance_group }}" --target-pools "{{ provision_prefix }}router-network-lb-pool" --zone "{{ gce_zone_name }}"
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute instance-groups managed set-target-pools "{{ openshift_gcp_prefix }}ig-m" --target-pools "{{ openshift_gcp_prefix }}master-network-lb-pool" --zone "{{ openshift_gcp_zone }}"
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" compute instance-groups managed set-target-pools "{{ openshift_gcp_prefix }}{{ openshift_gcp_infra_network_instance_group }}" --target-pools "{{ openshift_gcp_prefix }}router-network-lb-pool" --zone "{{ openshift_gcp_zone }}"
|
|
|
fi
|
|
|
) &
|
|
|
|
|
@@ -252,42 +254,42 @@ while true; do
|
|
|
rm -f $dns
|
|
|
|
|
|
# DNS record for master lb
|
|
|
- if ! gcloud --project "{{ gce_project_id }}" dns record-sets list -z "${dns_zone}" --name "{{ openshift_master_cluster_public_hostname }}" 2>/dev/null | grep -q "{{ openshift_master_cluster_public_hostname }}"; then
|
|
|
- IP=$(gcloud --project "{{ gce_project_id }}" compute addresses describe "{{ provision_prefix }}master-ssl-lb-ip" --global --format='value(address)')
|
|
|
+ if ! gcloud --project "{{ openshift_gcp_project }}" dns record-sets list -z "${dns_zone}" --name "{{ openshift_master_cluster_public_hostname }}" 2>/dev/null | grep -q "{{ openshift_master_cluster_public_hostname }}"; then
|
|
|
+ IP=$(gcloud --project "{{ openshift_gcp_project }}" compute addresses describe "{{ openshift_gcp_prefix }}master-ssl-lb-ip" --global --format='value(address)')
|
|
|
if [[ ! -f $dns ]]; then
|
|
|
- gcloud --project "{{ gce_project_id }}" dns record-sets transaction --transaction-file=$dns start -z "${dns_zone}"
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" dns record-sets transaction --transaction-file=$dns start -z "${dns_zone}"
|
|
|
fi
|
|
|
- gcloud --project "{{ gce_project_id }}" dns record-sets transaction --transaction-file=$dns add -z "${dns_zone}" --ttl 3600 --name "{{ openshift_master_cluster_public_hostname }}." --type A "$IP"
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" dns record-sets transaction --transaction-file=$dns add -z "${dns_zone}" --ttl 3600 --name "{{ openshift_master_cluster_public_hostname }}." --type A "$IP"
|
|
|
else
|
|
|
echo "DNS record for '{{ openshift_master_cluster_public_hostname }}' already exists"
|
|
|
fi
|
|
|
|
|
|
# DNS record for internal master lb
|
|
|
- if ! gcloud --project "{{ gce_project_id }}" dns record-sets list -z "${dns_zone}" --name "{{ openshift_master_cluster_hostname }}" 2>/dev/null | grep -q "{{ openshift_master_cluster_hostname }}"; then
|
|
|
- IP=$(gcloud --project "{{ gce_project_id }}" compute addresses describe "{{ provision_prefix }}master-network-lb-ip" --region "{{ gce_region_name }}" --format='value(address)')
|
|
|
+ if ! gcloud --project "{{ openshift_gcp_project }}" dns record-sets list -z "${dns_zone}" --name "{{ openshift_master_cluster_hostname }}" 2>/dev/null | grep -q "{{ openshift_master_cluster_hostname }}"; then
|
|
|
+ IP=$(gcloud --project "{{ openshift_gcp_project }}" compute addresses describe "{{ openshift_gcp_prefix }}master-network-lb-ip" --region "{{ openshift_gcp_region }}" --format='value(address)')
|
|
|
if [[ ! -f $dns ]]; then
|
|
|
- gcloud --project "{{ gce_project_id }}" dns record-sets transaction --transaction-file=$dns start -z "${dns_zone}"
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" dns record-sets transaction --transaction-file=$dns start -z "${dns_zone}"
|
|
|
fi
|
|
|
- gcloud --project "{{ gce_project_id }}" dns record-sets transaction --transaction-file=$dns add -z "${dns_zone}" --ttl 3600 --name "{{ openshift_master_cluster_hostname }}." --type A "$IP"
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" dns record-sets transaction --transaction-file=$dns add -z "${dns_zone}" --ttl 3600 --name "{{ openshift_master_cluster_hostname }}." --type A "$IP"
|
|
|
else
|
|
|
echo "DNS record for '{{ openshift_master_cluster_hostname }}' already exists"
|
|
|
fi
|
|
|
|
|
|
# DNS record for router lb
|
|
|
- if ! gcloud --project "{{ gce_project_id }}" dns record-sets list -z "${dns_zone}" --name "{{ wildcard_zone }}" 2>/dev/null | grep -q "{{ wildcard_zone }}"; then
|
|
|
- IP=$(gcloud --project "{{ gce_project_id }}" compute addresses describe "{{ provision_prefix }}router-network-lb-ip" --region "{{ gce_region_name }}" --format='value(address)')
|
|
|
+ if ! gcloud --project "{{ openshift_gcp_project }}" dns record-sets list -z "${dns_zone}" --name "{{ wildcard_zone }}" 2>/dev/null | grep -q "{{ wildcard_zone }}"; then
|
|
|
+ IP=$(gcloud --project "{{ openshift_gcp_project }}" compute addresses describe "{{ openshift_gcp_prefix }}router-network-lb-ip" --region "{{ openshift_gcp_region }}" --format='value(address)')
|
|
|
if [[ ! -f $dns ]]; then
|
|
|
- gcloud --project "{{ gce_project_id }}" dns record-sets transaction --transaction-file=$dns start -z "${dns_zone}"
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" dns record-sets transaction --transaction-file=$dns start -z "${dns_zone}"
|
|
|
fi
|
|
|
- gcloud --project "{{ gce_project_id }}" dns record-sets transaction --transaction-file=$dns add -z "${dns_zone}" --ttl 3600 --name "{{ wildcard_zone }}." --type A "$IP"
|
|
|
- gcloud --project "{{ gce_project_id }}" dns record-sets transaction --transaction-file=$dns add -z "${dns_zone}" --ttl 3600 --name "*.{{ wildcard_zone }}." --type CNAME "{{ wildcard_zone }}."
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" dns record-sets transaction --transaction-file=$dns add -z "${dns_zone}" --ttl 3600 --name "{{ wildcard_zone }}." --type A "$IP"
|
|
|
+ gcloud --project "{{ openshift_gcp_project }}" dns record-sets transaction --transaction-file=$dns add -z "${dns_zone}" --ttl 3600 --name "*.{{ wildcard_zone }}." --type CNAME "{{ wildcard_zone }}."
|
|
|
else
|
|
|
echo "DNS record for '{{ wildcard_zone }}' already exists"
|
|
|
fi
|
|
|
|
|
|
# Commit all DNS changes, retrying if preconditions are not met
|
|
|
if [[ -f $dns ]]; then
|
|
|
- if ! out="$( gcloud --project "{{ gce_project_id }}" dns record-sets transaction --transaction-file=$dns execute -z "${dns_zone}" 2>&1 )"; then
|
|
|
+ if ! out="$( gcloud --project "{{ openshift_gcp_project }}" dns record-sets transaction --transaction-file=$dns execute -z "${dns_zone}" 2>&1 )"; then
|
|
|
rc=$?
|
|
|
if [[ "${out}" == *"HTTPError 412: Precondition not met"* ]]; then
|
|
|
continue
|
|
@@ -301,17 +303,17 @@ done
|
|
|
|
|
|
# Create bucket for registry
|
|
|
(
|
|
|
-if ! gsutil ls -p "{{ gce_project_id }}" "gs://{{ openshift_hosted_registry_storage_gcs_bucket }}" &>/dev/null; then
|
|
|
- gsutil mb -p "{{ gce_project_id }}" -l "{{ gce_region_name }}" "gs://{{ openshift_hosted_registry_storage_gcs_bucket }}"
|
|
|
+if ! gsutil ls -p "{{ openshift_gcp_project }}" "gs://{{ openshift_gcp_registry_bucket_name }}" &>/dev/null; then
|
|
|
+ gsutil mb -p "{{ openshift_gcp_project }}" -l "{{ openshift_gcp_region }}" "gs://{{ openshift_gcp_registry_bucket_name }}"
|
|
|
else
|
|
|
- echo "Bucket '{{ openshift_hosted_registry_storage_gcs_bucket }}' already exists"
|
|
|
+ echo "Bucket '{{ openshift_gcp_registry_bucket_name }}' already exists"
|
|
|
fi
|
|
|
) &
|
|
|
|
|
|
# wait until all node groups are stable
|
|
|
-{% for node_group in provision_gce_node_groups %}
|
|
|
+{% for node_group in openshift_gcp_node_group_config %}
|
|
|
# wait for stable {{ node_group.name }}
|
|
|
-( gcloud --project "{{ gce_project_id }}" compute instance-groups managed wait-until-stable "{{ provision_prefix }}ig-{{ node_group.suffix }}" --zone "{{ gce_zone_name }}" --timeout=300) &
|
|
|
+( gcloud --project "{{ openshift_gcp_project }}" compute instance-groups managed wait-until-stable "{{ openshift_gcp_prefix }}ig-{{ node_group.suffix }}" --zone "{{ openshift_gcp_zone }}" --timeout=300) &
|
|
|
{% endfor %}
|
|
|
|
|
|
|