refactor: better name variables in pkg/webhook/tenantprefix

This commit is contained in:
Ludovico Russo
2021-05-04 17:49:13 +02:00
committed by Dario Tranchitella
parent 34c958371b
commit 36c90d485e
+3 -3
View File
@@ -84,13 +84,13 @@ func (r *handler) OnCreate(clt client.Client, decoder *admission.Decoder) capsul
return admission.Allowed("")
}
t := &v1alpha1.Tenant{}
tnt := &v1alpha1.Tenant{}
for _, or := range ns.ObjectMeta.OwnerReferences {
// retrieving the selected Tenant
if err := clt.Get(ctx, types.NamespacedName{Name: or.Name}, t); err != nil {
if err := clt.Get(ctx, types.NamespacedName{Name: or.Name}, tnt); err != nil {
return admission.Errored(http.StatusBadRequest, err)
}
if e := fmt.Sprintf("%s-%s", t.GetName(), ns.GetName()); !strings.HasPrefix(ns.GetName(), fmt.Sprintf("%s-", t.GetName())) {
if e := fmt.Sprintf("%s-%s", tnt.GetName(), ns.GetName()); !strings.HasPrefix(ns.GetName(), fmt.Sprintf("%s-", tnt.GetName())) {
return admission.Denied("The namespace doesn't match the tenant prefix, expected " + e)
}
}