mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-07 20:21:20 +00:00
Do not use namespace in url paths pre v1beta3 from client
This commit is contained in:
@@ -204,7 +204,7 @@ func (factory *ConfigFactory) pollMinions() (cache.Enumerator, error) {
|
||||
|
||||
func (factory *ConfigFactory) makeDefaultErrorFunc(backoff *podBackoff, podQueue *cache.FIFO) func(pod *api.Pod, err error) {
|
||||
return func(pod *api.Pod, err error) {
|
||||
glog.Errorf("Error scheduling %v: %v; retrying", pod.Name, err)
|
||||
glog.Errorf("Error scheduling %v %v: %v; retrying", pod.Namespace, pod.Name, err)
|
||||
backoff.gc()
|
||||
// Retry asynchronously.
|
||||
// Note that this is extremely rudimentary and we need a more real error handling path.
|
||||
|
@@ -19,6 +19,7 @@ package factory
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -183,6 +184,22 @@ func TestPollMinions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func makeNamespaceURL(namespace, suffix string, isClient bool) string {
|
||||
if client.NamespaceInPathFor(testapi.Version()) {
|
||||
return makeURL("/ns/" + namespace + suffix)
|
||||
}
|
||||
// if this is a url the client should call, encode the url
|
||||
if isClient {
|
||||
return makeURL(suffix + "?namespace=" + namespace)
|
||||
}
|
||||
// its not a client url, so its what the server needs to listen on
|
||||
return makeURL(suffix)
|
||||
}
|
||||
|
||||
func makeURL(suffix string) string {
|
||||
return path.Join("/api", testapi.Version(), suffix)
|
||||
}
|
||||
|
||||
func TestDefaultErrorFunc(t *testing.T) {
|
||||
testPod := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: "bar"}}
|
||||
handler := util.FakeHandler{
|
||||
@@ -191,8 +208,9 @@ func TestDefaultErrorFunc(t *testing.T) {
|
||||
T: t,
|
||||
}
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// FakeHandler musn't be sent requests other than the one you want to test.
|
||||
mux.Handle("/api/"+testapi.Version()+"/ns/bar/pods/foo", &handler)
|
||||
mux.Handle(makeNamespaceURL("bar", "/pods/foo", false), &handler)
|
||||
server := httptest.NewServer(mux)
|
||||
defer server.Close()
|
||||
factory := NewConfigFactory(client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Version()}))
|
||||
@@ -213,7 +231,7 @@ func TestDefaultErrorFunc(t *testing.T) {
|
||||
if !exists {
|
||||
continue
|
||||
}
|
||||
handler.ValidateRequest(t, "/api/"+testapi.Version()+"/ns/bar/pods/foo", "GET", nil)
|
||||
handler.ValidateRequest(t, makeNamespaceURL("bar", "/pods/foo", true), "GET", nil)
|
||||
if e, a := testPod, got; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("Expected %v, got %v", e, a)
|
||||
}
|
||||
|
Reference in New Issue
Block a user