Skip to content

Commit 5e23817

Browse files
committed
Add webhook
1 parent 6812440 commit 5e23817

29 files changed

+1381
-167
lines changed

operator/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Image URL to use all building/pushing image targets
2-
IMG ?= controller:latest
2+
IMG ?= functionstream/operator:latest
33

44
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
55
ifeq (,$(shell go env GOBIN))

operator/PROJECT

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ resources:
1414
controller: true
1515
domain: functionstream.github.io
1616
group: fs
17-
kind: Packages
17+
kind: Package
1818
path: github.com/FunctionStream/function-stream/operator/api/v1alpha1
1919
version: v1alpha1
20+
webhooks:
21+
defaulting: true
22+
validation: true
23+
webhookVersion: v1
2024
- api:
2125
crdVersion: v1
2226
namespaced: true
@@ -26,4 +30,8 @@ resources:
2630
kind: Function
2731
path: github.com/FunctionStream/function-stream/operator/api/v1alpha1
2832
version: v1alpha1
33+
webhooks:
34+
defaulting: true
35+
validation: true
36+
webhookVersion: v1
2937
version: "3"

operator/cmd/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939

4040
fsv1alpha1 "github.com/FunctionStream/function-stream/operator/api/v1alpha1"
4141
"github.com/FunctionStream/function-stream/operator/internal/controller"
42+
webhookfsv1alpha1 "github.com/FunctionStream/function-stream/operator/internal/webhook/v1alpha1"
4243
// +kubebuilder:scaffold:imports
4344
)
4445

@@ -231,6 +232,20 @@ func main() {
231232
setupLog.Error(err, "unable to create controller", "controller", "Function")
232233
os.Exit(1)
233234
}
235+
// nolint:goconst
236+
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
237+
if err = webhookfsv1alpha1.SetupFunctionWebhookWithManager(mgr); err != nil {
238+
setupLog.Error(err, "unable to create webhook", "webhook", "Function")
239+
os.Exit(1)
240+
}
241+
}
242+
// nolint:goconst
243+
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
244+
if err = webhookfsv1alpha1.SetupPackagesWebhookWithManager(mgr); err != nil {
245+
setupLog.Error(err, "unable to create webhook", "webhook", "Packages")
246+
os.Exit(1)
247+
}
248+
}
234249
// +kubebuilder:scaffold:builder
235250

236251
if metricsCertWatcher != 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: 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: 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
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: 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

operator/config/crd/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
resources:
55
- ./bases/fs.functionstream.github.io_packages.yaml
66
- bases/fs.functionstream.github.io_functions.yaml
7+
- bases/fs.functionstream.github.io_packages.yaml
78
# +kubebuilder:scaffold:crdkustomizeresource
89

910
patches:

0 commit comments

Comments
 (0)