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 kind: Ingress
metadata: metadata:
name: alertmanager-main name: alertmanager-main
@ -9,9 +9,12 @@ spec:
http: http:
paths: paths:
- backend: - backend:
serviceName: alertmanager-main service:
servicePort: web name: alertmanager-main
port:
name: web
path: / path: /
pathType: Prefix
tls: tls:
- hosts: - hosts:
- alertmanager.192.168.1.15.nip.io - 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 kind: Ingress
metadata: metadata:
name: grafana name: grafana
@ -9,9 +9,12 @@ spec:
http: http:
paths: paths:
- backend: - backend:
serviceName: grafana service:
servicePort: http name: grafana
port:
name: http
path: / path: /
pathType: Prefix
tls: tls:
- hosts: - hosts:
- grafana.192.168.1.15.nip.io - 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 kind: Ingress
metadata: metadata:
name: prometheus-k8s name: prometheus-k8s
@ -9,9 +9,12 @@ spec:
http: http:
paths: paths:
- backend: - backend:
serviceName: prometheus-k8s service:
servicePort: web name: prometheus-k8s
port:
name: web
path: / path: /
pathType: Prefix
tls: tls:
- hosts: - hosts:
- prometheus.192.168.1.15.nip.io - 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 // Creates ingress objects
newIngress(name, namespace, host, path, serviceName, servicePort):: ( newIngress(name, namespace, host, path, serviceName, servicePort):: (
local ingress = k.networking.v1beta1.ingress; {
local ingressTls = ingress.mixin.spec.tlsType; apiVersion: 'networking.k8s.io/v1',
local ingressRule = ingress.mixin.spec.rulesType; kind: 'Ingress',
local httpIngressPath = ingressRule.mixin.http.pathsType; metadata: {
name: name,
ingress.new() namespace: namespace,
+ ingress.mixin.metadata.withName(name) },
+ ingress.mixin.metadata.withNamespace(namespace) spec: {
+ ingress.mixin.spec.withRules( rules: [
ingressRule.new() {
+ ingressRule.withHost(host) host: host,
+ ingressRule.mixin.http.withPaths( http: {
httpIngressPath.new() paths: [
+ httpIngressPath.withPath(path) {
+ httpIngressPath.mixin.backend.withServiceName(serviceName) backend: {
+ httpIngressPath.mixin.backend.withServicePort(servicePort) service: {
), name: serviceName,
) port: {
name: servicePort,
},
},
},
path: path,
pathType: 'Prefix',
},
],
},
},
],
},
}
), ),
// Add TLS to Ingress resource with secret containing the certificates if exists // Add TLS to Ingress resource with secret containing the certificates if exists