Skip to content

Commit 0008b5b

Browse files
authored
Merge pull request #3775 from eratnch/tilt_cert_manager_ext
Use tilt cert_manager extension
2 parents c1a858c + ec91428 commit 0008b5b

File tree

4 files changed

+99
-60
lines changed

4 files changed

+99
-60
lines changed

Tiltfile

+2-60
Original file line numberDiff line numberDiff line change
@@ -140,33 +140,6 @@ COPY --from=tilt-helper /restart.sh .
140140
COPY manager .
141141
"""
142142

143-
cert_manager_test_resources = """
144-
apiVersion: v1
145-
kind: Namespace
146-
metadata:
147-
name: cert-manager-test
148-
---
149-
apiVersion: cert-manager.io/v1alpha2
150-
kind: Issuer
151-
metadata:
152-
name: test-selfsigned
153-
namespace: cert-manager-test
154-
spec:
155-
selfSigned: {}
156-
---
157-
apiVersion: cert-manager.io/v1alpha2
158-
kind: Certificate
159-
metadata:
160-
name: selfsigned-cert
161-
namespace: cert-manager-test
162-
spec:
163-
dnsNames:
164-
- example.com
165-
secretName: selfsigned-cert-tls
166-
issuerRef:
167-
name: test-selfsigned
168-
"""
169-
170143
# Configures a provider by doing the following:
171144
#
172145
# 1. Enables a local_resource go build of the provider's manager binary
@@ -234,39 +207,6 @@ def enable_provider(name):
234207
yaml = str(kustomize_with_envsubst(context + "/config"))
235208
k8s_yaml(blob(yaml))
236209

237-
# Prepull all the cert-manager images to your local environment and then load them directly into kind. This speeds up
238-
# setup if you're repeatedly destroying and recreating your kind cluster, as it doesn't have to pull the images over
239-
# the network each time.
240-
def deploy_cert_manager():
241-
registry = settings.get("cert_manager_registry", "quay.io/jetstack")
242-
version = settings.get("cert_manager_version", "v0.16.1")
243-
244-
# check if cert-mamager is already installed, otherwise pre-load images & apply the manifest
245-
# NB. this is required until https://github.com/jetstack/cert-manager/issues/3121 is addressed otherwise
246-
# when applying the manifest twice to same cluster kubectl get stuck
247-
existsCheck = str(local("kubectl get namespaces"))
248-
if existsCheck.find("cert-manager") == -1:
249-
# pre-load cert-manager images in kind
250-
images = ["cert-manager-controller", "cert-manager-cainjector", "cert-manager-webhook"]
251-
if settings.get("preload_images_for_kind"):
252-
for image in images:
253-
local("docker pull {}/{}:{}".format(registry, image, version))
254-
local("kind load docker-image --name {} {}/{}:{}".format(settings.get("kind_cluster_name"), registry, image, version))
255-
256-
# apply the cert-manager manifest
257-
local("kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/{}/cert-manager.yaml".format(version))
258-
259-
# verifies cert-manager is properly working (https://cert-manager.io/docs/installation/kubernetes/#verifying-the-installation)
260-
# 1. wait for the cert-manager to be running
261-
local("kubectl wait --for=condition=Available --timeout=300s -n cert-manager deployment/cert-manager")
262-
local("kubectl wait --for=condition=Available --timeout=300s -n cert-manager deployment/cert-manager-cainjector")
263-
local("kubectl wait --for=condition=Available --timeout=300s -n cert-manager deployment/cert-manager-webhook")
264-
265-
# 2. create a test certificate
266-
local("cat << EOF | kubectl apply -f - " + cert_manager_test_resources + "EOF")
267-
local("kubectl wait --for=condition=Ready --timeout=300s -n cert-manager-test certificate/selfsigned-cert ")
268-
local("cat << EOF | kubectl delete -f - " + cert_manager_test_resources + "EOF")
269-
270210
# Users may define their own Tilt customizations in tilt.d. This directory is excluded from git and these files will
271211
# not be checked in to version control.
272212
def include_user_tilt_files():
@@ -292,6 +232,8 @@ include_user_tilt_files()
292232

293233
load_provider_tiltfiles()
294234

235+
load("ext://cert_manager", "deploy_cert_manager")
236+
295237
if settings.get("deploy_cert_manager"):
296238
deploy_cert_manager()
297239

tilt_modules/cert_manager/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Cert-manager
2+
3+
This extension deploys cert-manager.
4+
5+
## Usage
6+
7+
Basic usage
8+
9+
```
10+
load('ext://cert_manager', 'deploy_cert_manager')
11+
12+
deploy_cert_manager()
13+
```
14+
15+
This will deploy cert-manager to you cluster and checks it actually works.
16+
17+
If working with Kind, its is possible to pass `load_to_kind=True` to `deploy_cert_manager` so
18+
all the cert-manager images will be pre-pulled to your local environment and then loaded into Kind before installing.
19+
This speeds up your workflow if you're repeatedly destroying and recreating your kind cluster, as it doesn't
20+
have to pull the images over the network each time.
21+
22+
The full list of parameters accepted by `deploy_cert_manager` includes:
23+
- `registry` from which images should be pulled, defaults to `quay.io/jetstack`
24+
- `version` of cert-manager to install, defaults to `v0.16.1`
25+
- `load_to_kind` (see above), defaults to `False`
26+
- `kind_cluster_name`, defaults to `kind`

tilt_modules/cert_manager/Tiltfile

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
cert_manager_test_resources = """
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: cert-manager-test
6+
---
7+
apiVersion: cert-manager.io/v1alpha2
8+
kind: Issuer
9+
metadata:
10+
name: test-selfsigned
11+
namespace: cert-manager-test
12+
spec:
13+
selfSigned: {}
14+
---
15+
apiVersion: cert-manager.io/v1alpha2
16+
kind: Certificate
17+
metadata:
18+
name: selfsigned-cert
19+
namespace: cert-manager-test
20+
spec:
21+
dnsNames:
22+
- example.com
23+
secretName: selfsigned-cert-tls
24+
issuerRef:
25+
name: test-selfsigned
26+
"""
27+
28+
# Deploys cert manager to your environment
29+
def deploy_cert_manager(registry="quay.io/jetstack", version="v0.16.1", load_to_kind=False, kind_cluster_name="kind"):
30+
silent=True
31+
32+
# check if cert-mamager is already installed, otherwise pre-load images & apply the manifest
33+
# NB. this is required until https://github.com/jetstack/cert-manager/issues/3121 is addressed otherwise
34+
# when applying the manifest twice to same cluster kubectl get stuck
35+
existsCheck = str(local("kubectl get namespaces", quiet=silent, echo_off=silent))
36+
if existsCheck.find("cert-manager") == -1:
37+
if load_to_kind == True:
38+
print("Loading images to kind")
39+
# Prepull all the cert-manager images to your local environment and then load them directly into kind. This speeds up
40+
# setup if you're repeatedly destroying and recreating your kind cluster, as it doesn't have to pull the images over
41+
# the network each time.
42+
images = ["cert-manager-controller", "cert-manager-cainjector", "cert-manager-webhook"]
43+
for image in images:
44+
local("docker pull {}/{}:{}".format(registry, image, version), quiet=silent, echo_off=silent)
45+
local("kind load docker-image --name {} {}/{}:{}".format(kind_cluster_name, registry, image, version), quiet=silent, echo_off=silent)
46+
47+
# apply the cert-manager manifest
48+
print("Installing cert-manager")
49+
local("kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/{}/cert-manager.yaml".format(version), quiet=silent, echo_off=silent)
50+
51+
# verifies cert-manager is properly working (https://cert-manager.io/docs/installation/kubernetes/#verifying-the-installation)
52+
# 1. wait for the cert-manager to be running
53+
print("Waiting for cert-manager to start")
54+
local("kubectl wait --for=condition=Available --timeout=300s -n cert-manager deployment/cert-manager", quiet=silent, echo_off=silent)
55+
local("kubectl wait --for=condition=Available --timeout=300s -n cert-manager deployment/cert-manager-cainjector", quiet=silent, echo_off=silent)
56+
local("kubectl wait --for=condition=Available --timeout=300s -n cert-manager deployment/cert-manager-webhook", quiet=silent, echo_off=silent)
57+
58+
# 2. create a test certificate
59+
print("Testing cert-manager")
60+
local("cat << EOF | kubectl apply -f - " + cert_manager_test_resources + "EOF", quiet=silent, echo_off=silent)
61+
local("kubectl wait --for=condition=Ready --timeout=300s -n cert-manager-test certificate/selfsigned-cert ", quiet=silent, echo_off=silent)
62+
local("cat << EOF | kubectl delete -f - " + cert_manager_test_resources + "EOF", quiet=silent, echo_off=silent)

tilt_modules/extensions.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Extensions": [
3+
{
4+
"Name": "cert_manager",
5+
"ExtensionRegistry": "https://github.com/tilt-dev/tilt-extensions",
6+
"TimeFetched": "2020-10-13T10:04:11.507324896-07:00"
7+
}
8+
]
9+
}

0 commit comments

Comments
 (0)