mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Service REST test: remove pointless scaffolding
This commit is contained in:
parent
48e591eba2
commit
d6208606f3
@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
@ -62,8 +63,7 @@ var (
|
|||||||
// in a completely different way. We should unify it.
|
// in a completely different way. We should unify it.
|
||||||
|
|
||||||
type serviceStorage struct {
|
type serviceStorage struct {
|
||||||
Services map[string]*api.Service
|
Services map[string]*api.Service
|
||||||
ServiceList *api.ServiceList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *serviceStorage) saveService(svc *api.Service) {
|
func (s *serviceStorage) saveService(svc *api.Service) {
|
||||||
@ -99,19 +99,18 @@ func (s *serviceStorage) NewList() runtime.Object {
|
|||||||
func (s *serviceStorage) List(ctx context.Context, options *metainternalversion.ListOptions) (runtime.Object, error) {
|
func (s *serviceStorage) List(ctx context.Context, options *metainternalversion.ListOptions) (runtime.Object, error) {
|
||||||
ns, _ := genericapirequest.NamespaceFrom(ctx)
|
ns, _ := genericapirequest.NamespaceFrom(ctx)
|
||||||
|
|
||||||
// Copy metadata from internal list into result
|
keys := make([]string, 0, len(s.Services))
|
||||||
res := new(api.ServiceList)
|
for k := range s.Services {
|
||||||
res.TypeMeta = s.ServiceList.TypeMeta
|
keys = append(keys, k)
|
||||||
res.ListMeta = s.ServiceList.ListMeta
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
if ns != metav1.NamespaceAll {
|
res := new(api.ServiceList)
|
||||||
for _, service := range s.ServiceList.Items {
|
for _, k := range keys {
|
||||||
if ns == service.Namespace {
|
svc := s.Services[k]
|
||||||
res.Items = append(res.Items, service)
|
if ns == metav1.NamespaceAll || ns == svc.Namespace {
|
||||||
}
|
res.Items = append(res.Items, *svc)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
res.Items = append([]api.Service{}, s.ServiceList.Items...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
@ -129,11 +128,6 @@ func (s *serviceStorage) Create(ctx context.Context, obj runtime.Object, createV
|
|||||||
s.saveService(svc)
|
s.saveService(svc)
|
||||||
s.Services[svc.Name].ResourceVersion = "1"
|
s.Services[svc.Name].ResourceVersion = "1"
|
||||||
|
|
||||||
if s.ServiceList == nil {
|
|
||||||
s.ServiceList = &api.ServiceList{}
|
|
||||||
}
|
|
||||||
|
|
||||||
s.ServiceList.Items = append(s.ServiceList.Items, *svc)
|
|
||||||
return s.Services[svc.Name].DeepCopy(), nil
|
return s.Services[svc.Name].DeepCopy(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user