Use knative.dev/test-infra (#1627)

This commit is contained in:
chaodaiG 2019-07-31 09:59:44 -07:00 committed by Knative Prow Robot
parent 0ef8366c97
commit 003aca0f76
18 changed files with 401 additions and 242 deletions

60
Gopkg.lock generated
View File

@ -11,7 +11,7 @@
"internal/optional", "internal/optional",
"internal/trace", "internal/trace",
"internal/version", "internal/version",
"storage", "storage"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "28a4bc8c44b3acbcc482cff0cdf7de29a4688b61" revision = "28a4bc8c44b3acbcc482cff0cdf7de29a4688b61"
@ -38,7 +38,7 @@
name = "github.com/eclipse/paho.mqtt.golang" name = "github.com/eclipse/paho.mqtt.golang"
packages = [ packages = [
".", ".",
"packets", "packets"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "36d01c2b4cbeb3d2a12063e4880ce30800af9560" revision = "36d01c2b4cbeb3d2a12063e4880ce30800af9560"
@ -53,7 +53,7 @@
"ptypes", "ptypes",
"ptypes/any", "ptypes/any",
"ptypes/duration", "ptypes/duration",
"ptypes/timestamp", "ptypes/timestamp"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "b4deda0973fb4c70b50d226b1af49f3da59f5265" revision = "b4deda0973fb4c70b50d226b1af49f3da59f5265"
@ -85,7 +85,7 @@
"stringclassifier", "stringclassifier",
"stringclassifier/internal/pq", "stringclassifier/internal/pq",
"stringclassifier/searchset", "stringclassifier/searchset",
"stringclassifier/searchset/tokenizer", "stringclassifier/searchset/tokenizer"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "c2a262e3078ad90718f59866f1ec18601b2fee1b" revision = "c2a262e3078ad90718f59866f1ec18601b2fee1b"
@ -114,17 +114,6 @@
revision = "e3702bed27f0d39777b0b37b664b6280e8ef8fbf" revision = "e3702bed27f0d39777b0b37b664b6280e8ef8fbf"
version = "v1.6.2" version = "v1.6.2"
[[projects]]
branch = "master"
digest = "1:8cbd2b6c179d93c5cdc5f75c1acda0aa7ef7649cf9ca138e587d9ac98a137802"
name = "github.com/knative/test-infra"
packages = [
"scripts",
"tools/dep-collector",
]
pruneopts = "UT"
revision = "7d0c44fb03a996501f10e3af4a718fd008fe9bed"
[[projects]] [[projects]]
digest = "1:5985ef4caf91ece5d54817c11ea25f182697534f8ae6521eadcd628c142ac4b6" digest = "1:5985ef4caf91ece5d54817c11ea25f182697534f8ae6521eadcd628c142ac4b6"
name = "github.com/matttproud/golang_protobuf_extensions" name = "github.com/matttproud/golang_protobuf_extensions"
@ -142,7 +131,7 @@
"model", "model",
"propagation", "propagation",
"reporter", "reporter",
"reporter/http", "reporter/http"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "f197ec29e729f226d23370ea60f0e49b8f44ccf4" revision = "f197ec29e729f226d23370ea60f0e49b8f44ccf4"
@ -153,7 +142,7 @@
name = "github.com/prometheus/client_golang" name = "github.com/prometheus/client_golang"
packages = [ packages = [
"prometheus", "prometheus",
"prometheus/promhttp", "prometheus/promhttp"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "c5b7fccd204277076155f10851dad72b76a49317" revision = "c5b7fccd204277076155f10851dad72b76a49317"
@ -174,7 +163,7 @@
packages = [ packages = [
"expfmt", "expfmt",
"internal/bitbucket.org/ww/goautoneg", "internal/bitbucket.org/ww/goautoneg",
"model", "model"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "7600349dcfe1abd18d72d3a1770870d9800a7801" revision = "7600349dcfe1abd18d72d3a1770870d9800a7801"
@ -187,7 +176,7 @@
".", ".",
"internal/util", "internal/util",
"nfs", "nfs",
"xfs", "xfs"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "ae68e2d4c00fed4943b5f6698d504a5fe083da8a" revision = "ae68e2d4c00fed4943b5f6698d504a5fe083da8a"
@ -225,7 +214,7 @@
"tag", "tag",
"trace", "trace",
"trace/internal", "trace/internal",
"trace/propagation", "trace/propagation"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "e262766cd0d230a1bb7c37281e345e465f19b41b" revision = "e262766cd0d230a1bb7c37281e345e465f19b41b"
@ -246,7 +235,7 @@
"internal/timeseries", "internal/timeseries",
"proxy", "proxy",
"trace", "trace",
"websocket", "websocket"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "d0887baf81f4598189d4e12a37c6da86f0bba4d0" revision = "d0887baf81f4598189d4e12a37c6da86f0bba4d0"
@ -260,7 +249,7 @@
"google", "google",
"internal", "internal",
"jws", "jws",
"jwt", "jwt"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "ef147856a6ddbb60760db74283d2424e98c87bff" revision = "ef147856a6ddbb60760db74283d2424e98c87bff"
@ -290,7 +279,7 @@
"unicode/bidi", "unicode/bidi",
"unicode/cldr", "unicode/cldr",
"unicode/norm", "unicode/norm",
"unicode/rangetable", "unicode/rangetable"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
@ -309,7 +298,7 @@
"option", "option",
"storage/v1", "storage/v1",
"transport/http", "transport/http",
"transport/http/internal/propagation", "transport/http/internal/propagation"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "19e022d8cf43ce81f046bae8cc18c5397cc7732f" revision = "19e022d8cf43ce81f046bae8cc18c5397cc7732f"
@ -328,7 +317,7 @@
"internal/modules", "internal/modules",
"internal/remote_api", "internal/remote_api",
"internal/urlfetch", "internal/urlfetch",
"urlfetch", "urlfetch"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "b1f26356af11148e710935ed1ac8a7f5702c7612" revision = "b1f26356af11148e710935ed1ac8a7f5702c7612"
@ -342,7 +331,7 @@
"googleapis/api/annotations", "googleapis/api/annotations",
"googleapis/iam/v1", "googleapis/iam/v1",
"googleapis/rpc/code", "googleapis/rpc/code",
"googleapis/rpc/status", "googleapis/rpc/status"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "ae2f86662275e140f395167f1dab7081a5bd5fa8" revision = "ae2f86662275e140f395167f1dab7081a5bd5fa8"
@ -381,7 +370,7 @@
"resolver/passthrough", "resolver/passthrough",
"stats", "stats",
"status", "status",
"tap", "tap"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "df014850f6dee74ba2fc94874043a9f3f75fbfd8" revision = "df014850f6dee74ba2fc94874043a9f3f75fbfd8"
@ -392,7 +381,7 @@
name = "gopkg.in/go-playground/webhooks.v3" name = "gopkg.in/go-playground/webhooks.v3"
packages = [ packages = [
".", ".",
"github", "github"
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "8ffb2ffc32b7af2c7e940944eccba4dcd66c692a" revision = "8ffb2ffc32b7af2c7e940944eccba4dcd66c692a"
@ -406,6 +395,17 @@
revision = "51d6538a90f86fe93ac480b35f37b2be17fef232" revision = "51d6538a90f86fe93ac480b35f37b2be17fef232"
version = "v2.2.2" version = "v2.2.2"
[[projects]]
branch = "master"
digest = "1:68050b4ce26531655bac0f6e109d04eb0a4550ead73e320119ed3c628ced4a0a"
name = "knative.dev/test-infra"
packages = [
"scripts",
"tools/dep-collector"
]
pruneopts = "UT"
revision = "17f2331e80ad0d3e170ea2bae45c3922744f83af"
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
@ -416,8 +416,6 @@
"github.com/golang/protobuf/proto", "github.com/golang/protobuf/proto",
"github.com/google/go-github/github", "github.com/google/go-github/github",
"github.com/gorilla/mux", "github.com/gorilla/mux",
"github.com/knative/test-infra/scripts",
"github.com/knative/test-infra/tools/dep-collector",
"github.com/openzipkin/zipkin-go", "github.com/openzipkin/zipkin-go",
"github.com/openzipkin/zipkin-go/reporter/http", "github.com/openzipkin/zipkin-go/reporter/http",
"github.com/satori/go.uuid", "github.com/satori/go.uuid",
@ -435,6 +433,8 @@
"gopkg.in/go-playground/webhooks.v3", "gopkg.in/go-playground/webhooks.v3",
"gopkg.in/go-playground/webhooks.v3/github", "gopkg.in/go-playground/webhooks.v3/github",
"gopkg.in/yaml.v2", "gopkg.in/yaml.v2",
"knative.dev/test-infra/scripts",
"knative.dev/test-infra/tools/dep-collector"
] ]
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View File

@ -2,8 +2,8 @@
# for detailed Gopkg.toml documentation. # for detailed Gopkg.toml documentation.
required = [ required = [
"github.com/knative/test-infra/scripts", "knative.dev/test-infra/scripts",
"github.com/knative/test-infra/tools/dep-collector", "knative.dev/test-infra/tools/dep-collector",
] ]
[prune] [prune]
@ -12,5 +12,5 @@ required = [
non-go = true non-go = true
[[prune.project]] [[prune.project]]
name = "github.com/knative/test-infra" name = "knative.dev/test-infra"
non-go = false non-go = false

View File

@ -18,7 +18,7 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
source $(dirname $0)/../vendor/github.com/knative/test-infra/scripts/library.sh source $(dirname $0)/../vendor/knative.dev/test-infra/scripts/library.sh
cd ${REPO_ROOT_DIR} cd ${REPO_ROOT_DIR}

View File

@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
source $(dirname $0)/../vendor/github.com/knative/test-infra/scripts/e2e-tests.sh source $(dirname $0)/../vendor/knative.dev/test-infra/scripts/e2e-tests.sh
function knative_setup() { function knative_setup() {
start_latest_knative_serving start_latest_knative_serving

View File

@ -22,7 +22,7 @@
DISABLE_MD_LINTING=1 DISABLE_MD_LINTING=1
DISABLE_MD_LINK_CHECK=1 DISABLE_MD_LINK_CHECK=1
source $(dirname $0)/../vendor/github.com/knative/test-infra/scripts/presubmit-tests.sh source $(dirname $0)/../vendor/knative.dev/test-infra/scripts/presubmit-tests.sh
# We use the default build, unit and integration test runners. # We use the default build, unit and integration test runners.

View File

@ -1,7 +1,7 @@
# Helper scripts # Helper scripts
This directory contains helper scripts used by Prow test jobs, as well and This directory contains helper scripts used by Prow test jobs, as well and local
local development scripts. development scripts.
## Using the `presubmit-tests.sh` helper script ## Using the `presubmit-tests.sh` helper script
@ -28,45 +28,47 @@ This is a helper script to run the presubmit tests. To use it:
in the `/test` directory. in the `/test` directory.
1. [optional] Customize the default build test runner, if you're using it. Set 1. [optional] Customize the default build test runner, if you're using it. Set
the following environment variables if the default values don't fit your needs: the following environment variables if the default values don't fit your
needs:
- `DISABLE_MD_LINTING`: Disable linting markdown files, defaults to 0 (false). - `DISABLE_MD_LINTING`: Disable linting markdown files, defaults to 0
(false).
- `DISABLE_MD_LINK_CHECK`: Disable checking links in markdown files, defaults - `DISABLE_MD_LINK_CHECK`: Disable checking links in markdown files, defaults
to 0 (false). to 0 (false).
- `PRESUBMIT_TEST_FAIL_FAST`: Fail the presubmit test immediately if a test fails, - `PRESUBMIT_TEST_FAIL_FAST`: Fail the presubmit test immediately if a test
defaults to 0 (false). fails, defaults to 0 (false).
1. [optional] Define the functions `pre_build_tests()` and/or 1. [optional] Define the functions `pre_build_tests()` and/or
`post_build_tests()`. These functions will be called before or after the `post_build_tests()`. These functions will be called before or after the
build tests (either your custom one or the default action) and will cause build tests (either your custom one or the default action) and will cause the
the test to fail if they don't return success. test to fail if they don't return success.
1. [optional] Define the function `unit_tests()`. If you don't define this 1. [optional] Define the function `unit_tests()`. If you don't define this
function, the default action for running the unit tests is to run all go tests function, the default action for running the unit tests is to run all go
in the repo. tests in the repo.
1. [optional] Define the functions `pre_unit_tests()` and/or 1. [optional] Define the functions `pre_unit_tests()` and/or
`post_unit_tests()`. These functions will be called before or after the `post_unit_tests()`. These functions will be called before or after the unit
unit tests (either your custom one or the default action) and will cause tests (either your custom one or the default action) and will cause the test
the test to fail if they don't return success. to fail if they don't return success.
1. [optional] Define the function `integration_tests()`. If you don't define 1. [optional] Define the function `integration_tests()`. If you don't define
this function, the default action for running the integration tests is to run this function, the default action for running the integration tests is to run
all run all `./test/e2e-*tests.sh` scripts, in sequence. all run all `./test/e2e-*tests.sh` scripts, in sequence.
1. [optional] Define the functions `pre_integration_tests()` and/or 1. [optional] Define the functions `pre_integration_tests()` and/or
`post_integration_tests()`. These functions will be called before or after the `post_integration_tests()`. These functions will be called before or after
integration tests (either your custom one or the default action) and will cause the integration tests (either your custom one or the default action) and will
the test to fail if they don't return success. cause the test to fail if they don't return success.
1. Call the `main()` function passing `$@` (without quotes). 1. Call the `main()` function passing `$@` (without quotes).
Running the script without parameters, or with the `--all-tests` flag causes Running the script without parameters, or with the `--all-tests` flag causes all
all tests to be executed, in the right order (i.e., build, then unit, then tests to be executed, in the right order (i.e., build, then unit, then
integration tests). integration tests).
Use the flags `--build-tests`, `--unit-tests` and `--integration-tests` to run Use the flags `--build-tests`, `--unit-tests` and `--integration-tests` to run a
a specific set of tests. The flag `--emit-metrics` is used to emit metrics when specific set of tests. The flag `--emit-metrics` is used to emit metrics when
running the tests, and is automatically handled by the default action for running the tests, and is automatically handled by the default action for
integration tests (see above). integration tests (see above).
@ -79,7 +81,7 @@ skipped.
### Sample presubmit test script ### Sample presubmit test script
```bash ```bash
source vendor/github.com/knative/test-infra/scripts/presubmit-tests.sh source vendor/knative.dev/test-infra/scripts/presubmit-tests.sh
function post_build_tests() { function post_build_tests() {
echo "Cleaning up after build tests" echo "Cleaning up after build tests"
@ -104,63 +106,64 @@ main $@
This is a helper script for Knative E2E test scripts. To use it: This is a helper script for Knative E2E test scripts. To use it:
1. [optional] Customize the test cluster. Set the following environment variables 1. [optional] Customize the test cluster. Set the following environment
if the default values don't fit your needs: variables if the default values don't fit your needs:
- `E2E_CLUSTER_REGION`: Cluster region, defaults to `us-central1`. - `E2E_CLUSTER_REGION`: Cluster region, defaults to `us-central1`.
- `E2E_CLUSTER_BACKUP_REGIONS`: Space-separated list of regions to retry test - `E2E_CLUSTER_BACKUP_REGIONS`: Space-separated list of regions to retry test
cluster creation in case of stockout. Defaults to `us-west1 us-east1`. cluster creation in case of stockout. Defaults to `us-west1 us-east1`.
- `E2E_CLUSTER_ZONE`: Cluster zone (e.g., `a`), defaults to none (i.e. use a regional - `E2E_CLUSTER_ZONE`: Cluster zone (e.g., `a`), defaults to none (i.e. use a
cluster). regional cluster).
- `E2E_CLUSTER_BACKUP_ZONES`: Space-separated list of zones to retry test cluster - `E2E_CLUSTER_BACKUP_ZONES`: Space-separated list of zones to retry test
creation in case of stockout. If defined, `E2E_CLUSTER_BACKUP_REGIONS` will be cluster creation in case of stockout. If defined,
ignored thus it defaults to none. `E2E_CLUSTER_BACKUP_REGIONS` will be ignored thus it defaults to none.
- `E2E_CLUSTER_MACHINE`: Cluster node machine type, defaults to `n1-standard-4}`. - `E2E_CLUSTER_MACHINE`: Cluster node machine type, defaults to
- `E2E_MIN_CLUSTER_NODES`: Minimum number of nodes in the cluster when autoscaling, `n1-standard-4}`.
defaults to 1. - `E2E_MIN_CLUSTER_NODES`: Minimum number of nodes in the cluster when
- `E2E_MAX_CLUSTER_NODES`: Maximum number of nodes in the cluster when autoscaling, autoscaling, defaults to 1.
defaults to 3. - `E2E_MAX_CLUSTER_NODES`: Maximum number of nodes in the cluster when
autoscaling, defaults to 3.
1. Source the script. 1. Source the script.
1. [optional] Write the `knative_setup()` function, which will set up your 1. [optional] Write the `knative_setup()` function, which will set up your
system under test (e.g., Knative Serving). This function won't be called if you system under test (e.g., Knative Serving). This function won't be called if
use the `--skip-knative-setup` flag. you use the `--skip-knative-setup` flag.
1. [optional] Write the `knative_teardown()` function, which will tear down your 1. [optional] Write the `knative_teardown()` function, which will tear down your
system under test (e.g., Knative Serving). This function won't be called if you system under test (e.g., Knative Serving). This function won't be called if
use the `--skip-knative-setup` flag. you use the `--skip-knative-setup` flag.
1. [optional] Write the `test_setup()` function, which will set up the test 1. [optional] Write the `test_setup()` function, which will set up the test
resources. resources.
1. [optional] Write the `test_teardown()` function, which will tear down the test 1. [optional] Write the `test_teardown()` function, which will tear down the
resources. test resources.
1. [optional] Write the `cluster_setup()` function, which will set up any resources 1. [optional] Write the `cluster_setup()` function, which will set up any
before the test cluster is created. resources before the test cluster is created.
1. [optional] Write the `cluster_teardown()` function, which will tear down any 1. [optional] Write the `cluster_teardown()` function, which will tear down any
resources after the test cluster is destroyed. resources after the test cluster is destroyed.
1. [optional] Write the `dump_extra_cluster_state()` function. It will be 1. [optional] Write the `dump_extra_cluster_state()` function. It will be called
called when a test fails, and can dump extra information about the current state when a test fails, and can dump extra information about the current state of
of the cluster (typically using `kubectl`). the cluster (typically using `kubectl`).
1. [optional] Write the `parse_flags()` function. It will be called whenever an 1. [optional] Write the `parse_flags()` function. It will be called whenever an
unrecognized flag is passed to the script, allowing you to define your own flags. unrecognized flag is passed to the script, allowing you to define your own
The function must return 0 if the flag is unrecognized, or the number of items flags. The function must return 0 if the flag is unrecognized, or the number
to skip in the command line if the flag was parsed successfully. For example, of items to skip in the command line if the flag was parsed successfully. For
return 1 for a simple flag, and 2 for a flag with a parameter. example, return 1 for a simple flag, and 2 for a flag with a parameter.
1. Call the `initialize()` function passing `$@` (without quotes). 1. Call the `initialize()` function passing `$@` (without quotes).
1. Write logic for the end-to-end tests. Run all go tests using `go_test_e2e()` 1. Write logic for the end-to-end tests. Run all go tests using `go_test_e2e()`
(or `report_go_test()` if you need a more fine-grained control) and call (or `report_go_test()` if you need a more fine-grained control) and call
`fail_test()` or `success()` if any of them failed. The environment variable `fail_test()` or `success()` if any of them failed. The environment variable
`KO_DOCKER_REPO` and `E2E_PROJECT_ID` will be set according to the test cluster. `KO_DOCKER_REPO` and `E2E_PROJECT_ID` will be set according to the test
You can also use the following boolean (0 is false, 1 is true) environment cluster. You can also use the following boolean (0 is false, 1 is true)
variables for the logic: environment variables for the logic:
- `EMIT_METRICS`: true if `--emit-metrics` was passed. - `EMIT_METRICS`: true if `--emit-metrics` was passed.
@ -175,25 +178,26 @@ This is a helper script for Knative E2E test scripts. To use it:
will immediately start the tests against the cluster currently configured for will immediately start the tests against the cluster currently configured for
`kubectl`. `kubectl`.
1. By default Istio is installed on the cluster via Addon, use `--skip-istio-addon` if 1. By default Istio is installed on the cluster via Addon, use
you choose not to have it preinstalled. `--skip-istio-addon` if you choose not to have it preinstalled.
1. You can force running the tests against a specific GKE cluster version by using 1. You can force running the tests against a specific GKE cluster version by
the `--cluster-version` flag and passing a full version as the flag value. using the `--cluster-version` flag and passing a full version as the flag
value.
### Sample end-to-end test script ### Sample end-to-end test script
This script will test that the latest Knative Serving nightly release works. It This script will test that the latest Knative Serving nightly release works. It
defines a special flag (`--no-knative-wait`) that causes the script not to defines a special flag (`--no-knative-wait`) that causes the script not to wait
wait for Knative Serving to be up before running the tests. It also requires that for Knative Serving to be up before running the tests. It also requires that the
the test cluster is created in a specific region, `us-west2`. test cluster is created in a specific region, `us-west2`.
```bash ```bash
# This test requires a cluster in LA # This test requires a cluster in LA
E2E_CLUSTER_REGION=us-west2 E2E_CLUSTER_REGION=us-west2
source vendor/github.com/knative/test-infra/scripts/e2e-tests.sh source vendor/knative.dev/test-infra/scripts/e2e-tests.sh
function knative_setup() { function knative_setup() {
start_latest_knative_serving start_latest_knative_serving
@ -226,40 +230,46 @@ This is a helper script for Knative release scripts. To use it:
1. Source the script. 1. Source the script.
1. [optional] By default, the release script will run `./test/presubmit-tests.sh` 1. [optional] By default, the release script will run
as the release validation tests. If you need to run something else, set the `./test/presubmit-tests.sh` as the release validation tests. If you need to
environment variable `VALIDATION_TESTS` to the executable to run. run something else, set the environment variable `VALIDATION_TESTS` to the
executable to run.
1. Write logic for building the release in a function named `build_release()`. 1. Write logic for building the release in a function named `build_release()`.
Set the environment variable `ARTIFACTS_TO_PUBLISH` to the list of files created, Set the environment variable `ARTIFACTS_TO_PUBLISH` to the list of files
space separated. Use the following boolean (0 is false, 1 is true) and string created, space separated. Use the following boolean (0 is false, 1 is true)
environment variables for the logic: and string environment variables for the logic:
- `RELEASE_VERSION`: contains the release version if `--version` was passed. This - `RELEASE_VERSION`: contains the release version if `--version` was passed.
also overrides the value of the `TAG` variable as `v<version>`. This also overrides the value of the `TAG` variable as `v<version>`.
- `RELEASE_BRANCH`: contains the release branch if `--branch` was passed. Otherwise - `RELEASE_BRANCH`: contains the release branch if `--branch` was passed.
it's empty and `master` HEAD will be considered the release branch. Otherwise it's empty and `master` HEAD will be considered the release
- `RELEASE_NOTES`: contains the filename with the release notes if `--release-notes` branch.
was passed. The release notes is a simple markdown file. - `RELEASE_NOTES`: contains the filename with the release notes if
- `RELEASE_GCS_BUCKET`: contains the GCS bucket name to store the manifests if `--release-notes` was passed. The release notes is a simple markdown file.
`--release-gcs` was passed, otherwise the default value `knative-nightly/<repo>` - `RELEASE_GCS_BUCKET`: contains the GCS bucket name to store the manifests
will be used. It is empty if `--publish` was not passed. if `--release-gcs` was passed, otherwise the default value
- `BUILD_COMMIT_HASH`: the commit short hash for the current repo. If the current `knative-nightly/<repo>` will be used. It is empty if `--publish` was not
git tree is dirty, it will have `-dirty` appended to it. passed.
- `BUILD_COMMIT_HASH`: the commit short hash for the current repo. If the
current git tree is dirty, it will have `-dirty` appended to it.
- `BUILD_YYYYMMDD`: current UTC date in `YYYYMMDD` format. - `BUILD_YYYYMMDD`: current UTC date in `YYYYMMDD` format.
- `BUILD_TIMESTAMP`: human-readable UTC timestamp in `YYYY-MM-DD HH:MM:SS` format. - `BUILD_TIMESTAMP`: human-readable UTC timestamp in `YYYY-MM-DD HH:MM:SS`
format.
- `BUILD_TAG`: a tag in the form `v$BUILD_YYYYMMDD-$BUILD_COMMIT_HASH`. - `BUILD_TAG`: a tag in the form `v$BUILD_YYYYMMDD-$BUILD_COMMIT_HASH`.
- `KO_DOCKER_REPO`: contains the GCR to store the images if `--release-gcr` was - `KO_DOCKER_REPO`: contains the GCR to store the images if `--release-gcr`
passed, otherwise the default value `gcr.io/knative-nightly` will be used. It was passed, otherwise the default value `gcr.io/knative-nightly` will be
is set to `ko.local` if `--publish` was not passed. used. It is set to `ko.local` if `--publish` was not passed.
- `SKIP_TESTS`: true if `--skip-tests` was passed. This is handled automatically. - `SKIP_TESTS`: true if `--skip-tests` was passed. This is handled
- `TAG_RELEASE`: true if `--tag-release` was passed. In this case, the environment automatically.
variable `TAG` will contain the release tag in the form `v$BUILD_TAG`. - `TAG_RELEASE`: true if `--tag-release` was passed. In this case, the
- `PUBLISH_RELEASE`: true if `--publish` was passed. In this case, the environment environment variable `TAG` will contain the release tag in the form
variable `KO_FLAGS` will be updated with the `-L` option and `TAG` will contain `v$BUILD_TAG`.
the release tag in the form `v$RELEASE_VERSION`. - `PUBLISH_RELEASE`: true if `--publish` was passed. In this case, the
- `PUBLISH_TO_GITHUB`: true if `--version`, `--branch` and `--publish-release` environment variable `KO_FLAGS` will be updated with the `-L` option and
were passed. `TAG` will contain the release tag in the form `v$RELEASE_VERSION`.
- `PUBLISH_TO_GITHUB`: true if `--version`, `--branch` and
`--publish-release` were passed.
All boolean environment variables default to false for safety. All boolean environment variables default to false for safety.
@ -271,7 +281,7 @@ This is a helper script for Knative release scripts. To use it:
### Sample release script ### Sample release script
```bash ```bash
source vendor/github.com/knative/test-infra/scripts/release.sh source vendor/knative.dev/test-infra/scripts/release.sh
function build_release() { function build_release() {
# config/ contains the manifests # config/ contains the manifests

View File

@ -83,7 +83,7 @@ function go_test_e2e() {
local go_options="" local go_options=""
(( EMIT_METRICS )) && test_options="-emitmetrics" (( EMIT_METRICS )) && test_options="-emitmetrics"
[[ ! " $@" == *" -tags="* ]] && go_options="-tags=e2e" [[ ! " $@" == *" -tags="* ]] && go_options="-tags=e2e"
report_go_test -v -count=1 ${go_options} $@ ${test_options} report_go_test -v -race -count=1 ${go_options} $@ ${test_options}
} }
# Dump info about the test cluster. If dump_extra_cluster_info() is defined, calls it too. # Dump info about the test cluster. If dump_extra_cluster_info() is defined, calls it too.
@ -127,29 +127,41 @@ function save_metadata() {
EOF EOF
} }
# Delete target pools and health checks that might have leaked. # Set E2E_CLUSTER_VERSION to a specific GKE version.
# See https://github.com/knative/serving/issues/959 for details. # Parameters: $1 - target GKE version (X.Y, X.Y.Z, X.Y.Z-gke.W, default or gke-latest).
# TODO(adrcunha): Remove once the leak issue is resolved. # $2 - region[-zone] where the clusteer will be created.
function delete_leaked_network_resources() { function resolve_k8s_version() {
# On boskos, don't bother with leaks as the janitor will delete everything in the project. local target_version="$1"
(( IS_BOSKOS )) && return if [[ "${target_version}" == "default" ]]; then
# Ensure we're using the GCP project used by kubetest local version="$(gcloud container get-server-config \
local gcloud_project="$(gcloud config get-value project)" --format='value(defaultClusterVersion)' \
local http_health_checks="$(gcloud compute target-pools list \ --zone=$2)"
--project=${gcloud_project} --format='value(healthChecks)' --filter="instances~-${E2E_CLUSTER_NAME}-" | \ [[ -z "${version}" ]] && return 1
grep httpHealthChecks | tr '\n' ' ')" E2E_CLUSTER_VERSION="${version}"
local target_pools="$(gcloud compute target-pools list \ echo "Using default version, ${E2E_CLUSTER_VERSION}"
--project=${gcloud_project} --format='value(name)' --filter="instances~-${E2E_CLUSTER_NAME}-" | \ return 0
tr '\n' ' ')"
if [[ -n "${target_pools}" ]]; then
echo "Found leaked target pools, deleting"
gcloud compute forwarding-rules delete -q --project=${gcloud_project} --region=${E2E_CLUSTER_REGION} ${target_pools}
gcloud compute target-pools delete -q --project=${gcloud_project} --region=${E2E_CLUSTER_REGION} ${target_pools}
fi fi
if [[ -n "${http_health_checks}" ]]; then # Fetch valid versions
echo "Found leaked health checks, deleting" local versions="$(gcloud container get-server-config \
gcloud compute http-health-checks delete -q --project=${gcloud_project} ${http_health_checks} --format='value(validMasterVersions)' \
--zone=$2)"
[[ -z "${versions}" ]] && return 1
local gke_versions=($(echo -n "${versions//;/ }"))
echo "Available GKE versions in $2 are [${versions//;/, }]"
if [[ "${target_version}" == "gke-latest" ]]; then
# Get first (latest) version, excluding the "-gke.#" suffix
E2E_CLUSTER_VERSION="${gke_versions[0]}"
echo "Using latest version, ${E2E_CLUSTER_VERSION}"
else
local latest="$(echo "${gke_versions[@]}" | tr ' ' '\n' | grep -E ^${target_version} | cut -f1 -d- | sort | tail -1)"
if [[ -z "${latest}" ]]; then
echo "ERROR: version ${target_version} is not available"
return 1
fi
E2E_CLUSTER_VERSION="${latest}"
echo "Using ${E2E_CLUSTER_VERSION} for supplied version ${target_version}"
fi fi
return 0
} }
# Create a test cluster with kubetest and call the current script again. # Create a test cluster with kubetest and call the current script again.
@ -172,9 +184,11 @@ function create_test_cluster() {
--deployment=gke --deployment=gke
--cluster="${E2E_CLUSTER_NAME}" --cluster="${E2E_CLUSTER_NAME}"
--gcp-network="${E2E_NETWORK_NAME}" --gcp-network="${E2E_NETWORK_NAME}"
--gcp-node-image="${SERVING_GKE_IMAGE}"
--gke-environment="${E2E_GKE_ENVIRONMENT}" --gke-environment="${E2E_GKE_ENVIRONMENT}"
--gke-command-group="${E2E_GKE_COMMAND_GROUP}" --gke-command-group="${E2E_GKE_COMMAND_GROUP}"
--test=false --test=false
--up
) )
if (( ! IS_BOSKOS )); then if (( ! IS_BOSKOS )); then
CLUSTER_CREATION_ARGS+=(--gcp-project=${GCP_PROJECT}) CLUSTER_CREATION_ARGS+=(--gcp-project=${GCP_PROJECT})
@ -200,21 +214,33 @@ function create_test_cluster() {
[[ -n "${GCP_PROJECT}" ]] && test_cmd_args+=" --gcp-project ${GCP_PROJECT}" [[ -n "${GCP_PROJECT}" ]] && test_cmd_args+=" --gcp-project ${GCP_PROJECT}"
[[ -n "${E2E_SCRIPT_CUSTOM_FLAGS[@]}" ]] && test_cmd_args+=" ${E2E_SCRIPT_CUSTOM_FLAGS[@]}" [[ -n "${E2E_SCRIPT_CUSTOM_FLAGS[@]}" ]] && test_cmd_args+=" ${E2E_SCRIPT_CUSTOM_FLAGS[@]}"
local extra_flags=() local extra_flags=()
# If using boskos, save time and let it tear down the cluster if (( IS_BOSKOS )); then # Add arbitrary duration, wait for Boskos projects acquisition before error out
(( ! IS_BOSKOS )) && extra_flags+=(--down) extra_flags+=(--boskos-wait-duration=20m)
else # Only let kubetest tear down the cluster if not using Boskos, it's done by Janitor if using Boskos
extra_flags+=(--down)
fi
# Set a minimal kubernetes environment that satisfies kubetest
# TODO(adrcunha): Remove once https://github.com/kubernetes/test-infra/issues/13029 is fixed.
local kubedir="$(mktemp -d -t kubernetes.XXXXXXXXXX)"
local test_wrapper="${kubedir}/e2e-test.sh"
mkdir ${kubedir}/cluster
ln -s "$(which kubectl)" ${kubedir}/cluster/kubectl.sh
echo "#!/bin/bash" > ${test_wrapper}
echo "cd $(pwd) && set -x" >> ${test_wrapper}
echo "${E2E_SCRIPT} ${test_cmd_args}" >> ${test_wrapper}
chmod +x ${test_wrapper}
cd ${kubedir}
# Create cluster and run the tests
create_test_cluster_with_retries "${CLUSTER_CREATION_ARGS[@]}" \ create_test_cluster_with_retries "${CLUSTER_CREATION_ARGS[@]}" \
--up \ --test-cmd "${test_wrapper}" \
--extract "${E2E_CLUSTER_VERSION}" \
--gcp-node-image "${SERVING_GKE_IMAGE}" \
--test-cmd "${E2E_SCRIPT}" \
--test-cmd-args "${test_cmd_args}" \
${extra_flags[@]} \ ${extra_flags[@]} \
${EXTRA_KUBETEST_FLAGS[@]} ${EXTRA_KUBETEST_FLAGS[@]}
echo "Test subprocess exited with code $?" echo "Test subprocess exited with code $?"
# Ignore any errors below, this is a best-effort cleanup and shouldn't affect the test result. # Ignore any errors below, this is a best-effort cleanup and shouldn't affect the test result.
set +o errexit set +o errexit
function_exists cluster_teardown && cluster_teardown function_exists cluster_teardown && cluster_teardown
delete_leaked_network_resources
local result=$(get_test_return_code) local result=$(get_test_return_code)
echo "Artifacts were written to ${ARTIFACTS}" echo "Artifacts were written to ${ARTIFACTS}"
echo "Test result code is ${result}" echo "Test result code is ${result}"
@ -240,21 +266,23 @@ function create_test_cluster_with_retries() {
echo "No backup region/zone set, cluster creation will fail in case of stockout" echo "No backup region/zone set, cluster creation will fail in case of stockout"
fi fi
local e2e_cluster_target_version="${E2E_CLUSTER_VERSION}"
for e2e_cluster_region in "${e2e_cluster_regions[@]}"; do for e2e_cluster_region in "${e2e_cluster_regions[@]}"; do
for e2e_cluster_zone in "${e2e_cluster_zones[@]}"; do for e2e_cluster_zone in "${e2e_cluster_zones[@]}"; do
E2E_CLUSTER_REGION=${e2e_cluster_region} E2E_CLUSTER_REGION=${e2e_cluster_region}
E2E_CLUSTER_ZONE=${e2e_cluster_zone} E2E_CLUSTER_ZONE=${e2e_cluster_zone}
[[ "${E2E_CLUSTER_ZONE}" == "${zone_not_provided}" ]] && E2E_CLUSTER_ZONE="" [[ "${E2E_CLUSTER_ZONE}" == "${zone_not_provided}" ]] && E2E_CLUSTER_ZONE=""
local cluster_creation_zone="${E2E_CLUSTER_REGION}"
[[ -n "${E2E_CLUSTER_ZONE}" ]] && cluster_creation_zone="${E2E_CLUSTER_REGION}-${E2E_CLUSTER_ZONE}"
resolve_k8s_version ${e2e_cluster_target_version} ${cluster_creation_zone} || return 1
local geoflag="--gcp-region=${E2E_CLUSTER_REGION}" header "Creating test cluster ${E2E_CLUSTER_VERSION} in ${cluster_creation_zone}"
[[ -n "${E2E_CLUSTER_ZONE}" ]] && geoflag="--gcp-zone=${E2E_CLUSTER_REGION}-${E2E_CLUSTER_ZONE}"
header "Creating test cluster in $E2E_CLUSTER_REGION $E2E_CLUSTER_ZONE"
# Don't fail test for kubetest, as it might incorrectly report test failure # Don't fail test for kubetest, as it might incorrectly report test failure
# if teardown fails (for details, see success() below) # if teardown fails (for details, see success() below)
set +o errexit set +o errexit
{ run_go_tool k8s.io/test-infra/kubetest \ export CLUSTER_API_VERSION=${E2E_CLUSTER_VERSION}
kubetest "$@" ${geoflag}; } 2>&1 | tee ${cluster_creation_log} run_go_tool k8s.io/test-infra/kubetest \
kubetest "$@" --gcp-region=${cluster_creation_zone} 2>&1 | tee ${cluster_creation_log}
# Exit if test succeeded # Exit if test succeeded
[[ "$(get_test_return_code)" == "0" ]] && return 0 [[ "$(get_test_return_code)" == "0" ]] && return 0
@ -262,7 +290,8 @@ function create_test_cluster_with_retries() {
# - stockout (https://github.com/knative/test-infra/issues/592) # - stockout (https://github.com/knative/test-infra/issues/592)
# - latest GKE not available in this region/zone yet (https://github.com/knative/test-infra/issues/694) # - latest GKE not available in this region/zone yet (https://github.com/knative/test-infra/issues/694)
[[ -z "$(grep -Fo 'does not have enough resources available to fulfill' ${cluster_creation_log})" \ [[ -z "$(grep -Fo 'does not have enough resources available to fulfill' ${cluster_creation_log})" \
&& -z "$(grep -Fo 'ResponseError: code=400, message=No valid versions with the prefix' ${cluster_creation_log})" ]] \ && -z "$(grep -Fo 'ResponseError: code=400, message=No valid versions with the prefix' ${cluster_creation_log})" \
&& -z "$(grep -Po 'ResponseError: code=400, message=Master version "[0-9a-z\-\.]+" is unsupported' ${cluster_creation_log})" ]] \
&& return 1 && return 1
done done
done done
@ -297,9 +326,14 @@ function setup_test_cluster() {
if [[ -z "$(kubectl get clusterrolebinding cluster-admin-binding 2> /dev/null)" ]]; then if [[ -z "$(kubectl get clusterrolebinding cluster-admin-binding 2> /dev/null)" ]]; then
acquire_cluster_admin_role ${k8s_user} ${E2E_CLUSTER_NAME} ${E2E_CLUSTER_REGION} ${E2E_CLUSTER_ZONE} acquire_cluster_admin_role ${k8s_user} ${E2E_CLUSTER_NAME} ${E2E_CLUSTER_REGION} ${E2E_CLUSTER_ZONE}
kubectl config set-context ${k8s_cluster} --namespace=default kubectl config set-context ${k8s_cluster} --namespace=default
export KO_DOCKER_REPO=gcr.io/${E2E_PROJECT_ID}/${E2E_BASE_NAME}-e2e-img # Incorporate an element of randomness to ensure that each run properly publishes images.
export KO_DOCKER_REPO=gcr.io/${E2E_PROJECT_ID}/${E2E_BASE_NAME}-e2e-img/${RANDOM}
fi fi
# Safety checks
is_protected_gcr ${KO_DOCKER_REPO} && \
abort "\$KO_DOCKER_REPO set to ${KO_DOCKER_REPO}, which is forbidden"
echo "- Project is ${E2E_PROJECT_ID}" echo "- Project is ${E2E_PROJECT_ID}"
echo "- Cluster is ${k8s_cluster}" echo "- Cluster is ${k8s_cluster}"
echo "- User is ${k8s_user}" echo "- User is ${k8s_user}"
@ -417,16 +451,12 @@ function initialize() {
echo "\$PROJECT_ID is set to '${PROJECT_ID}', using it to run the tests" echo "\$PROJECT_ID is set to '${PROJECT_ID}', using it to run the tests"
GCP_PROJECT="${PROJECT_ID}" GCP_PROJECT="${PROJECT_ID}"
fi fi
if (( ! IS_PROW )) && [[ -z "${GCP_PROJECT}" ]]; then if (( ! IS_PROW )) && (( ! RUN_TESTS )) && [[ -z "${GCP_PROJECT}" ]]; then
abort "set \$PROJECT_ID or use --gcp-project to select the GCP project where the tests are run" abort "set \$PROJECT_ID or use --gcp-project to select the GCP project where the tests are run"
fi fi
(( IS_PROW )) && [[ -z "${GCP_PROJECT}" ]] && IS_BOSKOS=1 (( IS_PROW )) && [[ -z "${GCP_PROJECT}" ]] && IS_BOSKOS=1
# Safety checks
is_protected_gcr ${KO_DOCKER_REPO} && \
abort "\$KO_DOCKER_REPO set to ${KO_DOCKER_REPO}, which is forbidden"
(( SKIP_ISTIO_ADDON )) || GKE_ADDONS="--addons=Istio" (( SKIP_ISTIO_ADDON )) || GKE_ADDONS="--addons=Istio"
readonly RUN_TESTS readonly RUN_TESTS

View File

@ -36,7 +36,8 @@ fi
# Useful environment variables # Useful environment variables
[[ -n "${PROW_JOB_ID:-}" ]] && IS_PROW=1 || IS_PROW=0 [[ -n "${PROW_JOB_ID:-}" ]] && IS_PROW=1 || IS_PROW=0
readonly IS_PROW readonly IS_PROW
readonly REPO_ROOT_DIR="$(git rev-parse --show-toplevel)" [[ -z "${REPO_ROOT_DIR:-}" ]] && REPO_ROOT_DIR="$(git rev-parse --show-toplevel)"
readonly REPO_ROOT_DIR
readonly REPO_NAME="$(basename ${REPO_ROOT_DIR})" readonly REPO_NAME="$(basename ${REPO_ROOT_DIR})"
# Useful flags about the current OS # Useful flags about the current OS
@ -75,6 +76,9 @@ function make_banner() {
local msg="$1$1$1$1 $2 $1$1$1$1" local msg="$1$1$1$1 $2 $1$1$1$1"
local border="${msg//[-0-9A-Za-z _.,\/()\']/$1}" local border="${msg//[-0-9A-Za-z _.,\/()\']/$1}"
echo -e "${border}\n${msg}\n${border}" echo -e "${border}\n${msg}\n${border}"
# TODO(adrcunha): Remove once logs have timestamps on Prow
# For details, see https://github.com/kubernetes/test-infra/issues/10100
echo -e "$1$1$1$1 $(TZ='America/Los_Angeles' date)\n${border}"
} }
# Simple header for logging purposes. # Simple header for logging purposes.
@ -253,7 +257,7 @@ function dump_app_logs() {
for pod in $(get_app_pods "$1" "$2") for pod in $(get_app_pods "$1" "$2")
do do
echo ">>> Pod: $pod" echo ">>> Pod: $pod"
kubectl -n "$2" logs "$pod" -c "$1" kubectl -n "$2" logs "$pod" --all-containers
done done
} }
@ -295,28 +299,72 @@ function acquire_cluster_admin_role() {
$2 ${geoflag} --project $(gcloud config get-value project) $2 ${geoflag} --project $(gcloud config get-value project)
} }
# Run a command through tee and capture its output.
# Parameters: $1 - file where the output will be stored.
# $2... - command to run.
function capture_output() {
local report="$1"
shift
"$@" 2>&1 | tee "${report}"
local failed=( ${PIPESTATUS[@]} )
[[ ${failed[0]} -eq 0 ]] && failed=${failed[1]} || failed=${failed[0]}
return ${failed}
}
# Create a JUnit XML for a test.
# Parameters: $1 - check class name as an identifier (e.g. BuildTests)
# $2 - check name as an identifier (e.g., GoBuild)
# $3 - failure message (can contain newlines), optional (means success)
function create_junit_xml() {
local xml="$(mktemp ${ARTIFACTS}/junit_XXXXXXXX.xml)"
local failure=""
if [[ "$3" != "" ]]; then
# Transform newlines into HTML code.
# Also escape `<` and `>` as here: https://github.com/golang/go/blob/50bd1c4d4eb4fac8ddeb5f063c099daccfb71b26/src/encoding/json/encode.go#L48,
# this is temporary solution for fixing https://github.com/knative/test-infra/issues/1204,
# which should be obsolete once Test-infra 2.0 is in place
local msg="$(echo -n "$3" | sed 's/$/\&#xA;/g' | sed 's/</\\u003c/' | sed 's/>/\\u003e/' | tr -d '\n')"
failure="<failure message=\"Failed\" type=\"\">${msg}</failure>"
fi
cat << EOF > "${xml}"
<testsuites>
<testsuite tests="1" failures="1" time="0.000" name="$1">
<testcase classname="" name="$2" time="0.0">
${failure}
</testcase>
</testsuite>
</testsuites>
EOF
}
# Runs a go test and generate a junit summary. # Runs a go test and generate a junit summary.
# Parameters: $1... - parameters to go test # Parameters: $1... - parameters to go test
function report_go_test() { function report_go_test() {
# Run tests in verbose mode to capture details. # Run tests in verbose mode to capture details.
# go doesn't like repeating -v, so remove if passed. # go doesn't like repeating -v, so remove if passed.
local args=" $@ " local args=" $@ "
local go_test="go test -race -v ${args/ -v / }" local go_test="go test -v ${args/ -v / }"
# Just run regular go tests if not on Prow. # Just run regular go tests if not on Prow.
echo "Running tests with '${go_test}'" echo "Running tests with '${go_test}'"
local report=$(mktemp) local report="$(mktemp)"
${go_test} | tee ${report} capture_output "${report}" ${go_test}
local failed=( ${PIPESTATUS[@]} ) local failed=$?
[[ ${failed[0]} -eq 0 ]] && failed=${failed[1]} || failed=${failed[0]}
echo "Finished run, return code is ${failed}" echo "Finished run, return code is ${failed}"
# Install go-junit-report if necessary. # Install go-junit-report if necessary.
run_go_tool github.com/jstemmer/go-junit-report go-junit-report --help > /dev/null 2>&1 run_go_tool github.com/jstemmer/go-junit-report go-junit-report --help > /dev/null 2>&1
local xml=$(mktemp ${ARTIFACTS}/junit_XXXXXXXX.xml) local xml=$(mktemp ${ARTIFACTS}/junit_XXXXXXXX.xml)
cat ${report} \ cat ${report} \
| go-junit-report \ | go-junit-report \
| sed -e "s#\"github.com/knative/${REPO_NAME}/#\"#g" \ | sed -e "s#\"\(github\.com/knative\|knative\.dev\)/${REPO_NAME}/#\"#g" \
> ${xml} > ${xml}
echo "XML report written to ${xml}" echo "XML report written to ${xml}"
if [[ -n "$(grep '<testsuites></testsuites>' ${xml})" ]]; then
# XML report is empty, something's wrong; use the output as failure reason
create_junit_xml _go_tests "GoTests" "$(cat ${report})"
fi
# Capture and report any race condition errors
local race_errors="$(sed -n '/^WARNING: DATA RACE$/,/^==================$/p' ${report})"
create_junit_xml _go_tests "DataRaceAnalysis" "${race_errors}"
if (( ! IS_PROW )); then if (( ! IS_PROW )); then
# Keep the suffix, so files are related. # Keep the suffix, so files are related.
local logfile=${xml/junit_/go_test_} local logfile=${xml/junit_/go_test_}
@ -327,24 +375,29 @@ function report_go_test() {
return ${failed} return ${failed}
} }
# Install the latest stable Knative/serving in the current cluster. # Install Knative Serving in the current cluster.
function start_latest_knative_serving() { # Parameters: $1 - Knative Serving manifest.
function start_knative_serving() {
header "Starting Knative Serving" header "Starting Knative Serving"
subheader "Installing Knative Serving" subheader "Installing Knative Serving"
echo "Installing Serving from ${KNATIVE_SERVING_RELEASE}" echo "Installing Serving CRDs from $1"
# Some CRDs defined in serving YAML are also referenced by other components in serving. As it takes kubectl apply --selector knative.dev/crd-install=true -f "$1"
# time for CRDs to become effective, there is a race condition between when the CRDs are effective echo "Installing the rest of serving components from $1"
# and when the resources that references those CRDs are created. kubectl apply -f "$1"
# The current workaround is to re-apply serving.yaml if it fails. Remove the retry logic after the
# race condition is fixed. (https://github.com/knative/serving/issues/4176)
if ! kubectl apply -f ${KNATIVE_SERVING_RELEASE}; then
echo "Install failed, waiting 60s and then retrying..."
sleep 60
kubectl apply -f ${KNATIVE_SERVING_RELEASE} || return 1
fi
wait_until_pods_running knative-serving || return 1 wait_until_pods_running knative-serving || return 1
} }
# Install the stable release Knative/serving in the current cluster.
# Parameters: $1 - Knative Serving version number, e.g. 0.6.0.
function start_release_knative_serving() {
start_knative_serving "https://storage.googleapis.com/knative-releases/serving/previous/v$1/serving.yaml"
}
# Install the latest stable Knative Serving in the current cluster.
function start_latest_knative_serving() {
start_knative_serving "${KNATIVE_SERVING_RELEASE}"
}
# Run a go tool, installing it first if necessary. # Run a go tool, installing it first if necessary.
# Parameters: $1 - tool package/dir for go get/install. # Parameters: $1 - tool package/dir for go get/install.
# $2 - tool to run. # $2 - tool to run.
@ -367,16 +420,17 @@ function update_licenses() {
cd ${REPO_ROOT_DIR} || return 1 cd ${REPO_ROOT_DIR} || return 1
local dst=$1 local dst=$1
shift shift
run_go_tool ./vendor/github.com/knative/test-infra/tools/dep-collector dep-collector $@ > ./${dst} run_go_tool knative.dev/test-infra/tools/dep-collector dep-collector $@ > ./${dst}
} }
# Run dep-collector to check for forbidden liceses. # Run dep-collector to check for forbidden liceses.
# Parameters: $1...$n - directories and files to inspect. # Parameters: $1...$n - directories and files to inspect.
function check_licenses() { function check_licenses() {
# Fetch the google/licenseclassifier for its license db # Fetch the google/licenseclassifier for its license db
rm -fr ${GOPATH}/src/github.com/google/licenseclassifier
go get -u github.com/google/licenseclassifier go get -u github.com/google/licenseclassifier
# Check that we don't have any forbidden licenses in our images. # Check that we don't have any forbidden licenses in our images.
run_go_tool ./vendor/github.com/knative/test-infra/tools/dep-collector dep-collector -check $@ run_go_tool knative.dev/test-infra/tools/dep-collector dep-collector -check $@
} }
# Run the given linter on the given files, checking it exists first. # Run the given linter on the given files, checking it exists first.
@ -457,7 +511,7 @@ function remove_broken_symlinks() {
target="${target##* -> }" target="${target##* -> }"
[[ ${target} == /* ]] || target="./${target}" [[ ${target} == /* ]] || target="./${target}"
target="$(cd `dirname ${link}` && cd ${target%/*} && echo $PWD/${target##*/})" target="$(cd `dirname ${link}` && cd ${target%/*} && echo $PWD/${target##*/})"
if [[ ${target} != *github.com/knative/* ]]; then if [[ ${target} != *github.com/knative/* && ${target} != *knative.dev/* ]]; then
unlink ${link} unlink ${link}
continue continue
fi fi
@ -475,31 +529,41 @@ function get_canonical_path() {
echo "$(cd ${path%/*} && echo $PWD/${path##*/})" echo "$(cd ${path%/*} && echo $PWD/${path##*/})"
} }
# Return the base url we use to build the actual knative yaml sources. # Returns the URL to the latest manifest for the given Knative project.
function get_knative_base_yaml_source() { # Parameters: $1 - repository name of the given project
local knative_base_yaml_source="https://storage.googleapis.com/knative-nightly/@/latest" # $2 - name of the yaml file, without extension
function get_latest_knative_yaml_source() {
local branch_name="" local branch_name=""
local repo_name="$1"
local yaml_name="$2"
# Get the branch name from Prow's env var, see https://github.com/kubernetes/test-infra/blob/master/prow/jobs.md. # Get the branch name from Prow's env var, see https://github.com/kubernetes/test-infra/blob/master/prow/jobs.md.
# Otherwise, try getting the current branch from git. # Otherwise, try getting the current branch from git.
(( IS_PROW )) && branch_name="${PULL_BASE_REF:-}" (( IS_PROW )) && branch_name="${PULL_BASE_REF:-}"
[[ -z "${branch_name}" ]] && branch_name="$(git rev-parse --abbrev-ref HEAD)" [[ -z "${branch_name}" ]] && branch_name="$(git rev-parse --abbrev-ref HEAD)"
# If it's a release branch, base URL should point to a specific version. # If it's a release branch, the yaml source URL should point to a specific version.
if [[ ${branch_name} =~ ^release-[0-9\.]+$ ]]; then if [[ ${branch_name} =~ ^release-[0-9\.]+$ ]]; then
# Get the latest tag name for the current branch, which is likely formatted as v0.5.0 # Get the latest tag name for the current branch, which is likely formatted as v0.5.0
local tag_name="$(git describe --tags --abbrev=0)" local tag_name="$(git describe --tags --abbrev=0)"
knative_base_yaml_source="https://storage.googleapis.com/knative-releases/@/previous/${tag_name}" # The given repo might not have this tag, so we need to find its latest release manifest with the same major&minor version.
local major_minor="$(echo ${tag_name} | cut -d. -f1-2)"
local yaml_source_path="$(gsutil ls gs://knative-releases/${repo_name}/previous/${major_minor}.*/${yaml_name}.yaml \
| sort \
| tail -n 1 \
| cut -b6-)"
echo "https://storage.googleapis.com/${yaml_source_path}"
# If it's not a release branch, the yaml source URL should be nightly build.
else
echo "https://storage.googleapis.com/knative-nightly/${repo_name}/latest/${yaml_name}.yaml"
fi fi
echo "${knative_base_yaml_source}"
} }
# Initializations that depend on previous functions. # Initializations that depend on previous functions.
# These MUST come last. # These MUST come last.
readonly _TEST_INFRA_SCRIPTS_DIR="$(dirname $(get_canonical_path ${BASH_SOURCE[0]}))" readonly _TEST_INFRA_SCRIPTS_DIR="$(dirname $(get_canonical_path ${BASH_SOURCE[0]}))"
readonly REPO_NAME_FORMATTED="Knative $(capitalize ${REPO_NAME//-/})" readonly REPO_NAME_FORMATTED="Knative $(capitalize ${REPO_NAME//-/ })"
# Public latest nightly or release yaml files. # Public latest nightly or release yaml files.
readonly KNATIVE_BASE_YAML_SOURCE="$(get_knative_base_yaml_source)" readonly KNATIVE_SERVING_RELEASE="$(get_latest_knative_yaml_source "serving" "serving")"
readonly KNATIVE_SERVING_RELEASE="${KNATIVE_BASE_YAML_SOURCE/@/serving}/serving.yaml" readonly KNATIVE_BUILD_RELEASE="$(get_latest_knative_yaml_source "build" "build")"
readonly KNATIVE_BUILD_RELEASE="${KNATIVE_BASE_YAML_SOURCE/@/build}/build.yaml" readonly KNATIVE_EVENTING_RELEASE="$(get_latest_knative_yaml_source "eventing" "release")"
readonly KNATIVE_EVENTING_RELEASE="${KNATIVE_BASE_YAML_SOURCE/@/eventing}/release.yaml"

View File

@ -111,6 +111,19 @@ function run_build_tests() {
return ${failed} return ${failed}
} }
# Run a build test and report its output as the failure if it fails.
# Parameters: $1 - report name.
# $2... - command (test) to run.
function report_build_test() {
local report="$(mktemp)"
local report_name="$1"
shift
local errors=""
capture_output "${report}" "$@" || errors="$(cat ${report})"
create_junit_xml _build_tests "${report_name}" "${errors}"
[[ -z "${errors}" ]]
}
# Perform markdown build tests if necessary, unless disabled. # Perform markdown build tests if necessary, unless disabled.
function markdown_build_tests() { function markdown_build_tests() {
(( DISABLE_MD_LINTING && DISABLE_MD_LINK_CHECK )) && return 0 (( DISABLE_MD_LINTING && DISABLE_MD_LINK_CHECK )) && return 0
@ -123,11 +136,11 @@ function markdown_build_tests() {
local failed=0 local failed=0
if (( ! DISABLE_MD_LINTING )); then if (( ! DISABLE_MD_LINTING )); then
subheader "Linting the markdown files" subheader "Linting the markdown files"
lint_markdown ${mdfiles} || failed=1 report_build_test Markdown_Lint lint_markdown ${mdfiles} || failed=1
fi fi
if (( ! DISABLE_MD_LINK_CHECK )); then if (( ! DISABLE_MD_LINK_CHECK )); then
subheader "Checking links in the markdown files" subheader "Checking links in the markdown files"
check_links_in_markdown ${mdfiles} || failed=1 report_build_test Markdown_Link check_links_in_markdown ${mdfiles} || failed=1
fi fi
return ${failed} return ${failed}
} }
@ -148,20 +161,34 @@ function default_build_test_runner() {
[[ -z "${go_pkg_dirs}" ]] && return ${failed} [[ -z "${go_pkg_dirs}" ]] && return ${failed}
# Ensure all the code builds # Ensure all the code builds
subheader "Checking that go code builds" subheader "Checking that go code builds"
go build -v ./... || failed=1 local report="$(mktemp)"
local errors_go1=""
local errors_go2=""
if ! capture_output "${report}" go build -v ./... ; then
failed=1
# Consider an error message everything that's not a package name.
errors_go1="$(grep -v '^\(github\.com\|knative\.dev\)/' "${report}" | sort | uniq)"
fi
# Get all build tags in go code (ignore /vendor) # Get all build tags in go code (ignore /vendor)
local tags="$(grep -r '// +build' . \ local tags="$(grep -r '// +build' . \
| grep -v '^./vendor/' | cut -f3 -d' ' | sort | uniq | tr '\n' ' ')" | grep -v '^./vendor/' | cut -f3 -d' ' | sort | uniq | tr '\n' ' ')"
if [[ -n "${tags}" ]]; then if [[ -n "${tags}" ]]; then
go test -run=^$ -tags="${tags}" ./... || failed=1 errors=""
if ! capture_output "${report}" go test -run=^$ -tags="${tags}" ./... ; then
failed=1
# Consider an error message everything that's not a successful test result.
errors_go2="$(grep -v '^\(ok\|\?\)\s\+\(github\.com\|knative\.dev\)/' "${report}")"
fi
fi fi
local errors_go="$(echo -e "${errors_go1}\n${errors_go2}" | uniq)"
create_junit_xml _build_tests Build_Go "${errors_go}"
if [[ -f ./hack/verify-codegen.sh ]]; then if [[ -f ./hack/verify-codegen.sh ]]; then
subheader "Checking autogenerated code is up-to-date" subheader "Checking autogenerated code is up-to-date"
./hack/verify-codegen.sh || failed=1 report_build_test Verify_CodeGen ./hack/verify-codegen.sh || failed=1
fi fi
# Check that we don't have any forbidden licenses in our images. # Check that we don't have any forbidden licenses in our images.
subheader "Checking for forbidden licenses" subheader "Checking for forbidden licenses"
check_licenses ${go_pkg_dirs} || failed=1 report_build_test Check_Licenses check_licenses ${go_pkg_dirs} || failed=1
return ${failed} return ${failed}
} }
@ -197,7 +224,7 @@ function run_unit_tests() {
# Default unit test runner that runs all go tests in the repo. # Default unit test runner that runs all go tests in the repo.
function default_unit_test_runner() { function default_unit_test_runner() {
report_go_test ./... report_go_test -race ./...
} }
# Run integration tests. If there's no `integration_tests` function, run the # Run integration tests. If there's no `integration_tests` function, run the
@ -272,12 +299,23 @@ function main() {
go version go version
echo ">> git version" echo ">> git version"
git version git version
echo ">> ko built from commit"
[[ -f /ko_version ]] && cat /ko_version || echo "unknown"
echo ">> bazel version" echo ">> bazel version"
bazel version 2> /dev/null [[ -f /bazel_version ]] && cat /bazel_version || echo "unknown"
if [[ "${DOCKER_IN_DOCKER_ENABLED}" == "true" ]]; then if [[ "${DOCKER_IN_DOCKER_ENABLED}" == "true" ]]; then
echo ">> docker version" echo ">> docker version"
docker version docker version
fi fi
# node/pod names are important for debugging purposes, but they are missing
# after migrating from bootstrap to podutil.
# Report it here with the same logic as in bootstrap until it is fixed.
# (https://github.com/kubernetes/test-infra/blob/09bd4c6709dc64308406443f8996f90cf3b40ed1/jenkins/bootstrap.py#L588)
# TODO(chaodaiG): follow up on https://github.com/kubernetes/test-infra/blob/0fabd2ea816daa8c15d410c77a0c93c0550b283f/prow/initupload/run.go#L49
echo ">> node name"
echo "$(curl -H "Metadata-Flavor: Google" 'http://169.254.169.254/computeMetadata/v1/instance/name' 2> /dev/null)"
echo ">> pod name"
echo ${HOSTNAME}
fi fi
[[ -z $1 ]] && set -- "--all-tests" [[ -z $1 ]] && set -- "--all-tests"

View File

@ -19,12 +19,15 @@
source $(dirname ${BASH_SOURCE})/library.sh source $(dirname ${BASH_SOURCE})/library.sh
# Organization name in GitHub; defaults to Knative.
readonly ORG_NAME="${ORG_NAME:-knative}"
# GitHub upstream. # GitHub upstream.
readonly KNATIVE_UPSTREAM="https://github.com/knative/${REPO_NAME}" readonly REPO_UPSTREAM="https://github.com/${ORG_NAME}/${REPO_NAME}"
# GCRs for Knative releases. # GCRs for Knative releases.
readonly NIGHTLY_GCR="gcr.io/knative-nightly/github.com/knative/${REPO_NAME}" readonly NIGHTLY_GCR="gcr.io/knative-nightly/github.com/${ORG_NAME}/${REPO_NAME}"
readonly RELEASE_GCR="gcr.io/knative-releases/github.com/knative/${REPO_NAME}" readonly RELEASE_GCR="gcr.io/knative-releases/github.com/${ORG_NAME}/${REPO_NAME}"
# Georeplicate images to {us,eu,asia}.gcr.io # Georeplicate images to {us,eu,asia}.gcr.io
readonly GEO_REPLICATION=(us eu asia) readonly GEO_REPLICATION=(us eu asia)
@ -108,7 +111,7 @@ function hub_tool() {
# Shortcut to "git push" that handles authentication. # Shortcut to "git push" that handles authentication.
# Parameters: $1..$n - arguments to "git push <repo>". # Parameters: $1..$n - arguments to "git push <repo>".
function git_push() { function git_push() {
local repo_url="${KNATIVE_UPSTREAM}" local repo_url="${REPO_UPSTREAM}"
[[ -n "${GITHUB_TOKEN}}" ]] && repo_url="${repo_url/:\/\//:\/\/${GITHUB_TOKEN}@}" [[ -n "${GITHUB_TOKEN}}" ]] && repo_url="${repo_url/:\/\//:\/\/${GITHUB_TOKEN}@}"
git push ${repo_url} $@ git push ${repo_url} $@
} }
@ -144,15 +147,15 @@ function setup_upstream() {
local upstream="$(git config --get remote.upstream.url)" local upstream="$(git config --get remote.upstream.url)"
echo "Remote upstream URL is '${upstream}'" echo "Remote upstream URL is '${upstream}'"
if [[ -z "${upstream}" ]]; then if [[ -z "${upstream}" ]]; then
echo "Setting remote upstream URL to '${KNATIVE_UPSTREAM}'" echo "Setting remote upstream URL to '${REPO_UPSTREAM}'"
git remote add upstream ${KNATIVE_UPSTREAM} git remote add upstream ${REPO_UPSTREAM}
fi fi
} }
# Fetch the release branch, so we can check it out. # Fetch the release branch, so we can check it out.
function setup_branch() { function setup_branch() {
[[ -z "${RELEASE_BRANCH}" ]] && return [[ -z "${RELEASE_BRANCH}" ]] && return
git fetch ${KNATIVE_UPSTREAM} ${RELEASE_BRANCH}:upstream/${RELEASE_BRANCH} git fetch ${REPO_UPSTREAM} ${RELEASE_BRANCH}:upstream/${RELEASE_BRANCH}
} }
# Setup version, branch and release notes for a auto release. # Setup version, branch and release notes for a auto release.
@ -198,6 +201,7 @@ function prepare_dot_release() {
echo "Dot release requested" echo "Dot release requested"
TAG_RELEASE=1 TAG_RELEASE=1
PUBLISH_RELEASE=1 PUBLISH_RELEASE=1
git fetch --all || abort "error fetching branches/tags from remote"
# List latest release # List latest release
local releases # don't combine with the line below, or $? will be 0 local releases # don't combine with the line below, or $? will be 0
releases="$(hub_tool release)" releases="$(hub_tool release)"
@ -210,21 +214,26 @@ function prepare_dot_release() {
fi fi
local last_version="$(echo "${releases}" | grep '^v[0-9]\+\.[0-9]\+\.[0-9]\+$' | sort -r | head -1)" local last_version="$(echo "${releases}" | grep '^v[0-9]\+\.[0-9]\+\.[0-9]\+$' | sort -r | head -1)"
[[ -n "${last_version}" ]] || abort "no previous release exist" [[ -n "${last_version}" ]] || abort "no previous release exist"
local major_minor_version=""
if [[ -z "${RELEASE_BRANCH}" ]]; then if [[ -z "${RELEASE_BRANCH}" ]]; then
echo "Last release is ${last_version}" echo "Last release is ${last_version}"
# Determine branch # Determine branch
local major_minor_version="$(master_version ${last_version})" major_minor_version="$(master_version ${last_version})"
RELEASE_BRANCH="release-${major_minor_version}" RELEASE_BRANCH="release-${major_minor_version}"
echo "Last release branch is ${RELEASE_BRANCH}" echo "Last release branch is ${RELEASE_BRANCH}"
else
major_minor_version="${RELEASE_BRANCH##release-}"
fi fi
[[ -n "${major_minor_version}" ]] || abort "cannot get release major/minor version"
# Ensure there are new commits in the branch, otherwise we don't create a new release # Ensure there are new commits in the branch, otherwise we don't create a new release
setup_branch setup_branch
local last_release_commit="$(git rev-list -n 1 ${last_version})" local last_release_commit="$(git rev-list -n 1 ${last_version})"
local release_branch_commit="$(git rev-list -n 1 upstream/${RELEASE_BRANCH})" local release_branch_commit="$(git rev-list -n 1 upstream/${RELEASE_BRANCH})"
[[ -n "${last_release_commit}" ]] || abort "cannot get last release commit" [[ -n "${last_release_commit}" ]] || abort "cannot get last release commit"
[[ -n "${release_branch_commit}" ]] || abort "cannot get release branch last commit" [[ -n "${release_branch_commit}" ]] || abort "cannot get release branch last commit"
echo "Version ${last_version} is at commit ${last_release_commit}"
echo "Branch ${RELEASE_BRANCH} is at commit ${release_branch_commit}"
if [[ "${last_release_commit}" == "${release_branch_commit}" ]]; then if [[ "${last_release_commit}" == "${release_branch_commit}" ]]; then
echo "*** Branch ${RELEASE_BRANCH} is at commit ${release_branch_commit}"
echo "*** Branch ${RELEASE_BRANCH} has no new cherry-picks since release ${last_version}" echo "*** Branch ${RELEASE_BRANCH} has no new cherry-picks since release ${last_version}"
echo "*** No dot release will be generated, as no changes exist" echo "*** No dot release will be generated, as no changes exist"
exit 0 exit 0
@ -549,10 +558,17 @@ function publish_to_github() {
git_push tag ${TAG} git_push tag ${TAG}
[[ -n "${RELEASE_BRANCH}" ]] && commitish="--commitish=${RELEASE_BRANCH}" [[ -n "${RELEASE_BRANCH}" ]] && commitish="--commitish=${RELEASE_BRANCH}"
hub_tool release create \ for i in {2..0}; do
--prerelease \ hub_tool release create \
${attachments[@]} \ --prerelease \
--file=${description} \ ${attachments[@]} \
${commitish} \ --file=${description} \
${TAG} ${commitish} \
${TAG} && return 0
if [[ "${i}" -gt 0 ]]; then
echo "Error publishing the release, retrying in 15s..."
sleep 15
fi
done
abort "Cannot publish release to GitHub"
} }

View File

@ -1,14 +1,14 @@
# dep-collector # dep-collector
`dep-collector` is a tool for gathering up a collection of licenses for Go `dep-collector` is a tool for gathering up a collection of licenses for Go
dependencies that have been pulled into the idiomatic `vendor/` directory. dependencies that have been pulled into the idiomatic `vendor/` directory. The
The resulting file from running `dep-collector` is intended for inclusion resulting file from running `dep-collector` is intended for inclusion in
in container images to respect the licenses of the included software. container images to respect the licenses of the included software.
## Basic Usage ## Basic Usage
You can run `dep-collector` on one or more Go import paths as entrypoints, You can run `dep-collector` on one or more Go import paths as entrypoints, and
and it will: it will:
1. Walk the transitive dependencies to identify vendored software packages, 1. Walk the transitive dependencies to identify vendored software packages,
1. Search for licenses for each vendored dependency, 1. Search for licenses for each vendored dependency,
@ -43,11 +43,11 @@ Import: github.com/mattmoor/warm-image/vendor/cloud.google.com/go
## CSV Usage ## CSV Usage
You can also run `dep-collector` in a mode that produces CSV output, You can also run `dep-collector` in a mode that produces CSV output, including
including basic classification of the license. basic classification of the license.
> In order to run dep-collector in this mode, you must first run: > In order to run dep-collector in this mode, you must first run: go get
> go get github.com/google/licenseclassifier > github.com/google/licenseclassifier
For example: For example:
@ -61,18 +61,19 @@ github.com/sergi/go-diff,Static,,https://github.com/mattmoor/dep-collector/blob/
The columns here are: The columns here are:
* Import Path, - Import Path,
* How the dependency is linked in (always reports "static"), - How the dependency is linked in (always reports "static"),
* A column for whether any modifications have been made (always empty), - A column for whether any modifications have been made (always empty),
* The URL by which to access the license file (assumes `master`), - The URL by which to access the license file (assumes `master`),
* A classification of what license this is ([using this](https://github.com/google/licenseclassifier)). - A classification of what license this is
([using this](https://github.com/google/licenseclassifier)).
## Check mode ## Check mode
`dep-collector` also includes a mode that will check for "forbidden" licenses. `dep-collector` also includes a mode that will check for "forbidden" licenses.
> In order to run dep-collector in this mode, you must first run: > In order to run dep-collector in this mode, you must first run: go get
> go get github.com/google/licenseclassifier > github.com/google/licenseclassifier
For example (failing): For example (failing):