Use upstream etcddata.GetResources in ETCD storage test
@@ -467,34 +467,27 @@ func TestEtcd3StoragePath(t *testing.T) {
etcdSeen := map[schema.GroupVersionResource]empty{}
cohabitatingResources := map[string]map[schema.GroupVersionKind]empty{}
- resourcesToPersist := []resourceToPersist{}
serverResources, err := kubeClient.Discovery().ServerResources()
if err != nil {
t.Fatal(err)
}
- resourcesToPersist = append(resourcesToPersist, getResourcesToPersist(serverResources, t)...)
oapiServerResources := &metav1.APIResourceList{
GroupVersion: "v1",
}
if err := kubeClient.Discovery().RESTClient().Get().AbsPath("oapi", "v1").Do().Into(oapiServerResources); err != nil {
t.Fatal(err)
}
- resourcesToPersist = append(resourcesToPersist, getResourcesToPersist([]*metav1.APIResourceList{oapiServerResources}, t)...)
+ resourcesToPersist := append(
+ etcddata.GetResources(t, serverResources),
+ etcddata.GetResources(t, []*metav1.APIResourceList{oapiServerResources})...,
+ )
for _, resourceToPersist := range resourcesToPersist {
- gvk := resourceToPersist.gvk
- gvResource := resourceToPersist.gvr
+ mapping := resourceToPersist.Mapping
+ gvResource := mapping.Resource
+ gvk := mapping.GroupVersionKind
kind := gvk.Kind
- mapping := &meta.RESTMapping{
- Resource: resourceToPersist.gvr,
- GroupVersionKind: resourceToPersist.gvk,
- Scope: meta.RESTScopeRoot,
- }
- if resourceToPersist.namespaced {
- mapping.Scope = meta.RESTScopeNamespace
- }
-
if kindWhiteList.Has(kind) {
kindSeen.Insert(kind)
continue
@@ -599,60 +592,6 @@ func TestEtcd3StoragePath(t *testing.T) {
}
}
-type resourceToPersist struct {
- gvk schema.GroupVersionKind
- gvr schema.GroupVersionResource
- namespaced bool
-}
-
-func getResourcesToPersist(serverResources []*metav1.APIResourceList, t *testing.T) []resourceToPersist {
- resourcesToPersist := []resourceToPersist{}
-
- for _, discoveryGroup := range serverResources {
- for _, discoveryResource := range discoveryGroup.APIResources {
- // this is a subresource, skip it
- if strings.Contains(discoveryResource.Name, "/") {
- continue
- }
- hasCreate := false
- hasGet := false
- for _, verb := range discoveryResource.Verbs {
- if string(verb) == "get" {
- hasGet = true
- }
- if string(verb) == "create" {
- hasCreate = true
- }
- }
- if !(hasCreate && hasGet) {
- continue
- }
-
- resourceGV, err := schema.ParseGroupVersion(discoveryGroup.GroupVersion)
- if err != nil {
- t.Fatal(err)
- }
- gvk := resourceGV.WithKind(discoveryResource.Kind)
- if len(discoveryResource.Group) > 0 || len(discoveryResource.Version) > 0 {
- gvk = schema.GroupVersionKind{
- Group: discoveryResource.Group,
- Version: discoveryResource.Version,
- Kind: discoveryResource.Kind,
- }
- }
- gvr := resourceGV.WithResource(discoveryResource.Name)
-
- resourcesToPersist = append(resourcesToPersist, resourceToPersist{
- gvk: gvk,
- gvr: gvr,
- namespaced: discoveryResource.Namespaced,
- })
- }
- }
-
- return resourcesToPersist
-}
-
func addGVKToEtcdBucket(cohabitatingResources map[string]map[schema.GroupVersionKind]empty, gvk schema.GroupVersionKind, bucket string) {
if cohabitatingResources[bucket] == nil {
cohabitatingResources[bucket] = map[schema.GroupVersionKind]empty{}
