Skip to content

Commit

Permalink
Remove skv2 dep in e2e tests (#10556)
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshu authored Jan 30, 2025
1 parent 1e88bf3 commit 1d9e219
Show file tree
Hide file tree
Showing 36 changed files with 210 additions and 191 deletions.
28 changes: 28 additions & 0 deletions pkg/utils/fsutils/fsutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ package fsutils

import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
)

// ToTempFile takes a string to write to a temp file. It returns the filename and an error.
Expand Down Expand Up @@ -33,3 +38,26 @@ func IsDirectory(dir string) bool {
}
return stat.IsDir()
}

// MustGetThisDir returns the absolute path to the diretory containing the .go file containing the calling function
func MustGetThisDir() string {
_, thisFile, _, ok := runtime.Caller(1)
if !ok {
log.Fatalf("Failed to get runtime.Caller")
}
return filepath.Dir(thisFile)
}

// GoModPath returns the absolute path to the go.mod file for the current dir
func GoModPath() string {
out, err := exec.Command("go", "env", "GOMOD").CombinedOutput()
if err != nil {
log.Fatal(err)
}
return strings.TrimSpace(string(out))
}

// GetModuleRoot returns the project root dir (based on gomod location)
func GetModuleRoot() string {
return filepath.Dir(GoModPath())
}
15 changes: 3 additions & 12 deletions projects/gateway2/translator/gateway/gateway_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package gateway_test
import (
"context"
"fmt"
"log"
"path/filepath"
"runtime"

"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/api/meta"
Expand All @@ -29,7 +28,7 @@ var _ = DescribeTable("Basic GatewayTranslator Tests",
func(in translatorTestCase) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
dir := MustGetThisDir()
dir := fsutils.MustGetThisDir()

results, err := TestCase{
InputFiles: []string{filepath.Join(dir, "testutils/inputs/", in.inputFile)},
Expand Down Expand Up @@ -306,7 +305,7 @@ var _ = DescribeTable("Basic GatewayTranslator Tests",
var _ = DescribeTable("Route Delegation translator",
func(inputFile string, errdesc string) {
ctx := context.TODO()
dir := MustGetThisDir()
dir := fsutils.MustGetThisDir()

results, err := TestCase{
InputFiles: []string{filepath.Join(dir, "testutils/inputs/delegation", inputFile)},
Expand Down Expand Up @@ -351,11 +350,3 @@ var _ = DescribeTable("Route Delegation translator",
// https://github.com/k8sgateway/k8sgateway/issues/10379
Entry("Multi-level multiple parents delegation", "bug-10379.yaml", ""),
)

func MustGetThisDir() string {
_, thisFile, _, ok := runtime.Caller(1)
if !ok {
log.Fatalf("Failed to get runtime.Caller")
}
return filepath.Dir(thisFile)
}
10 changes: 5 additions & 5 deletions test/kubernetes/e2e/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
"github.com/kgateway-dev/kgateway/pkg/utils/kubeutils/kubectl"
"github.com/solo-io/skv2/codegen/util"
)

var (
Expand All @@ -26,7 +26,7 @@ var (
},
}

CurlPodManifest = filepath.Join(util.MustGetThisDir(), "testdata", "curl_pod.yaml")
CurlPodManifest = filepath.Join(fsutils.MustGetThisDir(), "testdata", "curl_pod.yaml")

HttpEchoPod = &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -35,7 +35,7 @@ var (
},
}

HttpEchoPodManifest = filepath.Join(util.MustGetThisDir(), "testdata", "http_echo.yaml")
HttpEchoPodManifest = filepath.Join(fsutils.MustGetThisDir(), "testdata", "http_echo.yaml")

TcpEchoPod = &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -44,7 +44,7 @@ var (
},
}

TcpEchoPodManifest = filepath.Join(util.MustGetThisDir(), "testdata", "tcp_echo.yaml")
TcpEchoPodManifest = filepath.Join(fsutils.MustGetThisDir(), "testdata", "tcp_echo.yaml")

NginxPod = &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -60,7 +60,7 @@ var (
},
}

NginxPodManifest = filepath.Join(util.MustGetThisDir(), "testdata", "nginx_pod.yaml")
NginxPodManifest = filepath.Join(fsutils.MustGetThisDir(), "testdata", "nginx_pod.yaml")

NginxResponse = `<!DOCTYPE html>
<html>
Expand Down
6 changes: 3 additions & 3 deletions test/kubernetes/e2e/example/info_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/kgateway-dev/kgateway/pkg/utils/envutils"
"github.com/kgateway-dev/kgateway/test/testutils"

"github.com/solo-io/skv2/codegen/util"
"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
"github.com/stretchr/testify/suite"

"github.com/kgateway-dev/kgateway/test/kubernetes/e2e"
Expand All @@ -30,8 +30,8 @@ func TestInstallationWithInfoLogLevel(t *testing.T) {
t,
&gloogateway.Context{
InstallNamespace: installNs,
ProfileValuesManifestFile: filepath.Join(util.MustGetThisDir(), "manifests", "example-profile.yaml"),
ValuesManifestFile: filepath.Join(util.MustGetThisDir(), "manifests", "info-example.yaml"),
ProfileValuesManifestFile: filepath.Join(fsutils.MustGetThisDir(), "manifests", "example-profile.yaml"),
ValuesManifestFile: filepath.Join(fsutils.MustGetThisDir(), "manifests", "info-example.yaml"),
},
)

Expand Down
6 changes: 3 additions & 3 deletions test/kubernetes/e2e/features/admin_server/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ package admin_server
import (
"path/filepath"

"github.com/solo-io/skv2/codegen/util"
"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
upstreamManifest = filepath.Join(util.MustGetThisDir(), "testdata/upstream.yaml")
gatewayParametersManifest = filepath.Join(util.MustGetThisDir(), "testdata/gateway-parameters.yaml")
upstreamManifest = filepath.Join(fsutils.MustGetThisDir(), "testdata/upstream.yaml")
gatewayParametersManifest = filepath.Join(fsutils.MustGetThisDir(), "testdata/gateway-parameters.yaml")

// Upstream resource to be created
upstreamMeta = metav1.ObjectMeta{
Expand Down
12 changes: 6 additions & 6 deletions test/kubernetes/e2e/features/client_tls/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import (
"net/http"
"path/filepath"

"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
"github.com/kgateway-dev/kgateway/test/gomega/matchers"
"github.com/onsi/gomega"
"github.com/solo-io/skv2/codegen/util"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
annotatedNginxSvcManifestFile = filepath.Join(util.MustGetThisDir(), "testdata", "annotated-nginx-svc.yaml")
annotatedNginxOneWaySvcManifestFile = filepath.Join(util.MustGetThisDir(), "testdata", "annotated-oneway-nginx-svc.yaml")
nginxUpstreamManifestFile = filepath.Join(util.MustGetThisDir(), "testdata", "nginx-upstream.yaml")
nginxOneWayUpstreamManifestFile = filepath.Join(util.MustGetThisDir(), "testdata", "nginx-oneway-upstream.yaml")
tlsSecretManifestFile = filepath.Join(util.MustGetThisDir(), "testdata", "tls-secret.yaml")
annotatedNginxSvcManifestFile = filepath.Join(fsutils.MustGetThisDir(), "testdata", "annotated-nginx-svc.yaml")
annotatedNginxOneWaySvcManifestFile = filepath.Join(fsutils.MustGetThisDir(), "testdata", "annotated-oneway-nginx-svc.yaml")
nginxUpstreamManifestFile = filepath.Join(fsutils.MustGetThisDir(), "testdata", "nginx-upstream.yaml")
nginxOneWayUpstreamManifestFile = filepath.Join(fsutils.MustGetThisDir(), "testdata", "nginx-oneway-upstream.yaml")
tlsSecretManifestFile = filepath.Join(fsutils.MustGetThisDir(), "testdata", "tls-secret.yaml")

// When we apply the deployer-provision.yaml file, we expect resources to be created with this metadata
glooProxyObjectMeta = func(ns string) metav1.ObjectMeta {
Expand Down
4 changes: 2 additions & 2 deletions test/kubernetes/e2e/features/crd_categories/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ package crd_categories
import (
"path/filepath"

"github.com/solo-io/skv2/codegen/util"
"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
)

var (
emptyVsManifest = filepath.Join(util.MustGetThisDir(), "testdata/manifests", "empty-virtualservice.yaml")
emptyVsManifest = filepath.Join(fsutils.MustGetThisDir(), "testdata/manifests", "empty-virtualservice.yaml")

installedVs = "virtualservice.gateway.solo.io/empty-virtualservice"
)
12 changes: 6 additions & 6 deletions test/kubernetes/e2e/features/deployer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ package deployer
import (
"path/filepath"

"github.com/solo-io/skv2/codegen/util"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
"github.com/kgateway-dev/kgateway/projects/gateway2/api/v1alpha1"
)

var (
gatewayWithoutParameters = filepath.Join(util.MustGetThisDir(), "testdata", "gateway-without-parameters.yaml")
gatewayWithParameters = filepath.Join(util.MustGetThisDir(), "testdata", "gateway-with-parameters.yaml")
gatewayParametersCustom = filepath.Join(util.MustGetThisDir(), "testdata", "gatewayparameters-custom.yaml")
istioGatewayParameters = filepath.Join(util.MustGetThisDir(), "testdata", "istio-gateway-parameters.yaml")
selfManagedGateway = filepath.Join(util.MustGetThisDir(), "testdata", "self-managed-gateway.yaml")
gatewayWithoutParameters = filepath.Join(fsutils.MustGetThisDir(), "testdata", "gateway-without-parameters.yaml")
gatewayWithParameters = filepath.Join(fsutils.MustGetThisDir(), "testdata", "gateway-with-parameters.yaml")
gatewayParametersCustom = filepath.Join(fsutils.MustGetThisDir(), "testdata", "gatewayparameters-custom.yaml")
istioGatewayParameters = filepath.Join(fsutils.MustGetThisDir(), "testdata", "istio-gateway-parameters.yaml")
selfManagedGateway = filepath.Join(fsutils.MustGetThisDir(), "testdata", "self-managed-gateway.yaml")

// When we apply the deployer-provision.yaml file, we expect resources to be created with this metadata
glooProxyObjectMeta = metav1.ObjectMeta{
Expand Down
20 changes: 10 additions & 10 deletions test/kubernetes/e2e/features/directresponse/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwv1 "sigs.k8s.io/gateway-api/apis/v1"

"github.com/solo-io/skv2/codegen/util"
"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
)

var (
setupManifest = filepath.Join(util.MustGetThisDir(), "testdata", "setup.yaml")
gatewayManifest = filepath.Join(util.MustGetThisDir(), "testdata", "gateway.yaml")
basicDirectResposeManifests = filepath.Join(util.MustGetThisDir(), "testdata", "basic-direct-response.yaml")
basicDelegationManifests = filepath.Join(util.MustGetThisDir(), "testdata", "basic-delegation-direct-response.yaml")
invalidDelegationConflictingFiltersManifests = filepath.Join(util.MustGetThisDir(), "testdata", "invalid-delegation-conflicting-filters.yaml")
invalidMissingRefManifests = filepath.Join(util.MustGetThisDir(), "testdata", "invalid-missing-ref-direct-response.yaml")
invalidOverlappingFiltersManifests = filepath.Join(util.MustGetThisDir(), "testdata", "invalid-overlapping-filters.yaml")
invalidMultipleRouteActionsManifests = filepath.Join(util.MustGetThisDir(), "testdata", "invalid-multiple-route-actions.yaml")
invalidBackendRefFilterManifests = filepath.Join(util.MustGetThisDir(), "testdata", "invalid-backendRef-filter.yaml")
setupManifest = filepath.Join(fsutils.MustGetThisDir(), "testdata", "setup.yaml")
gatewayManifest = filepath.Join(fsutils.MustGetThisDir(), "testdata", "gateway.yaml")
basicDirectResposeManifests = filepath.Join(fsutils.MustGetThisDir(), "testdata", "basic-direct-response.yaml")
basicDelegationManifests = filepath.Join(fsutils.MustGetThisDir(), "testdata", "basic-delegation-direct-response.yaml")
invalidDelegationConflictingFiltersManifests = filepath.Join(fsutils.MustGetThisDir(), "testdata", "invalid-delegation-conflicting-filters.yaml")
invalidMissingRefManifests = filepath.Join(fsutils.MustGetThisDir(), "testdata", "invalid-missing-ref-direct-response.yaml")
invalidOverlappingFiltersManifests = filepath.Join(fsutils.MustGetThisDir(), "testdata", "invalid-overlapping-filters.yaml")
invalidMultipleRouteActionsManifests = filepath.Join(fsutils.MustGetThisDir(), "testdata", "invalid-multiple-route-actions.yaml")
invalidBackendRefFilterManifests = filepath.Join(fsutils.MustGetThisDir(), "testdata", "invalid-backendRef-filter.yaml")

glooProxyObjectMeta = metav1.ObjectMeta{
Name: "gloo-proxy-gw",
Expand Down
10 changes: 5 additions & 5 deletions test/kubernetes/e2e/features/discovery_watchlabels/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package discovery_watchlabels
import (
"path/filepath"

"github.com/solo-io/skv2/codegen/util"
"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
)

var (
serviceWithLabelsManifest = filepath.Join(util.MustGetThisDir(), "testdata/service-with-labels.yaml")
serviceWithModifiedLabelsManifest = filepath.Join(util.MustGetThisDir(), "testdata/service-with-modified-labels.yaml")
serviceWithoutLabelsManifest = filepath.Join(util.MustGetThisDir(), "testdata/service-without-labels.yaml")
serviceWithNoMatchingLabelsManifest = filepath.Join(util.MustGetThisDir(), "testdata/service-with-no-matching-labels.yaml")
serviceWithLabelsManifest = filepath.Join(fsutils.MustGetThisDir(), "testdata/service-with-labels.yaml")
serviceWithModifiedLabelsManifest = filepath.Join(fsutils.MustGetThisDir(), "testdata/service-with-modified-labels.yaml")
serviceWithoutLabelsManifest = filepath.Join(fsutils.MustGetThisDir(), "testdata/service-without-labels.yaml")
serviceWithNoMatchingLabelsManifest = filepath.Join(fsutils.MustGetThisDir(), "testdata/service-with-no-matching-labels.yaml")
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"log"
"path/filepath"

"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
"github.com/kgateway-dev/kgateway/projects/gloo/pkg/defaults"
"github.com/kgateway-dev/kgateway/test/kubernetes/e2e/features/headless_svc"
"github.com/kgateway-dev/kgateway/test/kubernetes/testutils/resources"
"github.com/solo-io/skv2/codegen/util"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand All @@ -21,7 +21,7 @@ func main() {

// use the k8s gateway api resources
k8sApiResources := []client.Object{headless_svc.K8sGateway, headless_svc.HeadlessSvcHTTPRoute}
k8sApiRoutingGeneratedExample := filepath.Join(util.MustGetThisDir(), "generated_example", headless_svc.K8sApiRoutingGeneratedFileName)
k8sApiRoutingGeneratedExample := filepath.Join(fsutils.MustGetThisDir(), "generated_example", headless_svc.K8sApiRoutingGeneratedFileName)

err := resources.WriteResourcesToFile(k8sApiResources, k8sApiRoutingGeneratedExample)
if err != nil {
Expand All @@ -31,7 +31,7 @@ func main() {
// use the Gloo Edge Gateway api resources
exampleNs := defaults.GlooSystem
edgeGatewayApiResources := headless_svc.GetEdgeGatewayResources(exampleNs)
edgeGatewayApiRoutingGeneratedExample := filepath.Join(util.MustGetThisDir(), "generated_example", headless_svc.EdgeGatewayApiRoutingGeneratedFileName)
edgeGatewayApiRoutingGeneratedExample := filepath.Join(fsutils.MustGetThisDir(), "generated_example", headless_svc.EdgeGatewayApiRoutingGeneratedFileName)
err = resources.WriteResourcesToFile(edgeGatewayApiResources, edgeGatewayApiRoutingGeneratedExample)
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions test/kubernetes/e2e/features/headless_svc/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
gwv1 "sigs.k8s.io/gateway-api/apis/v1"

"github.com/solo-io/skv2/codegen/util"
"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
v1 "github.com/solo-io/solo-apis/pkg/api/gateway.solo.io/v1"
soloapis_gloov1 "github.com/solo-io/solo-apis/pkg/api/gloo.solo.io/v1"
"github.com/solo-io/solo-apis/pkg/api/gloo.solo.io/v1/core/matchers"
Expand All @@ -31,7 +31,7 @@ const (
)

var (
headlessSvcSetupManifest = filepath.Join(util.MustGetThisDir(), "testdata", "setup.yaml")
headlessSvcSetupManifest = filepath.Join(fsutils.MustGetThisDir(), "testdata", "setup.yaml")

// GetEdgeGatewayResources returns the Gloo Gateway Edge API resources
GetEdgeGatewayResources = func(installNamespace string) []client.Object {
Expand Down
4 changes: 2 additions & 2 deletions test/kubernetes/e2e/features/helm/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"

"github.com/kgateway-dev/kgateway/pkg/utils/envoyutils/admincli"
"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
"github.com/kgateway-dev/kgateway/test/kubernetes/e2e"
"github.com/kgateway-dev/kgateway/test/kubernetes/e2e/tests/base"
"github.com/kgateway-dev/kgateway/test/kubernetes/testutils/helper"
"github.com/solo-io/skv2/codegen/util"
"github.com/solo-io/solo-kit/pkg/code-generator/schemagen"
)

Expand Down Expand Up @@ -79,7 +79,7 @@ func (s *testingSuite) TestChangedConfigMapTriggersRollout() {

func (s *testingSuite) TestApplyCRDs() {
var crdsByFileName = map[string]v1.CustomResourceDefinition{}
crdDir := filepath.Join(util.GetModuleRoot(), "install", "helm", s.TestHelper.HelmChartName, "crds")
crdDir := filepath.Join(fsutils.GetModuleRoot(), "install", "helm", s.TestHelper.HelmChartName, "crds")

err := filepath.Walk(crdDir, func(crdFile string, info os.FileInfo, err error) error {
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions test/kubernetes/e2e/features/helm/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ package helm
import (
"path/filepath"

"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
"github.com/kgateway-dev/kgateway/test/kubernetes/e2e/tests/base"
"github.com/solo-io/skv2/codegen/util"
)

var (
productionRecommendationsSetup = filepath.Join(util.MustGetThisDir(), "testdata/manifests", "production-recommendations.yaml")
configMapChangeSetup = filepath.Join(util.MustGetThisDir(), "testdata/manifests", "config-map-change.yaml")
productionRecommendationsSetup = filepath.Join(fsutils.MustGetThisDir(), "testdata/manifests", "production-recommendations.yaml")
configMapChangeSetup = filepath.Join(fsutils.MustGetThisDir(), "testdata/manifests", "config-map-change.yaml")

helmTestCases = map[string]*base.TestCase{
"TestProductionRecommendations": {
Expand Down
4 changes: 2 additions & 2 deletions test/kubernetes/e2e/features/helm_settings/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

"text/template"

"github.com/kgateway-dev/kgateway/pkg/utils/fsutils"
"github.com/kgateway-dev/kgateway/test/kubernetes/e2e"
"github.com/solo-io/skv2/codegen/util"
"github.com/stretchr/testify/suite"
)

Expand Down Expand Up @@ -56,7 +56,7 @@ func NewTestingSuite(ctx context.Context, testInst *e2e.TestInstallation) suite.
}

func (s *testingSuite) TestApplySettingsManifestsFromUnitTests() {
settingsFixturesFolder := filepath.Join(util.GetModuleRoot(), "install", "test", "fixtures", "settings")
settingsFixturesFolder := filepath.Join(fsutils.GetModuleRoot(), "install", "test", "fixtures", "settings")

err := filepath.Walk(settingsFixturesFolder, func(settingsFixtureFile string, info os.FileInfo, err error) error {
if err != nil {
Expand Down
Loading

0 comments on commit 1d9e219

Please sign in to comment.