diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/request/context.go b/staging/src/k8s.io/apiserver/pkg/endpoints/request/context.go index b63b84dc7db..e64facc5c4b 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/request/context.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/request/context.go @@ -21,6 +21,7 @@ import ( "time" "golang.org/x/net/context" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apiserver/pkg/apis/audit" "k8s.io/apiserver/pkg/authentication/user" @@ -66,8 +67,6 @@ const ( // auditKey is the context key for the audit event. auditKey - - namespaceDefault = "default" // TODO(sttts): solve import cycle when using metav1.NamespaceDefault ) // NewContext instantiates a base context object for request flows. @@ -77,7 +76,7 @@ func NewContext() Context { // NewDefaultContext instantiates a base context object for request flows in the default namespace func NewDefaultContext() Context { - return WithNamespace(NewContext(), namespaceDefault) + return WithNamespace(NewContext(), metav1.NamespaceDefault) } // WithValue returns a copy of parent in which the value associated with key is val. @@ -110,7 +109,7 @@ func NamespaceValue(ctx Context) string { func WithNamespaceDefaultIfNone(parent Context) Context { namespace, ok := NamespaceFrom(parent) if !ok || len(namespace) == 0 { - return WithNamespace(parent, namespaceDefault) + return WithNamespace(parent, metav1.NamespaceDefault) } return parent } diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/request/requestinfo.go b/staging/src/k8s.io/apiserver/pkg/endpoints/request/requestinfo.go index bb0f0604d21..ddbbde3991d 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/request/requestinfo.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/request/requestinfo.go @@ -21,6 +21,7 @@ import ( "net/http" "strings" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/sets" ) @@ -178,7 +179,7 @@ func (r *RequestInfoFactory) NewRequestInfo(req *http.Request) (*RequestInfo, er } } } else { - requestInfo.Namespace = "" // TODO(sttts): solve import cycle when using metav1.NamespaceNone + requestInfo.Namespace = metav1.NamespaceNone } // parsing successful, so we now know the proper value for .Parts diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/request/requestinfo_test.go b/staging/src/k8s.io/apiserver/pkg/endpoints/request/requestinfo_test.go index 8354cca06d7..9d5a4dbf9fa 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/request/requestinfo_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/request/requestinfo_test.go @@ -21,6 +21,7 @@ import ( "reflect" "testing" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/sets" ) @@ -31,7 +32,7 @@ func (f fakeRL) TryAccept() bool { return bool(f) } func (f fakeRL) Accept() {} func TestGetAPIRequestInfo(t *testing.T) { - namespaceAll := "" // TODO(sttts): solve import cycle when using metav1.NamespaceAll + namespaceAll := metav1.NamespaceAll successCases := []struct { method string url string