-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add webhook framework #713
base: main
Are you sure you want to change the base?
Changes from all commits
a5475a6
d9d0fcb
6638db5
7f603b3
d8e2a8d
b3eed96
c60c2b2
afcfa62
6e0c61b
913ea01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ go.work.sum | |
|
||
.DS_Store | ||
__pycache__ | ||
*.xml | ||
|
||
# Python virtual environment directory | ||
.venv | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,9 +52,22 @@ help: ## Display this help. | |
|
||
##@ Development | ||
|
||
GINKGO_VERSION ?= $(shell go list -m -f '{{.Version}}' github.com/onsi/ginkgo/v2) | ||
INTEGRATION_TARGET ?= ./test/integration/... | ||
|
||
GINKGO = $(shell pwd)/bin/ginkgo | ||
.PHONY: ginkgo | ||
ginkgo: ## Download ginkgo locally if necessary. | ||
test -s $(LOCALBIN)/ginkgo || \ | ||
GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION) | ||
|
||
.PHONY: manifests | ||
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. | ||
$(CONTROLLER_GEN) rbac:roleName=controller-manager-role crd:maxDescLen=0,generateEmbeddedObjectMeta=true webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
$(CONTROLLER_GEN) \ | ||
rbac:roleName=controller-manager-role output:rbac:artifacts:config=config/rbac/controller-manager \ | ||
crd:maxDescLen=0,generateEmbeddedObjectMeta=true output:crd:artifacts:config=config/crd/bases \ | ||
webhook output:webhook:artifacts:config=config/webhook \ | ||
paths="./..." | ||
|
||
.PHONY: generate | ||
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. | ||
|
@@ -81,6 +94,11 @@ vet: ## Run go vet against code. | |
test: manifests generate fmt vet envtest ## Run tests. | ||
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out | ||
|
||
.PHONY: test-integration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great! |
||
test-integration: manifests fmt vet envtest ginkgo ## Run integration tests. | ||
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" \ | ||
$(GINKGO) --junit-report=junit.xml --output-dir=$(ARTIFACTS) -v $(INTEGRATION_TARGET) | ||
|
||
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors. | ||
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up. | ||
test-e2e: | ||
|
@@ -272,7 +290,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION) | |
|
||
## Tool Versions | ||
KUSTOMIZE_VERSION ?= v5.3.0 | ||
CONTROLLER_TOOLS_VERSION ?= v0.14.0 | ||
CONTROLLER_TOOLS_VERSION ?= v0.16.1 | ||
ENVTEST_VERSION ?= release-0.17 | ||
GOLANGCI_LINT_VERSION ?= v1.57.2 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,9 +69,9 @@ type MetadataStorage struct { | |
|
||
type CacheSpec struct { | ||
// Replicas is the number of kvcache pods to deploy | ||
// +kubebuilder:validation:Required | ||
// +kubebuilder:default:=3 | ||
Replicas int `json:"replicas,omitempty"` | ||
// +optional | ||
Replicas *int `json:"replicas,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. separate PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This leads to a compile error so I changed here together, a separate PR here #740 |
||
|
||
// represent the kvcache's image | ||
// +kubebuilder:validation:Optional | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: controller-manager | ||
namespace: system | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: manager | ||
ports: | ||
- containerPort: 9443 | ||
name: webhook-server | ||
protocol: TCP | ||
volumeMounts: | ||
- mountPath: /tmp/k8s-webhook-server/serving-certs | ||
name: cert | ||
readOnly: true | ||
volumes: | ||
- name: cert | ||
secret: | ||
defaultMode: 420 | ||
secretName: webhook-server-cert |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This patch add annotation to admission webhook config and | ||
# CERTIFICATE_NAMESPACE and CERTIFICATE_NAME will be substituted by kustomize | ||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: MutatingWebhookConfiguration | ||
metadata: | ||
labels: | ||
app.kubernetes.io/name: mutatingwebhookconfiguration | ||
app.kubernetes.io/instance: mutating-webhook-configuration | ||
app.kubernetes.io/component: webhook | ||
app.kubernetes.io/created-by: aibrix | ||
app.kubernetes.io/part-of: aibrix | ||
app.kubernetes.io/managed-by: kustomize | ||
name: mutating-webhook-configuration | ||
annotations: | ||
cert-manager.io/inject-ca-from: CERTIFICATE_NAMESPACE/CERTIFICATE_NAME | ||
--- | ||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: ValidatingWebhookConfiguration | ||
metadata: | ||
labels: | ||
app.kubernetes.io/name: validatingwebhookconfiguration | ||
app.kubernetes.io/instance: validating-webhook-configuration | ||
app.kubernetes.io/component: webhook | ||
app.kubernetes.io/created-by: aibrix | ||
app.kubernetes.io/part-of: aibrix | ||
app.kubernetes.io/managed-by: kustomize | ||
name: validating-webhook-configuration | ||
annotations: | ||
cert-manager.io/inject-ca-from: CERTIFICATE_NAMESPACE/CERTIFICATE_NAME |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
resources: | ||
- secret.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: webhook-server-cert | ||
namespace: system |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
resources: | ||
- manifests.yaml | ||
- service.yaml | ||
|
||
configurations: | ||
- kustomizeconfig.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# the following config is for teaching kustomize where to look at when substituting nameReference. | ||
# It requires kustomize v2.1.0 or newer to work properly. | ||
nameReference: | ||
- kind: Service | ||
version: v1 | ||
fieldSpecs: | ||
- kind: MutatingWebhookConfiguration | ||
group: admissionregistration.k8s.io | ||
path: webhooks/clientConfig/service/name | ||
- kind: ValidatingWebhookConfiguration | ||
group: admissionregistration.k8s.io | ||
path: webhooks/clientConfig/service/name | ||
|
||
namespace: | ||
- kind: MutatingWebhookConfiguration | ||
group: admissionregistration.k8s.io | ||
path: webhooks/clientConfig/service/namespace | ||
create: true | ||
- kind: ValidatingWebhookConfiguration | ||
group: admissionregistration.k8s.io | ||
path: webhooks/clientConfig/service/namespace | ||
create: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: MutatingWebhookConfiguration | ||
metadata: | ||
name: mutating-webhook-configuration | ||
webhooks: | ||
- admissionReviewVersions: | ||
- v1 | ||
clientConfig: | ||
service: | ||
name: webhook-service | ||
namespace: system | ||
path: /mutate-model-aibrix-ai-v1alpha1-modeladapter | ||
failurePolicy: Fail | ||
name: mmodeladapter.kb.io | ||
rules: | ||
- apiGroups: | ||
- model.aibrix.ai | ||
apiVersions: | ||
- v1alpha1 | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
resources: | ||
- modeladapters | ||
sideEffects: None | ||
--- | ||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: ValidatingWebhookConfiguration | ||
metadata: | ||
name: validating-webhook-configuration | ||
webhooks: | ||
- admissionReviewVersions: | ||
- v1 | ||
clientConfig: | ||
service: | ||
name: webhook-service | ||
namespace: system | ||
path: /validate-model-aibrix-ai-v1alpha1-modeladapter | ||
failurePolicy: Fail | ||
name: vmodeladapter.kb.io | ||
rules: | ||
- apiGroups: | ||
- model.aibrix.ai | ||
apiVersions: | ||
- v1alpha1 | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
resources: | ||
- modeladapters | ||
sideEffects: None |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
app.kubernetes.io/name: service | ||
app.kubernetes.io/instance: webhook-service | ||
app.kubernetes.io/component: webhook | ||
app.kubernetes.io/created-by: aibrix | ||
app.kubernetes.io/part-of: aibrix | ||
app.kubernetes.io/managed-by: kustomize | ||
name: webhook-service | ||
namespace: system | ||
spec: | ||
ports: | ||
- port: 443 | ||
protocol: TCP | ||
targetPort: 9443 | ||
selector: | ||
control-plane: controller-manager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the past, we maintain this manually. some internal users want to use the component separately. so we change the folder structure to component based. If we use
config/rbac/controller-manager
. other components like orchestration will land into same subfolder?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert since kubebuilder can't separate the roles right now, and maybe unable in a long time. I added the roles manually as well.