Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit b76db7a

Browse files
committed
Wait for cert-manager to be ready
- cert-manager now uses a webhook validator so needs to be in a ready state before resources can be applied via kubectl - updates instructions on switching from staging to prod issuer Signed-off-by: Alex Ellis <alexellis2@gmail.com>
1 parent d6719e3 commit b76db7a

File tree

8 files changed

+68
-20
lines changed

8 files changed

+68
-20
lines changed

README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,32 @@ In order to enable TLS, edit the following configuration:
122122
If you need to test in Staging and then go to Production without resetting the cluster:
123123
* Use `issuer_type: "staging"`
124124
* Run ofc-bootstrap with the instructions bellow
125-
* Once you want to switch to Production run
125+
* Once you want to switch to the Production issuer
126+
127+
Flush out the staging certificates and orders
128+
129+
```sh
130+
kubectl delete certificates --all -n openfaas
131+
kubectl delete secret -n openfaas -l="certmanager.k8s.io/certificate-name"
132+
kubectl delete order -n openfaas --all
126133
```
134+
135+
Now update the staging references to "prod":
136+
137+
```sh
127138
sed -i '' s/letsencrypt-staging/letsencrypt-prod/g ./tmp/generated-ingress-ingress-wildcard.yaml
128-
kubectl apply -f ./tmp/generated-ingress-ingress-wildcard.yaml
129139
sed -i '' s/letsencrypt-staging/letsencrypt-prod/g ./tmp/generated-ingress-ingress.yaml
130-
kubectl apply -f ./tmp/generated-ingress-ingress.yaml
131140
sed -i '' s/letsencrypt-staging/letsencrypt-prod/g ./tmp/generated-tls-auth-domain-cert.yml
132-
kubectl apply -f ./tmp/generated-tls-auth-domain-cert.yml
133141
sed -i '' s/letsencrypt-staging/letsencrypt-prod/g ./tmp/generated-tls-wildcard-domain-cert.yml
134-
kubectl apply -f ./tmp/generated-tls-wildcard-domain-cert.yml
142+
```
135143

136-
kubectl delete certificates --all -n openfaas
144+
Now create the new ingress and certificates:
145+
146+
```sh
147+
kubectl apply -f ./tmp/generated-ingress-ingress-wildcard.yaml
148+
kubectl apply -f ./tmp/generated-ingress-ingress.yaml
149+
kubectl apply -f ./tmp/generated-tls-auth-domain-cert.yml
150+
kubectl apply -f ./tmp/generated-tls-wildcard-domain-cert.yml
137151
```
138152

139153
### Run the Bootstrapper

init.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ enable_oauth: false
135135
### your OpenFaaS Cloud.
136136
tls: true
137137
tls_config:
138-
email: "user@domain"
138+
# email: "user@domain"
139+
139140

140141
# issuer_type: "prod"
141142
issuer_type: "staging"

main.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ func process(plan types.Plan) error {
194194
log.Println(ofErr)
195195
}
196196

197+
for i := 0; i < retries; i++ {
198+
log.Printf("Is cert-manager ready? %d/%d\n", i+1, retries)
199+
ready := certManagerReady()
200+
if ready {
201+
break
202+
}
203+
time.Sleep(time.Second * 2)
204+
}
205+
197206
ingressErr := ingress.Apply(plan)
198207
if ingressErr != nil {
199208
log.Println(ingressErr)
@@ -334,8 +343,7 @@ func installIngressController() error {
334343
return err
335344
}
336345

337-
log.Println(res.Stdout)
338-
log.Println(res.Stderr)
346+
log.Println(res.ExitCode, res.Stdout, res.Stderr)
339347

340348
return nil
341349
}
@@ -374,8 +382,7 @@ func installOpenfaas() error {
374382
return err
375383
}
376384

377-
log.Println(res.Stdout)
378-
log.Println(res.Stderr)
385+
log.Println(res.ExitCode, res.Stdout, res.Stderr)
379386

380387
return nil
381388
}
@@ -414,8 +421,7 @@ func installCertmanager() error {
414421
return err
415422
}
416423

417-
log.Println(res.Stdout)
418-
log.Println(res.Stderr)
424+
log.Println(res.ExitCode, res.Stdout, res.Stderr)
419425

420426
return nil
421427
}
@@ -434,8 +440,7 @@ func createNamespaces() error {
434440
return err
435441
}
436442

437-
log.Println(res.Stdout)
438-
log.Println(res.Stderr)
443+
log.Println(res.ExitCode, res.Stdout, res.Stderr)
439444

440445
return nil
441446
}
@@ -491,6 +496,17 @@ func exportSealedSecretPubCert() string {
491496
return res.Stdout
492497
}
493498

499+
func certManagerReady() bool {
500+
task := execute.ExecTask{
501+
Command: "./scripts/get-cert-manager.sh",
502+
Shell: true,
503+
}
504+
505+
res, err := task.Execute()
506+
fmt.Println("cert-manager", res.ExitCode, res.Stdout, res.Stderr, err)
507+
return res.Stdout == "True"
508+
}
509+
494510
func tillerReady() bool {
495511

496512
task := execute.ExecTask{

pkg/ingress/ingress.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type IngressTemplate struct {
1818
DNSService string
1919
}
2020

21+
// Apply templates and applies any ingress records required
22+
// for the OpenFaaS Cloud ingress configuration
2123
func Apply(plan types.Plan) error {
2224

2325
err := apply("ingress-wildcard.yml", "ingress-wildcard", IngressTemplate{
@@ -90,7 +92,7 @@ func apply(source string, name string, ingress IngressTemplate) error {
9092
return execErr
9193
}
9294

93-
log.Println(execRes.Stdout)
95+
log.Println(execRes.ExitCode, execRes.Stdout, execRes.Stderr)
9496

9597
return nil
9698
}

pkg/tls/tls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func applyTemplate(tempFilePath string) error {
9797
return execErr
9898
}
9999

100-
log.Println(execRes.Stdout)
100+
log.Println(execRes.ExitCode, execRes.Stdout, execRes.Stderr)
101101

102102
return nil
103103
}

scripts/create-namespaces.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#!/bin/bash
22

33
kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml
4+
5+
kubectl create namespace cert-manager
6+
kubectl label namespace cert-manager certmanager.k8s.io/disable-validation=true
7+
8+
kubectl get namespaces

scripts/get-cert-manager.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
# cert-manager is ready for CRD objects when this condition is "True"
4+
CERT_READY=$(kubectl get cert/cert-manager-webhook-webhook-tls -n cert-manager -o jsonpath="{.status.conditions[0].status}")
5+
WEBHOOK_READY=$(kubectl get deploy/cert-manager-webhook -n cert-manager -o jsonpath="{.status.conditions[0].status}")
6+
7+
if [ "$CERT_READY" = "True" ]
8+
then
9+
if [ "$WEBHOOK_READY" = "True" ]
10+
then
11+
echo -n True
12+
fi
13+
fi

scripts/install-cert-manager.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
kubectl apply \
44
-f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.6/deploy/manifests/00-crds.yaml
55

6-
kubectl create namespace cert-manager
7-
kubectl label namespace cert-manager certmanager.k8s.io/disable-validation=true
8-
96
helm install \
107
--name cert-manager \
118
--namespace cert-manager \

0 commit comments

Comments
 (0)