diff --git a/test/e2e-tests.sh b/test/e2e-tests.sh index c41bce57f4c..ddf400590ea 100755 --- a/test/e2e-tests.sh +++ b/test/e2e-tests.sh @@ -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. @@ -55,25 +58,41 @@ 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 + 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} @@ -81,14 +100,11 @@ function knative_teardown() { 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 @@ -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() { + 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 } @@ -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 diff --git a/test/e2e/main_test.go b/test/e2e/main_test.go index e09c29d9f5c..8035bbcf009 100644 --- a/test/e2e/main_test.go +++ b/test/e2e/main_test.go @@ -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) {