Skip to content

Commit

Permalink
Move hostname lookup to its own script file and source from individua…
Browse files Browse the repository at this point in the history
…l init scripts

Signed-off-by: Aaron Wilson <[email protected]>
  • Loading branch information
aaronnw committed Dec 29, 2023
1 parent ddd270e commit 3a7a92b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 34 deletions.
20 changes: 20 additions & 0 deletions operator/pkg/resources/cmn/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
`
)
1 change: 1 addition & 0 deletions operator/pkg/resources/proxy/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 2 additions & 17 deletions operator/pkg/resources/proxy/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions operator/pkg/resources/target/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
19 changes: 2 additions & 17 deletions operator/pkg/resources/target/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3a7a92b

Please sign in to comment.