Skip to content

Commit 314a622

Browse files
pmorieVille Aikas
authored and
Ville Aikas
committed
Wire etcd prefix to storage and call complete with options (#1394)
1 parent bcf37fd commit 314a622

File tree

9 files changed

+33
-21
lines changed

9 files changed

+33
-21
lines changed

cmd/apiserver/app/server/etcd_options.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package server
1818

1919
import (
2020
"github.com/kubernetes-incubator/service-catalog/pkg/api"
21-
"github.com/pborman/uuid"
2221
"github.com/spf13/pflag"
2322
genericserveroptions "k8s.io/apiserver/pkg/server/options"
2423
"k8s.io/apiserver/pkg/storage/storagebackend"
@@ -32,10 +31,18 @@ type EtcdOptions struct {
3231
*genericserveroptions.EtcdOptions
3332
}
3433

34+
const (
35+
// DefaultEtcdPathPrefix is the default prefix that is prepended to all
36+
// resource paths in etcd. It is intended to allow an operator to
37+
// differentiate the storage of different API servers from one another in
38+
// a single etcd.
39+
DefaultEtcdPathPrefix = "/registry"
40+
)
41+
3542
// NewEtcdOptions creates a new, empty, EtcdOptions instance
3643
func NewEtcdOptions() *EtcdOptions {
3744
return &EtcdOptions{
38-
EtcdOptions: genericserveroptions.NewEtcdOptions(storagebackend.NewDefaultConfig(uuid.New(), api.Scheme, nil)),
45+
EtcdOptions: genericserveroptions.NewEtcdOptions(storagebackend.NewDefaultConfig(DefaultEtcdPathPrefix, api.Scheme, nil)),
3946
}
4047
}
4148

cmd/apiserver/app/server/server.go

-17
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/golang/glog"
2525
"github.com/kubernetes-incubator/service-catalog/pkg"
2626
"github.com/kubernetes-incubator/service-catalog/pkg/kubernetes/pkg/util/interrupt"
27-
"github.com/kubernetes-incubator/service-catalog/pkg/registry/servicecatalog/server"
2827
"github.com/kubernetes-incubator/service-catalog/plugin/pkg/admission/broker/authsarcheck"
2928
"github.com/kubernetes-incubator/service-catalog/plugin/pkg/admission/namespace/lifecycle"
3029
siclifecycle "github.com/kubernetes-incubator/service-catalog/plugin/pkg/admission/servicebindings/lifecycle"
@@ -40,14 +39,6 @@ const (
4039
// k8s core API server.
4140
certDirectory = "/var/run/kubernetes-service-catalog"
4241

43-
// I made this up to match some existing paths. I am not sure if there
44-
// are any restrictions on the format or structure beyond text
45-
// separated by slashes.
46-
etcdPathPrefix = "/k8s.io/service-catalog"
47-
48-
// GroupName I made this up. Maybe we'll need it.
49-
GroupName = "service-catalog.k8s.io"
50-
5142
storageTypeFlagName = "storageType"
5243
)
5344

@@ -94,14 +85,6 @@ func NewCommandServer(
9485
glog.Fatalf("invalid storage type '%s' (%s)", storageType, err)
9586
return nil, err
9687
}
97-
if storageType == server.StorageTypeEtcd {
98-
glog.Infof("using etcd for storage")
99-
// Store resources in etcd under our special prefix
100-
opts.EtcdOptions.StorageConfig.Prefix = etcdPathPrefix
101-
} else {
102-
// This should never happen, catch for potential bugs
103-
panic("Unexpected storage type: " + storageType)
104-
}
10588

10689
cmd.Run = func(c *cobra.Command, args []string) {
10790
h := interrupt.New(nil, func() {

pkg/apiserver/etcd_config.go

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ func (c completedEtcdConfig) NewServer() (*ServiceCatalogAPIServer, error) {
8888

8989
roFactory := etcdRESTOptionsFactory{
9090
deleteCollectionWorkers: c.extraConfig.deleteCollectionWorkers,
91+
// TODO https://github.com/kubernetes/kubernetes/issues/44507
92+
// we still need to enable it so finalizers are respected.
9193
enableGarbageCollection: true,
9294
storageFactory: c.extraConfig.storageFactory,
9395
storageDecorator: generic.UndecoratedStorage,

pkg/apiserver/etcd_rest_options_factory.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ func (f etcdRESTOptionsFactory) GetRESTOptions(resource schema.GroupResource) (g
4545
Decorator: f.storageDecorator,
4646
DeleteCollectionWorkers: f.deleteCollectionWorkers,
4747
EnableGarbageCollection: f.enableGarbageCollection,
48-
ResourcePrefix: f.storageFactory.ResourcePrefix(resource),
48+
ResourcePrefix: resource.Group + "/" + resource.Resource,
4949
}, nil
5050
}

pkg/registry/servicecatalog/binding/storage.go

+5
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ func NewStorage(opts server.Options) (rest.Storage, rest.Storage, error) {
139139
DestroyFunc: dFunc,
140140
}
141141

142+
options := &generic.StoreOptions{RESTOptions: opts.EtcdOptions.RESTOptions, AttrFunc: GetAttrs}
143+
if err := store.CompleteWithOptions(options); err != nil {
144+
panic(err) // TODO: Propagate error up
145+
}
146+
142147
statusStore := store
143148
statusStore.UpdateStrategy = bindingStatusUpdateStrategy
144149

pkg/registry/servicecatalog/broker/storage.go

+5
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ func NewStorage(opts server.Options) (brokers, brokersStatus rest.Storage) {
139139
DestroyFunc: dFunc,
140140
}
141141

142+
options := &generic.StoreOptions{RESTOptions: opts.EtcdOptions.RESTOptions, AttrFunc: GetAttrs}
143+
if err := store.CompleteWithOptions(options); err != nil {
144+
panic(err) // TODO: Propagate error up
145+
}
146+
142147
statusStore := store
143148
statusStore.UpdateStrategy = brokerStatusUpdateStrategy
144149

pkg/registry/servicecatalog/instance/storage.go

+4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ func NewStorage(opts server.Options) (rest.Storage, rest.Storage, rest.Storage)
137137
Storage: storageInterface,
138138
DestroyFunc: dFunc,
139139
}
140+
options := &generic.StoreOptions{RESTOptions: opts.EtcdOptions.RESTOptions, AttrFunc: GetAttrs}
141+
if err := store.CompleteWithOptions(options); err != nil {
142+
panic(err) // TODO: Propagate error up
143+
}
140144

141145
statusStore := store
142146
statusStore.UpdateStrategy = instanceStatusUpdateStrategy

pkg/registry/servicecatalog/rest/storage_servicecatalog_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ type GetRESTOptionsHelper struct {
3636

3737
func (g GetRESTOptionsHelper) GetRESTOptions(resource schema.GroupResource) (generic.RESTOptions, error) {
3838
return generic.RESTOptions{
39-
StorageConfig: &storagebackend.Config{},
39+
ResourcePrefix: resource.Group + "/" + resource.Resource,
40+
StorageConfig: &storagebackend.Config{},
4041
Decorator: generic.StorageDecorator(func(
4142
copier runtime.ObjectCopier,
4243
config *storagebackend.Config,

pkg/registry/servicecatalog/serviceclass/storage.go

+5
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ func NewStorage(opts server.Options) (rest.Storage, rest.Storage) {
146146
DestroyFunc: dFunc,
147147
}
148148

149+
options := &generic.StoreOptions{RESTOptions: opts.EtcdOptions.RESTOptions, AttrFunc: GetAttrs}
150+
if err := store.CompleteWithOptions(options); err != nil {
151+
panic(err) // TODO: Propagate error up
152+
}
153+
149154
statusStore := store
150155
statusStore.UpdateStrategy = serviceClassStatusUpdateStrategy
151156

0 commit comments

Comments
 (0)