From 53974406739f39182d75d4fbdd67a582f7be54cf Mon Sep 17 00:00:00 2001 From: ToMe25 Date: Tue, 12 Oct 2021 14:23:41 +0100 Subject: [PATCH] Generate ingress manifests exactly matching the manual changes This solution isn't perfect, but it works. --- manifests/ingress-alertmanager.yaml | 9 ++++-- manifests/ingress-grafana.yaml | 9 ++++-- manifests/ingress-prometheus.yaml | 9 ++++-- utils.libsonnet | 49 ++++++++++++++++++----------- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/manifests/ingress-alertmanager.yaml b/manifests/ingress-alertmanager.yaml index 7ceb184..5580065 100644 --- a/manifests/ingress-alertmanager.yaml +++ b/manifests/ingress-alertmanager.yaml @@ -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 diff --git a/manifests/ingress-grafana.yaml b/manifests/ingress-grafana.yaml index 5daee18..a8aecd3 100644 --- a/manifests/ingress-grafana.yaml +++ b/manifests/ingress-grafana.yaml @@ -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 diff --git a/manifests/ingress-prometheus.yaml b/manifests/ingress-prometheus.yaml index 03f0e50..ff4b826 100644 --- a/manifests/ingress-prometheus.yaml +++ b/manifests/ingress-prometheus.yaml @@ -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 diff --git a/utils.libsonnet b/utils.libsonnet index d9d4945..f5137af 100644 --- a/utils.libsonnet +++ b/utils.libsonnet @@ -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