Repository: knative/pkg
Pull request #1354 (2020-05-26 12:14:19)

[POST-RELEASE] Track master branches again.

knative-prow-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/1354#" title="Author self-approved">markusthoemmes</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **vaikas**
You can assign the PR to them by writing `/assign @vaikas` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/knative/pkg/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["vaikas"]} -->

Patch:
diff --git a/go.mod b/go.mod
index e4baf0641..8ac0748ad 100644
--- a/go.mod
+++ b/go.mod
@@ -48,7 +48,7 @@ require (
 	k8s.io/klog v1.0.0
 	k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a
 	k8s.io/test-infra v0.0.0-20200407001919-bc7f71ef65b8
-	knative.dev/test-infra v0.0.0-20200519015156-82551620b0a9
+	knative.dev/test-infra v0.0.0-20200522180958-6a0a9b9d893a
 )
 
 replace (
diff --git a/go.sum b/go.sum
index 80335d18d..88b841117 100644
--- a/go.sum
+++ b/go.sum
@@ -1349,12 +1349,15 @@ knative.dev/pkg v0.0.0-20191111150521-6d806b998379/go.mod h1:pgODObA1dTyhNoFxPZT
 knative.dev/pkg v0.0.0-20200428194351-90fc61bae7f7/go.mod h1:o+e8OVEJKIuvXPsGVPIautjXgs05xbos7G+QMRjuUps=
 knative.dev/pkg v0.0.0-20200505191044-3da93ebb24c2/go.mod h1:Q6sL35DdGs8hIQZKdaCXJGgY8f90BmNBKSb8z6d/BTM=
 knative.dev/pkg v0.0.0-20200515002500-16d7b963416f/go.mod h1:tMOHGbxtRz8zYFGEGpV/bpoTEM1o89MwYFC4YJXl3GY=
+knative.dev/pkg v0.0.0-20200520073958-94316e20e860/go.mod h1:QgNZTxnwpB/oSpNcfnLVlw+WpEwwyKAvJlvR3hgeltA=
 knative.dev/test-infra v0.0.0-20200407185800-1b88cb3b45a5/go.mod h1:xcdUkMJrLlBswIZqL5zCuBFOC22WIPMQoVX1L35i0vQ=
 knative.dev/test-infra v0.0.0-20200505052144-5ea2f705bb55/go.mod h1:WqF1Azka+FxPZ20keR2zCNtiQA1MP9ZB4BH4HuI+SIU=
 knative.dev/test-infra v0.0.0-20200513011557-d03429a76034 h1:JxqONCZVS7or+Fv3ebVQoipuIBH7Ig3Qbx170hgIF+A=
 knative.dev/test-infra v0.0.0-20200513011557-d03429a76034/go.mod h1:aMif0KXL4g19YCYwsy4Ocjjz5xgPlseYV+B95Oo4JGE=
 knative.dev/test-infra v0.0.0-20200519015156-82551620b0a9 h1:kKfV3QWsxugwXsqgjFd72MjZeAHJ381dWqAxH2KMknc=
 knative.dev/test-infra v0.0.0-20200519015156-82551620b0a9/go.mod h1:A5b2OAXTOeHT3hHhVQm3dmtbuWvIDP7qzgtqxA3/2pE=
+knative.dev/test-infra v0.0.0-20200522180958-6a0a9b9d893a h1:c0qTABRcNoxZVu5gsryLWPZtGa/s4zsvovz0nGefuzg=
+knative.dev/test-infra v0.0.0-20200522180958-6a0a9b9d893a/go.mod h1:n9eQkzmSNj8BiqNFl1lzoz68D09uMeJfyOjc132Gbik=
 modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
 modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
 modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
diff --git a/hack/update-deps.sh b/hack/update-deps.sh
index 71b1bf26f..a39fc858f 100755
--- a/hack/update-deps.sh
+++ b/hack/update-deps.sh
@@ -26,7 +26,7 @@ cd ${ROOT_DIR}
 # The list of dependencies that we track at HEAD and periodically
 # float forward in this repository.
 FLOATING_DEPS=(
-  "knative.dev/test-infra@release-0.15"
+  "knative.dev/test-infra@master"
 )
 
 # Parse flags to determine any we should pass to dep.
diff --git a/vendor/modules.txt b/vendor/modules.txt
index b1642c3ab..33822397a 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -914,7 +914,7 @@ k8s.io/utils/buffer
 k8s.io/utils/integer
 k8s.io/utils/pointer
 k8s.io/utils/trace
-# knative.dev/test-infra v0.0.0-20200519015156-82551620b0a9
+# knative.dev/test-infra v0.0.0-20200522180958-6a0a9b9d893a
 ## explicit
 knative.dev/test-infra/scripts
 # sigs.k8s.io/yaml v1.1.0
diff --git a/webhook/webhook.go b/webhook/webhook.go
index e29ea9611..ef7c238da 100644
--- a/webhook/webhook.go
+++ b/webhook/webhook.go
@@ -253,6 +253,7 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		default:
 			w.WriteHeader(http.StatusOK)
 		}
+		return
 	}
 
 	// Verify the content type is accurate.


