-
Notifications
You must be signed in to change notification settings - Fork 57
/
etcd.go
56 lines (45 loc) · 2 KB
/
etcd.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Copyright 2022 The KubeZoo 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 test_rest
import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
"github.com/kubewharf/kubezoo/pkg/apis/tenant/v1alpha1"
)
// REST implements a RESTStorage for audit sink against etcd
type REST struct {
*genericregistry.Store
}
// NewREST returns a RESTStorage object that will work against API services.
func NewREST(scheme *runtime.Scheme, optsGetter generic.RESTOptionsGetter) (*REST, error) {
strategy := NewStrategy(scheme)
store := &genericregistry.Store{
NewFunc: func() runtime.Object { return &v1alpha1.Tenant{} },
// E0111 12:55:20.698099 49243 cacher.go:428] unexpected ListAndWatch error: storage/cacher.go:/xuchens: Failed to list *v1alpha1.Xuchen: *v1alpha1.Xuchen is not a list: no Items field in this object
NewListFunc: func() runtime.Object { return &v1alpha1.TenantList{} },
PredicateFunc: MatchTenant,
DefaultQualifiedResource: Resource("tenants"),
CreateStrategy: strategy,
UpdateStrategy: strategy,
DeleteStrategy: strategy,
// TODO: define table converter that exposes more than name/creation timestamp
TableConvertor: rest.NewDefaultTableConvertor(Resource("tenants")),
}
options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: GetAttrs}
if err := store.CompleteWithOptions(options); err != nil {
return nil, err
}
return &REST{store}, nil
}