Skip to content
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

Merged
merged 2 commits into from
Nov 12, 2019

Conversation

jakubdyszkiewicz
Copy link
Contributor

Summary

Validation resources on K8S. We register one ValidatingWebhookConfiguration for all resources.

Copy link
Contributor

@yskopets yskopets left a 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

@jakubdyszkiewicz jakubdyszkiewicz force-pushed the feature/validation-kubernetes branch from 91b8e37 to 3052703 Compare November 11, 2019 16:57
@jakubdyszkiewicz jakubdyszkiewicz changed the base branch from feature/validation to master November 11, 2019 16:57
@jakubdyszkiewicz
Copy link
Contributor Author

Sorry the force push

Copy link
Contributor

@yskopets yskopets left a 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)
Copy link
Contributor

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)
Copy link
Contributor

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)

@jakubdyszkiewicz jakubdyszkiewicz requested a review from a team November 12, 2019 08:47
@jakubdyszkiewicz jakubdyszkiewicz merged commit b6ddb84 into master Nov 12, 2019
@jakubdyszkiewicz jakubdyszkiewicz deleted the feature/validation-kubernetes branch November 12, 2019 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants