Skip to content

Commit 514aa37

Browse files
ToMe25carlosedp
authored andcommitted
Add support for more then one suffix domain
1 parent c0807b6 commit 514aa37

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed

base_operator_stack.jsonnet

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ local vars = import 'vars.jsonnet';
77
namespace: 'monitoring',
88

99
urls+:: {
10-
prom_ingress: 'prometheus.' + vars.suffixDomain,
11-
alert_ingress: 'alertmanager.' + vars.suffixDomain,
12-
grafana_ingress: 'grafana.' + vars.suffixDomain,
10+
domains: [vars.suffixDomain] + vars.additionalDomains,
11+
prom_ingress: ['prometheus.' + domain for domain in $._config.urls.domains],
12+
alert_ingress: ['alertmanager.' + domain for domain in $._config.urls.domains],
13+
grafana_ingress: ['grafana.' + domain for domain in $._config.urls.domains],
1314
grafana_ingress_external: 'grafana.' + vars.suffixDomain,
1415
},
1516

@@ -76,7 +77,7 @@ local vars = import 'vars.jsonnet';
7677
retention: vars.prometheus.retention,
7778
scrapeInterval: vars.prometheus.scrapeInterval,
7879
scrapeTimeout: vars.prometheus.scrapeTimeout,
79-
externalUrl: 'http://' + $._config.urls.prom_ingress,
80+
externalUrl: 'http://' + $._config.urls.prom_ingress[0],
8081
}
8182
+ (if vars.enablePersistence.prometheus then {
8283
storage: {
@@ -139,29 +140,29 @@ local vars = import 'vars.jsonnet';
139140
local I = utils.newIngress('alertmanager-main', $._config.namespace, $._config.urls.alert_ingress, '/', 'alertmanager-main', 'web');
140141
if vars.TLSingress then
141142
if vars.UseProvidedCerts then
142-
utils.addIngressTLS(I, 'ingress-secret')
143+
utils.addIngressTLS(I, $._config.urls.alert_ingress, 'ingress-secret')
143144
else
144-
utils.addIngressTLS(I)
145+
utils.addIngressTLS(I, $._config.urls.alert_ingress)
145146
else
146147
I,
147148

148149
grafana:
149150
local I = utils.newIngress('grafana', $._config.namespace, $._config.urls.grafana_ingress, '/', 'grafana', 'http');
150151
if vars.TLSingress then
151152
if vars.UseProvidedCerts then
152-
utils.addIngressTLS(I, 'ingress-secret')
153+
utils.addIngressTLS(I, $._config.urls.grafana_ingress, 'ingress-secret')
153154
else
154-
utils.addIngressTLS(I)
155+
utils.addIngressTLS(I, $._config.urls.grafana_ingress)
155156
else
156157
I,
157158

158159
prometheus:
159160
local I = utils.newIngress('prometheus-k8s', $._config.namespace, $._config.urls.prom_ingress, '/', 'prometheus-k8s', 'web');
160161
if vars.TLSingress then
161162
if vars.UseProvidedCerts then
162-
utils.addIngressTLS(I, 'ingress-secret')
163+
utils.addIngressTLS(I, $._config.urls.prom_ingress, 'ingress-secret')
163164
else
164-
utils.addIngressTLS(I)
165+
utils.addIngressTLS(I, $._config.urls.prom_ingress)
165166
else
166167
I,
167168

utils.libsonnet

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
9191
),
9292

9393
// Creates ingress objects
94-
newIngress(name, namespace, host, path, serviceName, servicePort):: (
94+
newIngress(name, namespace, hosts, path, serviceName, servicePort):: (
9595
{
9696
apiVersion: 'networking.k8s.io/v1',
9797
kind: 'Ingress',
@@ -100,42 +100,44 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
100100
namespace: namespace,
101101
},
102102
spec: {
103-
rules: [
103+
rules: [$.newIngressHost(host, path, serviceName, servicePort) for host in hosts],
104+
},
105+
}
106+
),
107+
108+
// Add host to Ingress resource
109+
newIngressHost(host, path, serviceName, servicePort):: (
110+
{
111+
host: host,
112+
http: {
113+
paths: [
104114
{
105-
host: host,
106-
http: {
107-
paths: [
108-
{
109-
backend: {
110-
service: {
111-
name: serviceName,
112-
port: {
113-
name: servicePort,
114-
},
115-
},
116-
},
117-
path: path,
118-
pathType: 'Prefix',
115+
backend: {
116+
service: {
117+
name: serviceName,
118+
port: {
119+
name: servicePort,
119120
},
120-
],
121+
},
121122
},
123+
path: path,
124+
pathType: 'Prefix',
122125
},
123126
],
124127
},
125128
}
126129
),
127130

128131
// Add TLS to Ingress resource with secret containing the certificates if exists
129-
addIngressTLS(I, S=''):: (
132+
addIngressTLS(I, hosts, secretName=''):: (
130133
local ingress = k.networking.v1beta1.ingress;
131134
local ingressTls = ingress.mixin.spec.tlsType;
132-
local host = I.spec.rules[0].host;
133135
local namespace = I.metadata.namespace;
134136

135137
I + ingress.mixin.spec.withTls(
136138
ingressTls.new() +
137-
ingressTls.withHosts(host) +
138-
(if S != '' then { secretName: S } else {})
139+
ingressTls.withHosts(hosts) +
140+
(if secretName != '' then { secretName: secretName } else {})
139141
)
140142
),
141143

vars.jsonnet

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454

5555
// Domain suffix for the ingresses
5656
suffixDomain: '192.168.1.15.nip.io',
57+
// Additional domain suffixes for the ingresses.
58+
// For example suffixDomain could be an external one and this a local domain.
59+
additionalDomains: [],
5760
// If TLSingress is true, a self-signed HTTPS ingress with redirect will be created
5861
TLSingress: true,
5962
// If UseProvidedCerts is true, provided files will be used on created HTTPS ingresses.

0 commit comments

Comments
 (0)