Skip to content

Commit

Permalink
fix: Now uses hostAlias to inject k8s hostname and IP into /etc/hosts…
Browse files Browse the repository at this point in the history
… of the player
  • Loading branch information
Alan Christie committed Sep 20, 2024
1 parent bd072fb commit da2ef06
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions roles/player/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@
- fp_kubeconfig_file|length > 0
- fp_kubeconfig_file!='SetMe'

# Discover the hostname (an IP address) of the kubernetes cluster
# control plane. We do this to set a host alias in the Player Pod
# to avoid the need for a DNS lookup (something that may be unreliable on
# the chosen cluster)

- name: Run kubectl (to get the host)
command: kubectl config view --minify --output 'jsonpath={.clusters[0].cluster.server}'
register: k8s_host
changed_when: false

- name: Extract k8s hostname
set_fact:
k8s_hostname: "{{ k8s_host.stdout_lines[0] | urlsplit('hostname') }}"

- name: Use Python's 'dig' to get the IP address
set_fact:
k8s_ip: "{{ lookup('dig', k8s_hostname) }}"

- name: Display k8s hostname and address
debug:
msg: k8s_hostname={{ k8s_hostname }} k8s_ip={{ k8s_ip }}

# Go...

# There is no 'undeploy' fragmentation is a 'Job'
Expand Down
8 changes: 8 additions & 0 deletions roles/player/templates/job.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ spec:
labels:
name: fragmentor-player
spec:
# A host alias for the Kubernetes API.
# This ensures the host (and th IP address we provide)
# go into the Pod's /etc/hosts file.
hostAliases:
- ip: "{{ k8s_ip }}"
hostnames:
- "{{ k8s_hostname }}""

serviceAccountName: fragmentor

# A 'request' (not guaranteed)
Expand Down

0 comments on commit da2ef06

Please sign in to comment.