move testing/core to client-go
This commit is contained in:
@@ -72,6 +72,7 @@ function save() {
|
||||
save "discovery"
|
||||
save "dynamic"
|
||||
save "rest"
|
||||
save "testing"
|
||||
save "tools/auth"
|
||||
save "tools/cache"
|
||||
save "tools/clientcmd"
|
||||
@@ -90,11 +91,13 @@ function mkcp() {
|
||||
|
||||
# assemble all the other parts of the staging directory
|
||||
echo "copying client packages"
|
||||
# need to copy version. We aren't authoritative here
|
||||
# version has subdirs which we don't need. Only copy the files we want
|
||||
mkdir -p "${CLIENT_REPO_TEMP}/pkg/version"
|
||||
find "${MAIN_REPO}/pkg/version" -maxdepth 1 -type f | xargs -I{} cp {} "${CLIENT_REPO_TEMP}/pkg/version"
|
||||
# need to copy clientsets, though later we should copy APIs and later generate clientsets
|
||||
mkcp "pkg/client/clientset_generated/${CLIENTSET}" "pkg/client/clientset_generated"
|
||||
mkcp "/pkg/client/record" "/pkg/client"
|
||||
mkcp "/pkg/client/testing" "/pkg/client"
|
||||
# remove this test because it imports the internal clientset
|
||||
rm "${CLIENT_REPO_TEMP}"/pkg/client/testing/core/fake_test.go
|
||||
|
||||
mkcp "/pkg/client/unversioned/portforward" "/pkg/client/unversioned"
|
||||
|
||||
@@ -185,8 +188,6 @@ function mvfolder {
|
||||
mvfolder "pkg/client/clientset_generated/${CLIENTSET}" kubernetes
|
||||
mvfolder pkg/client/record tools/record
|
||||
mvfolder pkg/client/unversioned/portforward tools/portforward
|
||||
mvfolder pkg/client/testing/core testing
|
||||
mvfolder pkg/client/testing/cache tools/cache/testing
|
||||
if [ "$(find "${CLIENT_REPO_TEMP}"/pkg/client -type f -name "*.go")" ]; then
|
||||
echo "${CLIENT_REPO_TEMP}/pkg/client is expected to be empty"
|
||||
exit 1
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/client-go/pkg/version"
|
||||
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
||||
// Import solely to initialize client auth plugins.
|
||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||
)
|
||||
@@ -30,15 +30,14 @@ import (
|
||||
// MatchesServerVersion queries the server to compares the build version
|
||||
// (git hash) of the client with the server's build version. It returns an error
|
||||
// if it failed to contact the server or if the versions are not an exact match.
|
||||
func MatchesServerVersion(client DiscoveryInterface) error {
|
||||
cVer := version.Get()
|
||||
func MatchesServerVersion(clientVersion apimachineryversion.Info, client DiscoveryInterface) error {
|
||||
sVer, err := client.ServerVersion()
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't read version from server: %v\n", err)
|
||||
}
|
||||
// GitVersion includes GitCommit and GitTreeState, but best to be safe?
|
||||
if cVer.GitVersion != sVer.GitVersion || cVer.GitCommit != sVer.GitCommit || cVer.GitTreeState != sVer.GitTreeState {
|
||||
return fmt.Errorf("server version (%#v) differs from client version (%#v)!\n", sVer, cVer)
|
||||
if clientVersion.GitVersion != sVer.GitVersion || clientVersion.GitCommit != sVer.GitCommit || clientVersion.GitTreeState != sVer.GitTreeState {
|
||||
return fmt.Errorf("server version (%#v) differs from client version (%#v)!\n", sVer, clientVersion)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -33,9 +33,10 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/client-go/discovery"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/api/testapi"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/rest/fake"
|
||||
|
||||
_ "k8s.io/client-go/pkg/api/install"
|
||||
)
|
||||
|
||||
func objBody(object interface{}) io.ReadCloser {
|
||||
@@ -126,7 +127,7 @@ func TestNegotiateVersion(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
fakeClient := &fake.RESTClient{
|
||||
APIRegistry: api.Registry,
|
||||
NegotiatedSerializer: testapi.Default.NegotiatedSerializer(),
|
||||
NegotiatedSerializer: api.Codecs,
|
||||
Resp: &http.Response{
|
||||
StatusCode: test.statusCode,
|
||||
Body: objBody(&uapi.APIVersions{Versions: test.serverVersions}),
|
||||
|
||||
@@ -18,10 +18,10 @@ package fake
|
||||
|
||||
import (
|
||||
authenticationapi "k8s.io/client-go/pkg/apis/authentication/v1beta1"
|
||||
"k8s.io/client-go/testing"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeTokenReviews) Create(tokenReview *authenticationapi.TokenReview) (result *authenticationapi.TokenReview, err error) {
|
||||
obj, err := c.Fake.Invokes(testing.NewRootCreateAction(authenticationapi.SchemeGroupVersion.WithResource("tokenreviews"), tokenReview), &authenticationapi.TokenReview{})
|
||||
obj, err := c.Fake.Invokes(core.NewRootCreateAction(authenticationapi.SchemeGroupVersion.WithResource("tokenreviews"), tokenReview), &authenticationapi.TokenReview{})
|
||||
return obj.(*authenticationapi.TokenReview), err
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ package fake
|
||||
|
||||
import (
|
||||
authorizationapi "k8s.io/client-go/pkg/apis/authorization/v1beta1"
|
||||
"k8s.io/client-go/testing"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeLocalSubjectAccessReviews) Create(sar *authorizationapi.LocalSubjectAccessReview) (result *authorizationapi.LocalSubjectAccessReview, err error) {
|
||||
obj, err := c.Fake.Invokes(testing.NewCreateAction(authorizationapi.SchemeGroupVersion.WithResource("localsubjectaccessreviews"), c.ns, sar), &authorizationapi.SubjectAccessReview{})
|
||||
obj, err := c.Fake.Invokes(core.NewCreateAction(authorizationapi.SchemeGroupVersion.WithResource("localsubjectaccessreviews"), c.ns, sar), &authorizationapi.SubjectAccessReview{})
|
||||
return obj.(*authorizationapi.LocalSubjectAccessReview), err
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ package fake
|
||||
|
||||
import (
|
||||
authorizationapi "k8s.io/client-go/pkg/apis/authorization/v1beta1"
|
||||
"k8s.io/client-go/testing"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeSelfSubjectAccessReviews) Create(sar *authorizationapi.SelfSubjectAccessReview) (result *authorizationapi.SelfSubjectAccessReview, err error) {
|
||||
obj, err := c.Fake.Invokes(testing.NewRootCreateAction(authorizationapi.SchemeGroupVersion.WithResource("selfsubjectaccessreviews"), sar), &authorizationapi.SelfSubjectAccessReview{})
|
||||
obj, err := c.Fake.Invokes(core.NewRootCreateAction(authorizationapi.SchemeGroupVersion.WithResource("selfsubjectaccessreviews"), sar), &authorizationapi.SelfSubjectAccessReview{})
|
||||
return obj.(*authorizationapi.SelfSubjectAccessReview), err
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ package fake
|
||||
|
||||
import (
|
||||
authorizationapi "k8s.io/client-go/pkg/apis/authorization/v1beta1"
|
||||
"k8s.io/client-go/testing"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeSubjectAccessReviews) Create(sar *authorizationapi.SubjectAccessReview) (result *authorizationapi.SubjectAccessReview, err error) {
|
||||
obj, err := c.Fake.Invokes(testing.NewRootCreateAction(authorizationapi.SchemeGroupVersion.WithResource("subjectaccessreviews"), sar), &authorizationapi.SubjectAccessReview{})
|
||||
obj, err := c.Fake.Invokes(core.NewRootCreateAction(authorizationapi.SchemeGroupVersion.WithResource("subjectaccessreviews"), sar), &authorizationapi.SubjectAccessReview{})
|
||||
return obj.(*authorizationapi.SubjectAccessReview), err
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ package fake
|
||||
|
||||
import (
|
||||
certificates "k8s.io/client-go/pkg/apis/certificates/v1beta1"
|
||||
"k8s.io/client-go/testing"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeCertificateSigningRequests) UpdateApproval(certificateSigningRequest *certificates.CertificateSigningRequest) (result *certificates.CertificateSigningRequest, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewRootUpdateSubresourceAction(certificatesigningrequestsResource, "approval", certificateSigningRequest), &certificates.CertificateSigningRequest{})
|
||||
Invokes(core.NewRootUpdateSubresourceAction(certificatesigningrequestsResource, "approval", certificateSigningRequest), &certificates.CertificateSigningRequest{})
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
"k8s.io/client-go/testing"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeEvents) CreateWithEventNamespace(event *v1.Event) (*v1.Event, error) {
|
||||
action := testing.NewRootCreateAction(eventsResource, event)
|
||||
action := core.NewRootCreateAction(eventsResource, event)
|
||||
if c.ns != "" {
|
||||
action = testing.NewCreateAction(eventsResource, c.ns, event)
|
||||
action = core.NewCreateAction(eventsResource, c.ns, event)
|
||||
}
|
||||
obj, err := c.Fake.Invokes(action, event)
|
||||
if obj == nil {
|
||||
@@ -39,9 +39,9 @@ func (c *FakeEvents) CreateWithEventNamespace(event *v1.Event) (*v1.Event, error
|
||||
|
||||
// Update replaces an existing event. Returns the copy of the event the server returns, or an error.
|
||||
func (c *FakeEvents) UpdateWithEventNamespace(event *v1.Event) (*v1.Event, error) {
|
||||
action := testing.NewRootUpdateAction(eventsResource, event)
|
||||
action := core.NewRootUpdateAction(eventsResource, event)
|
||||
if c.ns != "" {
|
||||
action = testing.NewUpdateAction(eventsResource, c.ns, event)
|
||||
action = core.NewUpdateAction(eventsResource, c.ns, event)
|
||||
}
|
||||
obj, err := c.Fake.Invokes(action, event)
|
||||
if obj == nil {
|
||||
@@ -53,9 +53,9 @@ func (c *FakeEvents) UpdateWithEventNamespace(event *v1.Event) (*v1.Event, error
|
||||
|
||||
// PatchWithEventNamespace patches an existing event. Returns the copy of the event the server returns, or an error.
|
||||
func (c *FakeEvents) PatchWithEventNamespace(event *v1.Event, data []byte) (*v1.Event, error) {
|
||||
action := testing.NewRootPatchAction(eventsResource, event.Name, data)
|
||||
action := core.NewRootPatchAction(eventsResource, event.Name, data)
|
||||
if c.ns != "" {
|
||||
action = testing.NewPatchAction(eventsResource, c.ns, event.Name, data)
|
||||
action = core.NewPatchAction(eventsResource, c.ns, event.Name, data)
|
||||
}
|
||||
obj, err := c.Fake.Invokes(action, event)
|
||||
if obj == nil {
|
||||
@@ -67,9 +67,9 @@ func (c *FakeEvents) PatchWithEventNamespace(event *v1.Event, data []byte) (*v1.
|
||||
|
||||
// Search returns a list of events matching the specified object.
|
||||
func (c *FakeEvents) Search(objOrRef runtime.Object) (*v1.EventList, error) {
|
||||
action := testing.NewRootListAction(eventsResource, api.ListOptions{})
|
||||
action := core.NewRootListAction(eventsResource, api.ListOptions{})
|
||||
if c.ns != "" {
|
||||
action = testing.NewListAction(eventsResource, c.ns, api.ListOptions{})
|
||||
action = core.NewListAction(eventsResource, c.ns, api.ListOptions{})
|
||||
}
|
||||
obj, err := c.Fake.Invokes(action, &v1.EventList{})
|
||||
if obj == nil {
|
||||
@@ -80,7 +80,7 @@ func (c *FakeEvents) Search(objOrRef runtime.Object) (*v1.EventList, error) {
|
||||
}
|
||||
|
||||
func (c *FakeEvents) GetFieldSelector(involvedObjectName, involvedObjectNamespace, involvedObjectKind, involvedObjectUID *string) fields.Selector {
|
||||
action := testing.GenericActionImpl{}
|
||||
action := core.GenericActionImpl{}
|
||||
action.Verb = "get-field-selector"
|
||||
action.Resource = eventsResource
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ package fake
|
||||
|
||||
import (
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
"k8s.io/client-go/testing"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeNamespaces) Finalize(namespace *v1.Namespace) (*v1.Namespace, error) {
|
||||
action := testing.CreateActionImpl{}
|
||||
action := core.CreateActionImpl{}
|
||||
action.Verb = "create"
|
||||
action.Resource = namespacesResource
|
||||
action.Subresource = "finalize"
|
||||
|
||||
@@ -18,12 +18,12 @@ package fake
|
||||
|
||||
import (
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
"k8s.io/client-go/testing"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeNodes) PatchStatus(nodeName string, data []byte) (*v1.Node, error) {
|
||||
obj, err := c.Fake.Invokes(
|
||||
testing.NewRootPatchSubresourceAction(nodesResource, nodeName, data, "status"), &v1.Node{})
|
||||
core.NewRootPatchSubresourceAction(nodesResource, nodeName, data, "status"), &v1.Node{})
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ import (
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
policy "k8s.io/client-go/pkg/apis/policy/v1beta1"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/testing"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakePods) Bind(binding *v1.Binding) error {
|
||||
action := testing.CreateActionImpl{}
|
||||
action := core.CreateActionImpl{}
|
||||
action.Verb = "create"
|
||||
action.Resource = podsResource
|
||||
action.Subresource = "bindings"
|
||||
@@ -35,7 +35,7 @@ func (c *FakePods) Bind(binding *v1.Binding) error {
|
||||
}
|
||||
|
||||
func (c *FakePods) GetLogs(name string, opts *v1.PodLogOptions) *restclient.Request {
|
||||
action := testing.GenericActionImpl{}
|
||||
action := core.GenericActionImpl{}
|
||||
action.Verb = "get"
|
||||
action.Namespace = c.ns
|
||||
action.Resource = podsResource
|
||||
@@ -47,7 +47,7 @@ func (c *FakePods) GetLogs(name string, opts *v1.PodLogOptions) *restclient.Requ
|
||||
}
|
||||
|
||||
func (c *FakePods) Evict(eviction *policy.Eviction) error {
|
||||
action := testing.CreateActionImpl{}
|
||||
action := core.CreateActionImpl{}
|
||||
action.Verb = "create"
|
||||
action.Resource = podsResource
|
||||
action.Subresource = "eviction"
|
||||
|
||||
@@ -18,9 +18,9 @@ package fake
|
||||
|
||||
import (
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/testing"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeServices) ProxyGet(scheme, name, port, path string, params map[string]string) restclient.ResponseWrapper {
|
||||
return c.Fake.InvokesProxy(testing.NewProxyGetAction(servicesResource, c.ns, scheme, name, port, path, params))
|
||||
return c.Fake.InvokesProxy(core.NewProxyGetAction(servicesResource, c.ns, scheme, name, port, path, params))
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ package fake
|
||||
|
||||
import (
|
||||
"k8s.io/client-go/pkg/apis/extensions/v1beta1"
|
||||
"k8s.io/client-go/testing"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeDeployments) Rollback(deploymentRollback *v1beta1.DeploymentRollback) error {
|
||||
action := testing.CreateActionImpl{}
|
||||
action := core.CreateActionImpl{}
|
||||
action.Verb = "create"
|
||||
action.Resource = deploymentsResource
|
||||
action.Subresource = "rollback"
|
||||
|
||||
@@ -19,11 +19,11 @@ package fake
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/pkg/apis/extensions/v1beta1"
|
||||
"k8s.io/client-go/testing"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeScales) Get(kind string, name string) (result *v1beta1.Scale, err error) {
|
||||
action := testing.GetActionImpl{}
|
||||
action := core.GetActionImpl{}
|
||||
action.Verb = "get"
|
||||
action.Namespace = c.ns
|
||||
action.Resource = schema.GroupVersionResource{Resource: kind}
|
||||
@@ -35,7 +35,7 @@ func (c *FakeScales) Get(kind string, name string) (result *v1beta1.Scale, err e
|
||||
}
|
||||
|
||||
func (c *FakeScales) Update(kind string, scale *v1beta1.Scale) (result *v1beta1.Scale, err error) {
|
||||
action := testing.UpdateActionImpl{}
|
||||
action := core.UpdateActionImpl{}
|
||||
action.Verb = "update"
|
||||
action.Namespace = c.ns
|
||||
action.Resource = schema.GroupVersionResource{Resource: kind}
|
||||
|
||||
@@ -19,11 +19,11 @@ package fake
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
policy "k8s.io/client-go/pkg/apis/policy/v1beta1"
|
||||
testing "k8s.io/client-go/testing"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeEvictions) Evict(eviction *policy.Eviction) error {
|
||||
action := testing.GetActionImpl{}
|
||||
action := core.GetActionImpl{}
|
||||
action.Verb = "post"
|
||||
action.Namespace = c.ns
|
||||
action.Resource = schema.GroupVersionResource{Group: "", Version: "", Resource: "pods"}
|
||||
|
||||
@@ -16,4 +16,4 @@ limitations under the License.
|
||||
|
||||
// Package version supplies version information collected at build time to
|
||||
// kubernetes components.
|
||||
package version
|
||||
package version // import "k8s.io/client-go/pkg/version"
|
||||
|
||||
@@ -34,8 +34,10 @@ import (
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/diff"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/api/testapi"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
utiltesting "k8s.io/client-go/util/testing"
|
||||
|
||||
_ "k8s.io/client-go/pkg/api/install"
|
||||
)
|
||||
|
||||
type TestParam struct {
|
||||
@@ -91,7 +93,7 @@ func TestDoRequestFailed(t *testing.T) {
|
||||
Message: " \"\" not found",
|
||||
Details: &metav1.StatusDetails{},
|
||||
}
|
||||
expectedBody, _ := runtime.Encode(testapi.Default.Codec(), status)
|
||||
expectedBody, _ := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), status)
|
||||
fakeHandler := utiltesting.FakeHandler{
|
||||
StatusCode: 404,
|
||||
ResponseBody: string(expectedBody),
|
||||
@@ -130,7 +132,7 @@ func TestDoRawRequestFailed(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
expectedBody, _ := runtime.Encode(testapi.Default.Codec(), status)
|
||||
expectedBody, _ := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), status)
|
||||
fakeHandler := utiltesting.FakeHandler{
|
||||
StatusCode: 404,
|
||||
ResponseBody: string(expectedBody),
|
||||
@@ -229,7 +231,7 @@ func validate(testParam TestParam, t *testing.T, body []byte, fakeHandler *utilt
|
||||
t.Errorf("Expected object not to be created")
|
||||
}
|
||||
}
|
||||
statusOut, err := runtime.Decode(testapi.Default.Codec(), body)
|
||||
statusOut, err := runtime.Decode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), body)
|
||||
if testParam.testBody {
|
||||
if testParam.testBodyErrorIsNotNil {
|
||||
if err == nil {
|
||||
@@ -316,7 +318,7 @@ func TestCreateBackoffManager(t *testing.T) {
|
||||
|
||||
func testServerEnv(t *testing.T, statusCode int) (*httptest.Server, *utiltesting.FakeHandler, *metav1.Status) {
|
||||
status := &metav1.Status{Status: fmt.Sprintf("%s", metav1.StatusSuccess)}
|
||||
expectedBody, _ := runtime.Encode(testapi.Default.Codec(), status)
|
||||
expectedBody, _ := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), status)
|
||||
fakeHandler := utiltesting.FakeHandler{
|
||||
StatusCode: statusCode,
|
||||
ResponseBody: string(expectedBody),
|
||||
@@ -331,7 +333,7 @@ func restClient(testServer *httptest.Server) (*RESTClient, error) {
|
||||
Host: testServer.URL,
|
||||
ContentConfig: ContentConfig{
|
||||
GroupVersion: &api.Registry.GroupOrDie(api.GroupName).GroupVersion,
|
||||
NegotiatedSerializer: testapi.Default.NegotiatedSerializer(),
|
||||
NegotiatedSerializer: api.Codecs,
|
||||
},
|
||||
Username: "user",
|
||||
Password: "pass",
|
||||
|
||||
@@ -29,9 +29,10 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/diff"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/api/testapi"
|
||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||
"k8s.io/client-go/util/flowcontrol"
|
||||
|
||||
_ "k8s.io/client-go/pkg/api/install"
|
||||
)
|
||||
|
||||
func TestIsConfigTransportTLS(t *testing.T) {
|
||||
@@ -98,13 +99,13 @@ func TestSetKubernetesDefaultsUserAgent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRESTClientRequires(t *testing.T) {
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{NegotiatedSerializer: testapi.Default.NegotiatedSerializer()}}); err == nil {
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{NegotiatedSerializer: api.Codecs}}); err == nil {
|
||||
t.Errorf("unexpected non-error")
|
||||
}
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: &api.Registry.GroupOrDie(api.GroupName).GroupVersion}}); err == nil {
|
||||
t.Errorf("unexpected non-error")
|
||||
}
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: &api.Registry.GroupOrDie(api.GroupName).GroupVersion, NegotiatedSerializer: testapi.Default.NegotiatedSerializer()}}); err != nil {
|
||||
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: &api.Registry.GroupOrDie(api.GroupName).GroupVersion, NegotiatedSerializer: api.Codecs}}); err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/diff"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/api/testapi"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
"k8s.io/client-go/pkg/util/httpstream"
|
||||
"k8s.io/client-go/pkg/util/intstr"
|
||||
@@ -51,6 +50,8 @@ import (
|
||||
"k8s.io/client-go/util/clock"
|
||||
"k8s.io/client-go/util/flowcontrol"
|
||||
utiltesting "k8s.io/client-go/util/testing"
|
||||
|
||||
_ "k8s.io/client-go/pkg/api/install"
|
||||
)
|
||||
|
||||
func TestNewRequestSetsAccept(t *testing.T) {
|
||||
@@ -279,18 +280,18 @@ func (obj NotAnAPIObject) SetGroupVersionKind(gvk *schema.GroupVersionKind) {}
|
||||
func defaultContentConfig() ContentConfig {
|
||||
return ContentConfig{
|
||||
GroupVersion: &api.Registry.GroupOrDie(api.GroupName).GroupVersion,
|
||||
NegotiatedSerializer: testapi.Default.NegotiatedSerializer(),
|
||||
NegotiatedSerializer: api.Codecs,
|
||||
}
|
||||
}
|
||||
|
||||
func defaultSerializers() Serializers {
|
||||
return Serializers{
|
||||
Encoder: testapi.Default.Codec(),
|
||||
Decoder: testapi.Default.Codec(),
|
||||
StreamingSerializer: testapi.Default.Codec(),
|
||||
Encoder: api.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
Decoder: api.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
StreamingSerializer: api.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
Framer: runtime.DefaultFramer,
|
||||
RenegotiatedDecoder: func(contentType string, params map[string]string) (runtime.Decoder, error) {
|
||||
return testapi.Default.Codec(), nil
|
||||
return api.Codecs.LegacyCodec(v1.SchemeGroupVersion), nil
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -473,7 +474,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
Header: http.Header{"Content-Type": []string{"application/protobuf"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
Decoder: testapi.Default.Codec(),
|
||||
Decoder: api.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
|
||||
Called: true,
|
||||
ExpectContentType: "application/protobuf",
|
||||
@@ -489,7 +490,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
StatusCode: 500,
|
||||
Header: http.Header{"Content-Type": []string{"application/,others"}},
|
||||
},
|
||||
Decoder: testapi.Default.Codec(),
|
||||
Decoder: api.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
|
||||
Error: true,
|
||||
ErrFn: func(err error) bool {
|
||||
@@ -503,7 +504,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
Header: http.Header{"Content-Type": []string{"text/any"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
Decoder: testapi.Default.Codec(),
|
||||
Decoder: api.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
},
|
||||
{
|
||||
// no negotiation when no response content type specified
|
||||
@@ -512,7 +513,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
StatusCode: 200,
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
Decoder: testapi.Default.Codec(),
|
||||
Decoder: api.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
},
|
||||
{
|
||||
// unrecognized content type is not handled
|
||||
@@ -522,7 +523,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
Header: http.Header{"Content-Type": []string{"application/unrecognized"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
Decoder: testapi.Default.Codec(),
|
||||
Decoder: api.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
|
||||
NegotiateErr: fmt.Errorf("aaaa"),
|
||||
Called: true,
|
||||
@@ -785,7 +786,7 @@ func TestRequestWatch(t *testing.T) {
|
||||
client: clientFunc(func(req *http.Request) (*http.Response, error) {
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(testapi.Default.Codec(), &metav1.Status{
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), &metav1.Status{
|
||||
Status: metav1.StatusFailure,
|
||||
Reason: metav1.StatusReasonUnauthorized,
|
||||
})))),
|
||||
@@ -892,7 +893,7 @@ func TestRequestStream(t *testing.T) {
|
||||
client: clientFunc(func(req *http.Request) (*http.Response, error) {
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(testapi.Default.Codec(), &metav1.Status{
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), &metav1.Status{
|
||||
Status: metav1.StatusFailure,
|
||||
Reason: metav1.StatusReasonUnauthorized,
|
||||
})))),
|
||||
@@ -1021,7 +1022,7 @@ func TestDoRequestNewWay(t *testing.T) {
|
||||
Port: 12345,
|
||||
TargetPort: intstr.FromInt(12345),
|
||||
}}}}
|
||||
expectedBody, _ := runtime.Encode(testapi.Default.Codec(), expectedObj)
|
||||
expectedBody, _ := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), expectedObj)
|
||||
fakeHandler := utiltesting.FakeHandler{
|
||||
StatusCode: 200,
|
||||
ResponseBody: string(expectedBody),
|
||||
@@ -1045,7 +1046,7 @@ func TestDoRequestNewWay(t *testing.T) {
|
||||
} else if !api.Semantic.DeepDerivative(expectedObj, obj) {
|
||||
t.Errorf("Expected: %#v, got %#v", expectedObj, obj)
|
||||
}
|
||||
requestURL := testapi.Default.ResourcePathWithPrefix("foo/bar", "", "", "baz")
|
||||
requestURL := defaultResourcePathWithPrefix("foo/bar", "", "", "baz")
|
||||
requestURL += "?timeout=1s"
|
||||
fakeHandler.ValidateRequest(t, requestURL, "POST", &reqBody)
|
||||
}
|
||||
@@ -1246,13 +1247,13 @@ func BenchmarkCheckRetryClosesBody(b *testing.B) {
|
||||
|
||||
func TestDoRequestNewWayReader(t *testing.T) {
|
||||
reqObj := &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
||||
reqBodyExpected, _ := runtime.Encode(testapi.Default.Codec(), reqObj)
|
||||
reqBodyExpected, _ := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), reqObj)
|
||||
expectedObj := &api.Service{Spec: api.ServiceSpec{Ports: []api.ServicePort{{
|
||||
Protocol: "TCP",
|
||||
Port: 12345,
|
||||
TargetPort: intstr.FromInt(12345),
|
||||
}}}}
|
||||
expectedBody, _ := runtime.Encode(testapi.Default.Codec(), expectedObj)
|
||||
expectedBody, _ := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), expectedObj)
|
||||
fakeHandler := utiltesting.FakeHandler{
|
||||
StatusCode: 200,
|
||||
ResponseBody: string(expectedBody),
|
||||
@@ -1279,20 +1280,20 @@ func TestDoRequestNewWayReader(t *testing.T) {
|
||||
t.Errorf("Expected: %#v, got %#v", expectedObj, obj)
|
||||
}
|
||||
tmpStr := string(reqBodyExpected)
|
||||
requestURL := testapi.Default.ResourcePathWithPrefix("foo", "bar", "", "baz")
|
||||
requestURL := defaultResourcePathWithPrefix("foo", "bar", "", "baz")
|
||||
requestURL += "?" + metav1.LabelSelectorQueryParam(api.Registry.GroupOrDie(api.GroupName).GroupVersion.String()) + "=name%3Dfoo&timeout=1s"
|
||||
fakeHandler.ValidateRequest(t, requestURL, "POST", &tmpStr)
|
||||
}
|
||||
|
||||
func TestDoRequestNewWayObj(t *testing.T) {
|
||||
reqObj := &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
||||
reqBodyExpected, _ := runtime.Encode(testapi.Default.Codec(), reqObj)
|
||||
reqBodyExpected, _ := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), reqObj)
|
||||
expectedObj := &api.Service{Spec: api.ServiceSpec{Ports: []api.ServicePort{{
|
||||
Protocol: "TCP",
|
||||
Port: 12345,
|
||||
TargetPort: intstr.FromInt(12345),
|
||||
}}}}
|
||||
expectedBody, _ := runtime.Encode(testapi.Default.Codec(), expectedObj)
|
||||
expectedBody, _ := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), expectedObj)
|
||||
fakeHandler := utiltesting.FakeHandler{
|
||||
StatusCode: 200,
|
||||
ResponseBody: string(expectedBody),
|
||||
@@ -1319,14 +1320,14 @@ func TestDoRequestNewWayObj(t *testing.T) {
|
||||
t.Errorf("Expected: %#v, got %#v", expectedObj, obj)
|
||||
}
|
||||
tmpStr := string(reqBodyExpected)
|
||||
requestURL := testapi.Default.ResourcePath("foo", "", "bar/baz")
|
||||
requestURL := defaultResourcePathWithPrefix("", "foo", "", "bar/baz")
|
||||
requestURL += "?" + metav1.LabelSelectorQueryParam(api.Registry.GroupOrDie(api.GroupName).GroupVersion.String()) + "=name%3Dfoo&timeout=1s"
|
||||
fakeHandler.ValidateRequest(t, requestURL, "POST", &tmpStr)
|
||||
}
|
||||
|
||||
func TestDoRequestNewWayFile(t *testing.T) {
|
||||
reqObj := &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
||||
reqBodyExpected, err := runtime.Encode(testapi.Default.Codec(), reqObj)
|
||||
reqBodyExpected, err := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), reqObj)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -1348,7 +1349,7 @@ func TestDoRequestNewWayFile(t *testing.T) {
|
||||
Port: 12345,
|
||||
TargetPort: intstr.FromInt(12345),
|
||||
}}}}
|
||||
expectedBody, _ := runtime.Encode(testapi.Default.Codec(), expectedObj)
|
||||
expectedBody, _ := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), expectedObj)
|
||||
fakeHandler := utiltesting.FakeHandler{
|
||||
StatusCode: 200,
|
||||
ResponseBody: string(expectedBody),
|
||||
@@ -1376,14 +1377,14 @@ func TestDoRequestNewWayFile(t *testing.T) {
|
||||
t.Errorf("expected object was created")
|
||||
}
|
||||
tmpStr := string(reqBodyExpected)
|
||||
requestURL := testapi.Default.ResourcePathWithPrefix("foo/bar/baz", "", "", "")
|
||||
requestURL := defaultResourcePathWithPrefix("foo/bar/baz", "", "", "")
|
||||
requestURL += "?timeout=1s"
|
||||
fakeHandler.ValidateRequest(t, requestURL, "POST", &tmpStr)
|
||||
}
|
||||
|
||||
func TestWasCreated(t *testing.T) {
|
||||
reqObj := &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
||||
reqBodyExpected, err := runtime.Encode(testapi.Default.Codec(), reqObj)
|
||||
reqBodyExpected, err := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), reqObj)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -1393,7 +1394,7 @@ func TestWasCreated(t *testing.T) {
|
||||
Port: 12345,
|
||||
TargetPort: intstr.FromInt(12345),
|
||||
}}}}
|
||||
expectedBody, _ := runtime.Encode(testapi.Default.Codec(), expectedObj)
|
||||
expectedBody, _ := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), expectedObj)
|
||||
fakeHandler := utiltesting.FakeHandler{
|
||||
StatusCode: 201,
|
||||
ResponseBody: string(expectedBody),
|
||||
@@ -1422,7 +1423,7 @@ func TestWasCreated(t *testing.T) {
|
||||
}
|
||||
|
||||
tmpStr := string(reqBodyExpected)
|
||||
requestURL := testapi.Default.ResourcePathWithPrefix("foo/bar/baz", "", "", "")
|
||||
requestURL := defaultResourcePathWithPrefix("foo/bar/baz", "", "", "")
|
||||
requestURL += "?timeout=1s"
|
||||
fakeHandler.ValidateRequest(t, requestURL, "PUT", &tmpStr)
|
||||
}
|
||||
@@ -1520,7 +1521,7 @@ func TestBody(t *testing.T) {
|
||||
const data = "test payload"
|
||||
|
||||
obj := &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
||||
bodyExpected, _ := runtime.Encode(testapi.Default.Codec(), obj)
|
||||
bodyExpected, _ := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), obj)
|
||||
|
||||
f, err := ioutil.TempFile("", "test_body")
|
||||
if err != nil {
|
||||
@@ -1598,7 +1599,7 @@ func TestWatch(t *testing.T) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
flusher.Flush()
|
||||
|
||||
encoder := restclientwatch.NewEncoder(streaming.NewEncoder(w, testapi.Default.Codec()), testapi.Default.Codec())
|
||||
encoder := restclientwatch.NewEncoder(streaming.NewEncoder(w, api.Codecs.LegacyCodec(v1.SchemeGroupVersion)), api.Codecs.LegacyCodec(v1.SchemeGroupVersion))
|
||||
for _, item := range table {
|
||||
if err := encoder.Encode(&watch.Event{Type: item.t, Object: item.obj}); err != nil {
|
||||
panic(err)
|
||||
@@ -1672,7 +1673,7 @@ func testRESTClient(t testing.TB, srv *httptest.Server) *RESTClient {
|
||||
t.Fatalf("failed to parse test URL: %v", err)
|
||||
}
|
||||
}
|
||||
versionedAPIPath := testapi.Default.ResourcePath("", "", "")
|
||||
versionedAPIPath := defaultResourcePathWithPrefix("", "", "", "")
|
||||
client, err := NewRESTClient(baseURL, versionedAPIPath, defaultContentConfig(), 0, 0, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create a client: %v", err)
|
||||
@@ -1708,3 +1709,24 @@ func TestDoContext(t *testing.T) {
|
||||
t.Fatal("Expected context cancellation error")
|
||||
}
|
||||
}
|
||||
|
||||
func defaultResourcePathWithPrefix(prefix, resource, namespace, name string) string {
|
||||
var path string
|
||||
path = "/api/" + v1.SchemeGroupVersion.Version
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -28,8 +28,10 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/api/testapi"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
restclientwatch "k8s.io/client-go/rest/watch"
|
||||
|
||||
_ "k8s.io/client-go/pkg/api/install"
|
||||
)
|
||||
|
||||
func TestDecoder(t *testing.T) {
|
||||
@@ -37,13 +39,13 @@ func TestDecoder(t *testing.T) {
|
||||
|
||||
for _, eventType := range table {
|
||||
out, in := io.Pipe()
|
||||
codec := testapi.Default.Codec()
|
||||
codec := api.Codecs.LegacyCodec(v1.SchemeGroupVersion)
|
||||
decoder := restclientwatch.NewDecoder(streaming.NewDecoder(out, codec), codec)
|
||||
|
||||
expect := &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
||||
encoder := json.NewEncoder(in)
|
||||
go func() {
|
||||
data, err := runtime.Encode(testapi.Default.Codec(), expect)
|
||||
data, err := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), expect)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
@@ -90,7 +92,7 @@ func TestDecoder(t *testing.T) {
|
||||
|
||||
func TestDecoder_SourceClose(t *testing.T) {
|
||||
out, in := io.Pipe()
|
||||
codec := testapi.Default.Codec()
|
||||
codec := api.Codecs.LegacyCodec(v1.SchemeGroupVersion)
|
||||
decoder := restclientwatch.NewDecoder(streaming.NewDecoder(out, codec), codec)
|
||||
|
||||
done := make(chan struct{})
|
||||
|
||||
@@ -26,8 +26,10 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer/streaming"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
"k8s.io/client-go/pkg/api/testapi"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
restclientwatch "k8s.io/client-go/rest/watch"
|
||||
|
||||
_ "k8s.io/client-go/pkg/api/install"
|
||||
)
|
||||
|
||||
func TestEncodeDecodeRoundTrip(t *testing.T) {
|
||||
@@ -39,17 +41,17 @@ func TestEncodeDecodeRoundTrip(t *testing.T) {
|
||||
{
|
||||
watch.Added,
|
||||
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||
testapi.Default.Codec(),
|
||||
api.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
},
|
||||
{
|
||||
watch.Modified,
|
||||
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||
testapi.Default.Codec(),
|
||||
api.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
},
|
||||
{
|
||||
watch.Deleted,
|
||||
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||
testapi.Default.Codec(),
|
||||
api.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
},
|
||||
}
|
||||
for i, testCase := range testCases {
|
||||
|
||||
@@ -22,11 +22,11 @@ import (
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/apimachinery/registered"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
@@ -144,21 +144,23 @@ func ObjectReaction(tracker ObjectTracker, mapper meta.RESTMapper) ReactionFunc
|
||||
}
|
||||
|
||||
type tracker struct {
|
||||
scheme ObjectScheme
|
||||
decoder runtime.Decoder
|
||||
lock sync.RWMutex
|
||||
objects map[schema.GroupVersionKind][]runtime.Object
|
||||
registry *registered.APIRegistrationManager
|
||||
scheme ObjectScheme
|
||||
decoder runtime.Decoder
|
||||
lock sync.RWMutex
|
||||
objects map[schema.GroupVersionKind][]runtime.Object
|
||||
}
|
||||
|
||||
var _ ObjectTracker = &tracker{}
|
||||
|
||||
// NewObjectTracker returns an ObjectTracker that can be used to keep track
|
||||
// of objects for the fake clientset. Mostly useful for unit tests.
|
||||
func NewObjectTracker(scheme ObjectScheme, decoder runtime.Decoder) ObjectTracker {
|
||||
func NewObjectTracker(registry *registered.APIRegistrationManager, scheme ObjectScheme, decoder runtime.Decoder) ObjectTracker {
|
||||
return &tracker{
|
||||
scheme: scheme,
|
||||
decoder: decoder,
|
||||
objects: make(map[schema.GroupVersionKind][]runtime.Object),
|
||||
registry: registry,
|
||||
scheme: scheme,
|
||||
decoder: decoder,
|
||||
objects: make(map[schema.GroupVersionKind][]runtime.Object),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +202,7 @@ func (t *tracker) List(gvk schema.GroupVersionKind, ns string) (runtime.Object,
|
||||
}
|
||||
|
||||
func (t *tracker) Get(gvk schema.GroupVersionKind, ns, name string) (runtime.Object, error) {
|
||||
if err := checkNamespace(gvk, ns); err != nil {
|
||||
if err := checkNamespace(t.registry, gvk, ns); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -307,7 +309,7 @@ func (t *tracker) add(obj runtime.Object, ns string, replaceExisting bool) error
|
||||
return errors.NewBadRequest(msg)
|
||||
}
|
||||
|
||||
if err := checkNamespace(gvk, newMeta.GetNamespace()); err != nil {
|
||||
if err := checkNamespace(t.registry, gvk, newMeta.GetNamespace()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -359,7 +361,7 @@ func (t *tracker) addList(obj runtime.Object, replaceExisting bool) error {
|
||||
}
|
||||
|
||||
func (t *tracker) Delete(gvk schema.GroupVersionKind, ns, name string) error {
|
||||
if err := checkNamespace(gvk, ns); err != nil {
|
||||
if err := checkNamespace(t.registry, gvk, ns); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -413,8 +415,8 @@ func filterByNamespaceAndName(objs []runtime.Object, ns, name string) ([]runtime
|
||||
// checkNamespace makes sure that the scope of gvk matches ns. It
|
||||
// returns an error if namespace is empty but gvk is a namespaced
|
||||
// kind, or if ns is non-empty and gvk is a namespaced kind.
|
||||
func checkNamespace(gvk schema.GroupVersionKind, ns string) error {
|
||||
group, err := api.Registry.Group(gvk.Group)
|
||||
func checkNamespace(registry *registered.APIRegistrationManager, gvk schema.GroupVersionKind, ns string) error {
|
||||
group, err := registry.Group(gvk.Group)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user