Skip to content

Commit

Permalink
refactor: better name variables in pkg/webhook/services
Browse files Browse the repository at this point in the history
  • Loading branch information
ludusrusso authored and prometherion committed May 4, 2021
1 parent e1b2037 commit e5f17d1
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pkg/webhook/services/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,33 @@ func Handler() capsulewebhook.Handler {
}

func (r *handler) handleService(ctx context.Context, clt client.Client, decoder *admission.Decoder, req admission.Request) admission.Response {
s := &corev1.Service{}
if err := decoder.Decode(req, s); err != nil {
svc := &corev1.Service{}
if err := decoder.Decode(req, svc); err != nil {
return admission.Errored(http.StatusBadRequest, err)
}

if s.Spec.ExternalIPs == nil {
if svc.Spec.ExternalIPs == nil {
return admission.Allowed("")
}

tl := &v1alpha1.TenantList{}
if err := clt.List(ctx, tl, client.MatchingFieldsSelector{
Selector: fields.OneTermEqualSelector(".status.namespaces", s.GetNamespace()),
tntList := &v1alpha1.TenantList{}
if err := clt.List(ctx, tntList, client.MatchingFieldsSelector{
Selector: fields.OneTermEqualSelector(".status.namespaces", svc.GetNamespace()),
}); err != nil {
return admission.Errored(http.StatusBadRequest, err)
}
if len(tl.Items) == 0 {
if len(tntList.Items) == 0 {
return admission.Allowed("")
}
tnt := tl.Items[0]
tnt := tntList.Items[0]

if tnt.Spec.ExternalServiceIPs == nil {
return admission.Allowed("")
}

for _, allowed := range tnt.Spec.ExternalServiceIPs.Allowed {
_, allowedIP, _ := net.ParseCIDR(string(allowed))
for _, externalIP := range s.Spec.ExternalIPs {
for _, externalIP := range svc.Spec.ExternalIPs {
IP := net.ParseIP(externalIP)
if allowedIP.Contains(IP) {
return admission.Allowed("")
Expand Down

0 comments on commit e5f17d1

Please sign in to comment.