-
Notifications
You must be signed in to change notification settings - Fork 420
/
create-ingress.yaml
125 lines (123 loc) · 3.95 KB
/
create-ingress.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: create-ingress
spec:
volumes:
- name: work
emptyDir: {}
params:
- name: CreateCertificate
description: "Enables/disables the creation of a self-signed certificate for $(params.ExternalDomain)"
default: "true"
- name: CertificateKeyPassphrase
description: "Phrase that protects private key. This must be provided when the self-signed certificate is created"
- name: CertificateSecretName
description: "Secret name for Ingress certificate. The Secret should not exist if the self-signed certificate creation is enabled"
- name: ExternalDomain
description: "The external domain for the EventListener e.g. `$(params.EventListenerName).PROXYIP.nip.io`"
- name: Service
description: "The name of the Service used in the Ingress. This will also be the name of the Ingress."
- name: ServicePort
description: "The service port that the ingress is being created on"
- name: ServiceUID
description: "The uid of the service. If set, this creates an owner reference on the service"
default: ""
steps:
- name: generate-certificate
image: frapsoft/openssl
volumeMounts:
- name: work
mountPath: /var/tmp/work
command:
- sh
args:
- -ce
- |
set -e
cat <<EOF | sh
#!/bin/sh
if [ $(params.CreateCertificate) = "false" ];then
exit 0
fi
mkdir /var/tmp/work/ingress
openssl genrsa -des3 -out /var/tmp/work/ingress/key.pem -passout pass:$(params.CertificateKeyPassphrase) 2048
openssl req -x509 -new -nodes -key /var/tmp/work/ingress/key.pem -sha256 -days 1825 -out /var/tmp/work/ingress/certificate.pem -passin pass:$(params.CertificateKeyPassphrase) -subj /CN=$(params.ExternalDomain)
openssl rsa -in /var/tmp/work/ingress/key.pem -out /var/tmp/work/ingress/key.pem -passin pass:$(params.CertificateKeyPassphrase)
EOF
- name: create-certificate-secret
image: lachlanevenson/k8s-kubectl:latest
volumeMounts:
- name: work
mountPath: /var/tmp/work
command:
- sh
args:
- -ce
- |
set -e
cat <<EOF | sh
#!/bin/sh
if [ $(params.CreateCertificate) = "false" ];then
exit 0
fi
kubectl create secret tls $(params.CertificateSecretName) --cert=/var/tmp/work/ingress/certificate.pem --key=/var/tmp/work/ingress/key.pem || true
EOF
- name: create-ingress
image: lachlanevenson/k8s-kubectl:latest
command:
- sh
args:
- -ce
- |
set -e
if [ -n "$(params.ServiceUID)" ];then
cat <<EOF | kubectl create -f - || true
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: $(params.Service)
ownerReferences:
- name: $(params.Service)
apiVersion: v1
kind: Service
uid: $(params.ServiceUID)
spec:
tls:
- secretName: $(params.CertificateSecretName)
hosts:
- $(params.ExternalDomain)
rules:
- host: $(params.ExternalDomain)
http:
paths:
- pathType: ImplementationSpecific
backend:
service:
name: $(params.Service)
port:
number: $(params.ServicePort)
EOF
else
cat <<EOF | kubectl create -f - || true
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: $(params.Service)
spec:
tls:
- secretName: $(params.CertificateSecretName)
hosts:
- $(params.ExternalDomain)
rules:
- host: $(params.ExternalDomain)
http:
paths:
- pathType: ImplementationSpecific
backend:
service:
name: $(params.Service)
port:
number: $(params.ServicePort)
EOF
fi