Remove use of testapi codecs, selflink, resourcepath functions
This commit is contained in:
@@ -24,7 +24,6 @@ go_test(
|
||||
"//cmd/kube-apiserver/app/options:go_default_library",
|
||||
"//cmd/kube-apiserver/app/testing:go_default_library",
|
||||
"//pkg/api/legacyscheme:go_default_library",
|
||||
"//pkg/api/testapi:go_default_library",
|
||||
"//pkg/apis/autoscaling:go_default_library",
|
||||
"//pkg/apis/core:go_default_library",
|
||||
"//pkg/apis/extensions:go_default_library",
|
||||
|
@@ -30,7 +30,6 @@ import (
|
||||
"k8s.io/apiserver/pkg/authorization/authorizer"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/test/integration/framework"
|
||||
)
|
||||
@@ -62,7 +61,7 @@ func TestSubjectAccessReview(t *testing.T) {
|
||||
_, s, closeFn := framework.RunAMaster(masterConfig)
|
||||
defer closeFn()
|
||||
|
||||
clientset := clientset.NewForConfigOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Groups[api.GroupName].GroupVersion()}})
|
||||
clientset := clientset.NewForConfigOrDie(&restclient.Config{Host: s.URL})
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -157,7 +156,7 @@ func TestSelfSubjectAccessReview(t *testing.T) {
|
||||
_, s, closeFn := framework.RunAMaster(masterConfig)
|
||||
defer closeFn()
|
||||
|
||||
clientset := clientset.NewForConfigOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Groups[api.GroupName].GroupVersion()}})
|
||||
clientset := clientset.NewForConfigOrDie(&restclient.Config{Host: s.URL})
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -236,7 +235,7 @@ func TestLocalSubjectAccessReview(t *testing.T) {
|
||||
_, s, closeFn := framework.RunAMaster(masterConfig)
|
||||
defer closeFn()
|
||||
|
||||
clientset := clientset.NewForConfigOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Groups[api.GroupName].GroupVersion()}})
|
||||
clientset := clientset.NewForConfigOrDie(&restclient.Config{Host: s.URL})
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
|
@@ -47,8 +47,7 @@ import (
|
||||
"k8s.io/apiserver/pkg/authorization/authorizerfactory"
|
||||
"k8s.io/apiserver/plugin/pkg/authenticator/token/tokentest"
|
||||
"k8s.io/apiserver/plugin/pkg/authenticator/token/webhook"
|
||||
"k8s.io/client-go/tools/clientcmd/api/v1"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
v1 "k8s.io/client-go/tools/clientcmd/api/v1"
|
||||
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
@@ -94,26 +93,45 @@ func getTestWebhookTokenAuth(serverURL string) (authenticator.Request, error) {
|
||||
}
|
||||
|
||||
func path(resource, namespace, name string) string {
|
||||
return testapi.Default.ResourcePath(resource, namespace, name)
|
||||
return pathWithPrefix("", resource, namespace, name)
|
||||
}
|
||||
|
||||
func pathWithPrefix(prefix, resource, namespace, name string) string {
|
||||
return testapi.Default.ResourcePathWithPrefix(prefix, resource, namespace, name)
|
||||
path := "/api/v1"
|
||||
if prefix != "" {
|
||||
path = path + "/" + prefix
|
||||
}
|
||||
if namespace != "" {
|
||||
path = path + "/namespaces/" + namespace
|
||||
}
|
||||
// Resource names are lower case.
|
||||
resource = strings.ToLower(resource)
|
||||
if resource != "" {
|
||||
path = path + "/" + resource
|
||||
}
|
||||
if name != "" {
|
||||
path = path + "/" + name
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
func pathWithSubResource(resource, namespace, name, subresource string) string {
|
||||
return testapi.Default.SubResourcePath(resource, namespace, name, subresource)
|
||||
path := pathWithPrefix("", resource, namespace, name)
|
||||
if subresource != "" {
|
||||
path = path + "/" + subresource
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
func timeoutPath(resource, namespace, name string) string {
|
||||
return addTimeoutFlag(testapi.Default.ResourcePath(resource, namespace, name))
|
||||
return addTimeoutFlag(path(resource, namespace, name))
|
||||
}
|
||||
|
||||
// Bodies for requests used in subsequent tests.
|
||||
var aPod = `
|
||||
{
|
||||
"kind": "Pod",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "a",
|
||||
"creationTimestamp": null%s
|
||||
@@ -131,7 +149,7 @@ var aPod = `
|
||||
var aRC = `
|
||||
{
|
||||
"kind": "ReplicationController",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "a",
|
||||
"labels": {
|
||||
@@ -164,7 +182,7 @@ var aRC = `
|
||||
var aService = `
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "a",
|
||||
"labels": {
|
||||
@@ -188,7 +206,7 @@ var aService = `
|
||||
var aNode = `
|
||||
{
|
||||
"kind": "Node",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "a"%s
|
||||
},
|
||||
@@ -202,7 +220,7 @@ func aEvent(namespace string) string {
|
||||
return `
|
||||
{
|
||||
"kind": "Event",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "a"%s
|
||||
},
|
||||
@@ -219,7 +237,7 @@ func aEvent(namespace string) string {
|
||||
var aBinding = `
|
||||
{
|
||||
"kind": "Binding",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "a"%s
|
||||
},
|
||||
@@ -242,7 +260,7 @@ var emptyEndpoints = `
|
||||
var aEndpoints = `
|
||||
{
|
||||
"kind": "Endpoints",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "a"%s
|
||||
},
|
||||
@@ -267,7 +285,7 @@ var aEndpoints = `
|
||||
var deleteNow = `
|
||||
{
|
||||
"kind": "DeleteOptions",
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
"apiVersion": "v1",
|
||||
"gracePeriodSeconds": 0%s
|
||||
}
|
||||
`
|
||||
|
@@ -23,12 +23,12 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
gopath "path"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
api "k8s.io/api/core/v1"
|
||||
rbacapi "k8s.io/api/rbac/v1"
|
||||
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -49,7 +49,6 @@ import (
|
||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
rbachelper "k8s.io/kubernetes/pkg/apis/rbac/v1"
|
||||
"k8s.io/kubernetes/pkg/master"
|
||||
"k8s.io/kubernetes/pkg/registry/rbac/clusterrole"
|
||||
@@ -193,12 +192,9 @@ func (s statusCode) String() string {
|
||||
|
||||
// Declare a set of raw objects to use.
|
||||
var (
|
||||
// Make a role binding with the version enabled in testapi.Rbac
|
||||
// This assumes testapi is using rbac.authorization.k8s.io/v1beta1 or rbac.authorization.k8s.io/v1, which are identical in structure.
|
||||
// TODO: rework or remove testapi usage to allow writing integration tests that don't depend on envvars
|
||||
writeJobsRoleBinding = `
|
||||
{
|
||||
"apiVersion": "` + testapi.Rbac.GroupVersion().String() + `",
|
||||
"apiVersion": "rbac.authorization.k8s.io/v1",
|
||||
"kind": "RoleBinding",
|
||||
"metadata": {
|
||||
"name": "pi"%s
|
||||
@@ -260,7 +256,7 @@ var (
|
||||
`
|
||||
podNamespace = `
|
||||
{
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
"apiVersion": "v1",
|
||||
"kind": "Namespace",
|
||||
"metadata": {
|
||||
"name": "pod-namespace"%s
|
||||
@@ -269,7 +265,7 @@ var (
|
||||
`
|
||||
jobNamespace = `
|
||||
{
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
"apiVersion": "v1",
|
||||
"kind": "Namespace",
|
||||
"metadata": {
|
||||
"name": "job-namespace"%s
|
||||
@@ -278,7 +274,7 @@ var (
|
||||
`
|
||||
forbiddenNamespace = `
|
||||
{
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
"apiVersion": "v1",
|
||||
"kind": "Namespace",
|
||||
"metadata": {
|
||||
"name": "forbidden-namespace"%s
|
||||
@@ -287,7 +283,7 @@ var (
|
||||
`
|
||||
limitRangeNamespace = `
|
||||
{
|
||||
"apiVersion": "` + testapi.Groups[api.GroupName].GroupVersion().String() + `",
|
||||
"apiVersion": "v1",
|
||||
"kind": "Namespace",
|
||||
"metadata": {
|
||||
"name": "limitrange-namespace"%s
|
||||
@@ -560,12 +556,21 @@ func TestRBAC(t *testing.T) {
|
||||
previousResourceVersion := make(map[string]float64)
|
||||
|
||||
for j, r := range tc.requests {
|
||||
testGroup, ok := testapi.Groups[r.apiGroup]
|
||||
if !ok {
|
||||
t.Errorf("case %d %d: unknown api group %q, %s", i, j, r.apiGroup, r)
|
||||
continue
|
||||
path := "/"
|
||||
if r.apiGroup == "" {
|
||||
path = gopath.Join(path, "api/v1")
|
||||
} else {
|
||||
path = gopath.Join(path, "apis", r.apiGroup, "v1")
|
||||
}
|
||||
if r.namespace != "" {
|
||||
path = gopath.Join(path, "namespaces", r.namespace)
|
||||
}
|
||||
if r.resource != "" {
|
||||
path = gopath.Join(path, r.resource)
|
||||
}
|
||||
if r.name != "" {
|
||||
path = gopath.Join(path, r.name)
|
||||
}
|
||||
path := testGroup.ResourcePath(r.resource, r.namespace, r.name)
|
||||
|
||||
var body io.Reader
|
||||
if r.body != "" {
|
||||
@@ -652,7 +657,7 @@ func TestBootstrapping(t *testing.T) {
|
||||
_, s, closeFn := framework.RunAMaster(masterConfig)
|
||||
defer closeFn()
|
||||
|
||||
clientset := clientset.NewForConfigOrDie(&restclient.Config{BearerToken: superUser, Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Groups[api.GroupName].GroupVersion()}})
|
||||
clientset := clientset.NewForConfigOrDie(&restclient.Config{BearerToken: superUser, Host: s.URL})
|
||||
|
||||
watcher, err := clientset.RbacV1().ClusterRoles().Watch(metav1.ListOptions{ResourceVersion: "0"})
|
||||
if err != nil {
|
||||
@@ -712,7 +717,7 @@ func TestDiscoveryUpgradeBootstrapping(t *testing.T) {
|
||||
}))
|
||||
_, s, tearDownFn := framework.RunAMaster(masterConfig)
|
||||
|
||||
client := clientset.NewForConfigOrDie(&restclient.Config{BearerToken: superUser, Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Groups[api.GroupName].GroupVersion()}})
|
||||
client := clientset.NewForConfigOrDie(&restclient.Config{BearerToken: superUser, Host: s.URL})
|
||||
|
||||
// Modify the default RBAC discovery ClusterRoleBidnings to look more like the defaults that
|
||||
// existed prior to v1.14, but with user modifications.
|
||||
@@ -750,7 +755,7 @@ func TestDiscoveryUpgradeBootstrapping(t *testing.T) {
|
||||
// `system:discovery`, and respect auto-reconciliation annotations.
|
||||
_, s, tearDownFn = framework.RunAMaster(masterConfig)
|
||||
|
||||
client = clientset.NewForConfigOrDie(&restclient.Config{BearerToken: superUser, Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Groups[api.GroupName].GroupVersion()}})
|
||||
client = clientset.NewForConfigOrDie(&restclient.Config{BearerToken: superUser, Host: s.URL})
|
||||
|
||||
newDiscRoleBinding, err := client.RbacV1().ClusterRoleBindings().Get("system:discovery", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user