Commit bafe7447 authored by David McKay's avatar David McKay

feat(enterprise): use Perl to orchestrate entrypoint and cluster membership

parent 24ffe57c
......@@ -29,19 +29,47 @@ data:
dir = "/var/lib/influxdb/data"
wal-dir = "/var/lib/influxdb/wal"
entrypoint.sh: |+
#!/usr/bin/env sh
entrypoint.pl: |+
META_LEADER=$(hostname -f | sed -r 's/-[0-9]+./-0./' | sed -r 's/data/meta/g')
#!/usr/bin/env perl
$ENV{INFLUXDB_HOSTNAME} = `hostname -f`;
$ENV{INFLUXDB_HOSTNAME} =~ s/\n$//;
n=0
until [ "$n" -ge 1000 ]
do
curl -XPOST -Faddr=$(hostname -f):8088 http://${META_LEADER}:8091/add-data && break
sleep 2
n=$((n+1))
done
$pid = fork();
export INFLUXDB_HOSTNAME=$(hostname -f)
exec influxd
# Inside this conditional is our child process, which
# will return `influxd-meta`
if($pid == 0) {
exec('influxd') or die("Failed to execute influxd: $!\n");
}
$SIG{HUP} = sub { kill 'HUP', $pid };
$SIG{TERM} = sub { kill 'TERM', $pid };
$SIG{KILL} = sub { kill 'KILL', $pid };
# Register data node with meta leader
my $meta_leader = $ENV{INFLUXDB_HOSTNAME};
$meta_leader =~ s/-[0-9]+./-0./;
$meta_leader =~ s/data/meta/g;
# We're not going to define an exit strategy for failure here.
# This should be handled by the probes on the pods
while (true) {
# There's no LWP/Simple available in our images, so forking out to curl 😥
print "Attempting to register with meta service ...\n";
system('echo', 'curl', '-XPOST', "-Faddr=$ENV{INFLUXDB_HOSTNAME}:8088", "http://idb-meta:8091/add-data");
system('curl', '-XPOST', "-Faddr=$ENV{INFLUXDB_HOSTNAME}:8088", "http://idb-meta:8091/add-data");
if ($? == 0) {
print "Success\n";
last;
}
print "Failed: $!\n";
# Wait a few seconds and try again
# Maybe we should implement some rudamentary backoff
sleep(2);
}
waitpid($pid, 0);
exit $?
......@@ -35,9 +35,9 @@ spec:
containers:
- name: {{ .Chart.Name }}
command:
- "/bin/sh"
- "/usr/bin/perl"
args:
- "/etc/influxdb/entrypoint.sh"
- "/etc/influxdb/entrypoint.pl"
securityContext:
{{- toYaml .Values.data.securityContext | nindent 12 }}
image: "{{ .Values.data.image.repository | default "influxdb" }}:{{ .Values.data.image.tag | default (printf "%s-%s" .Chart.AppVersion "data") }}"
......
......@@ -22,12 +22,44 @@ data:
[meta]
dir = "/var/lib/influxdb/meta"
entrypoint.sh: |+
#!/usr/bin/env sh
set -e
META_LEADER=$(hostname -f | sed -r 's/-[0-9]+./-0./')
if [ $META_LEADER != $(hostname -f) ]; then
influxd-ctl join ${META_LEADER}:8091
else
influxd-ctl add-meta $(hostname -f):8091
fi
entrypoint.pl: |+
#!/usr/bin/env perl
$ENV{INFLUXDB_HOSTNAME} = `hostname -f`;
$ENV{INFLUXDB_HOSTNAME} =~ s/\n$//;
$pid = fork();
# Inside this conditional is our child process, which
# will return `influxd-meta`
if($pid == 0) {
exec('influxd-meta') or die("Failed to execute influxd-meta: $!\n");
}
$SIG{HUP} = sub { kill 'HUP', $pid };
$SIG{TERM} = sub { kill 'TERM', $pid };
$SIG{KILL} = sub { kill 'KILL', $pid };
# Register meta node
my $meta_leader = $ENV{INFLUXDB_HOSTNAME};
$meta_leader =~ s/-[0-9]+./-0./;
# We're not going to define an exit strategy for failure here.
# This should be handled by the probes on the pods
while (true) {
if($meta_leader eq $ENV{INFLUXDB_HOSTNAME}) {
system('influxd-ctl', 'add-meta', "$ENV{INFLUXDB_HOSTNAME}:8091");
} else {
system('influxd-ctl', 'join', "$meta_leader:8091");
}
if ($? == 0) {
last;
}
# Wait a few seconds and try again
# Maybe we should implement some rudamentary backoff
sleep(2);
}
waitpid($pid, 0);
exit $?
......@@ -37,18 +37,13 @@ spec:
containers:
- name: {{ .Chart.Name }}
command:
- "/bin/sh"
- "/usr/bin/perl"
args:
- "-c"
- "INFLUXDB_HOSTNAME=$(hostname -f) influxd-meta"
- "/etc/influxdb/entrypoint.pl"
securityContext:
{{- toYaml .Values.meta.securityContext | nindent 12 }}
image: "{{ .Values.meta.image.repository | default "influxdb" }}:{{ .Values.meta.image.tag | default (printf "%s-%s" .Chart.AppVersion "meta") }}"
imagePullPolicy: {{ .Values.meta.image.pullPolicy }}
lifecycle:
postStart:
exec:
command: ["/bin/sh", "/etc/influxdb/entrypoint.sh"]
ports:
- name: http
containerPort: 8091
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment