Generate ingress manifests exactly matching the manual changes

This solution isn't perfect, but it works.
This commit is contained in:
ToMe25 2021-10-12 14:23:41 +01:00
parent 3643fdedad
commit 5397440673
4 changed files with 49 additions and 27 deletions

View File

@ -1,4 +1,4 @@
apiVersion: networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: alertmanager-main
@ -9,9 +9,12 @@ spec:
http:
paths:
- backend:
serviceName: alertmanager-main
servicePort: web
service:
name: alertmanager-main
port:
name: web
path: /
pathType: Prefix
tls:
- hosts:
- alertmanager.192.168.1.15.nip.io

View File

@ -1,4 +1,4 @@
apiVersion: networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: grafana
@ -9,9 +9,12 @@ spec:
http:
paths:
- backend:
serviceName: grafana
servicePort: http
service:
name: grafana
port:
name: http
path: /
pathType: Prefix
tls:
- hosts:
- grafana.192.168.1.15.nip.io

View File

@ -1,4 +1,4 @@
apiVersion: networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: prometheus-k8s
@ -9,9 +9,12 @@ spec:
http:
paths:
- backend:
serviceName: prometheus-k8s
servicePort: web
service:
name: prometheus-k8s
port:
name: web
path: /
pathType: Prefix
tls:
- hosts:
- prometheus.192.168.1.15.nip.io

View File

@ -92,24 +92,37 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
// Creates ingress objects
newIngress(name, namespace, host, path, serviceName, servicePort):: (
local ingress = k.networking.v1beta1.ingress;
local ingressTls = ingress.mixin.spec.tlsType;
local ingressRule = ingress.mixin.spec.rulesType;
local httpIngressPath = ingressRule.mixin.http.pathsType;
ingress.new()
+ ingress.mixin.metadata.withName(name)
+ ingress.mixin.metadata.withNamespace(namespace)
+ ingress.mixin.spec.withRules(
ingressRule.new()
+ ingressRule.withHost(host)
+ ingressRule.mixin.http.withPaths(
httpIngressPath.new()
+ httpIngressPath.withPath(path)
+ httpIngressPath.mixin.backend.withServiceName(serviceName)
+ httpIngressPath.mixin.backend.withServicePort(servicePort)
),
)
{
apiVersion: 'networking.k8s.io/v1',
kind: 'Ingress',
metadata: {
name: name,
namespace: namespace,
},
spec: {
rules: [
{
host: host,
http: {
paths: [
{
backend: {
service: {
name: serviceName,
port: {
name: servicePort,
},
},
},
path: path,
pathType: 'Prefix',
},
],
},
},
],
},
}
),
// Add TLS to Ingress resource with secret containing the certificates if exists