Test patch:
diff --git a/vendor/knative.dev/test-infra/scripts/update-test-infra.sh b/vendor/knative.dev/test-infra/scripts/update-test-infra.sh
new file mode 100644
index 000000000..d443f3c20
--- /dev/null
+++ b/vendor/knative.dev/test-infra/scripts/update-test-infra.sh
@@ -0,0 +1,91 @@
+#!/usr/bin/env bash
+
+# Copyright 2020 The Knative Authors
+#
+# 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 -e
+
+# This script updates test-infra scripts in-repo.
+# Run it to update (usually from hack/update-deps.sh) the current scripts.
+# Scripts are installed to REPO_ROOT/scripts/test-infra
+
+# The following arguments are accepted:
+# --update
+#  Do the update
+# --ref X
+#  Defines which ref (branch, tag, commit) of test-infra to get scripts from; defaults to master
+# --first-time
+#  Run this script from your repo root directory to install scripts for the first time
+#  Will also sed -i non-vendor scripts in the current repo to point to new path
+# TODO: --verify
+#  Verify the contents of scripts/test-infra match the contents from commit sha in scripts/test-infra/COMMIT
+#  One can verify manually by running the script with '--ref $(cat scripts/test-infra/COMMIT)' and ensuring no files are staged
+
+declare -i FIRST_TIME_SETUP=0
+declare -i DO_UPDATE=0
+declare SCRIPTS_REF=master
+
+while [[ $# -ne 0 ]]; do
+  parameter="$1"
+  case ${parameter} in
+    --ref)
+      shift
+      SCRIPTS_REF="$1"
+      ;;
+    --first-time)
+      FIRST_TIME_SETUP=1
+      ;;
+    --update)
+      DO_UPDATE=1
+      ;;
+    *)
+      echo "unknown option ${parameter}"
+      exit 1
+      ;;
+  esac
+  shift
+done
+
+function do_read_tree() {
+    mkdir -p scripts/test-infra
+    git read-tree --prefix=scripts/test-infra -u "test-infra/${SCRIPTS_REF}:scripts"
+    git show-ref -s -- "refs/remotes/test-infra/${SCRIPTS_REF}" > scripts/test-infra/COMMIT
+    git add scripts/test-infra/COMMIT
+    echo "test-infra scripts installed to scripts/test-infra from branch ${SCRIPTS_REF}"
+}
+
+function run() {
+  if (( FIRST_TIME_SETUP )); then
+    if [[ ! -d .git ]]; then
+      echo "I don't believe you are in a repo root; exiting"
+      exit 5
+    fi
+    git remote add test-infra https://github.com/knative/test-infra.git || echo "test-infra remote already set; not changing"
+    git fetch test-infra "${SCRIPTS_REF}"
+    do_read_tree
+    echo "Attempting to point all scripts to use this new path"
+    grep -RiIl vendor/knative.dev/test-infra | grep -v ^vendor | grep -v ^scripts/test-infra | xargs sed -i 's+vendor/knative.dev/test-infra/scripts+scripts/test-infra+'
+  elif (( DO_UPDATE )); then
+    pushd "$(dirname "${BASH_SOURCE[0]}")/../.."
+    trap popd EXIT
+
+    git remote add test-infra https://github.com/knative/test-infra.git || true
+    git fetch test-infra "${SCRIPTS_REF}"
+    git rm -fr scripts/test-infra
+    rm -fR scripts/test-infra
+    do_read_tree
+  fi
+}
+
+run
diff --git a/webhook/webhook_test.go b/webhook/webhook_test.go
index bcdef62d9..19ce13a10 100644
--- a/webhook/webhook_test.go
+++ b/webhook/webhook_test.go
@@ -20,6 +20,8 @@ import (
 	"context"
 	"fmt"
 	"net"
+	"net/http"
+	"net/http/httptest"
 	"testing"
 	"time"
 
@@ -96,3 +98,51 @@ func TestRegistrationStopChanFire(t *testing.T) {
 		t.Errorf("Unexpected success to dial to port %d", opts.Port)
 	}
 }
+
+func TestWebhookKubeletProbe(t *testing.T) {
+	opts := newDefaultOptions()
+	ctx, webhook, cancel := newNonRunningTestWebhook(t, opts)
+	defer cancel()
+
+	recorder := bombRecorder{ResponseRecorder: httptest.NewRecorder()}
+	probeReq := httptest.NewRequest("GET", "/", nil)
+	probeReq.Header.Set("User-Agent", "kube-probe/1.16")
+
+	webhook.ServeHTTP(&recorder, probeReq)
+
+	if got, want := recorder.Code, http.StatusOK; got != want {
+		t.Fatalf("Probe got HTTP status %d - expected %d", got, want)
+	}
+
+	if got, want := recorder.writeCount, 1; got != want {
+		t.Errorf("HTTP status was written %d times - expected only one write", got)
+	}
+
+	// Stop the webhook - which means probes should fail
+	//
+	// The steps below aren't obvious and requires you to
+	// know the implementation details
+	cancel()
+	webhook.Run(ctx.Done())
+
+	recorder = bombRecorder{ResponseRecorder: httptest.NewRecorder()}
+	webhook.ServeHTTP(&recorder, probeReq)
+
+	if got, want := recorder.Code, http.StatusInternalServerError; got != want {
+		t.Fatalf("Probe got HTTP status %d - expected %d", got, want)
+	}
+
+	if got, want := recorder.writeCount, 1; got != want {
+		t.Errorf("HTTP status was written %d times - expected only one write", got)
+	}
+}
+
+type bombRecorder struct {
+	*httptest.ResponseRecorder
+	writeCount int
+}
+
+func (rw *bombRecorder) WriteHeader(code int) {
+	rw.writeCount += 1
+	rw.ResponseRecorder.WriteHeader(code)
+}