forked from acorn-io/mink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apigroup.go
35 lines (30 loc) · 1.2 KB
/
apigroup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package apigroup
import (
"github.com/hobbyfarm/mink/pkg/serializer"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apiserver/pkg/registry/rest"
genericapiserver "k8s.io/apiserver/pkg/server"
)
type AddToScheme func(*runtime.Scheme) error
func ForStores(scheme AddToScheme, stores map[string]rest.Storage, groupVersion schema.GroupVersion) (*genericapiserver.APIGroupInfo, error) {
newScheme := runtime.NewScheme()
if err := scheme(newScheme); err != nil {
return nil, err
}
for _, store := range stores {
newScheme.AddKnownTypes(schema.GroupVersion{
Group: groupVersion.Group,
Version: runtime.APIVersionInternal,
}, store.New())
}
codecs := runtimeserializer.NewCodecFactory(newScheme)
parameterCodec := runtime.NewParameterCodec(newScheme)
apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(groupVersion.Group, newScheme, parameterCodec, codecs)
apiGroupInfo.VersionedResourcesStorageMap[groupVersion.Version] = stores
if groupVersion.Group != "" {
apiGroupInfo.NegotiatedSerializer = serializer.NewNoProtobufSerializer(apiGroupInfo.NegotiatedSerializer)
}
return &apiGroupInfo, nil
}