Skip to content

Commit 07427be

Browse files
guillaumelfvGuillaume Lefevrefostersethrooftopcellist
authored
Allow multiple ingress hosts to be defined when using ingress (ansible#1377)
* Replace api version for deployment kind to apps/v1 * Add new multiple ingress spec and deprecate hostname and ingress_tls_secret * Manage new ingress_hosts.tls_secret backup separately * Fix ci molecule lint warnings and error * Fix documentation * Fix ingress_hosts tls_secret key being optional * Remove fieldDependency:ingress_type:Ingress for Ingress Hosts * Fix scenario when neither hostname or ingress_hosts is defined --------- Co-authored-by: Guillaume Lefevre <[email protected]> Co-authored-by: Seth Foster <[email protected]> Co-authored-by: Christian Adams <[email protected]>
1 parent c23bc68 commit 07427be

File tree

9 files changed

+124
-26
lines changed

9 files changed

+124
-26
lines changed

config/crd/bases/awx.ansible.com_awxs.yaml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ spec:
5454
description: Username to use for the admin account
5555
type: string
5656
default: admin
57-
hostname:
58-
description: The hostname of the instance
57+
hostname: # deprecated
58+
description: (Deprecated) The hostname of the instance
5959
type: string
6060
admin_email:
6161
description: The admin user email
@@ -123,12 +123,24 @@ spec:
123123
ingress_annotations:
124124
description: Annotations to add to the Ingress Controller
125125
type: string
126-
ingress_tls_secret:
127-
description: Secret where the Ingress TLS secret can be found
126+
ingress_tls_secret: # deprecated
127+
description: (Deprecated) Secret where the Ingress TLS secret can be found
128128
type: string
129129
ingress_class_name:
130130
description: The name of ingress class to use instead of the cluster default.
131131
type: string
132+
ingress_hosts:
133+
description: Ingress hostnames of the instance
134+
type: array
135+
items:
136+
type: object
137+
properties:
138+
hostname:
139+
description: Hostname of the instance
140+
type: string
141+
tls_secret:
142+
description: Secret where the Ingress TLS secret can be found
143+
type: string
132144
ingress_controller:
133145
description: Special configuration for specific Ingress Controllers
134146
type: string

config/manifests/bases/awx-operator.clusterserviceversion.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ spec:
212212
kind: AWX
213213
name: awxs.awx.ansible.com
214214
specDescriptors:
215-
- displayName: Hostname
215+
- displayName: Hostname (Deprecated)
216216
path: hostname
217217
x-descriptors:
218218
- urn:alm:descriptor:com.tectonic.ui:advanced
@@ -302,12 +302,17 @@ spec:
302302
- urn:alm:descriptor:com.tectonic.ui:advanced
303303
- urn:alm:descriptor:com.tectonic.ui:text
304304
- urn:alm:descriptor:com.tectonic.ui:fieldDependency:ingress_type:Ingress
305-
- displayName: Ingress TLS Secret
305+
- displayName: Ingress TLS Secret (Deprecated)
306306
path: ingress_tls_secret
307307
x-descriptors:
308308
- urn:alm:descriptor:com.tectonic.ui:advanced
309309
- urn:alm:descriptor:io.kubernetes:Secret
310310
- urn:alm:descriptor:com.tectonic.ui:fieldDependency:ingress_type:Ingress
311+
- displayName: Ingress Hosts
312+
path: ingress_hosts
313+
x-descriptors:
314+
- urn:alm:descriptor:com.tectonic.ui:advanced
315+
- urn:alm:descriptor:com.tectonic.ui:text
311316
- displayName: Ingress Controller
312317
path: ingress_controller
313318
x-descriptors:

docs/user-guide/network-and-tls-configuration.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The following variables are customizable only when `service_type=LoadBalancer`
3232
| --------------------- | ---------------------------------------- | ------- |
3333
| loadbalancer_protocol | Protocol to use for Loadbalancer ingress | http |
3434
| loadbalancer_port | Port used for Loadbalancer ingress | 80 |
35-
| loadbalancer_ip | Assign Loadbalancer IP | '' |
35+
| loadbalancer_ip | Assign Loadbalancer IP | '' |
3636

3737
```yaml
3838
---
@@ -86,22 +86,26 @@ spec:
8686

8787
The following variables are customizable when `ingress_type=ingress`. The `ingress` type creates an Ingress resource as [documented](https://kubernetes.io/docs/concepts/services-networking/ingress/) which can be shared with many other Ingress Controllers as [listed](https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/).
8888

89-
| Name | Description | Default |
90-
| ------------------- | ---------------------------------------- | --------------------------- |
91-
| ingress_annotations | Ingress annotations | Empty string |
92-
| ingress_tls_secret | Secret that contains the TLS information | Empty string |
93-
| ingress_class_name | Define the ingress class name | Cluster default |
94-
| hostname | Define the FQDN | {{ meta.name }}.example.com |
95-
| ingress_path | Define the ingress path to the service | / |
96-
| ingress_path_type | Define the type of the path (for LBs) | Prefix |
97-
| ingress_api_version | Define the Ingress resource apiVersion | 'networking.k8s.io/v1' |
89+
| Name | Description | Default |
90+
| ---------------------------------- | ---------------------------------------------------------------------------------- | --------------------------- |
91+
| ingress_annotations | Ingress annotations | Empty string |
92+
| ingress_tls_secret _(deprecated)_ | Secret that contains the TLS information | Empty string |
93+
| ingress_class_name | Define the ingress class name | Cluster default |
94+
| hostname _(deprecated)_ | Define the FQDN | {{ meta.name }}.example.com |
95+
| ingress_hosts | Define one or multiple FQDN with optional Secret that contains the TLS information | Empty string |
96+
| ingress_path | Define the ingress path to the service | / |
97+
| ingress_path_type | Define the type of the path (for LBs) | Prefix |
98+
| ingress_api_version | Define the Ingress resource apiVersion | 'networking.k8s.io/v1' |
9899

99100
```yaml
100101
---
101102
spec:
102103
...
103104
ingress_type: ingress
104-
hostname: awx-demo.example.com
105+
ingress_hosts:
106+
- hostname: awx-demo.example.com
107+
- hostname: awx-demo.sample.com
108+
tls_secret: sample-tls-secret
105109
ingress_annotations: |
106110
environment: testing
107111
```
@@ -119,7 +123,10 @@ Some Ingress Controllers need a special configuration to fully support AWX, add
119123
spec:
120124
...
121125
ingress_type: ingress
122-
hostname: awx-demo.example.com
126+
ingress_hosts:
127+
- hostname: awx-demo.example.com
128+
- hostname: awx-demo.sample.com
129+
tls_secret: sample-tls-secret
123130
ingress_controller: contour
124131
```
125132

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
3+
- name: Get secret
4+
k8s_info:
5+
version: v1
6+
kind: Secret
7+
namespace: '{{ ansible_operator_meta.namespace }}'
8+
name: "{{ item }}"
9+
register: _secret
10+
no_log: "{{ no_log }}"
11+
12+
- name: Backup secret if exists
13+
block:
14+
- name: Set secret key
15+
set_fact:
16+
_data: "{{ _secret['resources'][0]['data'] }}"
17+
_type: "{{ _secret['resources'][0]['type'] }}"
18+
no_log: "{{ no_log }}"
19+
20+
- name: Create and Add secret names and data to dictionary
21+
set_fact:
22+
secret_dict: "{{ secret_dict | default({}) | combine({item: { 'name': item, 'data': _data, 'type': _type }}) }}"
23+
no_log: "{{ no_log }}"
24+
when: _secret | length

roles/backup/tasks/secrets.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@
1212
include_tasks: dump_secret.yml
1313
loop:
1414
- route_tls_secret
15+
# ingress_tls_secret is deprecated in favor of ingress_hosts.tls_secret
1516
- ingress_tls_secret
1617
- ldap_cacert_secret
1718
- bundle_cacert_secret
1819
- ee_pull_credentials_secret
1920

21+
- name: Dump ingress tls secret names from awx spec and data into file
22+
include_tasks: dump_ingress_tls_secrets.yml
23+
with_items:
24+
- "{{ awx_spec.spec['ingress_hosts'] | default('') | map(attribute='tls_secret', default='') | select() | list }}"
25+
when: "{{ awx_spec.spec['ingress_hosts'] | default('') | map(attribute='tls_secret', default='') | select() | list | length }}"
26+
2027
- name: Dump receptor secret names and data into file
2128
include_tasks: dump_receptor_secrets.yml
2229
loop:

roles/installer/defaults/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ ingress_tls_secret: ''
4040
# ingress_controller: contour
4141
ingress_controller: ''
4242

43+
# One or multiple FQDN with optional Secret that contains the TLS information.
44+
# The TLS secret either has to exist before hand with
45+
# the corresponding cert and key or just be an indicator for where an automated
46+
# process like cert-manager (enabled via annotations) will store the TLS
47+
# certificate and key.
48+
# ingress_hosts:
49+
# - hostname: awx-demo.example.com
50+
# tls_secret: example-com-tls
51+
ingress_hosts: ''
52+
4353
loadbalancer_protocol: 'http'
4454
loadbalancer_port: '80'
4555
service_annotations: ''

roles/installer/tasks/install.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- name: Delete old deployment for before installing during upgrade
33
k8s:
44
kind: Deployment
5-
api_version: v1
5+
api_version: apps/v1
66
namespace: "{{ ansible_operator_meta.namespace }}"
77
name: "{{ ansible_operator_meta.name }}"
88
state: absent

roles/installer/tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
- name: Check for presence of awx-task Deployment
1111
k8s_info:
12-
api_version: v1
12+
api_version: apps/v1
1313
kind: Deployment
1414
name: "{{ ansible_operator_meta.name }}-task"
1515
namespace: "{{ ansible_operator_meta.namespace }}"
1616
register: awx_task_deployment
1717

1818
- name: Check for presence of awx-web Deployment
1919
k8s_info:
20-
api_version: v1
20+
api_version: apps/v1
2121
kind: Deployment
2222
name: "{{ ansible_operator_meta.name }}-web"
2323
namespace: "{{ ansible_operator_meta.namespace }}"

roles/installer/templates/networking/ingress.yaml.j2

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ metadata:
1313
annotations:
1414
{% if ingress_annotations %}
1515
{{ ingress_annotations | indent(width=4) }}
16-
{% endif %}
16+
{%- endif %}
1717
{% if ingress_controller|lower == "contour" %}
1818
projectcontour.io/websocket-routes: "/websocket"
1919
kubernetes.io/ingress.class: contour
@@ -24,6 +24,7 @@ spec:
2424
ingressClassName: '{{ ingress_class_name }}'
2525
{% endif %}
2626
rules:
27+
{% if not ingress_hosts %}
2728
- http:
2829
paths:
2930
- path: '{{ ingress_path }}'
@@ -33,6 +34,9 @@ spec:
3334
name: '{{ ansible_operator_meta.name }}-service'
3435
port:
3536
number: 80
37+
{% if hostname %}
38+
host: {{ hostname }}
39+
{% endif %}
3640
{% if ingress_controller|lower == "contour" %}
3741
- path: '{{ ingress_path.rstrip("/") }}/websocket'
3842
pathType: '{{ ingress_path_type }}'
@@ -42,16 +46,45 @@ spec:
4246
port:
4347
number: 80
4448
{% endif %}
45-
{% if hostname %}
46-
host: {{ hostname }}
47-
{% endif %}
4849
{% if ingress_tls_secret %}
4950
tls:
5051
- hosts:
51-
- {{ hostname }}
52+
- {{ hostname }}
5253
secretName: {{ ingress_tls_secret }}
5354
{% endif %}
5455
{% endif %}
56+
{% if ingress_hosts %}
57+
{% for item in ingress_hosts %}
58+
- host: {{ item.hostname }}
59+
http:
60+
paths:
61+
- path: '{{ ingress_path }}'
62+
pathType: '{{ ingress_path_type }}'
63+
backend:
64+
service:
65+
name: '{{ ansible_operator_meta.name }}-service'
66+
port:
67+
number: 80
68+
{% if ingress_controller|lower == "contour" %}
69+
- path: '{{ ingress_path.rstrip("/") }}/websocket'
70+
pathType: '{{ ingress_path_type }}'
71+
backend:
72+
service:
73+
name: '{{ ansible_operator_meta.name }}-service'
74+
port:
75+
number: 80
76+
{% endif %}
77+
{% endfor %}
78+
tls:
79+
{% for item in ingress_hosts %}
80+
{% if 'tls_secret' in item %}
81+
- hosts:
82+
- {{ item.hostname }}
83+
secretName: {{ item.tls_secret }}
84+
{% endif %}
85+
{% endfor %}
86+
{% endif %}
87+
{% endif %}
5588

5689
{% if ingress_type|lower == "route" %}
5790
---

0 commit comments

Comments
 (0)