Handling all the events from Storage and Ingress classes (#108)

This commit is contained in:
Dario Tranchitella
2020-10-17 14:40:07 +02:00
committed by GitHub
parent 8f3fd8dfee
commit b0310cd42f
4 changed files with 20 additions and 12 deletions

View File

@@ -170,7 +170,7 @@ var _ = Describe("when Tenant handles Ingress classes", func() {
minor, err := strconv.Atoi(v.Minor)
Expect(err).ToNot(HaveOccurred())
if major == 1 && minor < 18 {
Skip("Running test ont Kubernetes " + v.String() + ", doesn't provide .spec.ingressClassName")
Skip("Running test on Kubernetes " + v.String() + ", doesn't provide .spec.ingressClassName")
}
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)

View File

@@ -144,8 +144,8 @@ func main() {
// webhooks
wl := append(
make([]webhook.Webhook, 0),
ingress.Webhook(utils.InCapsuleGroup(capsuleGroup, ingress.Handler())),
pvc.Webhook(utils.InCapsuleGroup(capsuleGroup, pvc.Handler())),
ingress.Webhook(ingress.Handler()),
pvc.Webhook(pvc.Handler()),
owner_reference.Webhook(utils.InCapsuleGroup(capsuleGroup, owner_reference.Handler(forceTenantPrefix))),
namespace_quota.Webhook(utils.InCapsuleGroup(capsuleGroup, namespace_quota.Handler())),
network_policies.Webhook(utils.InCapsuleGroup(capsuleGroup, network_policies.Handler())),

View File

@@ -110,11 +110,6 @@ func (r *handler) ingressFromRequest(req admission.Request, decoder *admission.D
func (r *handler) validateIngress(ctx context.Context, c client.Client, object Ingress) admission.Response {
var valid, matched bool
ingressClass := object.IngressClass()
if ingressClass == nil {
return admission.Errored(http.StatusBadRequest, NewIngressClassNotValid())
}
tl := &v1alpha1.TenantList{}
if err := c.List(ctx, tl, client.MatchingFieldsSelector{
@@ -123,6 +118,15 @@ func (r *handler) validateIngress(ctx context.Context, c client.Client, object I
return admission.Errored(http.StatusBadRequest, err)
}
if len(tl.Items) == 0 {
return admission.Allowed("")
}
ingressClass := object.IngressClass()
if ingressClass == nil {
return admission.Errored(http.StatusBadRequest, NewIngressClassNotValid())
}
if len(tl.Items[0].Spec.IngressClasses.Allowed) > 0 {
valid = tl.Items[0].Spec.IngressClasses.Allowed.IsStringInList(*ingressClass)
}

View File

@@ -68,10 +68,6 @@ func (h *handler) OnCreate(c client.Client, decoder *admission.Decoder) capsulew
return admission.Errored(http.StatusBadRequest, err)
}
if pvc.Spec.StorageClassName == nil {
return admission.Errored(http.StatusBadRequest, NewStorageClassNotValid())
}
tl := &capsulev1alpha1.TenantList{}
if err := c.List(ctx, tl, client.MatchingFieldsSelector{
Selector: fields.OneTermEqualSelector(".status.namespaces", pvc.Namespace),
@@ -79,6 +75,14 @@ func (h *handler) OnCreate(c client.Client, decoder *admission.Decoder) capsulew
return admission.Errored(http.StatusBadRequest, err)
}
if len(tl.Items) == 0 {
return admission.Allowed("")
}
if pvc.Spec.StorageClassName == nil {
return admission.Errored(http.StatusBadRequest, NewStorageClassNotValid())
}
sc := *pvc.Spec.StorageClassName
if len(tl.Items[0].Spec.StorageClasses.Allowed) > 0 {