Skip to content

Commit

Permalink
chore: Use v1beta1 gateway API on more files
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Apr 9, 2024
1 parent e9ac472 commit d0ca00d
Show file tree
Hide file tree
Showing 30 changed files with 172 additions and 173 deletions.
5 changes: 2 additions & 3 deletions internal/cmd/egctl/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gwv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"

Expand Down Expand Up @@ -120,14 +119,14 @@ func runStatus(ctx context.Context, cli client.Client, resourceType, namespace s

switch strings.ToLower(resourceType) {
case "gc", "gatewayclass":
gc := gwv1.GatewayClassList{}
gc := gwv1b1.GatewayClassList{}
if err := cli.List(ctx, &gc, client.InNamespace(namespace)); err != nil {
return err
}
resourcesList = &gc

case "gtw", "gateway":
gtw := gwv1.GatewayList{}
gtw := gwv1b1.GatewayList{}
if err := cli.List(ctx, &gtw, client.InNamespace(namespace)); err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions internal/cmd/egctl/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func translateGatewayAPIToIR(resources *gatewayapi.Resources) (*gatewayapi.Trans

t := &gatewayapi.Translator{
GatewayControllerName: egv1a1.GatewayControllerName,
GatewayClassName: gwapiv1.ObjectName(resources.GatewayClass.Name),
GatewayClassName: gwapiv1b1.ObjectName(resources.GatewayClass.Name),
GlobalRateLimitEnabled: true,
EndpointRoutingDisabled: true,
EnvoyPatchPolicyEnabled: true,
Expand All @@ -305,7 +305,7 @@ func translateGatewayAPIToGatewayAPI(resources *gatewayapi.Resources) (gatewayap
// Translate from Gateway API to Xds IR
gTranslator := &gatewayapi.Translator{
GatewayControllerName: egv1a1.GatewayControllerName,
GatewayClassName: gwapiv1.ObjectName(resources.GatewayClass.Name),
GatewayClassName: gwapiv1b1.ObjectName(resources.GatewayClass.Name),
GlobalRateLimitEnabled: true,
EndpointRoutingDisabled: true,
EnvoyPatchPolicyEnabled: true,
Expand Down Expand Up @@ -337,7 +337,7 @@ func translateGatewayAPIToXds(dnsDomain string, resourceType string, resources *
// Translate from Gateway API to Xds IR
gTranslator := &gatewayapi.Translator{
GatewayControllerName: egv1a1.GatewayControllerName,
GatewayClassName: gwapiv1.ObjectName(resources.GatewayClass.Name),
GatewayClassName: gwapiv1b1.ObjectName(resources.GatewayClass.Name),
GlobalRateLimitEnabled: true,
EndpointRoutingDisabled: true,
EnvoyPatchPolicyEnabled: true,
Expand Down Expand Up @@ -543,7 +543,7 @@ func addMissingServices(requiredServices map[string]*v1.Service, obj interface{}
var objNamespace string
protocol := v1.Protocol(gatewayapi.TCPProtocol)

refs := []gwapiv1.BackendRef{}
refs := []gwapiv1b1.BackendRef{}
switch route := obj.(type) {
case *gwapiv1b1.HTTPRoute:
objNamespace = route.Namespace
Expand Down Expand Up @@ -687,7 +687,7 @@ func kubernetesYAMLToResources(str string, addMissingResources bool) (*gatewayap
Name: name,
Namespace: namespace,
},
Spec: typedSpec.(gwapiv1.GatewayClassSpec),
Spec: typedSpec.(gwapiv1b1.GatewayClassSpec),
}
resources.GatewayClass = gatewayClass
case gatewayapi.KindGateway:
Expand All @@ -697,7 +697,7 @@ func kubernetesYAMLToResources(str string, addMissingResources bool) (*gatewayap
Name: name,
Namespace: namespace,
},
Spec: typedSpec.(gwapiv1.GatewaySpec),
Spec: typedSpec.(gwapiv1b1.GatewaySpec),
}
resources.Gateways = append(resources.Gateways, gateway)
case gatewayapi.KindTCPRoute:
Expand Down Expand Up @@ -946,9 +946,9 @@ func addDefaultEnvoyProxy(resources *gatewayapi.Resources) error {
},
}
resources.EnvoyProxy = ep
ns := gwapiv1.Namespace(namespace)
resources.GatewayClass.Spec.ParametersRef = &gwapiv1.ParametersReference{
Group: gwapiv1.Group(egv1a1.GroupVersion.Group),
ns := gwapiv1b1.Namespace(namespace)
resources.GatewayClass.Spec.ParametersRef = &gwapiv1b1.ParametersReference{
Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group),
Kind: gatewayapi.KindEnvoyProxy,
Name: defaultEnvoyProxyName,
Namespace: &ns,
Expand Down
6 changes: 3 additions & 3 deletions internal/envoygateway/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"testing"

"github.com/stretchr/testify/require"
v1 "sigs.k8s.io/gateway-api/apis/v1"
gwv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/logging"
)

var (
TLSSecretKind = v1.Kind("Secret")
TLSUnrecognizedKind = v1.Kind("Unrecognized")
TLSSecretKind = gwv1b1.Kind("Secret")
TLSUnrecognizedKind = gwv1b1.Kind("Unrecognized")
)

func TestValidate(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions internal/envoygateway/config/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/envoyproxy/gateway/api/v1alpha1"
)
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestDecode(t *testing.T) {
Redis: &v1alpha1.RateLimitRedisSettings{
URL: "localhost:6379",
TLS: &v1alpha1.RedisTLSSettings{
CertificateRef: &gwapiv1.SecretObjectReference{
CertificateRef: &gwapiv1b1.SecretObjectReference{
Name: "ratelimit-cert",
},
},
Expand Down
21 changes: 10 additions & 11 deletions internal/extension/registry/extension_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@ import (
"errors"
"fmt"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"

corev1 "k8s.io/api/core/v1"
k8scli "sigs.k8s.io/controller-runtime/pkg/client"
k8sclicfg "sigs.k8s.io/controller-runtime/pkg/client/config"
v1 "sigs.k8s.io/gateway-api/apis/v1"

"github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/envoygateway"
"github.com/envoyproxy/gateway/internal/envoygateway/config"
extTypes "github.com/envoyproxy/gateway/internal/extension/types"
"github.com/envoyproxy/gateway/internal/kubernetes"
"github.com/envoyproxy/gateway/proto/extension"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
corev1 "k8s.io/api/core/v1"
k8scli "sigs.k8s.io/controller-runtime/pkg/client"
k8sclicfg "sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/gateway-api/apis/v1beta1"
)

const grpcServiceConfig = `{
Expand Down Expand Up @@ -76,11 +75,11 @@ func NewManager(cfg *config.Server) (extTypes.Manager, error) {

// HasExtension checks to see whether a given Group and Kind has an
// associated extension registered for it.
func (m *Manager) HasExtension(g v1.Group, k v1.Kind) bool {
func (m *Manager) HasExtension(g v1beta1.Group, k v1beta1.Kind) bool {
extension := m.extension
// TODO: not currently checking the version since extensionRef only supports group and kind.
for _, gvk := range extension.Resources {
if g == v1.Group(gvk.Group) && k == v1.Kind(gvk.Kind) {
if g == v1beta1.Group(gvk.Group) && k == v1beta1.Kind(gvk.Kind) {
return true
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/extension/testutils/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package testutils

import (
v1 "sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/envoyproxy/gateway/api/v1alpha1"
extType "github.com/envoyproxy/gateway/internal/extension/types"
Expand All @@ -24,11 +24,11 @@ func NewManager(ext v1alpha1.ExtensionManager) extType.Manager {
}
}

func (m *Manager) HasExtension(g v1.Group, k v1.Kind) bool {
func (m *Manager) HasExtension(g v1beta1.Group, k v1beta1.Kind) bool {
extension := m.extension
// TODO: not currently checking the version since extensionRef only supports group and kind.
for _, gvk := range extension.Resources {
if g == v1.Group(gvk.Group) && k == v1.Kind(gvk.Kind) {
if g == v1beta1.Group(gvk.Group) && k == v1beta1.Kind(gvk.Kind) {
return true
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/extension/types/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package types

import (
v1 "sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/envoyproxy/gateway/api/v1alpha1"
)
Expand All @@ -19,7 +19,7 @@ type Manager interface {
//
// If a Group and Kind is registered with an extension, then it should
// return true, otherwise return false.
HasExtension(g v1.Group, k v1.Kind) bool
HasExtension(g v1beta1.Group, k v1beta1.Kind) bool

// GetPreXDSHookClient checks if the registered extension makes use of a particular hook type that modifies inputs
// that are used to generate an xDS resource.
Expand Down
3 changes: 2 additions & 1 deletion internal/gatewayapi/backendtlspolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import (
"k8s.io/utils/ptr"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/envoyproxy/gateway/internal/ir"
"github.com/envoyproxy/gateway/internal/status"
)

func (t *Translator) processBackendTLSPolicy(
backendRef gwapiv1.BackendObjectReference,
backendRef gwapiv1b1.BackendObjectReference,
backendNamespace string,
parent gwapiv1a2.ParentReference,
resources *Resources) *ir.TLSUpstreamConfig {
Expand Down
2 changes: 1 addition & 1 deletion internal/gatewayapi/clienttrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/ptr"
gwv1b1 "sigs.k8s.io/gateway-api/apis/v1"
gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gwv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/ir"
Expand Down
4 changes: 2 additions & 2 deletions internal/gatewayapi/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ type GatewayContext struct {
// ListenerContexts from the Gateway spec.
func (g *GatewayContext) ResetListeners() {
numListeners := len(g.Spec.Listeners)
g.Status.Listeners = make([]gwapiv1.ListenerStatus, numListeners)
g.Status.Listeners = make([]gwapiv1b1.ListenerStatus, numListeners)
g.listeners = make([]*ListenerContext, numListeners)
for i := range g.Spec.Listeners {
listener := &g.Spec.Listeners[i]
g.Status.Listeners[i] = gwapiv1.ListenerStatus{Name: listener.Name}
g.Status.Listeners[i] = gwapiv1b1.ListenerStatus{Name: listener.Name}
g.listeners[i] = &ListenerContext{
Listener: listener,
gateway: g.Gateway,
Expand Down
22 changes: 11 additions & 11 deletions internal/gatewayapi/contexts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func TestContexts(t *testing.T) {
Namespace: "envoy-gateway",
Name: "gateway-1",
},
Spec: gwapiv1.GatewaySpec{
Listeners: []gwapiv1.Listener{
Spec: gwapiv1b1.GatewaySpec{
Listeners: []gwapiv1b1.Listener{
{
Name: "http",
},
Expand All @@ -48,7 +48,7 @@ func TestContexts(t *testing.T) {
require.EqualValues(t, gwapiv1.ListenerReasonUnsupportedProtocol, gateway.Status.Listeners[0].Conditions[0].Reason)
require.EqualValues(t, "HTTPS protocol is not supported yet", gateway.Status.Listeners[0].Conditions[0].Message)

lctx.SetSupportedKinds(gwapiv1.RouteGroupKind{Group: GroupPtr(gwapiv1.GroupName), Kind: "HTTPRoute"})
lctx.SetSupportedKinds(gwapiv1b1.RouteGroupKind{Group: GroupPtr(gwapiv1b1.GroupName), Kind: "HTTPRoute"})

require.Len(t, gateway.Status.Listeners, 1)
require.Len(t, gateway.Status.Listeners[0].SupportedKinds, 1)
Expand All @@ -64,8 +64,8 @@ func TestContextsStaleListener(t *testing.T) {
Namespace: "envoy-gateway",
Name: "gateway-1",
},
Spec: gwapiv1.GatewaySpec{
Listeners: []gwapiv1.Listener{
Spec: gwapiv1b1.GatewaySpec{
Listeners: []gwapiv1b1.Listener{
{
Name: "https",
},
Expand All @@ -74,8 +74,8 @@ func TestContextsStaleListener(t *testing.T) {
},
},
},
Status: gwapiv1.GatewayStatus{
Listeners: []gwapiv1.ListenerStatus{
Status: gwapiv1b1.GatewayStatus{
Listeners: []gwapiv1b1.ListenerStatus{
{
Name: "https",
Conditions: []metav1.Condition{
Expand All @@ -99,15 +99,15 @@ func TestContextsStaleListener(t *testing.T) {
gCtx := &GatewayContext{Gateway: gateway}

httpsListenerCtx := &ListenerContext{
Listener: &gwapiv1.Listener{
Listener: &gwapiv1b1.Listener{
Name: "https",
},
gateway: gateway,
listenerStatusIdx: 0,
}

httpListenerCtx := &ListenerContext{
Listener: &gwapiv1.Listener{
Listener: &gwapiv1b1.Listener{
Name: "http",
},
gateway: gateway,
Expand All @@ -126,7 +126,7 @@ func TestContextsStaleListener(t *testing.T) {

require.Len(t, gCtx.Status.Listeners, 2)

expectedListenerStatuses := []gwapiv1.ListenerStatus{
expectedListenerStatuses := []gwapiv1b1.ListenerStatus{
{
Name: "https",
},
Expand All @@ -143,7 +143,7 @@ func TestContextsStaleListener(t *testing.T) {

// Ensure the listener status has been updated and the stale listener has been
// removed.
expectedListenerStatus := []gwapiv1.ListenerStatus{{Name: "https"}}
expectedListenerStatus := []gwapiv1b1.ListenerStatus{{Name: "https"}}
require.EqualValues(t, expectedListenerStatus, gCtx.Gateway.Status.Listeners)

// Ensure that the listeners within GatewayContext have been properly updated.
Expand Down
2 changes: 1 addition & 1 deletion internal/gatewayapi/envoypatchpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
gwv1b1 "sigs.k8s.io/gateway-api/apis/v1"
gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gwv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/ir"
Expand Down
Loading

0 comments on commit d0ca00d

Please sign in to comment.