Skip to content

Commit fb08751

Browse files
committed
Set the listen address to the predictable IP for mdns
Have mDNS listen and use the predictable IP for apps expecting replies from mDNS to be from the same address that was used for the request. Jira: OSPRH-15638
1 parent bfdee84 commit fb08751

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

pkg/designatemdns/statefulset.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
appsv1 "k8s.io/api/apps/v1"
2727
corev1 "k8s.io/api/core/v1"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29-
"k8s.io/apimachinery/pkg/util/intstr"
3029
)
3130

3231
// StatefulSet func
@@ -63,25 +62,27 @@ func StatefulSet(
6362
ReadOnly: true,
6463
})
6564

65+
// Ideally we would use the connection probe but the mdns service does
66+
// not listen on a cluster allocated IP
6667
livenessProbe := &corev1.Probe{
6768
// TODO might need tuning
6869
TimeoutSeconds: 15,
6970
PeriodSeconds: 13,
7071
InitialDelaySeconds: 15,
7172
}
72-
readinessProbe := &corev1.Probe{
73+
startupProbe := &corev1.Probe{
7374
// TODO might need tuning
7475
TimeoutSeconds: 15,
7576
PeriodSeconds: 13,
7677
InitialDelaySeconds: 10,
7778
}
7879

79-
livenessProbe.TCPSocket = &corev1.TCPSocketAction{
80-
Port: intstr.IntOrString{Type: intstr.Int, IntVal: int32(5354)},
81-
}
82-
readinessProbe.TCPSocket = &corev1.TCPSocketAction{
83-
Port: intstr.IntOrString{Type: intstr.Int, IntVal: int32(5354)},
80+
livenessProbe.Exec = &corev1.ExecAction{
81+
Command: []string{
82+
"/usr/bin/pgrep", "-r", "DRST", "-f", "designate.mdns",
83+
},
8484
}
85+
startupProbe.Exec = livenessProbe.Exec
8586

8687
envVars := map[string]env.Setter{}
8788
envVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS")
@@ -119,11 +120,11 @@ func StatefulSet(
119120
SecurityContext: &corev1.SecurityContext{
120121
RunAsUser: &rootUser,
121122
},
122-
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
123-
VolumeMounts: volumeMounts,
124-
Resources: instance.Spec.Resources,
125-
ReadinessProbe: readinessProbe,
126-
LivenessProbe: livenessProbe,
123+
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
124+
VolumeMounts: volumeMounts,
125+
Resources: instance.Spec.Resources,
126+
StartupProbe: startupProbe,
127+
LivenessProbe: livenessProbe,
127128
},
128129
},
129130
},

templates/common/setipalias.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@
77

88
mapping_prefix = os.environ.get("MAP_PREFIX")
99
if not len(mapping_prefix):
10-
print(f"{sys.argv[0]} requires MAP_PREFIX to be set in environment variables")
10+
print(f"{sys.argv[0]} requires MAP_PREFIX to be set in environment variables", file=sys.stderr)
1111
sys.exit(1)
1212

13-
print(f"Using {mapping_prefix} as the map prefix")
13+
print(f"Using {mapping_prefix} as the map prefix", file=sys.stderr)
1414

1515
nodefile = ""
1616
podname = os.environ.get("POD_NAME").strip()
1717
if not len(podname):
18-
print(f"{sys.argv[0]} requires POD_NAME in environment variables")
18+
print(f"{sys.argv[0]} requires POD_NAME in environment variables", file=sys.stderr)
1919
sys.exit(1)
2020

21-
print(f"Pod name is {podname}")
21+
print(f"Pod name is {podname}", file=sys.stderr)
2222
namepieces = podname.split('-')
2323
pod_index = namepieces[-1]
2424
nodefile = f"{mapping_prefix}{pod_index}"
2525

2626
interface_name = os.environ.get("NAD_NAME", "designate").strip()
2727

28-
print(f"working with address file {nodefile}")
28+
print(f"working with address file {nodefile}", file=sys.stderr)
2929
filename = os.path.join('/var/lib/predictableips', nodefile)
3030
if not os.path.exists(filename):
31-
print(f"Required alias address file {filename} does not exist")
31+
print(f"Required alias address file {filename} does not exist", file=sys.stderr)
3232
sys.exit(1)
3333

3434
ip = IPRoute()
3535
designateinterface = ip.link_lookup(ifname=interface_name)
3636

3737
if not len(designateinterface):
38-
print(f"{interface_name} attachment not present")
38+
print(f"{interface_name} attachment not present", file=sys.stderr)
3939
sys.exit(1)
4040

4141

@@ -44,7 +44,9 @@
4444
ipfile.close()
4545

4646
if ipaddr:
47-
print(f"Setting {ipaddr} on {interface_name}")
47+
print(f"Setting {ipaddr} on {interface_name}", file=sys.stderr)
48+
# output the ipaddr to stdout so that the container-scripts/setipalias.sh can read it
49+
print(f"{ipaddr}")
4850
# Get our current addresses so we can avoid trying to set the
4951
# same address again.
5052
version = ipaddress.ip_address(ipaddr).version
@@ -57,6 +59,6 @@
5759
mask_value = 128
5860
ip.addr('add', index = designateinterface[0], address=ipaddr, mask=mask_value)
5961
else:
60-
print('No IP address found')
62+
print('No IP address found', file=sys.stderr)
6163

6264
ip.close()

templates/designatemdns/bin/setipalias.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ set -ex
1818
# expect that the common.sh is in the same dir as the calling script
1919
#
2020
SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
21+
SVC_CFG_MERGED=/var/lib/config-data/merged/designate.conf
2122

22-
/usr/local/bin/container-scripts/setipalias.py
23+
IPADDR=$(/usr/local/bin/container-scripts/setipalias.py)
24+
if [ $? -eq 0 ] && [ -n "$IPADDR" ]; then
25+
crudini --set $SVC_CFG_MERGED 'service:mdns' 'listen' "${IPADDR}:5354"
26+
fi

0 commit comments

Comments
 (0)