Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Gateway api v1 #609

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ require (
k8s.io/apiextensions-apiserver v0.28.3
k8s.io/apimachinery v0.28.3
k8s.io/client-go v0.28.3
sigs.k8s.io/controller-runtime v0.16.2
sigs.k8s.io/controller-runtime v0.16.3
sigs.k8s.io/controller-tools v0.13.0
sigs.k8s.io/gateway-api v0.5.0
sigs.k8s.io/gateway-api v1.0.0
sigs.k8s.io/yaml v1.4.0
)

Expand All @@ -36,7 +36,6 @@ require (
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.4 // indirect
Expand Down Expand Up @@ -76,7 +75,6 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
go.mongodb.org/mongo-driver v1.13.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
Expand All @@ -89,8 +87,8 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231113174909-778a5567bc1e // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
Expand Down
17 changes: 9 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/go-faker/faker/v4 v4.2.0 h1:dGebOupKwssrODV51E0zbMrv5e2gO9VWSLNC1WDCpWg=
github.com/go-faker/faker/v4 v4.2.0/go.mod h1:F/bBy8GH9NxOxMInug5Gx4WYeG6fHJZ8Ol/dhcpRub4=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/zapr v1.2.4 h1:QHVo+6stLbfJmYGkQ7uGHUCu5hnAFAj6mDe6Ea0SeOo=
Expand Down Expand Up @@ -467,18 +468,18 @@ k8s.io/apimachinery v0.28.3 h1:B1wYx8txOaCQG0HmYF6nbpU8dg6HvA06x5tEffvOe7A=
k8s.io/apimachinery v0.28.3/go.mod h1:uQTKmIqs+rAYaq+DFaoD2X7pcjLOqbQX2AOiO0nIpb8=
k8s.io/client-go v0.28.3 h1:2OqNb72ZuTZPKCl+4gTKvqao0AMOl9f3o2ijbAj3LI4=
k8s.io/client-go v0.28.3/go.mod h1:LTykbBp9gsA7SwqirlCXBWtK0guzfhpoW4qSm7i9dxo=
k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0=
k8s.io/klog/v2 v2.110.1/go.mod h1:YGtd1984u+GgbuZ7e08/yBuAfKLSO0+uR1Fhi6ExXjo=
k8s.io/kube-openapi v0.0.0-20231113174909-778a5567bc1e h1:snPmy96t93RredGRjKfMFt+gvxuVAncqSAyBveJtr4Q=
k8s.io/kube-openapi v0.0.0-20231113174909-778a5567bc1e/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/AuzbMm96cd3YHRTU83I780=
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/controller-runtime v0.16.2 h1:mwXAVuEk3EQf478PQwQ48zGOXvW27UJc8NHktQVuIPU=
sigs.k8s.io/controller-runtime v0.16.2/go.mod h1:vpMu3LpI5sYWtujJOa2uPK61nB5rbwlN7BAB8aSLvGU=
sigs.k8s.io/controller-runtime v0.16.3 h1:2TuvuokmfXvDUamSx1SuAOO3eTyye+47mJCigwG62c4=
sigs.k8s.io/controller-runtime v0.16.3/go.mod h1:j7bialYoSn142nv9sCOJmQgDXQXxnroFU4VnX/brVJ0=
sigs.k8s.io/controller-tools v0.13.0 h1:NfrvuZ4bxyolhDBt/rCZhDnx3M2hzlhgo5n3Iv2RykI=
sigs.k8s.io/controller-tools v0.13.0/go.mod h1:5vw3En2NazbejQGCeWKRrE7q4P+CW8/klfVqP8QZkgA=
sigs.k8s.io/gateway-api v0.5.0 h1:ze+k9fJqvmL8s1t3e4q1ST8RnN+f09dEv+gfacahlAE=
sigs.k8s.io/gateway-api v0.5.0/go.mod h1:x0AP6gugkFV8fC/oTlnOMU0pnmuzIR8LfIPRVUjxSqA=
sigs.k8s.io/gateway-api v1.0.0 h1:iPTStSv41+d9p0xFydll6d7f7MOBGuqXM6p2/zVYMAs=
sigs.k8s.io/gateway-api v1.0.0/go.mod h1:4cUgr0Lnp5FZ0Cdq8FdRwCvpiWws7LVhLHGIudLlf4c=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
Expand Down
13 changes: 6 additions & 7 deletions pkg/gateways/gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/gateway-api/apis/v1alpha2"
"sigs.k8s.io/gateway-api/apis/v1beta1"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
)

