Skip to content
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
96 changes: 63 additions & 33 deletions test/e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,24 @@ source $(dirname $0)/../vendor/github.com/knative/test-infra/scripts/e2e-tests.s

readonly EVENTING_CONFIG="config/"

# In-memory provisioner config.
readonly IN_MEMORY_CHANNEL_CONFIG="config/provisioners/in-memory-channel/in-memory-channel.yaml"

# GCP PubSub config template.
# GCP PubSub provisioner config template.
readonly GCP_PUBSUB_CONFIG_TEMPLATE="contrib/gcppubsub/config/gcppubsub.yaml"
# Real GCP PubSub config, generated from the template.
# Real GCP PubSub provisioner config, generated from the template.
readonly GCP_PUBSUB_CONFIG="$(mktemp)"

# TODO(Fredy-Z): delete this flag after https://github.com/knative/test-infra/pull/692 is merged and updated
E2E_PROJECT_ID=""

# Constants used for creating ServiceAccount for GCP PubSub provisioner setup if it's not running on Prow.
readonly PUBSUB_SERVICE_ACCOUNT="eventing_pubsub_test"
readonly PUBSUB_SERVICE_ACCOUNT="eventing-pubsub-test"
readonly PUBSUB_SERVICE_ACCOUNT_KEY="$(mktemp)"
readonly PUBSUB_SECRET_NAME="gcppubsub-channel-key"

# NATS Streaming installation config.
readonly NATSS_INSTALLATION_CONFIG="contrib/natss/config/broker/natss.yaml"
# NATSS provisioner config.
readonly NATSS_CONFIG="contrib/natss/config/provisioner.yaml"

# Setup the Knative environment for running tests.
function knative_setup() {
# Install the latest stable Knative/serving in the current cluster.
Expand All @@ -55,40 +58,53 @@ function knative_setup() {
echo "Installing Knative Eventing"
ko apply -f ${EVENTING_CONFIG} || return 1
wait_until_pods_running knative-eventing || fail_test "Knative Eventing did not come up"
}

# Teardown the Knative environment after tests finish.
function knative_teardown() {
echo ">> Stopping Knative Eventing"
echo "Uninstalling Knative Eventing"
ko delete --ignore-not-found=true --now --timeout 60s -f ${EVENTING_CONFIG}
}

# Setup resources common to all eventing tests.
function test_setup() {
# Install provisioners used by the tests.
echo "Installing In-Memory ClusterChannelProvisioner"
ko apply -f ${IN_MEMORY_CHANNEL_CONFIG} || return 1
wait_until_pods_running knative-eventing || fail_test "Failed to install the In-Memory ClusterChannelProvisioner"

E2E_PROJECT_ID="$(gcloud config get-value project)"
echo "Installing GCPPubSub ClusterChannelProvisioner"
gcppubsub_setup
gcppubsub_setup || return 1
sed "s/REPLACE_WITH_GCP_PROJECT/${E2E_PROJECT_ID}/" ${GCP_PUBSUB_CONFIG_TEMPLATE} > ${GCP_PUBSUB_CONFIG}
ko apply -f ${GCP_PUBSUB_CONFIG}
ko apply -f ${GCP_PUBSUB_CONFIG} || return 1
wait_until_pods_running knative-eventing || fail_test "Failed to install the GCPPubSub ClusterChannelProvisioner"
}

# Teardown the Knative environment after tests finish.
function knative_teardown() {
echo ">> Stopping Knative Eventing"
echo "Uninstalling Knative Eventing"
ko delete --ignore-not-found=true --now --timeout 60s -f ${EVENTING_CONFIG}
echo "Installing NATSS ClusterChannelProvisioner"
natss_setup || return 1
Comment thread
chizhg marked this conversation as resolved.
ko apply -f ${NATSS_CONFIG} || return 1
wait_until_pods_running knative-eventing || fail_test "Failed to install the NATSS ClusterChannelProvisioner"

# Publish test images.
echo ">> Publishing test images"
$(dirname $0)/upload-test-images.sh e2e || fail_test "Error uploading test images"
}

# Tear down resources used in the eventing tests.
function test_teardown() {
# Uninstall provisioners used by the tests.
echo "Uninstalling In-Memory ClusterChannelProvisioner"
ko delete --ignore-not-found=true --now --timeout 60s -f ${IN_MEMORY_CHANNEL_CONFIG}

echo "Uninstalling GCPPubSub ClusterChannelProvisioner"
gcppubsub_teardown
ko delete --ignore-not-found=true --now --timeout 60s -f ${GCP_PUBSUB_CONFIG}

wait_until_object_does_not_exist namespaces knative-eventing
}
echo "Uninstalling NATSS ClusterChannelProvisioner"
natss_teardown
ko delete --ignore-not-found=true --now --timeout 60s -f ${NATSS_CONFIG}

# Setup resources common to all eventing tests.
function test_setup() {
# Publish test images.
echo ">> Publishing test images"
$(dirname $0)/upload-test-images.sh e2e || fail_test "Error uploading test images"
wait_until_object_does_not_exist namespaces knative-eventing
}

# Create resources required for GCP PubSub provisioner setup
Expand Down Expand Up @@ -124,19 +140,33 @@ function gcppubsub_teardown() {
kubectl -n knative-eventing delete secret ${PUBSUB_SECRET_NAME}
}

# Create resources required for NATSS provisioner setup
function natss_setup() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should this be in a separate script ? I assume this file can become messy w/ future addons, like for Kafka.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1 for moving support functions to a separate file. But this can be done in a separate PR IMO.

echo "Installing NATS Streaming"
kubectl create namespace natss || return 1
kubectl label namespace natss istio-injection=enabled || return 1
kubectl apply -n natss -f ${NATSS_INSTALLATION_CONFIG} || return 1
}

