-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create objects to facilitate ingress from an extragateway network * Add retries to builds since nodes can be in a precarious state during post-deployment * Increase build retries and add conditional to prevent eg IC being created * Add quotes to missing build Ansible task name * Add quotes to missing build Ansible task name * Alter EG network name var to match deploy vars.yml, and add -ve route selector so eg/net2 routes don't go onto default ic * Tweak net2 LB pool selection, and add conditional so that internet only clusters don't have ukc-ingress jobs * Late tweak to ensure EG lb pool selection works Co-authored-by: Gareth Ellner <29887711+gellner@users.noreply.github.com>
- Loading branch information
Showing
16 changed files
with
369 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# FROM ansible-runner:latest | ||
FROM docker.io/ansible/ansible-runner@sha256:4c6034798b5e724c5a59466f5438e14480c53bc4adac5cc9db5e3997a286a0e4 | ||
|
||
WORKDIR /usr/local/ | ||
|
||
ADD ./playbooks /usr/local/playbooks | ||
COPY ./pip-requirements.txt /usr/local/pip-requirements.txt | ||
COPY ./ansible-requirements.yml /usr/local/ansible-requirements.yml | ||
|
||
# Upgrade pip and install requirements for Kubernetes/Openstack modules | ||
RUN pip3 install --upgrade pip && \ | ||
pip3 install -U setuptools && \ | ||
pip3 install -r /usr/local/pip-requirements.txt --ignore-installed PyYAML | ||
|
||
# Install Ansible collections for Kubernetes/Openstack modules | ||
RUN ansible-galaxy collection install -r /usr/local/ansible-requirements.yml | ||
|
||
ENTRYPOINT /usr/local/playbooks/entrypoint.sh |
6 changes: 6 additions & 0 deletions
6
post-deployment/openstack/eg-ingress/build/ansible-requirements.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
collections: | ||
- name: openstack.cloud | ||
version: "1.2.0" | ||
- name: community.kubernetes | ||
version: "1.2.0" |
6 changes: 6 additions & 0 deletions
6
post-deployment/openstack/eg-ingress/build/pip-requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
openshift~=0.12.0 | ||
PyYAML~=5.4.1 | ||
jmespath~=0.10.0 | ||
openstacksdk~=0.56.0 | ||
python-octaviaclient~=2.3.0 | ||
python-openstackclient~=5.5.0 |
10 changes: 10 additions & 0 deletions
10
post-deployment/openstack/eg-ingress/build/playbooks/entrypoint.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export K8S_AUTH_VERIFY_SSL=no | ||
|
||
# Add uid to /etc/passwd to allow Ansible to run | ||
if [ `id -u` -ge 500 ]; then | ||
echo "runner:x:`id -u`:`id -g`:,,,:/runner:/bin/bash" > /tmp/passwd | ||
cat /tmp/passwd >> /etc/passwd | ||
rm /tmp/passwd | ||
fi | ||
|
||
ansible-playbook /usr/local/playbooks/update_eg_loadbalancer_members.yaml |
95 changes: 95 additions & 0 deletions
95
post-deployment/openstack/eg-ingress/build/playbooks/update_eg_loadbalancer_members.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--- | ||
- hosts: localhost | ||
connection: local | ||
gather_facts: no | ||
|
||
tasks: | ||
- name: 'Retrieve OpenStack secret' | ||
community.kubernetes.k8s_info: | ||
kind: Secret | ||
name: openstack-credentials | ||
namespace: kube-system | ||
register: openstackCredentialRaw | ||
|
||
- name: 'Extract OpenStack credential' | ||
ansible.builtin.set_fact: | ||
openstackCredential: "{{ openstackCredentialRaw | to_json | from_json | json_query(openstackCredentialQuery) }}" | ||
vars: | ||
openstackCredentialQuery: 'resources[0].data."clouds.yaml"' | ||
|
||
- name: 'Write OpenStack credential to file' | ||
ansible.builtin.copy: | ||
dest: /etc/openstack/clouds.yaml | ||
content: "{{ openstackCredential | b64decode }}" | ||
|
||
- name: 'Get infra nodes' | ||
community.kubernetes.k8s_info: | ||
kind: Node | ||
label_selectors: | ||
- node-role.kubernetes.io/infra = | ||
register: infraNodes | ||
|
||
- name: 'Extract infra node IPs' | ||
ansible.builtin.set_fact: | ||
infraMembersRaw: "{{ infraNodes | to_json | from_json | json_query(infraMembersRawQuery) }}" | ||
vars: | ||
infraMembersRawQuery: "resources[*].status.addresses[?type=='InternalIP'].address" | ||
|
||
- name: 'Build infra node IP dict' | ||
ansible.builtin.set_fact: | ||
infraMembers: "{{ infraMembers | default([]) + [ item ] }}" | ||
with_items: "{{ infraMembersRaw }}" | ||
|
||
- name: 'Get loadbalancer pools' | ||
ansible.builtin.shell: openstack loadbalancer pool list -c name -f value | grep -- -eg- | ||
register: loadbalancerPoolsRaw | ||
|
||
- name: 'Sanitise loadbalancer pools' | ||
ansible.builtin.set_fact: | ||
loadbalancerPools: "{{ loadbalancerPoolsRaw.stdout_lines }}" | ||
|
||
- name: 'Get loadbalancer pool members' | ||
ansible.builtin.command: openstack loadbalancer member list "{{ loadbalancerPools | first }}" -c address -f value | ||
register: loadbalancerMembersRaw | ||
|
||
- name: 'Sanitise loadbalancer pool members' | ||
ansible.builtin.set_fact: | ||
loadbalancerMembers: "{{ loadbalancerMembersRaw.stdout_lines }}" | ||
|
||
- name: 'Determine members to be added' | ||
ansible.builtin.set_fact: | ||
loadbalancerMembersToAdd: "{{ loadbalancerMembersToAdd | default([]) + [ item ] }}" | ||
with_items: "{{ infraMembers }}" | ||
when: | ||
- infraMembers is defined | ||
- item not in loadbalancerMembers | ||
|
||
- name: 'Determine members to be deleted' | ||
ansible.builtin.set_fact: | ||
loadbalancerMembersToDelete: "{{ loadbalancerMembersToDelete | default([]) + [ item ] }}" | ||
with_items: "{{ loadbalancerMembers }}" | ||
when: | ||
- infraMembers is defined | ||
- item not in infraMembers | ||
|
||
- name: 'Add loadbalancer members' | ||
openstack.cloud.lb_member: | ||
name: "{{ item[1] }}" | ||
address: "{{ item[1] }}" | ||
pool: "{{ item[0] }}" | ||
protocol_port: "{{ 30443 if '-HTTPS-' in item[0] else 30080 }}" | ||
state: present | ||
with_nested: | ||
- "{{ loadbalancerPools }}" | ||
- "{{ loadbalancerMembersToAdd }}" | ||
when: loadbalancerMembersToAdd is defined | ||
|
||
- name: 'Delete loadbalancer members' | ||
openstack.cloud.lb_member: | ||
name: "{{ item[1] }}" | ||
pool: "{{ item[0] }}" | ||
state: absent | ||
with_nested: | ||
- "{{ loadbalancerPools }}" | ||
- "{{ loadbalancerMembersToDelete }}" | ||
when: loadbalancerMembersToDelete is defined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
--- | ||
- hosts: localhost | ||
connection: local | ||
|
||
vars: | ||
namespace: "ukc-ingress" | ||
extraGatewayNetworkName: "{{ egExternalNetwork | replace(' ','-') | replace('_','-') | lower }}" | ||
|
||
tasks: | ||
- name: Create ImageStream | ||
k8s: | ||
state: present | ||
definition: | ||
apiVersion: image.openshift.io/v1 | ||
kind: ImageStream | ||
metadata: | ||
name: update-eg-loadbalancer-members | ||
namespace: "{{ namespace }}" | ||
spec: | ||
lookupPolicy: | ||
local: true | ||
|
||
- name: Create BuildConfig | ||
k8s: | ||
state: present | ||
definition: | ||
apiVersion: build.openshift.io/v1 | ||
kind: BuildConfig | ||
metadata: | ||
labels: | ||
build: update-eg-loadbalancer-members | ||
name: update-eg-loadbalancer-members | ||
namespace: "{{ namespace }}" | ||
spec: | ||
output: | ||
to: | ||
kind: ImageStreamTag | ||
name: update-eg-loadbalancer-members:latest | ||
source: | ||
binary: {} | ||
type: Binary | ||
strategy: | ||
dockerStrategy: {} | ||
type: Docker | ||
|
||
- name: Run Docker build | ||
command: "oc start-build update-eg-loadbalancer-members --from-dir . -F -n {{ namespace }}" | ||
args: | ||
chdir: "./build" | ||
register: egLoadbalancerBuildStatus | ||
until: | ||
- "'Push successful' in egLoadbalancerBuildStatus.stdout_lines" | ||
retries: 5 | ||
delay: 60 | ||
|
||
- name: Delete BuildConfig | ||
k8s: | ||
state: absent | ||
definition: | ||
apiVersion: build.openshift.io/v1 | ||
kind: BuildConfig | ||
metadata: | ||
name: update-eg-loadbalancer-members | ||
namespace: "{{ namespace }}" | ||
|
||
- name: Create update-eg-loadbalancer-members CronJob | ||
k8s: | ||
state: present | ||
definition: "{{ lookup('template', 'templates/cronjob-update-eg-loadbalancer-members.j2') }}" | ||
|
||
- name: Create IngressController | ||
k8s: | ||
state: present | ||
definition: | ||
apiVersion: operator.openshift.io/v1 | ||
kind: IngressController | ||
metadata: | ||
namespace: openshift-ingress-operator | ||
name: extragateway | ||
spec: | ||
domain: "{{ extraGatewayNetworkName }}.{{ domainSuffix }}" | ||
nodePlacement: | ||
nodeSelector: | ||
matchLabels: | ||
node-role.kubernetes.io/infra: "" | ||
endpointPublishingStrategy: | ||
type: NodePortService | ||
replicas: 2 | ||
routeSelector: | ||
matchExpressions: | ||
- key: network | ||
operator: In | ||
values: | ||
- "{{ extraGatewayNetworkName }}" | ||
|
||
- name: Statically set NodePortService port numbers | ||
k8s: | ||
state: present | ||
definition: | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: router-nodeport-extragateway | ||
namespace: openshift-ingress | ||
spec: | ||
ports: | ||
- name: http | ||
nodePort: 30080 | ||
port: 80 | ||
protocol: TCP | ||
targetPort: http | ||
- name: https | ||
nodePort: 30443 | ||
port: 443 | ||
protocol: TCP | ||
targetPort: https | ||
|
||
- name: Ensure default IngressController does not pickup EG routes | ||
k8s: | ||
state: present | ||
definition: | ||
apiVersion: operator.openshift.io/v1 | ||
kind: IngressController | ||
metadata: | ||
name: default | ||
namespace: openshift-ingress-operator | ||
spec: | ||
routeSelector: | ||
matchExpressions: | ||
- key: network | ||
operator: DoesNotExist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
post-deployment/openstack/ingress/build/playbooks/templates/eg_ingress_controller.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: operator.openshift.io/v1 | ||
kind: IngressController | ||
metadata: | ||
namespace: openshift-ingress-operator | ||
name: extragateway | ||
spec: | ||
replicas: {{ infraNodes.resources | length }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.