#!/bin/bash # # Copyright 2020 VEXXHOST, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. function get_kubernetes_service_ip { local svc="$1" for i in {1..60}; do ip=$(kubectl get svc/$svc -ojsonpath='{.spec.clusterIP}') && break || sleep 1; done echo "$ip" } function kubernetes_rollout_status { local resource="$1" for i in {1..60}; do kubectl get $resource && break || sleep 1; done kubectl rollout status --timeout=300s $resource } function kubernetes_rollout_restart { local resource="$1" for i in {1..60}; do kubectl get $resource && break || sleep 1; done kubectl rollout restart $resource } function kubernetes_ensure_resource { local resource="$1" kubectl logs deployment/openstack-operator -n default for i in {1..120}; do kubectl get $resource && break || sleep 5; done } function proxy_pass_to_kubernetes { local url=$1 local svc=$2 local conf=$3 local ip=$(get_kubernetes_service_ip $svc) local apache_conf=$(apache_site_config_for $conf) enable_apache_mod proxy enable_apache_mod proxy_http echo "KeepAlive Off" | sudo tee $apache_conf echo "SetEnv proxy-sendchunked 1" | sudo tee -a $apache_conf echo "ProxyPass \"${url}\" \"http://${ip}/\"" | sudo tee $apache_conf enable_apache_site $conf restart_apache_server } # Gets or creates service # Usage: get_or_create_service function get_or_create_service { cat < function _get_or_create_endpoint_with_interface { cat < function get_data_from_secret { local secret=$1 local ns=$2 local key=$3 local data=$(kubectl get secret -n $ns $secret -o jsonpath="{.data.$key}" | base64 --decode) echo $data } export -f get_data_from_secret