Skip to content

Commit

Permalink
Fix test breakage after merge post-knative-extensions#315
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Anderson committed Jul 11, 2022
1 parent 17dba7f commit 4045dce
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 36 deletions.
12 changes: 6 additions & 6 deletions pkg/reconciler/ingress/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
gwapiclient "knative.dev/net-gateway-api/pkg/client/gatewayapi/injection/client"
gatewayinformer "knative.dev/net-gateway-api/pkg/client/gatewayapi/injection/informers/apis/v1alpha2/gateway"
httprouteinformer "knative.dev/net-gateway-api/pkg/client/gatewayapi/injection/informers/apis/v1alpha2/httproute"
referencepolicyinformer "knative.dev/net-gateway-api/pkg/client/gatewayapi/injection/informers/apis/v1alpha2/referencepolicy"
referencegrantinformer "knative.dev/net-gateway-api/pkg/client/gatewayapi/injection/informers/apis/v1alpha2/referencegrant"
"knative.dev/net-gateway-api/pkg/reconciler/ingress/config"
)

Expand All @@ -56,15 +56,15 @@ func NewController(

ingressInformer := ingressinformer.Get(ctx)
httprouteInformer := httprouteinformer.Get(ctx)
referencePolicyInformer := referencepolicyinformer.Get(ctx)
referenceGrantInformer := referencegrantinformer.Get(ctx)
gatewayInformer := gatewayinformer.Get(ctx)
endpointsInformer := endpointsinformer.Get(ctx)

c := &Reconciler{
gwapiclient: gwapiclient.Get(ctx),
httprouteLister: httprouteInformer.Lister(),
referencePolicyLister: referencePolicyInformer.Lister(),
gatewayLister: gatewayInformer.Lister(),
gwapiclient: gwapiclient.Get(ctx),
httprouteLister: httprouteInformer.Lister(),
referenceGrantLister: referenceGrantInformer.Lister(),
gatewayLister: gatewayInformer.Lister(),
}

filterFunc := reconciler.AnnotationFilterFunc(networking.IngressClassAnnotationKey, gatewayAPIIngressClassName, false)
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/ingress/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

_ "knative.dev/net-gateway-api/pkg/client/gatewayapi/injection/informers/apis/v1alpha2/gateway/fake"
_ "knative.dev/net-gateway-api/pkg/client/gatewayapi/injection/informers/apis/v1alpha2/httproute/fake"
_ "knative.dev/net-gateway-api/pkg/client/gatewayapi/injection/informers/apis/v1alpha2/referencepolicy/fake"
_ "knative.dev/net-gateway-api/pkg/client/gatewayapi/injection/informers/apis/v1alpha2/referencegrant/fake"
"knative.dev/net-gateway-api/pkg/reconciler/ingress/config"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Reconciler struct {
// Listers index properties about resources
httprouteLister gatewayListers.HTTPRouteLister

referencePolicyLister gatewayListers.ReferencePolicyLister
referenceGrantLister gatewayListers.ReferenceGrantLister

gatewayLister gatewayListers.GatewayLister
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/reconciler/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,10 @@ func TestReconcileTLS(t *testing.T) {

table.Test(t, GatewayFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher, tr *TableRow) controller.Reconciler {
r := &Reconciler{
gwapiclient: fakegwapiclientset.Get(ctx),
httprouteLister: listers.GetHTTPRouteLister(),
referencePolicyLister: listers.GetReferencePolicyLister(),
gatewayLister: listers.GetGatewayLister(),
gwapiclient: fakegwapiclientset.Get(ctx),
httprouteLister: listers.GetHTTPRouteLister(),
referenceGrantLister: listers.GetReferenceGrantLister(),
gatewayLister: listers.GetGatewayLister(),
statusManager: &fakeStatusManager{FakeIsReady: func(context.Context, *v1alpha1.Ingress) (bool, error) {
return true, nil
}},
Expand Down Expand Up @@ -571,7 +571,7 @@ func tlsListener(hostname, nsName, secretName string) GatewayOption {
Protocol: "HTTPS",
TLS: &gatewayv1alpha2.GatewayTLSConfig{
Mode: (*gatewayv1alpha2.TLSModeType)(pointer.String("Terminate")),
CertificateRefs: []*gatewayv1alpha2.SecretObjectReference{{
CertificateRefs: []gatewayv1alpha2.SecretObjectReference{{
Group: (*gatewayv1alpha2.Group)(pointer.String("")),
Kind: (*gatewayv1alpha2.Kind)(pointer.String("Secret")),
Name: gatewayv1alpha2.ObjectName(secretName),
Expand Down Expand Up @@ -622,9 +622,9 @@ func secret(name, ns string) *corev1.Secret {
}
}

func rp(to *corev1.Secret) *gatewayv1alpha2.ReferencePolicy {
func rp(to *corev1.Secret) *gatewayv1alpha2.ReferenceGrant {
t := true
return &gatewayv1alpha2.ReferencePolicy{
return &gatewayv1alpha2.ReferenceGrant{
ObjectMeta: metav1.ObjectMeta{
Name: to.Name + "-" + testNamespace,
Namespace: to.Namespace,
Expand All @@ -636,13 +636,13 @@ func rp(to *corev1.Secret) *gatewayv1alpha2.ReferencePolicy {
BlockOwnerDeletion: &t,
}},
},
Spec: gatewayv1alpha2.ReferencePolicySpec{
From: []gatewayv1alpha2.ReferencePolicyFrom{{
Spec: gatewayv1alpha2.ReferenceGrantSpec{
From: []gatewayv1alpha2.ReferenceGrantFrom{{
Group: "gateway.networking.k8s.io",
Kind: "Gateway",
Namespace: gatewayv1alpha2.Namespace(testNamespace),
}},
To: []gatewayv1alpha2.ReferencePolicyTo{{
To: []gatewayv1alpha2.ReferenceGrantTo{{
Group: gatewayv1alpha2.Group(""),
Kind: gatewayv1alpha2.Kind("Secret"),
Name: (*gatewayv1alpha2.ObjectName)(&to.Name),
Expand Down
20 changes: 10 additions & 10 deletions pkg/reconciler/ingress/reconcile_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,32 +119,32 @@ func (c *Reconciler) reconcileTLS(

desired := resources.MakeReferenceGrant(ctx, ing, secret, gateway)

rp, err := c.referencePolicyLister.ReferencePolicies(desired.Namespace).Get(desired.Name)
rp, err := c.referenceGrantLister.ReferenceGrants(desired.Namespace).Get(desired.Name)

if apierrs.IsNotFound(err) {
rp, err = c.gwapiclient.GatewayV1alpha2().ReferencePolicies(desired.Namespace).Create(ctx, desired, metav1.CreateOptions{})
rp, err = c.gwapiclient.GatewayV1alpha2().ReferenceGrants(desired.Namespace).Create(ctx, desired, metav1.CreateOptions{})

if err != nil {
recorder.Eventf(ing, corev1.EventTypeWarning, "CreationFailed", "Failed to create ReferencePolicy: %v", err)
return nil, fmt.Errorf("failed to create ReferencePolicy: %w", err)
recorder.Eventf(ing, corev1.EventTypeWarning, "CreationFailed", "Failed to create ReferenceGrant: %v", err)
return nil, fmt.Errorf("failed to create ReferenceGrant: %w", err)
}
} else if err != nil {
return nil, err
}

if !metav1.IsControlledBy(rp, ing) {
recorder.Eventf(ing, corev1.EventTypeWarning, "NotOwned", "ReferencePolicy %s not owned by this object", desired.Name)
return nil, fmt.Errorf("ReferencePolicy %s not owned by %s", rp.Name, ing.Name)
recorder.Eventf(ing, corev1.EventTypeWarning, "NotOwned", "ReferenceGrant %s not owned by this object", desired.Name)
return nil, fmt.Errorf("ReferenceGrant %s not owned by %s", rp.Name, ing.Name)
}

if !equality.Semantic.DeepEqual(rp.Spec, desired.Spec) {
update := rp.DeepCopy()
update.Spec = desired.Spec

_, err := c.gwapiclient.GatewayV1alpha2().ReferencePolicies(update.Namespace).Update(ctx, update, metav1.UpdateOptions{})
_, err := c.gwapiclient.GatewayV1alpha2().ReferenceGrants(update.Namespace).Update(ctx, update, metav1.UpdateOptions{})
if err != nil {
recorder.Eventf(ing, corev1.EventTypeWarning, "UpdateFailed", "Failed to update ReferencePolicy: %v", err)
return nil, fmt.Errorf("failed to update ReferencePolicy: %w", err)
recorder.Eventf(ing, corev1.EventTypeWarning, "UpdateFailed", "Failed to update ReferenceGrant: %v", err)
return nil, fmt.Errorf("failed to update ReferenceGrant: %w", err)
}
}

Expand All @@ -162,7 +162,7 @@ func (c *Reconciler) reconcileTLS(
Protocol: gatewayv1alpha2.HTTPSProtocolType,
TLS: &gatewayv1alpha2.GatewayTLSConfig{
Mode: &mode,
CertificateRefs: []*gatewayv1alpha2.SecretObjectReference{{
CertificateRefs: []gatewayv1alpha2.SecretObjectReference{{
Group: (*gatewayv1alpha2.Group)(pointer.String("")),
Kind: (*gatewayv1alpha2.Kind)(pointer.String("Secret")),
Name: gatewayv1alpha2.ObjectName(tls.SecretName),
Expand Down
11 changes: 5 additions & 6 deletions pkg/reconciler/ingress/resources/reference_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,28 @@ import (
)

// Grant the resource "to" access to the resource "from"
// N.B. ReferencePolicy will be renamed ReferenceGrant in v1beta1
func MakeReferenceGrant(ctx context.Context, ing *netv1alpha1.Ingress, to, from metav1.PartialObjectMetadata) *gatewayv1alpha2.ReferencePolicy {
func MakeReferenceGrant(ctx context.Context, ing *netv1alpha1.Ingress, to, from metav1.PartialObjectMetadata) *gatewayv1alpha2.ReferenceGrant {
name := to.Name
if len(name)+len(from.Namespace) > 62 {
name = name[:62-len(from.Namespace)]
}
name += "-" + from.Namespace

retval := &gatewayv1alpha2.ReferencePolicy{
retval := &gatewayv1alpha2.ReferenceGrant{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: to.Namespace,
Labels: to.Labels,
Annotations: to.Annotations,
OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(ing)},
},
Spec: gatewayv1alpha2.ReferencePolicySpec{
From: []gatewayv1alpha2.ReferencePolicyFrom{{
Spec: gatewayv1alpha2.ReferenceGrantSpec{
From: []gatewayv1alpha2.ReferenceGrantFrom{{
Group: gatewayv1alpha2.Group(from.GroupVersionKind().Group),
Kind: gatewayv1alpha2.Kind(from.Kind),
Namespace: gatewayv1alpha2.Namespace(from.Namespace),
}},
To: []gatewayv1alpha2.ReferencePolicyTo{{
To: []gatewayv1alpha2.ReferenceGrantTo{{
Group: gatewayv1alpha2.Group(to.GroupVersionKind().Group),
Kind: gatewayv1alpha2.Kind(to.Kind),
Name: (*gatewayv1alpha2.ObjectName)(&to.Name),
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/testing/listers.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ func (l *Listers) GetGatewayLister() gatewayListers.GatewayLister {
return gatewayListers.NewGatewayLister(l.IndexerFor(&gatewayv1alpa2.Gateway{}))
}

func (l *Listers) GetReferencePolicyLister() gatewayListers.ReferencePolicyLister {
return gatewayListers.NewReferencePolicyLister(l.IndexerFor(&gatewayv1alpa2.ReferencePolicy{}))
func (l *Listers) GetReferenceGrantLister() gatewayListers.ReferenceGrantLister {
return gatewayListers.NewReferenceGrantLister(l.IndexerFor(&gatewayv1alpa2.ReferenceGrant{}))
}

0 comments on commit 4045dce

Please sign in to comment.