Skip to content

Commit 50337ce

Browse files
committed
Validating webhooks created for NIMCache and NIMService: ValidateUpdate and ValidateCreate. Helm deployment configured as well. Addressed linting, public functions, and git issues.
Signed-off-by: Aryan <gorwadearyan@gmail.com>
1 parent 9e3375e commit 50337ce

26 files changed

+1288
-7
lines changed

PROJECT

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
domain: nvidia.com
66
layout:
77
- go.kubebuilder.io/v4
8+
multigroup: true
89
projectName: k8s-nim-operator
910
repo: github.com/NVIDIA/k8s-nim-operator
1011
resources:
@@ -17,6 +18,9 @@ resources:
1718
kind: NIMService
1819
path: github.com/NVIDIA/k8s-nim-operator/api/apps/v1alpha1
1920
version: v1alpha1
21+
webhooks:
22+
validation: true
23+
webhookVersion: v1
2024
- api:
2125
crdVersion: v1
2226
namespaced: true
@@ -26,6 +30,9 @@ resources:
2630
kind: NIMCache
2731
path: github.com/NVIDIA/k8s-nim-operator/api/apps/v1alpha1
2832
version: v1alpha1
33+
webhooks:
34+
validation: true
35+
webhookVersion: v1
2936
- api:
3037
crdVersion: v1
3138
namespaced: true

cmd/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import (
4747
"github.com/NVIDIA/k8s-nim-operator/internal/controller/platform/kserve"
4848
"github.com/NVIDIA/k8s-nim-operator/internal/controller/platform/standalone"
4949
"github.com/NVIDIA/k8s-nim-operator/internal/render"
50+
webhookappsv1alpha1 "github.com/NVIDIA/k8s-nim-operator/internal/webhook/apps/v1alpha1"
5051
// +kubebuilder:scaffold:imports
5152
)
5253

@@ -256,6 +257,20 @@ func main() {
256257
os.Exit(1)
257258
}
258259

260+
// nolint:goconst
261+
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
262+
if err := webhookappsv1alpha1.SetupNIMCacheWebhookWithManager(mgr); err != nil {
263+
setupLog.Error(err, "unable to create webhook", "webhook", "NIMCache")
264+
os.Exit(1)
265+
}
266+
}
267+
// nolint:goconst
268+
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
269+
if err := webhookappsv1alpha1.SetupNIMServiceWebhookWithManager(mgr); err != nil {
270+
setupLog.Error(err, "unable to create webhook", "webhook", "NIMService")
271+
os.Exit(1)
272+
}
273+
}
259274
// +kubebuilder:scaffold:builder
260275

261276
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# The following manifests contain a self-signed issuer CR and a metrics certificate CR.
2+
# More document can be found at https://docs.cert-manager.io
3+
apiVersion: cert-manager.io/v1
4+
kind: Certificate
5+
metadata:
6+
labels:
7+
app.kubernetes.io/name: k8s-nim-operator
8+
app.kubernetes.io/managed-by: kustomize
9+
name: metrics-certs # this name should match the one appeared in kustomizeconfig.yaml
10+
namespace: system
11+
spec:
12+
dnsNames:
13+
# SERVICE_NAME and SERVICE_NAMESPACE will be substituted by kustomize
14+
# replacements in the config/default/kustomization.yaml file.
15+
- SERVICE_NAME.SERVICE_NAMESPACE.svc
16+
- SERVICE_NAME.SERVICE_NAMESPACE.svc.cluster.local
17+
issuerRef:
18+
kind: Issuer
19+
name: selfsigned-issuer
20+
secretName: metrics-server-cert
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# The following manifests contain a self-signed issuer CR and a certificate CR.
2+
# More document can be found at https://docs.cert-manager.io
3+
apiVersion: cert-manager.io/v1
4+
kind: Certificate
5+
metadata:
6+
labels:
7+
app.kubernetes.io/name: k8s-nim-operator
8+
app.kubernetes.io/managed-by: kustomize
9+
name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml
10+
namespace: system
11+
spec:
12+
# SERVICE_NAME and SERVICE_NAMESPACE will be substituted by kustomize
13+
# replacements in the config/default/kustomization.yaml file.
14+
dnsNames:
15+
- SERVICE_NAME.SERVICE_NAMESPACE.svc
16+
- SERVICE_NAME.SERVICE_NAMESPACE.svc.cluster.local
17+
issuerRef:
18+
kind: Issuer
19+
name: selfsigned-issuer
20+
secretName: webhook-server-cert

