-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactory.go
More file actions
59 lines (50 loc) · 1.51 KB
/
factory.go
File metadata and controls
59 lines (50 loc) · 1.51 KB
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
57
58
59
package spanner
import (
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage/storagebackend"
"k8s.io/apiserver/pkg/storage/storagebackend/factory"
"k8s.io/apiserver/pkg/storage/value/encrypt/identity"
)
// BackendFactory is the type expected by kplane-dev/storage.DecoratorConfig.BackendFactory.
// Duplicated here to avoid importing kplane-dev/storage (which would create a cycle).
type BackendFactory func(
config *storagebackend.ConfigForResource,
newFunc, newListFunc func() runtime.Object,
resourcePrefix string,
) (storage.Interface, factory.DestroyFunc, error)
// NewBackendFactory returns a BackendFactory that creates Spanner-backed
// storage.Interface instances. Each call to the returned factory creates a
// new store sharing the same Spanner client.
func NewBackendFactory(cfg SpannerConfig) BackendFactory {
return func(
config *storagebackend.ConfigForResource,
newFunc, newListFunc func() runtime.Object,
resourcePrefix string,
) (storage.Interface, factory.DestroyFunc, error) {
ctx := context.Background()
client, err := cfg.NewClient(ctx)
if err != nil {
return nil, nil, err
}
transformer := config.Transformer
if transformer == nil {
transformer = identity.NewEncryptCheckTransformer()
}
s := NewStore(
client,
config.Codec,
newFunc,
newListFunc,
config.Prefix,
resourcePrefix,
transformer,
config.WrapDecodedObject,
)
destroyFunc := func() {
client.Close()
}
return s, destroyFunc, nil
}
}