-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: shyunny <shyunny@outlook.com>
- Loading branch information
Showing
7 changed files
with
332 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
//go:build e2e | ||
// +build e2e | ||
|
||
package lifecycle | ||
|
||
import ( | ||
"flag" | ||
"io/fs" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/client/config" | ||
"sigs.k8s.io/gateway-api/conformance/utils/flags" | ||
"sigs.k8s.io/gateway-api/conformance/utils/suite" | ||
"sigs.k8s.io/gateway-api/pkg/features" | ||
|
||
"github.com/envoyproxy/gateway/test/e2e" | ||
"github.com/envoyproxy/gateway/test/e2e/tests" | ||
) | ||
|
||
func TestEGLifecycle(t *testing.T) { | ||
flag.Parse() | ||
|
||
cfg, err := config.GetConfig() | ||
require.NoError(t, err) | ||
|
||
c, err := client.New(cfg, client.Options{}) | ||
require.NoError(t, err) | ||
|
||
if flags.RunTest != nil && *flags.RunTest != "" { | ||
t.Logf("Running E2E test %s with %s GatewayClass\n cleanup: %t\n debug: %t", | ||
*flags.RunTest, *flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug) | ||
} else { | ||
t.Logf("Running E2E tests with %s GatewayClass\n cleanup: %t\n debug: %t", | ||
*flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug) | ||
} | ||
|
||
cSuite, err := suite.NewConformanceTestSuite(suite.ConformanceOptions{ | ||
Client: c, | ||
GatewayClassName: *flags.GatewayClassName, | ||
Debug: *flags.ShowDebug, | ||
CleanupBaseResources: *flags.CleanupBaseResources, | ||
ManifestFS: []fs.FS{e2e.Manifests}, | ||
RunTest: *flags.RunTest, | ||
// SupportedFeatures cannot be empty, so we set it to SupportGateway | ||
// All e2e tests should leave Features empty. | ||
SupportedFeatures: sets.New[features.SupportedFeature](features.SupportGateway), | ||
}) | ||
if err != nil { | ||
t.Fatalf("Failed to create test suite: %v", err) | ||
} | ||
|
||
t.Logf("Running %d lifecycle tests", len(tests.LifecycleTests)) | ||
cSuite.Setup(t, tests.LifecycleTests) | ||
|
||
err = cSuite.Run(t, tests.LifecycleTests) | ||
if err != nil { | ||
t.Fatalf("Failed to run tests: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: gateway.networking.k8s.io/v1 | ||
kind: HTTPRoute | ||
metadata: | ||
name: http-backend-eg-lifecycle | ||
namespace: gateway-lifecycle-infra | ||
spec: | ||
parentRefs: | ||
- name: lifecycle-gateway | ||
rules: | ||
- matches: | ||
- path: | ||
type: PathPrefix | ||
value: /eg-lifecycle | ||
backendRefs: | ||
- name: infra-backend | ||
port: 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
//go:build e2e | ||
// +build e2e | ||
|
||
package tests | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/utils/ptr" | ||
"sigs.k8s.io/gateway-api/conformance/utils/http" | ||
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes" | ||
"sigs.k8s.io/gateway-api/conformance/utils/suite" | ||
|
||
"github.com/envoyproxy/gateway/internal/cmd/options" | ||
"github.com/envoyproxy/gateway/internal/utils/helm" | ||
) | ||
|
||
func init() { | ||
LifecycleTests = append(LifecycleTests, EGUninstallAndInstallTest, EGUpgradeTest) | ||
} | ||
|
||
var EGUninstallAndInstallTest = suite.ConformanceTest{ | ||
ShortName: "EGUninstallAndInstall", | ||
Description: "Uninstall and Install Envoy Gateway using Helm Package Tool", | ||
Manifests: []string{"testdata/eg-lifecycle.yaml"}, | ||
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { | ||
t.Run("Uninstall Envoy Gateway should succeed", func(t *testing.T) { | ||
// first ensure that EG provides services normally | ||
ns := "gateway-lifecycle-infra" | ||
routeNN := types.NamespacedName{ | ||
Name: "http-backend-eg-lifecycle", | ||
Namespace: ns, | ||
} | ||
gwNN := types.NamespacedName{ | ||
Name: "lifecycle-gateway", | ||
Namespace: ns, | ||
} | ||
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, | ||
suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) | ||
expectedResponse := http.ExpectedResponse{ | ||
Request: http.Request{ | ||
Path: "/eg-lifecycle", | ||
}, | ||
Response: http.Response{ | ||
StatusCode: 200, | ||
}, | ||
Namespace: ns, | ||
} | ||
req := http.MakeRequest(t, &expectedResponse, gwAddr, "HTTP", "http") | ||
cReq, cResp, err := suite.RoundTripper.CaptureRoundTrip(req) | ||
if err != nil { | ||
t.Errorf("failed to get expected response before the install process started: %v", err) | ||
} | ||
if err := http.CompareRequest(t, &req, cReq, cResp, expectedResponse); err != nil { | ||
t.Errorf("failed to compare request and response before the uninstall and install process started: %v", err) | ||
} | ||
|
||
// we will start the uninstallation process after ensuring that the envoy gateway normal service. | ||
relName := "eg" | ||
relNamespace := "envoy-gateway-system" | ||
options.DefaultConfigFlags.Namespace = ptr.To(relNamespace) | ||
|
||
ht := helm.NewPackageTool() | ||
if err = ht.Setup(); err != nil { | ||
t.Errorf("failed to setup of packageTool: %v", err) | ||
} | ||
|
||
t.Log("start uninstall envoy gateway resources") | ||
if err := ht.RunUninstall(&helm.PackageOptions{ | ||
ReleaseName: relName, | ||
}); err != nil { | ||
t.Errorf("failed to uninstall envoy-gateway: %v", err) | ||
} | ||
t.Log("success to uninstall envoy gateway resources") | ||
}) | ||
t.Run("Install Envoy Gateway should succeed", func(t *testing.T) { | ||
ns := "gateway-lifecycle-infra" | ||
routeNN := types.NamespacedName{ | ||
Name: "http-backend-eg-lifecycle", | ||
Namespace: ns, | ||
} | ||
gwNN := types.NamespacedName{ | ||
Name: "lifecycle-gateway", | ||
Namespace: ns, | ||
} | ||
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, | ||
suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) | ||
expectedResponse := http.ExpectedResponse{ | ||
Request: http.Request{ | ||
Path: "/eg-lifecycle", | ||
}, | ||
Response: http.Response{ | ||
StatusCode: 200, | ||
}, | ||
Namespace: ns, | ||
} | ||
req := http.MakeRequest(t, &expectedResponse, gwAddr, "HTTP", "http") | ||
|
||
relName := "eg" | ||
relNamespace := "envoy-gateway-system" | ||
options.DefaultConfigFlags.Namespace = ptr.To(relNamespace) | ||
lastVersionTag := os.Getenv("last_version_tag") | ||
if lastVersionTag == "" { | ||
lastVersionTag = "v0.0.0-latest" // Default version tag if not specified | ||
} | ||
|
||
ht := helm.NewPackageTool() | ||
if err := ht.Setup(); err != nil { | ||
t.Errorf("failed to setup of packageTool: %v", err) | ||
} | ||
|
||
t.Log("start install envoy gateway resource") | ||
if err := ht.RunInstall(&helm.PackageOptions{ | ||
SkipCRD: true, | ||
ReleaseName: relName, | ||
ReleaseNamespace: relNamespace, | ||
Version: lastVersionTag, | ||
Timeout: time.Minute * 5, | ||
}); err != nil { | ||
t.Errorf("failed to install envoy-gateway: %v", err) | ||
} | ||
|
||
// finally, ensure that the envoy-gateway is in normal service. | ||
cReq, cResp, err := suite.RoundTripper.CaptureRoundTrip(req) | ||
if err != nil { | ||
t.Errorf("failed to get expected response before the install process started: %v", err) | ||
} | ||
if err := http.CompareRequest(t, &req, cReq, cResp, expectedResponse); err != nil { | ||
t.Errorf("failed to compare request and response before the uninstall and install process started: %v", err) | ||
} | ||
t.Log("success to install envoy gateway resources") | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters