Skip to content

Commit

Permalink
chore: bump Gateway API's Gateway from v1alpha2 to v1beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Sep 6, 2022
1 parent cd73e4b commit 2685449
Show file tree
Hide file tree
Showing 34 changed files with 641 additions and 595 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@
- Added support for Kong 3.0 upstream `query_arg` and `uri_capture` hash
configuration to KongIngress.
[#2822](https://github.com/Kong/kubernetes-ingress-controller/issues/2822)
- Added support for Gateway API's v1beta1 versions of: GatewayClass, Gateway
and HTTPRoute.
- Added support for Gateway API's `v1beta1` versions of: `GatewayClass`, `Gateway`
and `HTTPRoute`.
[#2889](https://github.com/Kong/kubernetes-ingress-controller/issues/2889)
[#2894](https://github.com/Kong/kubernetes-ingress-controller/issues/2894)
[#2900](https://github.com/Kong/kubernetes-ingress-controller/issues/2900)

#### Fixed

Expand Down
11 changes: 5 additions & 6 deletions internal/admission/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

configuration "github.com/kong/kubernetes-ingress-controller/v2/pkg/apis/configuration/v1"
Expand Down Expand Up @@ -184,13 +183,13 @@ var (
Resource: "secrets",
}
gatewayGVResource = metav1.GroupVersionResource{
Group: gatewayv1alpha2.SchemeGroupVersion.Group,
Version: gatewayv1alpha2.SchemeGroupVersion.Version,
Group: gatewayv1beta1.SchemeGroupVersion.Group,
Version: gatewayv1beta1.SchemeGroupVersion.Version,
Resource: "gateways",
}
httprouteGVResource = metav1.GroupVersionResource{
Group: gatewayv1alpha2.SchemeGroupVersion.Group,
Version: gatewayv1alpha2.SchemeGroupVersion.Version,
Group: gatewayv1beta1.SchemeGroupVersion.Group,
Version: gatewayv1beta1.SchemeGroupVersion.Version,
Resource: "httproutes",
}
)
Expand Down Expand Up @@ -294,7 +293,7 @@ func (a RequestHandler) handleValidation(ctx context.Context, request admissionv
return nil, fmt.Errorf("unknown operation '%v'", string(request.Operation))
}
case gatewayGVResource:
gateway := gatewayv1alpha2.Gateway{}
gateway := gatewayv1beta1.Gateway{}
deserializer := codecs.UniversalDeserializer()
_, _, err = deserializer.Decode(request.Object.Raw, nil, &gateway)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions internal/admission/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
admissionv1 "k8s.io/api/admission/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

configuration "github.com/kong/kubernetes-ingress-controller/v2/pkg/apis/configuration/v1"
Expand Down Expand Up @@ -51,7 +50,7 @@ func (v KongFakeValidator) ValidateCredential(ctx context.Context, secret corev1
return v.Result, v.Message, v.Error
}

func (v KongFakeValidator) ValidateGateway(ctx context.Context, gateway gatewayv1alpha2.Gateway) (bool, string, error) {
func (v KongFakeValidator) ValidateGateway(ctx context.Context, gateway gatewayv1beta1.Gateway) (bool, string, error) {
return v.Result, v.Message, v.Error
}

Expand Down
20 changes: 9 additions & 11 deletions internal/admission/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/kong/kubernetes-ingress-controller/v2/internal/annotations"
gatewaycontroller "github.com/kong/kubernetes-ingress-controller/v2/internal/controllers/gateway"
Expand All @@ -28,8 +26,8 @@ type KongValidator interface {
ValidatePlugin(ctx context.Context, plugin kongv1.KongPlugin) (bool, string, error)
ValidateClusterPlugin(ctx context.Context, plugin kongv1.KongClusterPlugin) (bool, string, error)
ValidateCredential(ctx context.Context, secret corev1.Secret) (bool, string, error)
ValidateGateway(ctx context.Context, gateway gatewayv1alpha2.Gateway) (bool, string, error)
ValidateHTTPRoute(ctx context.Context, httproute gatewayv1beta1.HTTPRoute) (bool, string, error)
ValidateGateway(ctx context.Context, gateway gatewaycontroller.Gateway) (bool, string, error)
ValidateHTTPRoute(ctx context.Context, httproute gatewaycontroller.HTTPRoute) (bool, string, error)
}

// KongHTTPValidator implements KongValidator interface to validate Kong
Expand Down Expand Up @@ -298,15 +296,15 @@ func (validator KongHTTPValidator) ValidateClusterPlugin(
}

func (validator KongHTTPValidator) ValidateGateway(
ctx context.Context, gateway gatewayv1alpha2.Gateway,
ctx context.Context, gateway gatewaycontroller.Gateway,
) (bool, string, error) {
// check if the gateway declares a gateway class
if gateway.Spec.GatewayClassName == "" {
return true, "", nil
}

// validate the gatewayclass reference
gwc := gatewayv1beta1.GatewayClass{}
gwc := gatewaycontroller.GatewayClass{}
if err := validator.ManagerClient.Get(ctx, client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, &gwc); err != nil {
if strings.Contains(err.Error(), "not found") {
return true, "", nil // not managed by this controller
Expand All @@ -316,19 +314,19 @@ func (validator KongHTTPValidator) ValidateGateway(

// validate whether the gatewayclass is a supported class, if not
// then this gateway belongs to another controller.
if string(gwc.Spec.ControllerName) != string(gatewaycontroller.ControllerName) {
if gwc.Spec.ControllerName != gatewaycontroller.ControllerName {
return true, "", nil
}

return true, "", nil
}

func (validator KongHTTPValidator) ValidateHTTPRoute(
ctx context.Context, httproute gatewayv1beta1.HTTPRoute,
ctx context.Context, httproute gatewaycontroller.HTTPRoute,
) (bool, string, error) {
// in order to be sure whether or not an HTTPRoute resource is managed by this
// controller we disallow references to Gateway resources that do not exist.
var managedGateways []*gatewayv1alpha2.Gateway
var managedGateways []*gatewaycontroller.Gateway
for _, parentRef := range httproute.Spec.ParentRefs {
// determine the namespace of the gateway referenced via parentRef. If no
// explicit namespace is provided, assume the namespace of the route.
Expand All @@ -339,7 +337,7 @@ func (validator KongHTTPValidator) ValidateHTTPRoute(

// gather the Gateway resource referenced by parentRef and fail validation
// if there is no such Gateway resource.
gateway := gatewayv1alpha2.Gateway{}
gateway := gatewaycontroller.Gateway{}
if err := validator.ManagerClient.Get(ctx, client.ObjectKey{
Namespace: namespace,
Name: string(parentRef.Name),
Expand All @@ -348,7 +346,7 @@ func (validator KongHTTPValidator) ValidateHTTPRoute(
}

// pull the referenced GatewayClass object from the Gateway
gatewayClass := gatewayv1beta1.GatewayClass{}
gatewayClass := gatewaycontroller.GatewayClass{}
if err := validator.ManagerClient.Get(ctx, client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, &gatewayClass); err != nil {
return false, fmt.Sprintf("couldn't retrieve referenced gatewayclass %s", gateway.Spec.GatewayClassName), err
}
Expand Down
Loading

0 comments on commit 2685449

Please sign in to comment.