Skip to content

Commit

Permalink
chore: add gateway-api/apis/v1alpha3 to k8s client support (#3350)
Browse files Browse the repository at this point in the history
* add gateway-api/apis/v1alpha3 to k8s client support

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

* update AddToScheme to Install for all the gateway-api resources

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

* address comments

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

* fix name

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

---------

Signed-off-by: shawnh2 <shawnhxh@outlook.com>
  • Loading branch information
shawnh2 authored May 8, 2024
1 parent 0457ee7 commit 4b22373
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 54 deletions.
31 changes: 2 additions & 29 deletions internal/cmd/egctl/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ import (

adminv3 "github.com/envoyproxy/go-control-plane/envoy/admin/v3"
"google.golang.org/protobuf/reflect/protoreflect"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
gwv1 "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/envoygateway"
)

type envoyConfigType string
Expand Down Expand Up @@ -73,31 +69,8 @@ func findXDSResourceFromConfigDump(resourceType envoyConfigType, globalConfigs *
return nil, fmt.Errorf("unknown resourceType %s", resourceType)
}

// newGatewayScheme creates scheme for K8s Gateway API and Envoy Gateway.
func newGatewayScheme() (*runtime.Scheme, error) {
scheme := runtime.NewScheme()

if err := gwv1.AddToScheme(scheme); err != nil {
return nil, err
}
if err := gwv1b1.AddToScheme(scheme); err != nil {
return nil, err
}
if err := gwv1a2.AddToScheme(scheme); err != nil {
return nil, err
}
if err := egv1a1.AddToScheme(scheme); err != nil {
return nil, err
}

return scheme, nil
}

func newK8sClient() (client.Client, error) {
scheme, err := newGatewayScheme()
if err != nil {
return nil, fmt.Errorf("failed to load gateway shceme: %w", err)
}
scheme := envoygateway.GetScheme()

cli, err := client.New(config.GetConfigOrDie(), client.Options{Scheme: scheme})
if err != nil {
Expand Down
11 changes: 3 additions & 8 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gwapiv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
"sigs.k8s.io/gateway-api/conformance/utils/flags"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/pkg/features"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/test/e2e/tests"
)

Expand All @@ -36,10 +32,9 @@ func TestE2E(t *testing.T) {

c, err := client.New(cfg, client.Options{})
require.NoError(t, err)
require.NoError(t, gwapiv1a3.AddToScheme(c.Scheme()))
require.NoError(t, gwapiv1a2.AddToScheme(c.Scheme()))
require.NoError(t, gwapiv1.AddToScheme(c.Scheme()))
require.NoError(t, egv1a1.AddToScheme(c.Scheme()))

// Install all the scheme for kubernetes client.
CheckInstallScheme(t, c)

if flags.RunTest != nil && *flags.RunTest != "" {
t.Logf("Running E2E test %s with %s GatewayClass\n cleanup: %t\n debug: %t",
Expand Down
22 changes: 21 additions & 1 deletion test/e2e/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,27 @@

package e2e

import "embed"
import (
"embed"
"testing"

"github.com/stretchr/testify/require"
"sigs.k8s.io/controller-runtime/pkg/client"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gwapiv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
)

//go:embed testdata/*.yaml base/*
var Manifests embed.FS

func CheckInstallScheme(t *testing.T, c client.Client) {
require.NoError(t, gwapiv1a3.Install(c.Scheme()))
require.NoError(t, gwapiv1a2.Install(c.Scheme()))
require.NoError(t, gwapiv1b1.Install(c.Scheme()))
require.NoError(t, gwapiv1.Install(c.Scheme()))
require.NoError(t, egv1a1.AddToScheme(c.Scheme()))
}
11 changes: 3 additions & 8 deletions test/e2e/merge_gateways/merge_gateways_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gwapiv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
"sigs.k8s.io/gateway-api/conformance/utils/flags"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/pkg/features"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/test/e2e"
"github.com/envoyproxy/gateway/test/e2e/tests"
)
Expand All @@ -38,10 +34,9 @@ func TestMergeGateways(t *testing.T) {

c, err := client.New(cfg, client.Options{})
require.NoError(t, err)
require.NoError(t, gwapiv1a3.AddToScheme(c.Scheme()))
require.NoError(t, gwapiv1a2.AddToScheme(c.Scheme()))
require.NoError(t, gwapiv1.AddToScheme(c.Scheme()))
require.NoError(t, egv1a1.AddToScheme(c.Scheme()))

// Install all the scheme to kubernetes client.
e2e.CheckInstallScheme(t, c)

if flags.RunTest != nil && *flags.RunTest != "" {
t.Logf("Running E2E test %s with %s GatewayClass\n cleanup: %t\n debug: %t",
Expand Down
11 changes: 3 additions & 8 deletions test/e2e/upgrade/eg_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gwapiv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
"sigs.k8s.io/gateway-api/conformance/utils/flags"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/pkg/features"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/test/e2e"
"github.com/envoyproxy/gateway/test/e2e/tests"
)
Expand All @@ -37,10 +33,9 @@ func TestEGUpgrade(t *testing.T) {

c, err := client.New(cfg, client.Options{})
require.NoError(t, err)
require.NoError(t, gwapiv1a3.AddToScheme(c.Scheme()))
require.NoError(t, gwapiv1a2.AddToScheme(c.Scheme()))
require.NoError(t, gwapiv1.AddToScheme(c.Scheme()))
require.NoError(t, egv1a1.AddToScheme(c.Scheme()))

// Install all the scheme to kubernetes client.
e2e.CheckInstallScheme(t, c)

if flags.RunTest != nil && *flags.RunTest != "" {
t.Logf("Running E2E test %s with %s GatewayClass\n cleanup: %t\n debug: %t",
Expand Down

0 comments on commit 4b22373

Please sign in to comment.