Skip to content

Commit

Permalink
switch to using v1beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
dprotaso committed Dec 1, 2022
1 parent 75e0379 commit 4afc0a7
Show file tree
Hide file tree
Showing 22 changed files with 681 additions and 690 deletions.
16 changes: 8 additions & 8 deletions pkg/reconciler/ingress/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import (
"knative.dev/pkg/reconciler"

gwapiclient "knative.dev/net-gateway-api/pkg/client/injection/client"
gatewayinformer "knative.dev/net-gateway-api/pkg/client/injection/informers/apis/v1alpha2/gateway"
httprouteinformer "knative.dev/net-gateway-api/pkg/client/injection/informers/apis/v1alpha2/httproute"
referencepolicyinformer "knative.dev/net-gateway-api/pkg/client/injection/informers/apis/v1alpha2/referencepolicy"
referencegrantinformer "knative.dev/net-gateway-api/pkg/client/injection/informers/apis/v1alpha2/referencegrant"
gatewayinformer "knative.dev/net-gateway-api/pkg/client/injection/informers/apis/v1beta1/gateway"
httprouteinformer "knative.dev/net-gateway-api/pkg/client/injection/informers/apis/v1beta1/httproute"
"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
6 changes: 3 additions & 3 deletions pkg/reconciler/ingress/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
"knative.dev/pkg/configmap"
"knative.dev/pkg/system"

_ "knative.dev/net-gateway-api/pkg/client/injection/informers/apis/v1alpha2/gateway/fake"
_ "knative.dev/net-gateway-api/pkg/client/injection/informers/apis/v1alpha2/httproute/fake"
_ "knative.dev/net-gateway-api/pkg/client/injection/informers/apis/v1alpha2/referencepolicy/fake"
_ "knative.dev/net-gateway-api/pkg/client/injection/informers/apis/v1alpha2/referencegrant/fake"
_ "knative.dev/net-gateway-api/pkg/client/injection/informers/apis/v1beta1/gateway/fake"
_ "knative.dev/net-gateway-api/pkg/client/injection/informers/apis/v1beta1/httproute/fake"
_ "knative.dev/networking/pkg/client/injection/informers/networking/v1alpha1/ingress/fake"
_ "knative.dev/pkg/client/injection/kube/informers/core/v1/endpoints/fake"

Expand Down
15 changes: 8 additions & 7 deletions pkg/reconciler/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import (
"knative.dev/pkg/network"
pkgreconciler "knative.dev/pkg/reconciler"

gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayapi "sigs.k8s.io/gateway-api/apis/v1beta1"
gatewayclientset "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"
gatewaylisters "sigs.k8s.io/gateway-api/pkg/client/listers/apis/v1alpha2"
gatewayalphalisters "sigs.k8s.io/gateway-api/pkg/client/listers/apis/v1alpha2"
gatewaylisters "sigs.k8s.io/gateway-api/pkg/client/listers/apis/v1beta1"
)

const (
Expand All @@ -49,7 +50,7 @@ type Reconciler struct {
// Listers index properties about resources
httprouteLister gatewaylisters.HTTPRouteLister

referencePolicyLister gatewaylisters.ReferencePolicyLister
referenceGrantLister gatewayalphalisters.ReferenceGrantLister

gatewayLister gatewaylisters.GatewayLister
}
Expand Down Expand Up @@ -109,7 +110,7 @@ func (c *Reconciler) reconcileIngress(ctx context.Context, ing *v1alpha1.Ingress
}
}

listeners := make([]*gatewayv1alpha2.Listener, 0, len(ing.Spec.TLS))
listeners := make([]*gatewayapi.Listener, 0, len(ing.Spec.TLS))
for _, tls := range ing.Spec.TLS {
tls := tls

Expand Down Expand Up @@ -158,7 +159,7 @@ func (c *Reconciler) reconcileIngress(ctx context.Context, ing *v1alpha1.Ingress

// isHTTPRouteReady will check the status conditions of the ingress and return true if
// all gateways have been admitted.
func isHTTPRouteReady(r *gatewayv1alpha2.HTTPRoute) bool {
func isHTTPRouteReady(r *gatewayapi.HTTPRoute) bool {
if r.Status.Parents == nil {
return false
}
Expand All @@ -171,9 +172,9 @@ func isHTTPRouteReady(r *gatewayv1alpha2.HTTPRoute) bool {
return true
}

func isGatewayAdmitted(gw gatewayv1alpha2.RouteParentStatus) bool {
func isGatewayAdmitted(gw gatewayapi.RouteParentStatus) bool {
for _, condition := range gw.Conditions {
if condition.Type == string(gatewayv1alpha2.RouteConditionAccepted) {
if condition.Type == string(gatewayapi.RouteConditionAccepted) {
return condition.Status == metav1.ConditionTrue
}
}
Expand Down
87 changes: 44 additions & 43 deletions pkg/reconciler/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import (
"k8s.io/apimachinery/pkg/types"
clientgotesting "k8s.io/client-go/testing"
"k8s.io/utils/pointer"
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

fakegwapiclientset "knative.dev/net-gateway-api/pkg/client/injection/client/fake"
"knative.dev/net-gateway-api/pkg/reconciler/ingress/config"
"knative.dev/net-gateway-api/pkg/reconciler/ingress/resources"
"knative.dev/networking/pkg/apis/networking"
"knative.dev/networking/pkg/apis/networking/v1alpha1"
fakeingressclient "knative.dev/networking/pkg/client/injection/client/fake"
Expand All @@ -42,12 +44,11 @@ import (
"knative.dev/pkg/logging"
"knative.dev/pkg/network"

gatewayapialpha "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayapi "sigs.k8s.io/gateway-api/apis/v1beta1"

. "knative.dev/net-gateway-api/pkg/reconciler/testing"
. "knative.dev/pkg/reconciler/testing"

fakegwapiclientset "knative.dev/net-gateway-api/pkg/client/injection/client/fake"
"knative.dev/net-gateway-api/pkg/reconciler/ingress/config"
"knative.dev/net-gateway-api/pkg/reconciler/ingress/resources"
)

var (
Expand Down Expand Up @@ -392,10 +393,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 All @@ -404,9 +405,9 @@ func TestReconcileTLS(t *testing.T) {
// so create this via explicit call (per note in client-go/testing/fixture.go in tracker.Add)
fakeCreates := []runtime.Object{}
for _, x := range tr.Objects {
myGw, ok := x.(*gatewayv1alpha2.Gateway)
myGw, ok := x.(*gatewayapi.Gateway)
if ok {
fakegwapiclientset.Get(ctx).GatewayV1alpha2().Gateways(myGw.Namespace).Create(ctx, myGw, metav1.CreateOptions{})
fakegwapiclientset.Get(ctx).GatewayV1beta1().Gateways(myGw.Namespace).Create(ctx, myGw, metav1.CreateOptions{})
tr.SkipNamespaceValidation = true
fakeCreates = append(fakeCreates, myGw)
}
Expand Down Expand Up @@ -500,7 +501,7 @@ func httpRoute(t *testing.T, i *v1alpha1.Ingress, opts ...HTTPRouteOption) runti
return httpRoute
}

type HTTPRouteOption func(h *gatewayv1alpha2.HTTPRoute)
type HTTPRouteOption func(h *gatewayapi.HTTPRoute)

func withGatewayAPIclass(i *v1alpha1.Ingress) {
withAnnotation(map[string]string{
Expand Down Expand Up @@ -536,15 +537,15 @@ func GatewayFactory(ctor func(context.Context, *Listers, configmap.Watcher, *Tab
}
}

type GatewayOption func(*gatewayv1alpha2.Gateway)
type GatewayOption func(*gatewayapi.Gateway)

func gw(opts ...GatewayOption) *gatewayv1alpha2.Gateway {
g := &gatewayv1alpha2.Gateway{
func gw(opts ...GatewayOption) *gatewayapi.Gateway {
g := &gatewayapi.Gateway{
ObjectMeta: metav1.ObjectMeta{
Name: publicName,
Namespace: testNamespace,
},
Spec: gatewayv1alpha2.GatewaySpec{
Spec: gatewayapi.GatewaySpec{
GatewayClassName: gatewayAPIIngressClassName,
},
}
Expand All @@ -554,41 +555,41 @@ func gw(opts ...GatewayOption) *gatewayv1alpha2.Gateway {
return g
}

func defaultListener(g *gatewayv1alpha2.Gateway) {
g.Spec.Listeners = append(g.Spec.Listeners, gatewayv1alpha2.Listener{
func defaultListener(g *gatewayapi.Gateway) {
g.Spec.Listeners = append(g.Spec.Listeners, gatewayapi.Listener{
Name: "http",
Port: 80,
Protocol: "HTTP",
})
}

func tlsListener(hostname, nsName, secretName string) GatewayOption {
return func(g *gatewayv1alpha2.Gateway) {
g.Spec.Listeners = append(g.Spec.Listeners, gatewayv1alpha2.Listener{
Name: gatewayv1alpha2.SectionName("kni-"),
Hostname: (*gatewayv1alpha2.Hostname)(&hostname),
return func(g *gatewayapi.Gateway) {
g.Spec.Listeners = append(g.Spec.Listeners, gatewayapi.Listener{
Name: gatewayapi.SectionName("kni-"),
Hostname: (*gatewayapi.Hostname)(&hostname),
Port: 443,
Protocol: "HTTPS",
TLS: &gatewayv1alpha2.GatewayTLSConfig{
Mode: (*gatewayv1alpha2.TLSModeType)(pointer.String("Terminate")),
CertificateRefs: []gatewayv1alpha2.SecretObjectReference{{
Group: (*gatewayv1alpha2.Group)(pointer.String("")),
Kind: (*gatewayv1alpha2.Kind)(pointer.String("Secret")),
Name: gatewayv1alpha2.ObjectName(secretName),
Namespace: (*gatewayv1alpha2.Namespace)(&nsName),
TLS: &gatewayapi.GatewayTLSConfig{
Mode: (*gatewayapi.TLSModeType)(pointer.String("Terminate")),
CertificateRefs: []gatewayapi.SecretObjectReference{{
Group: (*gatewayapi.Group)(pointer.String("")),
Kind: (*gatewayapi.Kind)(pointer.String("Secret")),
Name: gatewayapi.ObjectName(secretName),
Namespace: (*gatewayapi.Namespace)(&nsName),
}},
Options: map[gatewayv1alpha2.AnnotationKey]gatewayv1alpha2.AnnotationValue{},
Options: map[gatewayapi.AnnotationKey]gatewayapi.AnnotationValue{},
},
AllowedRoutes: &gatewayv1alpha2.AllowedRoutes{
Namespaces: &gatewayv1alpha2.RouteNamespaces{
From: (*gatewayv1alpha2.FromNamespaces)(pointer.String("Selector")),
AllowedRoutes: &gatewayapi.AllowedRoutes{
Namespaces: &gatewayapi.RouteNamespaces{
From: (*gatewayapi.FromNamespaces)(pointer.String("Selector")),
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"kubernetes.io/metadata.name": nsName,
},
},
},
Kinds: []gatewayv1alpha2.RouteGroupKind{},
Kinds: []gatewayapi.RouteGroupKind{},
},
})
}
Expand Down Expand Up @@ -622,9 +623,9 @@ func secret(name, ns string) *corev1.Secret {
}
}

func rp(to *corev1.Secret) *gatewayv1alpha2.ReferencePolicy {
func rp(to *corev1.Secret) *gatewayapialpha.ReferenceGrant {
t := true
return &gatewayv1alpha2.ReferencePolicy{
return &gatewayapialpha.ReferenceGrant{
ObjectMeta: metav1.ObjectMeta{
Name: to.Name + "-" + testNamespace,
Namespace: to.Namespace,
Expand All @@ -636,16 +637,16 @@ func rp(to *corev1.Secret) *gatewayv1alpha2.ReferencePolicy {
BlockOwnerDeletion: &t,
}},
},
Spec: gatewayv1alpha2.ReferenceGrantSpec{
From: []gatewayv1alpha2.ReferenceGrantFrom{{
Spec: gatewayapialpha.ReferenceGrantSpec{
From: []gatewayapialpha.ReferenceGrantFrom{{
Group: "gateway.networking.k8s.io",
Kind: "Gateway",
Namespace: gatewayv1alpha2.Namespace(testNamespace),
Namespace: gatewayapialpha.Namespace(testNamespace),
}},
To: []gatewayv1alpha2.ReferenceGrantTo{{
Group: gatewayv1alpha2.Group(""),
Kind: gatewayv1alpha2.Kind("Secret"),
Name: (*gatewayv1alpha2.ObjectName)(&to.Name),
To: []gatewayapialpha.ReferenceGrantTo{{
Group: gatewayapialpha.Group(""),
Kind: gatewayapialpha.Kind("Secret"),
Name: (*gatewayapialpha.ObjectName)(&to.Name),
}},
},
}
Expand Down
Loading

0 comments on commit 4afc0a7

Please sign in to comment.