-
Notifications
You must be signed in to change notification settings - Fork 339
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
feat(kuma-cp) validate resources on kubernetes #401
Conversation
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.
The output of kubectl apply
is not user-friendly.
E.g., I use the following test resource
echo "apiVersion: kuma.io/v1alpha1
kind: Dataplane
mesh: default
metadata:
name: example
namespace: kuma-example
spec:
networking:
inbound:
- interface: 127.0.0.1:11011:abc
tags:
version: v2
env: production
outbound:
- interface: :cd
service2: database" | kubectl apply -f -
and I get back
Error from server (validation error: Inbound[0]: Interface: invalid format: expected format is <DATAPLANE_IP>:<DATAPLANE_PORT>:<WORKLOAD_PORT> ex. 192.168.0.100:9090:8080; "service" tag has to exist and be non empty; Outbound[0]: Interface: invalid format: expected ^(?P<dataplane_ip>(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|):(?P<dataplane_port>[0-9]{1,5})$, got ":cd"; Service cannot be empty): error when creating "STDIN": admission webhook "validator.kuma-admission.kuma.io" denied the request: validation error: Inbound[0]: Interface: invalid format: expected format is <DATAPLANE_IP>:<DATAPLANE_PORT>:<WORKLOAD_PORT> ex. 192.168.0.100:9090:8080; "service" tag has to exist and be non empty; Outbound[0]: Interface: invalid format: expected ^(?P<dataplane_ip>(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|):(?P<dataplane_port>[0-9]{1,5})$, got ":cd"; Service cannot be empty
91b8e37
to
3052703
Compare
Sorry the force push |
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.
Awesome! 👍
|
||
coreRes, err := h.coreRegistry.NewObject(resType) | ||
if err != nil { | ||
return admission.Errored(http.StatusInternalServerError, err) |
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.
Let's do return admission.Errored(http.StatusBadRequest, err)
} | ||
obj, err := h.k8sRegistry.NewObject(coreRes.GetSpec()) | ||
if err != nil { | ||
return admission.Errored(http.StatusInternalServerError, err) |
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.
Let's do return admission.Errored(http.StatusBadRequest, err)
Summary
Validation resources on K8S. We register one ValidatingWebhookConfiguration for all resources.