Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Restore inclusion of ReferencePolicy in Grant lookup (#280)
Browse files Browse the repository at this point in the history
The ReferencePolicy needs to be included for backward compatibility; however, it couldn't be included until v0.5.0-rc2 of kubernetes-sigs/gateway-api
  • Loading branch information
nathancoleman committed Jul 12, 2022
1 parent 08a028b commit 6c63d38
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions internal/k8s/gatewayclient/gatewayclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,31 +538,30 @@ func (g *gatewayClient) GetReferenceGrantsInNamespace(ctx context.Context, names
}
refGrants := refGrantList.Items

// TODO: this can't be enabled until the ReferencePolicy object is restored
// lookup ReferencePolicies here too for backwards compatibility, create
// ReferenceGrants from them and add to list
// refPolicyList := &gwv1alpha2.ReferencePolicyList{}
// if err := g.Client.List(ctx, refPolicyList, client.InNamespace(namespace)); err != nil {
// return nil, NewK8sError(err)
// }
// for _, refPolicy := range refPolicyList {
// refGrant := gwv1alpha2.ReferenceGrant{}
// for _, refPolicyFrom := range refPolicy.Spec.From {
// refGrant.Spec.From = append(refGrant.Spec.From, gwv1alpha2.ReferenceGrantFrom{
// Group: refPolicyFrom.Group,
// Kind: refPolicyFrom.Kind,
// Namespace: refPolicyFrom.Namespace,
// })
// }
// for _, refPolicyTo := range refPolicy.Spec.To {
// refGrant.Spec.To = append(refGrant.Spec.To, gwv1alpha2.ReferenceGrantTo{
// Group: refPolicyTo.Group,
// Kind: refPolicyTo.Kind,
// Name: refPolicyTo.Name,
// })
// }
// refGrants = append(refGrants, refGrant)
// }
// Lookup ReferencePolicies here too for backwards compatibility, create
// ReferenceGrants from them, and add them to list
refPolicyList := &gwv1alpha2.ReferencePolicyList{}
if err := g.Client.List(ctx, refPolicyList, client.InNamespace(namespace)); err != nil {
return nil, NewK8sError(err)
}
for _, refPolicy := range refPolicyList.Items {
refGrant := gwv1alpha2.ReferenceGrant{}
for _, refPolicyFrom := range refPolicy.Spec.From {
refGrant.Spec.From = append(refGrant.Spec.From, gwv1alpha2.ReferenceGrantFrom{
Group: refPolicyFrom.Group,
Kind: refPolicyFrom.Kind,
Namespace: refPolicyFrom.Namespace,
})
}
for _, refPolicyTo := range refPolicy.Spec.To {
refGrant.Spec.To = append(refGrant.Spec.To, gwv1alpha2.ReferenceGrantTo{
Group: refPolicyTo.Group,
Kind: refPolicyTo.Kind,
Name: refPolicyTo.Name,
})
}
refGrants = append(refGrants, refGrant)
}

return refGrants, nil
}

0 comments on commit 6c63d38

Please sign in to comment.