Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove skv2 dep in e2e tests #10556

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pkg/utils/fsutils/fsutils.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels like this entire util package could/should live under test/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wasn't sure if it should/could since it's referenced from projects/gateway2/translator/gateway/gateway_translator_test.go too

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