mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-17 23:57:49 +00:00
Merge pull request #57821 from hzxuzhonghu/hard-code
Automatic merge from submit-queue (batch tested with PRs 57696, 57821, 56317). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. remove hard-coded namespace **What this PR does / why we need it**: Since import cycle is solved, should use metav1.Namespace* instead of hard coding. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
541b1103bf
@ -11,7 +11,10 @@ go_test(
|
|||||||
srcs = ["requestinfo_test.go"],
|
srcs = ["requestinfo_test.go"],
|
||||||
embed = [":go_default_library"],
|
embed = [":go_default_library"],
|
||||||
importpath = "k8s.io/apiserver/pkg/endpoints/request",
|
importpath = "k8s.io/apiserver/pkg/endpoints/request",
|
||||||
deps = ["//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library"],
|
deps = [
|
||||||
|
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
|
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
go_library(
|
go_library(
|
||||||
@ -26,6 +29,7 @@ go_library(
|
|||||||
deps = [
|
deps = [
|
||||||
"//vendor/github.com/golang/glog:go_default_library",
|
"//vendor/github.com/golang/glog:go_default_library",
|
||||||
"//vendor/golang.org/x/net/context:go_default_library",
|
"//vendor/golang.org/x/net/context:go_default_library",
|
||||||
|
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||||
"//vendor/k8s.io/apiserver/pkg/apis/audit:go_default_library",
|
"//vendor/k8s.io/apiserver/pkg/apis/audit:go_default_library",
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apiserver/pkg/apis/audit"
|
"k8s.io/apiserver/pkg/apis/audit"
|
||||||
"k8s.io/apiserver/pkg/authentication/user"
|
"k8s.io/apiserver/pkg/authentication/user"
|
||||||
@ -66,8 +67,6 @@ const (
|
|||||||
|
|
||||||
// auditKey is the context key for the audit event.
|
// auditKey is the context key for the audit event.
|
||||||
auditKey
|
auditKey
|
||||||
|
|
||||||
namespaceDefault = "default" // TODO(sttts): solve import cycle when using metav1.NamespaceDefault
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewContext instantiates a base context object for request flows.
|
// 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
|
// NewDefaultContext instantiates a base context object for request flows in the default namespace
|
||||||
func NewDefaultContext() Context {
|
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.
|
// 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 {
|
func WithNamespaceDefaultIfNone(parent Context) Context {
|
||||||
namespace, ok := NamespaceFrom(parent)
|
namespace, ok := NamespaceFrom(parent)
|
||||||
if !ok || len(namespace) == 0 {
|
if !ok || len(namespace) == 0 {
|
||||||
return WithNamespace(parent, namespaceDefault)
|
return WithNamespace(parent, metav1.NamespaceDefault)
|
||||||
}
|
}
|
||||||
return parent
|
return parent
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -178,7 +179,7 @@ func (r *RequestInfoFactory) NewRequestInfo(req *http.Request) (*RequestInfo, er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
// parsing successful, so we now know the proper value for .Parts
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ func (f fakeRL) TryAccept() bool { return bool(f) }
|
|||||||
func (f fakeRL) Accept() {}
|
func (f fakeRL) Accept() {}
|
||||||
|
|
||||||
func TestGetAPIRequestInfo(t *testing.T) {
|
func TestGetAPIRequestInfo(t *testing.T) {
|
||||||
namespaceAll := "" // TODO(sttts): solve import cycle when using metav1.NamespaceAll
|
namespaceAll := metav1.NamespaceAll
|
||||||
successCases := []struct {
|
successCases := []struct {
|
||||||
method string
|
method string
|
||||||
url string
|
url string
|
||||||
|
Loading…
Reference in New Issue
Block a user