Skip to content

Commit

Permalink
Merge pull request #3 from eltorio/apiv1
Browse files Browse the repository at this point in the history
Apiv1
  • Loading branch information
eltorio authored Jan 31, 2024
2 parents bf5681b + b1a41f7 commit 82bda10
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 49 deletions.
10 changes: 4 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ 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.8.1
sigs.k8s.io/yaml v1.3.0
sigs.k8s.io/gateway-api v1.0.0
sigs.k8s.io/yaml v1.4.0
)

require (
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 @@ -90,7 +88,7 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230928205116-a78145627833 // 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
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -470,19 +470,19 @@ 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.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20230928205116-a78145627833 h1:iFFEmmB7szQhJP42AvRD2+gzdVP7EuIKY1rJgxf0JZY=
k8s.io/kube-openapi v0.0.0-20230928205116-a78145627833/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
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.8.1 h1:Bo4NMAQFYkQZnHXOfufbYwbPW7b3Ic5NjpbeW6EJxuU=
sigs.k8s.io/gateway-api v0.8.1/go.mod h1:0PteDrsrgkRmr13nDqFWnev8tOysAVrwnvfFM55tSVg=
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=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
12 changes: 6 additions & 6 deletions pkg/gateways/gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +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/v1beta1"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
)

var logger = utils.GetLogger()
Expand All @@ -39,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 @@ -245,7 +245,7 @@ MAIN_LOOP:
if listener.AllowedRoutes != nil {
validRGK := []store.RouteGroupKind{}
for _, kind := range listener.AllowedRoutes.Kinds {
if (kind.Group == nil || *kind.Group == v1beta1.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 @@ -550,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 != v1beta1.GroupName) || kind.Kind != K8S_TCPROUTE_KIND {
if (kind.Group != nil && *kind.Group != gatewayv1.GroupName) || kind.Kind != K8S_TCPROUTE_KIND {
continue
}
gkAllowed = true
Expand All @@ -563,13 +563,13 @@ func (gm GatewayManagerImpl) isTCPRouteAllowedByListener(listener store.Listener
if allowedRoutesNamespaces != nil {
from := allowedRoutesNamespaces.From
if from == nil {
v := (string)(v1beta1.NamespacesFromSame)
v := (string)(gatewayv1.NamespacesFromSame)
from = &v
}
if *from == "Same" {
return routeNamespace == gatewayNamespace
}
if *from == (string)(v1beta1.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 := v1beta1.RouteParentStatus{
ControllerName: v1beta1.GatewayController(statusMgr.gatewayControllerName),
ParentRef: v1beta1.ParentReference{
Group: (*v1beta1.Group)(&parentStatusRecord.parentRef.Group),
Kind: (*v1beta1.Kind)(&parentStatusRecord.parentRef.Kind),
Namespace: (*v1beta1.Namespace)(parentStatusRecord.parentRef.Namespace),
Name: v1beta1.ObjectName(parentStatusRecord.parentRef.Name),
SectionName: (*v1beta1.SectionName)(parentStatusRecord.parentRef.SectionName),
Port: (*v1beta1.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
15 changes: 8 additions & 7 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 | *gatewayv1beta1.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

0 comments on commit 82bda10

Please sign in to comment.