Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
e2e: install Consul API Gateway CRDs alongside Gateway API CRDs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemorris committed Jun 16, 2022
1 parent 958cd8f commit b5f685e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 59 deletions.
38 changes: 0 additions & 38 deletions internal/testing/e2e/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ import (
"context"
"log"
"os"
"path"
"strings"
"time"

"golang.org/x/sync/errgroup"
api "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/e2e-framework/pkg/env"
"sigs.k8s.io/e2e-framework/pkg/envconf"

Expand All @@ -20,7 +15,6 @@ import (
"github.com/hashicorp/consul-api-gateway/internal/envoy"
"github.com/hashicorp/consul-api-gateway/internal/k8s"
"github.com/hashicorp/consul-api-gateway/internal/store/memory"
apigwv1alpha1 "github.com/hashicorp/consul-api-gateway/pkg/apis/v1alpha1"
"github.com/hashicorp/go-hclog"
)

Expand Down Expand Up @@ -155,35 +149,3 @@ func DestroyTestGatewayServer(ctx context.Context, cfg *envconf.Config) (context
}
return ctx, nil
}

func InstallConsulAPIGatewayCRDs(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
directory := path.Join("..", "..", "..", "config", "crd", "bases")
entries, err := os.ReadDir(directory)
crds := []*api.CustomResourceDefinition{}
if err != nil {
return nil, err
}
for _, file := range entries {
if strings.HasPrefix(file.Name(), ".") {
continue
}
data, err := os.ReadFile(path.Join(directory, file.Name()))
if err != nil {
return nil, err
}
fileCRDs, err := readCRDs(data)
if err != nil {
return nil, err
}
crds = append(crds, fileCRDs...)
}
if _, err := envtest.InstallCRDs(cfg.Client().RESTConfig(), envtest.CRDInstallOptions{
CRDs: crds,
}); err != nil {
return nil, err
}

apigwv1alpha1.RegisterTypes(scheme.Scheme)

return ctx, nil
}
31 changes: 12 additions & 19 deletions internal/testing/e2e/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"io"
"log"
"os"
"path"

"github.com/cenkalti/backoff"
consulapigw "github.com/hashicorp/consul-api-gateway/pkg/apis/v1alpha1"
core "k8s.io/api/core/v1"
rbac "k8s.io/api/rbac/v1"
api "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand All @@ -29,35 +31,22 @@ type k8sTokenContext struct{}

var k8sTokenContextKey = k8sTokenContext{}

const gatewayCRDsStandard = "github.com/kubernetes-sigs/gateway-api/config/crd?ref=v0.5.0-rc1"
const gatewayCRDsExperimental = "github.com/kubernetes-sigs/gateway-api/config/crd/experimental?ref=v0.5.0-rc1"
func InstallCRDs(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
log.Print("Installing CRDs")

func installKustomizedCRDs(ctx context.Context, cfg *envconf.Config, path string) error {
log.Printf("Installing Gateway CRDs: %s", path)

crds, err := kubectlKustomizeCRDs(ctx, path)
dir := path.Join("..", "..", "..", "config", "crd")
crds, err := kubectlKustomizeCRDs(ctx, dir)
if err != nil {
return err
return nil, err
}

if _, err := envtest.InstallCRDs(cfg.Client().RESTConfig(), envtest.CRDInstallOptions{
CRDs: crds,
}); err != nil {
return err
}

return nil
}

func InstallGatewayCRDs(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
if err := installKustomizedCRDs(ctx, cfg, gatewayCRDsStandard); err != nil {
return nil, err
}

if err := installKustomizedCRDs(ctx, cfg, gatewayCRDsExperimental); err != nil {
return nil, err
}

// Register Gateway API v1beta1 types
scheme.Scheme.AddKnownTypes(
gwv1beta1.SchemeGroupVersion,
&gwv1beta1.GatewayClass{},
Expand All @@ -69,6 +58,7 @@ func InstallGatewayCRDs(ctx context.Context, cfg *envconf.Config) (context.Conte
)
meta.AddToGroupVersion(scheme.Scheme, gwv1beta1.SchemeGroupVersion)

// Register Gateway API v1alpha2 types
scheme.Scheme.AddKnownTypes(
gwv1alpha2.SchemeGroupVersion,
&gwv1alpha2.TCPRoute{},
Expand All @@ -78,6 +68,9 @@ func InstallGatewayCRDs(ctx context.Context, cfg *envconf.Config) (context.Conte
)
meta.AddToGroupVersion(scheme.Scheme, gwv1alpha2.SchemeGroupVersion)

// Register Consul API Gateway types
consulapigw.RegisterTypes(scheme.Scheme)

return ctx, nil
}

Expand Down
1 change: 1 addition & 0 deletions internal/testing/e2e/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
api "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
)

// TODO: switch this to krusty implementation after integration for conformance tests
func kubectlKustomizeCRDs(ctx context.Context, url string) ([]*api.CustomResourceDefinition, error) {
var stdout, stderr bytes.Buffer
timeoutContext, cancel := context.WithTimeout(ctx, 10*time.Second)
Expand Down
3 changes: 1 addition & 2 deletions internal/testing/e2e/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ func SetUpStack(hostRoute string) env.Func {
CreateKindCluster(kindClusterName),
LoadKindDockerImage(kindClusterName),
envfuncs.CreateNamespace(namespace),
InstallGatewayCRDs,
InstallCRDs,
CreateServiceAccount(namespace, "consul-api-gateway", getBasePath()+"/config/rbac/role.yaml"),
CreateTestConsulContainer(kindClusterName, namespace),
CreateConsulACLPolicy,
CreateConsulAuthMethod(),
CreateConsulNamespace,
InstallConsulAPIGatewayCRDs,
CreateTestGatewayServer(namespace),
} {
ctx, err = f(ctx, cfg)
Expand Down

0 comments on commit b5f685e

Please sign in to comment.