diff --git a/pkg/api/BUILD b/pkg/api/BUILD index d334e8db34009..27b3008b026b7 100644 --- a/pkg/api/BUILD +++ b/pkg/api/BUILD @@ -17,7 +17,6 @@ go_library( "field_constants.go", "helpers.go", "json.go", - "meta.go", "ref.go", "register.go", "resource_helpers.go", diff --git a/pkg/api/meta.go b/pkg/api/meta.go deleted file mode 100644 index 3df6a2e79f68a..0000000000000 --- a/pkg/api/meta.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package api - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// HasObjectMetaSystemFieldValues returns true if fields that are managed by the system on ObjectMeta have values. -func HasObjectMetaSystemFieldValues(meta *metav1.ObjectMeta) bool { - return !meta.CreationTimestamp.Time.IsZero() || - len(meta.UID) != 0 -} diff --git a/pkg/genericapiserver/endpoints/BUILD b/pkg/genericapiserver/endpoints/BUILD index 23221576e0778..5710e6e01bfec 100644 --- a/pkg/genericapiserver/endpoints/BUILD +++ b/pkg/genericapiserver/endpoints/BUILD @@ -63,7 +63,6 @@ go_library( ], tags = ["automanaged"], deps = [ - "//pkg/apis/extensions:go_default_library", "//pkg/genericapiserver/endpoints/handlers:go_default_library", "//pkg/genericapiserver/endpoints/handlers/responsewriters:go_default_library", "//pkg/genericapiserver/registry/rest:go_default_library", diff --git a/pkg/genericapiserver/endpoints/filters/BUILD b/pkg/genericapiserver/endpoints/filters/BUILD index acb0546f658c9..2200b1145c941 100644 --- a/pkg/genericapiserver/endpoints/filters/BUILD +++ b/pkg/genericapiserver/endpoints/filters/BUILD @@ -20,7 +20,6 @@ go_test( library = ":go_default_library", tags = ["automanaged"], deps = [ - "//pkg/apis/authentication:go_default_library", "//pkg/apis/batch:go_default_library", "//pkg/genericapiserver/endpoints/handlers/responsewriters:go_default_library", "//vendor:k8s.io/apimachinery/pkg/util/sets", @@ -28,6 +27,7 @@ go_test( "//vendor:k8s.io/apiserver/pkg/authentication/user", "//vendor:k8s.io/apiserver/pkg/authorization/authorizer", "//vendor:k8s.io/apiserver/pkg/endpoints/request", + "//vendor:k8s.io/client-go/pkg/apis/authentication", ], ) @@ -43,8 +43,6 @@ go_library( ], tags = ["automanaged"], deps = [ - "//pkg/api:go_default_library", - "//pkg/apis/authentication:go_default_library", "//pkg/genericapiserver/endpoints/handlers/responsewriters:go_default_library", "//vendor:github.com/golang/glog", "//vendor:github.com/pborman/uuid", @@ -56,6 +54,8 @@ go_library( "//vendor:k8s.io/apiserver/pkg/authorization/authorizer", "//vendor:k8s.io/apiserver/pkg/endpoints/request", "//vendor:k8s.io/apiserver/pkg/server/httplog", + "//vendor:k8s.io/client-go/pkg/api", + "//vendor:k8s.io/client-go/pkg/apis/authentication", ], ) diff --git a/pkg/genericapiserver/endpoints/filters/audit.go b/pkg/genericapiserver/endpoints/filters/audit.go index 251bbea45b941..0e2e9455b756e 100644 --- a/pkg/genericapiserver/endpoints/filters/audit.go +++ b/pkg/genericapiserver/endpoints/filters/audit.go @@ -31,7 +31,7 @@ import ( utilnet "k8s.io/apimachinery/pkg/util/net" "k8s.io/apiserver/pkg/endpoints/request" - authenticationapi "k8s.io/kubernetes/pkg/apis/authentication" + authenticationapi "k8s.io/client-go/pkg/apis/authentication" "k8s.io/kubernetes/pkg/genericapiserver/endpoints/handlers/responsewriters" ) diff --git a/pkg/genericapiserver/endpoints/filters/impersonation.go b/pkg/genericapiserver/endpoints/filters/impersonation.go index d682909f65440..ccd0704c0a109 100644 --- a/pkg/genericapiserver/endpoints/filters/impersonation.go +++ b/pkg/genericapiserver/endpoints/filters/impersonation.go @@ -29,8 +29,8 @@ import ( "k8s.io/apiserver/pkg/authorization/authorizer" "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/server/httplog" - "k8s.io/kubernetes/pkg/api" - authenticationapi "k8s.io/kubernetes/pkg/apis/authentication" + "k8s.io/client-go/pkg/api" + authenticationapi "k8s.io/client-go/pkg/apis/authentication" "k8s.io/kubernetes/pkg/genericapiserver/endpoints/handlers/responsewriters" ) diff --git a/pkg/genericapiserver/endpoints/filters/impersonation_test.go b/pkg/genericapiserver/endpoints/filters/impersonation_test.go index 3d0eb23c50e4b..29d1249d9810b 100644 --- a/pkg/genericapiserver/endpoints/filters/impersonation_test.go +++ b/pkg/genericapiserver/endpoints/filters/impersonation_test.go @@ -27,7 +27,7 @@ import ( "k8s.io/apiserver/pkg/authentication/user" "k8s.io/apiserver/pkg/authorization/authorizer" "k8s.io/apiserver/pkg/endpoints/request" - authenticationapi "k8s.io/kubernetes/pkg/apis/authentication" + authenticationapi "k8s.io/client-go/pkg/apis/authentication" ) type impersonateAuthorizer struct{} diff --git a/pkg/genericapiserver/endpoints/installer.go b/pkg/genericapiserver/endpoints/installer.go index 43416ae67e4e8..878985c3da593 100644 --- a/pkg/genericapiserver/endpoints/installer.go +++ b/pkg/genericapiserver/endpoints/installer.go @@ -38,7 +38,6 @@ import ( "k8s.io/apiserver/pkg/endpoints/handlers/negotiation" "k8s.io/apiserver/pkg/endpoints/metrics" "k8s.io/apiserver/pkg/endpoints/request" - "k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/genericapiserver/endpoints/handlers" "k8s.io/kubernetes/pkg/genericapiserver/registry/rest" @@ -154,8 +153,9 @@ func (a *APIInstaller) getResourceKind(path string, storage rest.Storage) (schem break } - // TODO This keeps it doing what it was doing before, but it doesn't feel right. - if fqKind.Group == extensions.GroupName && fqKind.Kind == "ThirdPartyResourceData" { + // TODO: keep rid of extensions api group dependency here + // This keeps it doing what it was doing before, but it doesn't feel right. + if fqKind.Group == "extensions" && fqKind.Kind == "ThirdPartyResourceData" { fqKindToRegister = a.group.GroupVersion.WithKind(fqKind.Kind) } } diff --git a/pkg/genericapiserver/registry/rest/meta_test.go b/pkg/genericapiserver/registry/rest/meta_test.go index 36131a3f4f604..dbf10c2969d33 100644 --- a/pkg/genericapiserver/registry/rest/meta_test.go +++ b/pkg/genericapiserver/registry/rest/meta_test.go @@ -49,11 +49,11 @@ func TestFillObjectMetaSystemFields(t *testing.T) { func TestHasObjectMetaSystemFieldValues(t *testing.T) { ctx := genericapirequest.NewDefaultContext() resource := metav1.ObjectMeta{} - if api.HasObjectMetaSystemFieldValues(&resource) { + if metav1.HasObjectMetaSystemFieldValues(&resource) { t.Errorf("the resource does not have all fields yet populated, but incorrectly reports it does") } FillObjectMetaSystemFields(ctx, &resource) - if !api.HasObjectMetaSystemFieldValues(&resource) { + if !metav1.HasObjectMetaSystemFieldValues(&resource) { t.Errorf("the resource does have all fields populated, but incorrectly reports it does not") } } diff --git a/pkg/genericapiserver/registry/rest/resttest/resttest.go b/pkg/genericapiserver/registry/rest/resttest/resttest.go index 23befacfb731b..3981265df35c5 100644 --- a/pkg/genericapiserver/registry/rest/resttest/resttest.go +++ b/pkg/genericapiserver/registry/rest/resttest/resttest.go @@ -328,7 +328,7 @@ func (t *Tester) testCreateHasMetadata(valid runtime.Object) { t.Fatalf("Unexpected object from result: %#v", obj) } defer t.delete(t.TestContext(), obj) - if !api.HasObjectMetaSystemFieldValues(objectMeta) { + if !metav1.HasObjectMetaSystemFieldValues(objectMeta) { t.Errorf("storage did not populate object meta field values") } } diff --git a/pkg/genericapiserver/server/BUILD b/pkg/genericapiserver/server/BUILD index 660e991caed7b..aaa8b353b54d7 100644 --- a/pkg/genericapiserver/server/BUILD +++ b/pkg/genericapiserver/server/BUILD @@ -21,7 +21,6 @@ go_test( deps = [ "//pkg/api:go_default_library", "//pkg/api/testapi:go_default_library", - "//pkg/api/v1:go_default_library", "//pkg/apis/extensions:go_default_library", "//pkg/client/clientset_generated/clientset:go_default_library", "//pkg/generated/openapi:go_default_library", @@ -35,6 +34,7 @@ go_test( "//vendor:k8s.io/apimachinery/pkg/apis/meta/v1", "//vendor:k8s.io/apimachinery/pkg/runtime", "//vendor:k8s.io/apimachinery/pkg/runtime/schema", + "//vendor:k8s.io/apimachinery/pkg/runtime/serializer", "//vendor:k8s.io/apimachinery/pkg/util/net", "//vendor:k8s.io/apimachinery/pkg/util/sets", "//vendor:k8s.io/apimachinery/pkg/version", diff --git a/pkg/genericapiserver/server/genericapiserver_test.go b/pkg/genericapiserver/server/genericapiserver_test.go index 26e9bf2a2158d..326e45b03ea6e 100644 --- a/pkg/genericapiserver/server/genericapiserver_test.go +++ b/pkg/genericapiserver/server/genericapiserver_test.go @@ -37,21 +37,42 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/runtime/serializer" utilnet "k8s.io/apimachinery/pkg/util/net" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/version" "k8s.io/apiserver/pkg/authentication/user" "k8s.io/apiserver/pkg/authorization/authorizer" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" - "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/testapi" - "k8s.io/kubernetes/pkg/api/v1" - "k8s.io/kubernetes/pkg/apis/extensions" openapigen "k8s.io/kubernetes/pkg/generated/openapi" "k8s.io/kubernetes/pkg/genericapiserver/registry/rest" etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing" ) +const ( + extensionsGroupName = "extensions" +) + +var ( + v1GroupVersion = schema.GroupVersion{Group: "", Version: "v1"} + + scheme = runtime.NewScheme() + codecs = serializer.NewCodecFactory(scheme) + parameterCodec = runtime.NewParameterCodec(scheme) +) + +func init() { + metav1.AddToGroupVersion(scheme, metav1.SchemeGroupVersion) + scheme.AddUnversionedTypes(v1GroupVersion, + &metav1.Status{}, + &metav1.APIVersions{}, + &metav1.APIGroupList{}, + &metav1.APIGroup{}, + &metav1.APIResourceList{}, + ) +} + // setUp is a convience function for setting up for (most) tests. func setUp(t *testing.T) (*etcdtesting.EtcdTestServer, Config, *assert.Assertions) { etcdServer, _ := etcdtesting.NewUnsecuredEtcd3TestClientServer(t) @@ -119,8 +140,8 @@ func TestInstallAPIGroups(t *testing.T) { scheme := runtime.NewScheme() scheme.AddKnownTypeWithName(gv.WithKind("Getter"), getter.New()) scheme.AddKnownTypeWithName(gv.WithKind("NoVerb"), noVerbs.New()) - scheme.AddKnownTypes(v1.SchemeGroupVersion, &metav1.Status{}) - metav1.AddToGroupVersion(scheme, v1.SchemeGroupVersion) + scheme.AddKnownTypes(v1GroupVersion, &metav1.Status{}) + metav1.AddToGroupVersion(scheme, v1GroupVersion) interfacesFor := func(version schema.GroupVersion) (*meta.VersionInterfaces, error) { return &meta.VersionInterfaces{ @@ -146,15 +167,15 @@ func TestInstallAPIGroups(t *testing.T) { }, }, OptionsExternalVersion: &schema.GroupVersion{Version: "v1"}, - ParameterCodec: api.ParameterCodec, - NegotiatedSerializer: api.Codecs, + ParameterCodec: parameterCodec, + NegotiatedSerializer: codecs, Scheme: scheme, } } apis := []APIGroupInfo{ testAPI(schema.GroupVersion{Group: "", Version: "v1"}), - testAPI(schema.GroupVersion{Group: "extensions", Version: "v1"}), + testAPI(schema.GroupVersion{Group: extensionsGroupName, Version: "v1"}), testAPI(schema.GroupVersion{Group: "batch", Version: "v1"}), } @@ -467,11 +488,11 @@ func TestDiscoveryAtAPIS(t *testing.T) { }, } extensionsPreferredVersion := metav1.GroupVersionForDiscovery{ - GroupVersion: extensions.GroupName + "/preferred", + GroupVersion: extensionsGroupName + "/preferred", Version: "preferred", } master.AddAPIGroupForDiscovery(metav1.APIGroup{ - Name: extensions.GroupName, + Name: extensionsGroupName, Versions: extensionsVersions, PreferredVersion: extensionsPreferredVersion, }) @@ -483,13 +504,13 @@ func TestDiscoveryAtAPIS(t *testing.T) { assert.Equal(1, len(groupList.Groups)) groupListGroup := groupList.Groups[0] - assert.Equal(extensions.GroupName, groupListGroup.Name) + assert.Equal(extensionsGroupName, groupListGroup.Name) assert.Equal(extensionsVersions, groupListGroup.Versions) assert.Equal(extensionsPreferredVersion, groupListGroup.PreferredVersion) assert.Equal(master.discoveryAddresses.ServerAddressByClientCIDRs(utilnet.GetClientIP(&http.Request{})), groupListGroup.ServerAddressByClientCIDRs) // Remove the group. - master.RemoveAPIGroupForDiscovery(extensions.GroupName) + master.RemoveAPIGroupForDiscovery(extensionsGroupName) groupList, err = getGroupList(server) if err != nil { t.Fatalf("unexpected error: %v", err) diff --git a/pkg/registry/core/service/rest_test.go b/pkg/registry/core/service/rest_test.go index cec3b37ae7416..a652f83ddb683 100644 --- a/pkg/registry/core/service/rest_test.go +++ b/pkg/registry/core/service/rest_test.go @@ -98,7 +98,7 @@ func TestServiceRegistryCreate(t *testing.T) { t.Fatalf("Unexpected error: %v", err) } created_service := created_svc.(*api.Service) - if !api.HasObjectMetaSystemFieldValues(&created_service.ObjectMeta) { + if !metav1.HasObjectMetaSystemFieldValues(&created_service.ObjectMeta) { t.Errorf("storage did not populate object meta field values") } if created_service.Name != "foo" { @@ -218,7 +218,7 @@ func TestServiceRegistryCreateMultiNodePortsService(t *testing.T) { t.Fatalf("Unexpected error: %v", err) } created_service := created_svc.(*api.Service) - if !api.HasObjectMetaSystemFieldValues(&created_service.ObjectMeta) { + if !metav1.HasObjectMetaSystemFieldValues(&created_service.ObjectMeta) { t.Errorf("storage did not populate object meta field values") } if created_service.Name != test.name { diff --git a/pkg/storage/storagebackend/factory/BUILD b/pkg/storage/storagebackend/factory/BUILD index c397a04dabe4d..1da0327a2f61b 100644 --- a/pkg/storage/storagebackend/factory/BUILD +++ b/pkg/storage/storagebackend/factory/BUILD @@ -35,13 +35,16 @@ go_test( library = ":go_default_library", tags = ["automanaged"], deps = [ - "//pkg/api:go_default_library", - "//pkg/api/testapi:go_default_library", "//pkg/storage/etcd/testing/testingcert:go_default_library", "//vendor:github.com/coreos/etcd/integration", "//vendor:github.com/coreos/etcd/pkg/transport", "//vendor:golang.org/x/net/context", + "//vendor:k8s.io/apimachinery/pkg/runtime", + "//vendor:k8s.io/apimachinery/pkg/runtime/schema", + "//vendor:k8s.io/apimachinery/pkg/runtime/serializer", "//vendor:k8s.io/apiserver/pkg/storage/storagebackend", + "//vendor:k8s.io/client-go/pkg/api", + "//vendor:k8s.io/client-go/pkg/api/v1", ], ) diff --git a/pkg/storage/storagebackend/factory/tls_test.go b/pkg/storage/storagebackend/factory/tls_test.go index 3ff1cd2bedce9..cfa95df3b1cac 100644 --- a/pkg/storage/storagebackend/factory/tls_test.go +++ b/pkg/storage/storagebackend/factory/tls_test.go @@ -25,16 +25,27 @@ import ( "golang.org/x/net/context" + "k8s.io/apimachinery/pkg/runtime/schema" + runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/apiserver/pkg/storage/storagebackend" - "k8s.io/kubernetes/pkg/api" - "k8s.io/kubernetes/pkg/api/testapi" + clientapi "k8s.io/client-go/pkg/api" + clientapiv1 "k8s.io/client-go/pkg/api/v1" "k8s.io/kubernetes/pkg/storage/etcd/testing/testingcert" "github.com/coreos/etcd/integration" "github.com/coreos/etcd/pkg/transport" + "k8s.io/apimachinery/pkg/runtime" ) func TestTLSConnection(t *testing.T) { + scheme := runtime.NewScheme() + codecs := runtimeserializer.NewCodecFactory(scheme) + codec := codecs.LegacyCodec(schema.GroupVersion{Version: "v1"}) + + // TODO: use k8s.io/apiserver internal type instead of borrowing it from client-go + clientapi.AddToScheme(scheme) + clientapiv1.AddToScheme(scheme) + certFile, keyFile, caFile := configureTLSCerts(t) defer os.RemoveAll(filepath.Dir(certFile)) @@ -56,14 +67,14 @@ func TestTLSConnection(t *testing.T) { CertFile: certFile, KeyFile: keyFile, CAFile: caFile, - Codec: testapi.Default.Codec(), + Codec: codec, } storage, destroyFunc, err := newETCD3Storage(cfg) defer destroyFunc() if err != nil { t.Fatal(err) } - err = storage.Create(context.TODO(), "/abc", &api.Pod{}, nil, 0) + err = storage.Create(context.TODO(), "/abc", &clientapi.Pod{}, nil, 0) if err != nil { t.Fatalf("Create failed: %v", err) } diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go index 877aa193d3437..b62dd9ee02c21 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go @@ -226,3 +226,9 @@ func NewUIDPreconditions(uid string) *Preconditions { u := types.UID(uid) return &Preconditions{UID: &u} } + +// HasObjectMetaSystemFieldValues returns true if fields that are managed by the system on ObjectMeta have values. +func HasObjectMetaSystemFieldValues(meta *ObjectMeta) bool { + return !meta.CreationTimestamp.Time.IsZero() || + len(meta.UID) != 0 +}