diff --git a/operator/pkg/resources/cmn/scripts.go b/operator/pkg/resources/cmn/scripts.go index 1f1a4ddc..95aa6aca 100644 --- a/operator/pkg/resources/cmn/scripts.go +++ b/operator/pkg/resources/cmn/scripts.go @@ -53,4 +53,24 @@ const ( [[ "${stat}" == "200" ]] && exit 0 exit 1 ` + HostnameMapSh = ` + #!/bin/bash + # Lookup the hostnames in the hostname config map (allows for multiple host ips) + hostname_map="/var/global_config/hostname_map" + if [ -f "$hostname_map" ]; then + read -ra pairs <<< "$(cat "$hostname_map")" + + for pair in "${pairs[@]}"; do + IFS='=' read -ra parts <<< "$pair" + key="${parts[0]}" + value="${parts[1]}" + + if [ "$key" = "$AIS_PUBLIC_HOSTNAME" ]; then + echo "Setting AIS_PUBLIC_HOSTNAME to value from configMap: ${value}" + export AIS_PUBLIC_HOSTNAME="$value" + break + fi + done + fi +` ) diff --git a/operator/pkg/resources/proxy/configmap.go b/operator/pkg/resources/proxy/configmap.go index 7aa67183..da92ea1b 100644 --- a/operator/pkg/resources/proxy/configmap.go +++ b/operator/pkg/resources/proxy/configmap.go @@ -38,6 +38,7 @@ func NewProxyCM(ais *aisv1.AIStore) (*corev1.ConfigMap, error) { }, Data: map[string]string{ "ais_local.json": confLocal, + "hostname_lookup.sh": cmn.HostnameMapSh, "set_initial_primary_proxy_env.sh": initProxySh, }, }, nil diff --git a/operator/pkg/resources/proxy/scripts.go b/operator/pkg/resources/proxy/scripts.go index 76245277..6635e392 100644 --- a/operator/pkg/resources/proxy/scripts.go +++ b/operator/pkg/resources/proxy/scripts.go @@ -20,23 +20,8 @@ pod_dns="${MY_POD}.${MY_SERVICE}.${K8S_NS}.svc.${cluster_domain}" export AIS_INTRA_HOSTNAME=${pod_dns} export AIS_DATA_HOSTNAME=${pod_dns} -# Lookup the hostnames in the hostname config map (allows for multiple host ips) -hostname_map="/var/global_config/hostname_map" -if [ -f "$hostname_map" ]; then - read -ra pairs <<< "$(cat "$hostname_map")" - - for pair in "${pairs[@]}"; do - IFS='=' read -ra parts <<< "$pair" - key="${parts[0]}" - value="${parts[1]}" - - if [ "$key" = "$AIS_PUBLIC_HOSTNAME" ]; then - echo "Setting AIS_PUBLIC_HOSTNAME to value from configMap: ${value}" - export AIS_PUBLIC_HOSTNAME="$value" - break - fi - done -fi +# Run script to replace AIS_PUBLIC_HOSTNAME with its entry in the hostname config map if provided +source hostname_lookup.sh local_conf_template="/var/ais_config_template/ais_local.json" local_conf_file="/var/ais_config/ais_local.json" diff --git a/operator/pkg/resources/target/configmap.go b/operator/pkg/resources/target/configmap.go index ff1cda18..4114e610 100644 --- a/operator/pkg/resources/target/configmap.go +++ b/operator/pkg/resources/target/configmap.go @@ -37,6 +37,7 @@ func NewTargetCM(ais *aisv1.AIStore) (*corev1.ConfigMap, error) { Namespace: ais.Namespace, }, Data: map[string]string{ + "hostname_lookup.sh": cmn.HostnameMapSh, "set_initial_target_env.sh": initTargetSh, "ais_local.json": confLocal, }, diff --git a/operator/pkg/resources/target/scripts.go b/operator/pkg/resources/target/scripts.go index 91459081..7d81d2fc 100644 --- a/operator/pkg/resources/target/scripts.go +++ b/operator/pkg/resources/target/scripts.go @@ -36,23 +36,8 @@ pod_dns="${MY_POD}.${MY_SERVICE}.${K8S_NS}.svc.${cluster_domain}" export AIS_INTRA_HOSTNAME=${pod_dns} export AIS_DATA_HOSTNAME=${pod_dns} -# Lookup the hostnames in the hostname config map (allows for multiple host ips) -hostname_map="/var/global_config/hostname_map" -if [ -f "$hostname_map" ]; then - read -ra pairs <<< "$(cat "$hostname_map")" - - for pair in "${pairs[@]}"; do - IFS='=' read -ra parts <<< "$pair" - key="${parts[0]}" - value="${parts[1]}" - - if [ "$key" = "$AIS_PUBLIC_HOSTNAME" ]; then - echo "Setting AIS_PUBLIC_HOSTNAME to value from configMap: ${value}" - export AIS_PUBLIC_HOSTNAME="$value" - break - fi - done -fi +# Replace AIS_PUBLIC_HOSTNAME with its entry the hostname config map if provided +source "hostname_lookup.sh" local_conf_template="/var/ais_config_template/ais_local.json" local_conf_file="/var/ais_config/ais_local.json"