Merge pull request #44421 from mml/windows

Automatic merge from submit-queue (batch tested with PRs 44362, 44421, 44468, 43878, 44480)

Drop leading path of KUBECTL.EXE if it shows up in User-Agent.

Partial fix for #44419 

Release note: kube-apiserver now drops unneeded path information if an older version of Windows kubectl sends it.
pull/6/head
Kubernetes Submit Queue 2017-04-14 01:46:01 -07:00 committed by GitHub
commit 079dc0d78e
2 changed files with 13 additions and 0 deletions

View File

@ -109,9 +109,14 @@ func InstrumentRouteFunc(verb, resource string, routeFunc restful.RouteFunction)
}
func cleanUserAgent(ua string) string {
// We collapse all "web browser"-type user agents into one "browser" to reduce metric cardinality.
if strings.HasPrefix(ua, "Mozilla/") {
return "Browser"
}
// If an old "kubectl.exe" has passed us its full path, we discard the path portion.
if exeIdx := strings.LastIndex(strings.ToLower(ua), "kubectl.exe"); exeIdx != -1 {
return ua[exeIdx:]
}
return ua
}

View File

@ -31,6 +31,14 @@ func TestCleanUserAgent(t *testing.T) {
In: "kubectl/v1.2.4",
Out: "kubectl/v1.2.4",
},
{
In: `C:\Users\Kubernetes\kubectl.exe/v1.5.4`,
Out: "kubectl.exe/v1.5.4",
},
{
In: `C:\Program Files\kubectl.exe/v1.5.4`,
Out: "kubectl.exe/v1.5.4",
},
} {
if cleanUserAgent(tc.In) != tc.Out {
t.Errorf("Failed to clean User-Agent: %s", tc.In)