var logger = utils.GetLogger()
Expand All @@ -40,7 +39,7 @@ var logger = utils.GetLogger()
const (
K8S_CORE_GROUP = ""
K8S_NETWORKING_GROUP = networkingv1.GroupName
K8S_GATEWAY_GROUP = v1beta1.GroupName
K8S_GATEWAY_GROUP = gatewayv1.GroupName
K8S_TCPROUTE_KIND = "TCPRoute"
K8S_SERVICE_KIND = "Service"
)
Expand Down Expand Up @@ -246,7 +245,7 @@ MAIN_LOOP:
if listener.AllowedRoutes != nil {
validRGK := []store.RouteGroupKind{}
for _, kind := range listener.AllowedRoutes.Kinds {
if (kind.Group == nil || *kind.Group == v1alpha2.GroupName) && kind.Kind == K8S_TCPROUTE_KIND {
if (kind.Group == nil || *kind.Group == gatewayv1.GroupName) && kind.Kind == K8S_TCPROUTE_KIND {
validRGK = append(validRGK, kind)
}
}
Expand Down Expand Up @@ -551,7 +550,7 @@ func (gm GatewayManagerImpl) isTCPRouteAllowedByListener(listener store.Listener

gkAllowed := listener.AllowedRoutes.Kinds == nil || len(listener.AllowedRoutes.Kinds) == 0
for _, kind := range listener.AllowedRoutes.Kinds {
if (kind.Group != nil && *kind.Group != v1alpha2.GroupName) || kind.Kind != K8S_TCPROUTE_KIND {
if (kind.Group != nil && *kind.Group != gatewayv1.GroupName) || kind.Kind != K8S_TCPROUTE_KIND {
continue
}
gkAllowed = true
Expand All @@ -564,13 +563,13 @@ func (gm GatewayManagerImpl) isTCPRouteAllowedByListener(listener store.Listener
if allowedRoutesNamespaces != nil {
from := allowedRoutesNamespaces.From
if from == nil {
v := (string)(v1alpha2.NamespacesFromSame)
v := (string)(gatewayv1.NamespacesFromSame)
from = &v
}
if *from == "Same" {
return routeNamespace == gatewayNamespace
}
if *from == (string)(v1alpha2.NamespacesFromSelector) {
if *from == (string)(gatewayv1.NamespacesFromSelector) {
if allowedRoutesNamespaces.Selector == nil {
return false
}
Expand Down
44 changes: 22 additions & 22 deletions pkg/gateways/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"github.com/haproxytech/kubernetes-ingress/pkg/store"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
v1 "sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/gateway-api/apis/v1alpha2"
"sigs.k8s.io/gateway-api/apis/v1beta1"
)

// UpdateStatusGatewayclasses is responsible of updating the statuses of the accepted gateway classes.
Expand All @@ -32,7 +32,7 @@ func (statusMgr *StatusManagerImpl) UpdateStatusGatewayclasses(gatewayclasses []
if gwClass.Status == store.EMPTY || gwClass.Status == store.DELETED {
continue
}
gwc := &v1beta1.GatewayClass{}
gwc := &v1.GatewayClass{}
err := statusMgr.k8sRestClient.Get(context.TODO(), types.NamespacedName{
Name: gwClass.Name,
}, gwc)
Expand All @@ -41,7 +41,7 @@ func (statusMgr *StatusManagerImpl) UpdateStatusGatewayclasses(gatewayclasses []
continue
}

gwc.Status = v1beta1.GatewayClassStatus{
gwc.Status = v1.GatewayClassStatus{
Conditions: []metav1.Condition{{
Type: GatewayClassConditionStatusAccepted,
ObservedGeneration: gwc.Generation,
Expand All @@ -66,8 +66,8 @@ func (statusMgr *StatusManagerImpl) UpdateStatusGateways(gatewayStatusRecords []
continue
}

gwStatus := v1beta1.GatewayStatus{
Listeners: make([]v1beta1.ListenerStatus, len(gatewayStatusRecord.listenersStatusesRecords)),
gwStatus := v1.GatewayStatus{
Listeners: make([]v1.ListenerStatus, len(gatewayStatusRecord.listenersStatusesRecords)),
Conditions: []metav1.Condition{{
Type: GatewayConditionReady,
ObservedGeneration: gatewayStatusRecord.generation,
Expand All @@ -82,8 +82,8 @@ func (statusMgr *StatusManagerImpl) UpdateStatusGateways(gatewayStatusRecords []
if numRoutesByListener := numRoutesByListenerByGateway[gatewayStatusRecord.namespace+"/"+gatewayStatusRecord.name]; numRoutesByListener != nil {
numRoutes = numRoutesByListener[listenerStatusRecord.name]
}
gwStatus.Listeners[i] = v1beta1.ListenerStatus{
Name: v1beta1.SectionName(listenerStatusRecord.name),
gwStatus.Listeners[i] = v1.ListenerStatus{
Name: v1.SectionName(listenerStatusRecord.name),
SupportedKinds: RouteGroupKinds(listenerStatusRecord.validRGK).asK8SGroupKind(),
AttachedRoutes: numRoutes,
}
Expand Down Expand Up @@ -134,7 +134,7 @@ func (statusMgr *StatusManagerImpl) UpdateStatusGateways(gatewayStatusRecords []
gwStatus.Listeners[i].Conditions = listenerConditions
}

gw := &v1beta1.Gateway{}
gw := &v1.Gateway{}
err := statusMgr.k8sRestClient.Get(context.TODO(), types.NamespacedName{
Namespace: gatewayStatusRecord.namespace,
Name: gatewayStatusRecord.name,
Expand Down Expand Up @@ -177,15 +177,15 @@ func (statusMgr *StatusManagerImpl) UpdateStatusTCPRoutes(routesStatusRecords []
for _, parentStatusRecord := range tcprouteStatusRecord.parentsStatusesRecords {
parentStatusRecord := parentStatusRecord
conditions := []metav1.Condition{}
routeParentStatus := v1alpha2.RouteParentStatus{
ControllerName: v1alpha2.GatewayController(statusMgr.gatewayControllerName),
ParentRef: v1alpha2.ParentReference{
Group: (*v1alpha2.Group)(&parentStatusRecord.parentRef.Group),
Kind: (*v1alpha2.Kind)(&parentStatusRecord.parentRef.Kind),
Namespace: (*v1alpha2.Namespace)(parentStatusRecord.parentRef.Namespace),
Name: v1alpha2.ObjectName(parentStatusRecord.parentRef.Name),
SectionName: (*v1alpha2.SectionName)(parentStatusRecord.parentRef.SectionName),
Port: (*v1alpha2.PortNumber)(parentStatusRecord.parentRef.Port),
routeParentStatus := v1.RouteParentStatus{
ControllerName: v1.GatewayController(statusMgr.gatewayControllerName),
ParentRef: v1.ParentReference{
Group: (*v1.Group)(&parentStatusRecord.parentRef.Group),
Kind: (*v1.Kind)(&parentStatusRecord.parentRef.Kind),
Namespace: (*v1.Namespace)(parentStatusRecord.parentRef.Namespace),
Name: v1.ObjectName(parentStatusRecord.parentRef.Name),
SectionName: (*v1.SectionName)(parentStatusRecord.parentRef.SectionName),
Port: (*v1.PortNumber)(parentStatusRecord.parentRef.Port),
},
}

Expand Down Expand Up @@ -267,12 +267,12 @@ func hasNumberOfRoutesForAnyListenerChanged(gatewayStatusRecord gatewayStatusRec

type RouteGroupKinds []store.RouteGroupKind

func (rgk RouteGroupKinds) asK8SGroupKind() []v1beta1.RouteGroupKind {
routeGroupKind := make([]v1beta1.RouteGroupKind, len(rgk))
func (rgk RouteGroupKinds) asK8SGroupKind() []v1.RouteGroupKind {
routeGroupKind := make([]v1.RouteGroupKind, len(rgk))
for i, rgk := range rgk {
routeGroupKind[i] = v1beta1.RouteGroupKind{
Group: (*v1beta1.Group)(rgk.Group),
Kind: v1beta1.Kind(rgk.Kind),
routeGroupKind[i] = v1.RouteGroupKind{
Group: (*v1.Group)(rgk.Group),
Kind: v1.Kind(rgk.Kind),
}
}
return routeGroupKind
Expand Down
21 changes: 11 additions & 10 deletions pkg/k8s/informers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/haproxytech/kubernetes-ingress/pkg/store"
"github.com/haproxytech/kubernetes-ingress/pkg/utils"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
gatewaynetworking "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions"
Expand Down Expand Up @@ -744,12 +745,12 @@ type InformerGetter interface {
}

type GatewayRelatedType interface {
*gatewayv1beta1.GatewayClass | *gatewayv1beta1.Gateway | *gatewayv1alpha2.TCPRoute | *gatewayv1alpha2.ReferenceGrant
*gatewayv1.GatewayClass | *gatewayv1.Gateway | *gatewayv1beta1.GatewayClass | *gatewayv1beta1.Gateway | *gatewayv1alpha2.TCPRoute | *gatewayv1beta1.ReferenceGrant
}

type GatewayInformerFunc[GWType GatewayRelatedType] func(gwObj GWType, eventChan chan SyncDataEvent, status store.Status)

func manageGatewayClass(gatewayclass *gatewayv1beta1.GatewayClass, eventChan chan SyncDataEvent, status store.Status) {
func manageGatewayClass(gatewayclass *gatewayv1.GatewayClass, eventChan chan SyncDataEvent, status store.Status) {
logger.Infof("gwapi: gatewayclass: informers: got '%s'", gatewayclass.Name)
item := store.GatewayClass{
Name: gatewayclass.Name,
Expand All @@ -762,7 +763,7 @@ func manageGatewayClass(gatewayclass *gatewayv1beta1.GatewayClass, eventChan cha
eventChan <- SyncDataEvent{SyncType: GATEWAYCLASS, Data: &item}
}

func manageGateway(gateway *gatewayv1beta1.Gateway, eventChan chan SyncDataEvent, status store.Status) {
func manageGateway(gateway *gatewayv1.Gateway, eventChan chan SyncDataEvent, status store.Status) {
logger.Infof("gwapi: gateway: informers: got '%s/%s'", gateway.Namespace, gateway.Name)
listeners := make([]store.Listener, len(gateway.Spec.Listeners))
for i, listener := range gateway.Spec.Listeners {
Expand Down Expand Up @@ -873,14 +874,14 @@ func manageTCPRoute(tcproute *gatewayv1alpha2.TCPRoute, eventChan chan SyncDataE
}

func (k k8s) getGatewayClassesInformer(eventChan chan SyncDataEvent, factory gatewaynetworking.SharedInformerFactory) cache.SharedIndexInformer {
informer := factory.Gateway().V1beta1().GatewayClasses()
PopulateInformer(eventChan, informer, GatewayInformerFunc[*gatewayv1beta1.GatewayClass](manageGatewayClass))
informer := factory.Gateway().V1().GatewayClasses()
PopulateInformer(eventChan, informer, GatewayInformerFunc[*gatewayv1.GatewayClass](manageGatewayClass))
return informer.Informer()
}

func (k k8s) getGatewayInformer(eventChan chan SyncDataEvent, factory gatewaynetworking.SharedInformerFactory) cache.SharedIndexInformer {
informer := factory.Gateway().V1beta1().Gateways()
PopulateInformer(eventChan, informer, GatewayInformerFunc[*gatewayv1beta1.Gateway](manageGateway))
informer := factory.Gateway().V1().Gateways()
PopulateInformer(eventChan, informer, GatewayInformerFunc[*gatewayv1.Gateway](manageGateway))
return informer.Informer()
}

Expand Down Expand Up @@ -910,12 +911,12 @@ func PopulateInformer[IT InformerGetter, GWType GatewayRelatedType, GWF GatewayI
}

func (k k8s) getReferenceGrantInformer(eventChan chan SyncDataEvent, factory gatewaynetworking.SharedInformerFactory) cache.SharedIndexInformer {
informer := factory.Gateway().V1alpha2().ReferenceGrants()
PopulateInformer(eventChan, informer, GatewayInformerFunc[*gatewayv1alpha2.ReferenceGrant](manageReferenceGrant))
informer := factory.Gateway().V1beta1().ReferenceGrants()
PopulateInformer(eventChan, informer, GatewayInformerFunc[*gatewayv1beta1.ReferenceGrant](manageReferenceGrant))
return informer.Informer()
}

func manageReferenceGrant(referenceGrant *gatewayv1alpha2.ReferenceGrant, eventChan chan SyncDataEvent, status store.Status) {
func manageReferenceGrant(referenceGrant *gatewayv1beta1.ReferenceGrant, eventChan chan SyncDataEvent, status store.Status) {
logger.Debugf("gwapi: referencegrant: informers: got '%s/%s'", referenceGrant.Namespace, referenceGrant.Name)
item := store.ReferenceGrant{
Name: referenceGrant.Name,
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ var logger = utils.GetK8sLogger()
const (
CRSGroupVersionV1alpha1 = "core.haproxy.org/v1alpha1"
CRSGroupVersionV1alpha2 = "core.haproxy.org/v1alpha2"
GATEWAY_API_VERSION = "v1.0.0" //nolint:golint,stylecheck
CRSGroupVersionV1 = "ingress.v1.haproxy.org/v1"
GATEWAY_API_VERSION = "v0.5.1" //nolint:golint,stylecheck
)

var ErrIgnored = errors.New("ignored resource")
Expand Down
Loading