mirror of https://github.com/linkerd/linkerd2.git
28 lines
851 B
Go
28 lines
851 B
Go
package validator
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/linkerd/linkerd2/controller/k8s"
|
|
"github.com/linkerd/linkerd2/pkg/profiles"
|
|
admissionv1beta1 "k8s.io/api/admission/v1beta1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/client-go/tools/record"
|
|
)
|
|
|
|
// AdmitSP verifies that the received Admission Request contains a valid
|
|
// Service Profile definition
|
|
func AdmitSP(
|
|
_ context.Context, _ *k8s.MetadataAPI, request *admissionv1beta1.AdmissionRequest, _ record.EventRecorder,
|
|
) (*admissionv1beta1.AdmissionResponse, error) {
|
|
admissionResponse := &admissionv1beta1.AdmissionResponse{
|
|
UID: request.UID,
|
|
Allowed: true,
|
|
}
|
|
if err := profiles.Validate(request.Object.Raw); err != nil {
|
|
admissionResponse.Allowed = false
|
|
admissionResponse.Result = &metav1.Status{Message: err.Error(), Code: 400}
|
|
}
|
|
return admissionResponse, nil
|
|
}
|