diff --git a/cluster/log-dump/log-dump.sh b/cluster/log-dump/log-dump.sh index 2c8a33f1f27..69cff81550e 100755 --- a/cluster/log-dump/log-dump.sh +++ b/cluster/log-dump/log-dump.sh @@ -22,6 +22,7 @@ set -o nounset set -o pipefail readonly report_dir="${1:-_artifacts}" +readonly gcs_artifacts_dir="${2:-}" # In order to more trivially extend log-dump for custom deployments, # check for a function named log_dump_custom_get_instances. If it's @@ -271,7 +272,6 @@ function dump_nodes_with_logexporter() { # Obtain parameters required by logexporter. local -r service_account_credentials="$(cat ${GOOGLE_APPLICATION_CREDENTIALS} | base64)" local -r cloud_provider="${KUBERNETES_PROVIDER}" - local -r gcs_artifacts_dir="${GCS_ARTIFACTS_DIR}" local -r enable_hollow_node_logs="${ENABLE_HOLLOW_NODE_LOGS:-false}" local -r logexport_timeout_seconds="$(( 30 + NUM_NODES / 10 ))" @@ -347,12 +347,8 @@ function main() { fi # Copy logs from nodes to GCS directly or to artifacts dir locally (through SSH). - if [[ "${ENABLE_LOGEXPORTER:-}" == "true" ]]; then - if [[ -z "${GCS_ARTIFACTS_DIR:-}" ]]; then - echo "Env var GCS_ARTIFACTS_DIR is empty. Failed to dump node logs to GCS." - exit 1 - fi - echo "Dumping logs from nodes to GCS directly at '${GCS_ARTIFACTS_DIR}'" + if [[ -n "${gcs_artifacts_dir}" ]]; then + echo "Dumping logs from nodes to GCS directly at '${gcs_artifacts_dir}' using logexporter" dump_nodes_with_logexporter else echo "Dumping logs from nodes locally to '${report_dir}'" diff --git a/hack/verify-flags/known-flags.txt b/hack/verify-flags/known-flags.txt index 33d02fdd602..19ca34aec23 100644 --- a/hack/verify-flags/known-flags.txt +++ b/hack/verify-flags/known-flags.txt @@ -448,6 +448,7 @@ load-balancer-ip lock-file log-flush-frequency log-lines-total +logexporter-gcs-path long-running-request-regexp low-diskspace-threshold-mb make-iptables-util-chains diff --git a/test/e2e/framework/test_context.go b/test/e2e/framework/test_context.go index 9da61182737..49bf0e2b6ff 100644 --- a/test/e2e/framework/test_context.go +++ b/test/e2e/framework/test_context.go @@ -87,6 +87,8 @@ type TestContextType struct { DumpLogsOnFailure bool // Disables dumping cluster log from master and nodes after all tests. DisableLogDump bool + // Path to the GCS artifacts directory to dump logs from nodes. Logexporter gets enabled if this is non-empty. + LogexporterGCSPath string // If the garbage collector is enabled in the kube-apiserver and kube-controller-manager. GarbageCollectorEnabled bool // FeatureGates is a set of key=value pairs that describe feature gates for alpha/experimental features. @@ -174,6 +176,7 @@ func RegisterCommonFlags() { flag.StringVar(&TestContext.OutputPrintType, "output-print-type", "json", "Format in which summaries should be printed: 'hr' for human readable, 'json' for JSON ones.") flag.BoolVar(&TestContext.DumpLogsOnFailure, "dump-logs-on-failure", true, "If set to true test will dump data about the namespace in which test was running.") flag.BoolVar(&TestContext.DisableLogDump, "disable-log-dump", false, "If set to true, logs from master and nodes won't be gathered after test run.") + flag.StringVar(&TestContext.LogexporterGCSPath, "logexporter-gcs-path", "", "Path to the GCS artifacts directory to dump logs from nodes. Logexporter gets enabled if this is non-empty.") flag.BoolVar(&TestContext.DeleteNamespace, "delete-namespace", true, "If true tests will delete namespace after completion. It is only designed to make debugging easier, DO NOT turn it off by default.") flag.BoolVar(&TestContext.DeleteNamespaceOnFailure, "delete-namespace-on-failure", true, "If true, framework will delete test namespace on failure. Used only during test debugging.") flag.IntVar(&TestContext.AllowedNotReadyNodes, "allowed-not-ready-nodes", 0, "If non-zero, framework will allow for that many non-ready nodes when checking for all ready nodes.") diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 93d788c1a9c..c5d84b83366 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -4303,7 +4303,14 @@ func CoreDump(dir string) { Logf("Skipping dumping logs from cluster") return } - cmd := exec.Command(path.Join(TestContext.RepoRoot, "cluster", "log-dump", "log-dump.sh"), dir) + var cmd *exec.Cmd + if TestContext.LogexporterGCSPath != "" { + Logf("Dumping logs from nodes to GCS directly at path: %s", TestContext.LogexporterGCSPath) + cmd = exec.Command(path.Join(TestContext.RepoRoot, "cluster", "log-dump", "log-dump.sh"), dir, TestContext.LogexporterGCSPath) + } else { + Logf("Dumping logs locally to: %s", dir) + cmd = exec.Command(path.Join(TestContext.RepoRoot, "cluster", "log-dump", "log-dump.sh"), dir) + } cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil {