Skip to content

Commit

Permalink
Merge pull request #40658 from sttts/sttts-more-cutoffs-4
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 40798, 40658)

genericapiserver: cut off more dependencies – episode 4

Follow-up of #40426.

TODO:
- [x] resync client-go before "genericapiserver: cutting off pkg/api deps" when #40426 went in and mirror repos are synched.

approved based on #40363
  • Loading branch information
Kubernetes Submit Queue authored Feb 1, 2017
2 parents 44f22e1 + 7a6366b commit 0567280
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 63 deletions.
1 change: 0 additions & 1 deletion pkg/api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ go_library(
"field_constants.go",
"helpers.go",
"json.go",
"meta.go",
"ref.go",
"register.go",
"resource_helpers.go",
Expand Down
27 changes: 0 additions & 27 deletions pkg/api/meta.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/genericapiserver/endpoints/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions pkg/genericapiserver/endpoints/filters/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ 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",
"//vendor:k8s.io/apiserver/pkg/authentication/authenticator",
"//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",
],
)

Expand All @@ -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",
Expand All @@ -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",
],
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/genericapiserver/endpoints/filters/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/genericapiserver/endpoints/filters/impersonation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
6 changes: 3 additions & 3 deletions pkg/genericapiserver/endpoints/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/genericapiserver/registry/rest/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/genericapiserver/registry/rest/resttest/resttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/genericapiserver/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
45 changes: 33 additions & 12 deletions pkg/genericapiserver/server/genericapiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand All @@ -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"}),
}

Expand Down Expand Up @@ -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,
})
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/core/service/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions pkg/storage/storagebackend/factory/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
19 changes: 15 additions & 4 deletions pkg/storage/storagebackend/factory/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 0567280

Please sign in to comment.