Skip to content

Commit 218cc62

Browse files
authored
[TPU Provisioner] Add Skaffold for development and Cert Manager to admission controller (#696)
* Add skaffold and cert manager to TPU provisioner admission controller * Fix cert injection annotation * Update README.md
1 parent f3e12b3 commit 218cc62

File tree

4 files changed

+77
-26
lines changed

4 files changed

+77
-26
lines changed

tpu-provisioner/admission_controller/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ WORKDIR /webhook
33
COPY requirements.txt /webhook
44
COPY admission_controller.py /webhook
55
RUN pip install --no-cache-dir --upgrade -r /webhook/requirements.txt
6-
CMD ["uvicorn", "admission_controller:app", "--host", "0.0.0.0", "--port", "5000","--ssl-keyfile=/certs/webhook.key", "--ssl-certfile=/certs/webhook.crt"]
6+
CMD ["uvicorn", "admission_controller:app", "--host", "0.0.0.0", "--port", "5000","--ssl-keyfile=/certs/tls.key", "--ssl-certfile=/certs/tls.crt"]

tpu-provisioner/admission_controller/README.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ for changing to fit their use case.
3030

3131
Update the Deployment in `manifests/manifest.yaml` with this container image.
3232

33+
### Local Development
34+
35+
Create a minikube (or kind) cluster.
36+
37+
```bash
38+
minikube create cluster
39+
# OR: kind create cluster
40+
```
41+
42+
Install dependencies.
43+
44+
```bash
45+
kubectl apply --server-side -f https://github.com/kubernetes-sigs/jobset/releases/download/v0.5.1/manifests.yaml
46+
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.5/cert-manager.yaml
47+
```
48+
49+
Deploy the controller locally.
50+
51+
```bash
52+
skaffold dev
53+
```
54+
3355
### Run Unit tests
3456

3557
This project uses [pytest](https://docs.pytest.org) for unit testing.
@@ -43,4 +65,4 @@ E2E testing is currently done manually via the following steps:
4365
1. [Install JobSet](https://jobset.sigs.k8s.io/docs/installation/)
4466
2. **Deploy admission controller**: Run `kubectl apply -f manifests/` from the `admission_controller/` directory.
4567
3. **Create a test JobSet**: Run `kubectl apply -f test/test-jobset.yaml`
46-
4. **Check Jobs were mutated correctly**: Run `kubectl describe jobs` and view the nodeSelectors in the pod template.
68+
4. **Check Jobs were mutated correctly**: Run `kubectl describe jobs` and view the nodeSelectors in the pod template.
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
apiVersion: v1
2-
kind: Secret
3-
metadata:
4-
name: admission-tls
5-
type: Opaque
6-
data:
7-
webhook.crt: "" # base64 encoded certificate
8-
webhook.key: "" # base64 encoded private key
9-
---
10-
apiVersion: v1
112
kind: Service
123
metadata:
13-
name: mutating-webhook
4+
name: admission-controller
5+
namespace: tpu-provisioner-system
146
spec:
157
selector:
16-
app: mutating-webhook
8+
app: admission-controller
179
ports:
1810
- port: 5000
1911
---
2012
apiVersion: admissionregistration.k8s.io/v1
2113
kind: MutatingWebhookConfiguration
2214
metadata:
23-
name: mutating-webhook
15+
name: tpu-provisioner-admission-controller
16+
annotations:
17+
cert-manager.io/inject-ca-from: tpu-provisioner-system/admission-controller
2418
webhooks:
25-
- name: mutating-webhook.default.svc
19+
- name: admission-controller.tpu-provisioner-system.svc
2620
matchPolicy: Equivalent
2721
admissionReviewVersions: ["v1"]
2822
sideEffects: None
@@ -32,34 +26,36 @@ webhooks:
3226
apiVersions: ["v1"]
3327
resources: ["jobs"]
3428
scope: "Namespaced"
35-
failurePolicy: Ignore
29+
failurePolicy: Fail
3630
timeoutSeconds: 20
3731
clientConfig:
38-
caBundle: # base64 CA bundle here
32+
#caBundle: # base64 CA bundle here
3933
service:
40-
namespace: default
41-
name: mutating-webhook
34+
namespace: tpu-provisioner-system
35+
name: admission-controller
4236
path: /mutate
4337
port: 5000
4438
---
4539
apiVersion: apps/v1
4640
kind: Deployment
4741
metadata:
48-
name: mutating-webhook
42+
name: admission-controller
43+
namespace: tpu-provisioner-system
4944
spec:
5045
replicas: 1
5146
selector:
5247
matchLabels:
53-
app: mutating-webhook
48+
app: admission-controller
5449
template:
5550
metadata:
5651
labels:
57-
app: mutating-webhook
52+
app: admission-controller
5853
spec:
5954
containers:
60-
- name: mutating-webhook
61-
image: "" # build container image, push to repository and add it here
62-
imagePullPolicy: Always
55+
- name: webhook
56+
# build container image, push to repository and add it here
57+
image: example.com/tpu-provisioner/admission-controller
58+
imagePullPolicy: IfNotPresent
6359
ports:
6460
- containerPort: 5000
6561
env:
@@ -75,4 +71,24 @@ spec:
7571
volumes:
7672
- name: certs-volume
7773
secret:
78-
secretName: admission-tls
74+
secretName: admission-controller-tls
75+
---
76+
apiVersion: cert-manager.io/v1
77+
kind: Issuer
78+
metadata:
79+
name: admission-controller-issuer
80+
namespace: tpu-provisioner-system
81+
spec:
82+
selfSigned: {}
83+
---
84+
apiVersion: cert-manager.io/v1
85+
kind: Certificate
86+
metadata:
87+
name: admission-controller
88+
namespace: tpu-provisioner-system
89+
spec:
90+
secretName: admission-controller-tls
91+
dnsNames:
92+
- admission-controller.tpu-provisioner-system.svc
93+
issuerRef:
94+
name: admission-controller-issuer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: skaffold/v4beta11
2+
kind: Config
3+
metadata:
4+
name: admission-controller
5+
build:
6+
local: {}
7+
artifacts:
8+
- image: example.com/tpu-provisioner/admission-controller
9+
docker:
10+
dockerfile: Dockerfile
11+
manifests:
12+
rawYaml:
13+
- manifests/manifest.yaml

0 commit comments

Comments
 (0)