generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 87
Initial e2e structure #240
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
Open
rikatz
wants to merge
1
commit into
kubernetes-sigs:main
Choose a base branch
from
rikatz:implement-e2e
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+240
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,13 @@ | ||
| # Ingress2Gateway e2e tests | ||
|
|
||
| This folder contains the e2e tests for ingress2gateway. Implementors willing to | ||
| add new features or migrate MUST add tests to the subfolder of the provider, to | ||
| guarantee that the desired migration is working as expected. | ||
|
|
||
| The tests are written using [BATS](https://bats-core.readthedocs.io/en/stable/index.html) | ||
| to guarantee that the desired user behavior happens as they were really operating | ||
| a cluster and avoiding to write Go programs that may not reflect the desired | ||
| behavior of the test. | ||
|
|
||
| To execute the tests, you should run from the root directory of the project the | ||
| command `make e2e`. |
This file contains hidden or 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,43 @@ | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: backend | ||
| spec: | ||
| selector: | ||
| app: backend | ||
| ports: | ||
| - name: http-port | ||
| protocol: TCP | ||
| port: 8080 | ||
| targetPort: 3000 | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: backend | ||
| labels: | ||
| app: backend | ||
| spec: | ||
| selector: | ||
| matchLabels: | ||
| app: backend | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: backend | ||
| spec: | ||
| containers: | ||
| - name: backend | ||
| image: gcr.io/k8s-staging-gateway-api/echo-basic:v20240412-v1.0.0-394-g40c666fd | ||
| env: | ||
| - name: POD_NAME | ||
| valueFrom: | ||
| fieldRef: | ||
| fieldPath: metadata.name | ||
| - name: NAMESPACE | ||
| valueFrom: | ||
| fieldRef: | ||
| fieldPath: metadata.namespace | ||
| resources: | ||
| requests: | ||
| cpu: 10m |
This file contains hidden or 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,10 @@ | ||
| apiVersion: gateway.networking.k8s.io/v1 | ||
| kind: Gateway | ||
| metadata: | ||
| name: eg | ||
| spec: | ||
| gatewayClassName: eg | ||
| listeners: | ||
| - name: http | ||
| protocol: HTTP | ||
| port: 80 |
This file contains hidden or 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,6 @@ | ||
| apiVersion: gateway.networking.k8s.io/v1 | ||
| kind: GatewayClass | ||
| metadata: | ||
| name: eg | ||
| spec: | ||
| controllerName: gateway.envoyproxy.io/gatewayclass-controller |
This file contains hidden or 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: networking.k8s.io/v1 | ||
| kind: Ingress | ||
| metadata: | ||
| name: simple | ||
| spec: | ||
| rules: | ||
| - host: some.test | ||
| http: | ||
| paths: | ||
| - backend: | ||
| service: | ||
| name: backend | ||
| port: | ||
| number: 3000 | ||
| path: / | ||
| pathType: Exact |
This file contains hidden or 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,10 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| #### This test suite contains just the simple ingress test, and should not have any Provider specifics | ||
|
|
||
| load functions.bash | ||
|
|
||
| @test "Simple Ingress manifest test" { | ||
| i2g simple/simple.yaml | ||
| do_request | ||
| } |
This file contains hidden or 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,25 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
| set -o pipefail | ||
|
|
||
| function log() { | ||
| echo "# LOG: $1" >&3 | ||
| } | ||
|
|
||
| function do_request() { | ||
| HOST=${1:-localhost} | ||
| log "Doing an initial request to Gateway on ${HOST}:${GATEWAY_FORWARDED_PORT}" | ||
| curl --fail -kv --max-time 5 --resolve ${HOST}:${GATEWAY_FORWARDED_PORT}:127.0.0.1 "http://${HOST}:${GATEWAY_FORWARDED_PORT}" | ||
| } | ||
|
|
||
| function i2g() { | ||
| MANIFEST="${1:-}" | ||
| if [ -z "${MANIFEST}" ]; then | ||
| echo "The source manifest is mandatory" | ||
| exit 1 | ||
| fi | ||
| log "Running i2g on e2e/manifests/${MANIFEST}" | ||
| ${I2G} print --input-file e2e/manifests/"${MANIFEST}" | ||
| } |
This file contains hidden or 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,47 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
| set -o pipefail | ||
|
|
||
| export GATEWAY_FORWARDED_PORT="${GATEWAY_PORT:-8888}" | ||
|
|
||
| source e2e/tests/functions.bash | ||
|
|
||
| # TODO: We may want to accept other providers, for now to keep it simple we will go with Envoy Gateway | ||
| function setup_suite { | ||
| log "Installing envoy gateway" | ||
|
|
||
| kubectl apply --server-side -f https://github.com/envoyproxy/gateway/releases/download/v1.5.0/install.yaml | ||
| kubectl wait --timeout=5m -n envoy-gateway-system deployment/envoy-gateway --for=condition=Available | ||
|
|
||
| # Install envoy gateway class | ||
| log "Creating GatewayClass" | ||
| kubectl apply -f e2e/manifests/infrastructure/gatewayclass.yaml | ||
| kubectl wait gatewayclass/eg --for=condition=Accepted=True | ||
| # TODO: Add HTTPS listener | ||
| log "Creating Gateway" | ||
| kubectl apply -f e2e/manifests/infrastructure/gateway.yaml | ||
| sleep 3 # Give some time for controller to reconcile gateway and start a deployment | ||
| export GATEWAY_NAME=$(kubectl get deploy -n envoy-gateway-system --selector=gateway.envoyproxy.io/owning-gateway-namespace=default,gateway.envoyproxy.io/owning-gateway-name=eg -o name |cut -f 2 -d /) | ||
| kubectl wait --timeout=2m deploy -n envoy-gateway-system ${GATEWAY_NAME} --for=condition=Available | ||
| log "Starting port-forwarding to gateway" | ||
| kubectl -n envoy-gateway-system port-forward service/${GATEWAY_NAME} ${GATEWAY_FORWARDED_PORT}:80 & | ||
| export KUBECTL_FORWARDER_PID=$! | ||
|
|
||
| log "Setting the sample application" | ||
| kubectl apply -f e2e/manifests/infrastructure/backend.yaml | ||
| kubectl wait --timeout=2m deploy backend --for=condition=Available | ||
| log "Test is ready to roll" | ||
| } | ||
|
|
||
| # We don't remove envoy gateway during teardown to avoid the reinstallation that has high cost | ||
| function teardown_suite { | ||
| kill ${KUBECTL_FORWARDER_PID} | ||
| log "Killed port-forwarding" | ||
| log "Removing the sample application" | ||
| kubectl delete -f e2e/manifests/infrastructure/backend.yaml | ||
| log "Cleaning gateway and gatewayclass resources" | ||
| kubectl delete -f e2e/manifests/infrastructure/gateway.yaml | ||
| kubectl delete -f e2e/manifests/infrastructure/gatewayclass.yaml | ||
| } |
This file contains hidden or 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,53 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Copyright 2014 The Kubernetes Authors. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :D
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dammit copy/pasta |
||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
| set -o pipefail | ||
|
|
||
| # TODO: make this configurable | ||
| export PROVIDER="ingress-nginx" | ||
| export I2G="${I2G:-$(pwd)/ingress2gateway}" | ||
| export TESTS_DIR="${TESTS_DIR:-$(pwd)/e2e/tests}" | ||
|
|
||
|
|
||
| function pre_check() { | ||
| if ! ${I2G} &>/dev/null; then | ||
| echo "Error executing ingress2gateway, please be sure the variable I2G is pointing to the right location" | ||
| exit 1 | ||
| fi | ||
| if ! command -v bats &> /dev/null; then | ||
| echo "BATS needs to be installed. Please check https://bats-core.readthedocs.io/en/stable/installation.html" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! command -v curl &> /dev/null; then | ||
| echo "cURL needs to be installed to execute the tests" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! kubectl version; then | ||
| echo "Error executing kubectl. Please be sure you have a Kubernetes cluster running before executing the test" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| function run_tests() { | ||
| bats "${TESTS_DIR}" | ||
| } | ||
|
|
||
| pre_check | ||
| run_tests | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can we do I2GW?