# Delete resources used for NATSS provisioner setup
function natss_teardown() {
echo "Uninstalling NATS Streaming"
kubectl delete -f ${NATSS_INSTALLATION_CONFIG}
kubectl delete namespace natss
}

function dump_extra_cluster_state() {
# Collecting logs from all knative's eventing pods.
echo "============================================================"
for namespace in "knative-eventing" "e2etestfn3"; do
for pod in $(kubectl get pod -n $namespace | grep Running | awk '{print $1}' ); do
for container in $(kubectl get pod "${pod}" -n $namespace -ojsonpath='{.spec.containers[*].name}'); do
echo "Namespace, Pod, Container: ${namespace}, ${pod}, ${container}"
kubectl logs -n $namespace "${pod}" -c "${container}" || true
echo "----------------------------------------------------------"
echo "Namespace, Pod, Container (Previous instance): ${namespace}, ${pod}, ${container}"
kubectl logs -p -n $namespace "${pod}" -c "${container}" || true
echo "============================================================"
done
local namespace="knative-eventing"
for pod in $(kubectl get pod -n $namespace | grep Running | awk '{print $1}' ); do
for container in $(kubectl get pod "${pod}" -n $namespace -ojsonpath='{.spec.containers[*].name}'); do
echo "Namespace, Pod, Container: ${namespace}, ${pod}, ${container}"
kubectl logs -n $namespace "${pod}" -c "${container}" || true
echo "----------------------------------------------------------"
echo "Namespace, Pod, Container (Previous instance): ${namespace}, ${pod}, ${container}"
kubectl logs -p -n $namespace "${pod}" -c "${container}" || true
echo "============================================================"
done
done
}
Expand All @@ -145,6 +175,6 @@ function dump_extra_cluster_state() {

initialize $@

go_test_e2e -timeout=20m ./test/e2e -run ^TestMain$ -runFromMain=true -clusterChannelProvisioners=in-memory-channel,in-memory || fail_test
go_test_e2e -timeout=20m ./test/e2e -run ^TestMain$ -runFromMain=true -clusterChannelProvisioners=in-memory-channel,in-memory,natss || fail_test

success
6 changes: 6 additions & 0 deletions test/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ var channelTestMap = map[string][]func(t *testing.T){
TestEventTransformation,
TestChannelChain,
},
test.NatssProvisioner: {
TestSingleBinaryEvent,
TestSingleStructuredEvent,
TestEventTransformation,
TestChannelChain,
},
}

func TestMain(t *testing.T) {
Expand Down