config/certmanager/issuer.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# The following manifest contains a self-signed issuer CR.
2+
# More information can be found at https://docs.cert-manager.io
3+
# WARNING: Targets CertManager v1.0. Check https://cert-manager.io/docs/installation/upgrading/ for breaking changes.
4+
apiVersion: cert-manager.io/v1
5+
kind: Issuer
6+
metadata:
7+
labels:
8+
app.kubernetes.io/name: k8s-nim-operator
9+
app.kubernetes.io/managed-by: kustomize
10+
name: selfsigned-issuer
11+
namespace: system
12+
spec:
13+
selfSigned: {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resources:
2+
- issuer.yaml
3+
- certificate-webhook.yaml
4+
- certificate-metrics.yaml
5+
6+
configurations:
7+
- kustomizeconfig.yaml
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This configuration is for teaching kustomize how to update name ref substitution
2+
nameReference:
3+
- kind: Issuer
4+
group: cert-manager.io
5+
fieldSpecs:
6+
- kind: Certificate
7+
group: cert-manager.io
8+
path: spec/issuerRef/name

config/default/kustomization.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Adds namespace to all resources.
2-
namespace: k8s-nim-operator-system
2+
namespace: nim-operator
33

44
# Value of this field is prepended to the
55
# names of all resources, e.g. a deployment named
@@ -20,7 +20,7 @@ resources:
2020
- ../manager
2121
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
2222
# crd/kustomization.yaml
23-
#- ../webhook
23+
# - ../webhook
2424
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
2525
#- ../certmanager
2626
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
@@ -29,7 +29,7 @@ resources:
2929
#- metrics_service.yaml
3030

3131
# Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager
32-
#patches:
32+
# patches:
3333
# [METRICS] The following patch will enable the metrics endpoint. Ensure that you also protect this endpoint.
3434
# More info: https://book.kubebuilder.io/reference/metrics
3535
# If you want to expose the metric endpoint of your controller-manager uncomment the following line.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This patch ensures the webhook certificates are properly mounted in the manager container.
2+
# It configures the necessary arguments, volumes, volume mounts, and container ports.
3+
4+
# Add the --webhook-cert-path argument for configuring the webhook certificate path
5+
- op: add
6+
path: /spec/template/spec/containers/0/args/-
7+
value: --webhook-cert-path=/tmp/k8s-webhook-server/serving-certs
8+
9+
# Add the volumeMount for the webhook certificates
10+
- op: add
11+
path: /spec/template/spec/containers/0/volumeMounts/-
12+
value:
13+
mountPath: /tmp/k8s-webhook-server/serving-certs
14+
name: webhook-certs
15+
readOnly: true
16+
17+
# Add the port configuration for the webhook server
18+
- op: add
19+
path: /spec/template/spec/containers/0/ports/-
20+
value:
21+
containerPort: 9443
22+
name: webhook-server
23+
protocol: TCP
24+
25+
# Add the volume configuration for the webhook certificates
26+
- op: add
27+
path: /spec/template/spec/volumes/-
28+
value:
29+
name: webhook-certs
30+
secret:
31+
secretName: webhook-server-cert

config/manager/kustomization.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
44
kind: Kustomization
55
images:
66
- name: controller
7-
newName: nvcr.io/nvidia/cloud-native/nim-operator
8-
newTag: v1.0.0
7+
newName: localhost:5000/k8s-nim-operator
8+
newTag: dev

0 commit comments

Comments
 (0)