Skip to content

Commit c8ac2d5

Browse files
committed
use a more 'normal' storage factory
1 parent e0e1f19 commit c8ac2d5

File tree

9 files changed

+135
-188
lines changed

9 files changed

+135
-188
lines changed

pkg/cmd/openshift-apiserver/openshiftapiserver/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import (
2525
"github.com/openshift/origin/pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing"
2626
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
2727
originadmission "github.com/openshift/origin/pkg/cmd/server/origin/admission"
28-
originrest "github.com/openshift/origin/pkg/cmd/server/origin/rest"
2928
"github.com/openshift/origin/pkg/image/apiserver/registryhostname"
3029
sccstorage "github.com/openshift/origin/pkg/security/apiserver/registry/securitycontextconstraints/etcd"
3130
usercache "github.com/openshift/origin/pkg/user/cache"
31+
"github.com/openshift/origin/pkg/util/restoptions"
3232
"github.com/openshift/origin/pkg/version"
3333
)
3434

@@ -49,7 +49,7 @@ func NewOpenshiftAPIConfig(openshiftAPIServerConfig *configapi.MasterConfig) (*O
4949
if err != nil {
5050
return nil, err
5151
}
52-
restOptsGetter, err := originrest.StorageOptions(*openshiftAPIServerConfig)
52+
restOptsGetter, err := restoptions.NewConfigGetter(*openshiftAPIServerConfig)
5353
if err != nil {
5454
return nil, err
5555
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package configprocessing
2+
3+
import (
4+
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
5+
cmdflags "github.com/openshift/origin/pkg/cmd/util/flags"
6+
"k8s.io/apimachinery/pkg/runtime/schema"
7+
utilerrors "k8s.io/apimachinery/pkg/util/errors"
8+
"k8s.io/apiserver/pkg/server/options"
9+
"k8s.io/apiserver/pkg/storage/storagebackend"
10+
)
11+
12+
// GetEtcdOptions takes configuration information and flag overrides to produce the upstream etcdoptions.
13+
func GetEtcdOptions(startingFlags map[string][]string, etcdConnectionInfo configapi.EtcdConnectionInfo, storagePrefix string, defaultWatchCacheSizes map[schema.GroupResource]int) (*options.EtcdOptions, error) {
14+
storageConfig := storagebackend.NewDefaultConfig(storagePrefix, nil)
15+
storageConfig.Type = "etcd3"
16+
storageConfig.ServerList = etcdConnectionInfo.URLs
17+
storageConfig.KeyFile = etcdConnectionInfo.ClientCert.KeyFile
18+
storageConfig.CertFile = etcdConnectionInfo.ClientCert.CertFile
19+
storageConfig.CAFile = etcdConnectionInfo.CA
20+
21+
etcdOptions := options.NewEtcdOptions(storageConfig)
22+
etcdOptions.DefaultStorageMediaType = "application/vnd.kubernetes.protobuf"
23+
etcdOptions.DefaultWatchCacheSize = 0
24+
if err := cmdflags.ResolveIgnoreMissing(startingFlags, etcdOptions.AddFlags); len(err) > 0 {
25+
return nil, utilerrors.NewAggregate(err)
26+
}
27+
28+
if etcdOptions.EnableWatchCache {
29+
watchCacheSizes := map[schema.GroupResource]int{}
30+
for k, v := range defaultWatchCacheSizes {
31+
watchCacheSizes[k] = v
32+
}
33+
34+
if userSpecified, err := options.ParseWatchCacheSizes(etcdOptions.WatchCacheSizes); err == nil {
35+
for resource, size := range userSpecified {
36+
watchCacheSizes[resource] = size
37+
}
38+
}
39+
40+
var err error
41+
etcdOptions.WatchCacheSizes, err = options.WriteWatchCacheSizes(watchCacheSizes)
42+
if err != nil {
43+
return nil, err
44+
}
45+
}
46+
47+
return etcdOptions, nil
48+
}

pkg/cmd/server/kubernetes/master/master_config.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,10 @@ func BuildKubeAPIserverOptions(masterConfig configapi.MasterConfig) (*kapiserver
121121
}
122122
}
123123

124-
server.Etcd.EnableGarbageCollection = true
125-
server.Etcd.StorageConfig.Type = "etcd3"
126-
server.Etcd.DefaultStorageMediaType = "application/json" // TODO(post-1.6.1-rebase): enable protobuf with etcd3 as upstream
127-
server.Etcd.StorageConfig.Quorum = true
128-
server.Etcd.StorageConfig.Prefix = masterConfig.EtcdStorageConfig.KubernetesStoragePrefix
129-
server.Etcd.StorageConfig.ServerList = masterConfig.EtcdClientInfo.URLs
130-
server.Etcd.StorageConfig.KeyFile = masterConfig.EtcdClientInfo.ClientCert.KeyFile
131-
server.Etcd.StorageConfig.CertFile = masterConfig.EtcdClientInfo.ClientCert.CertFile
132-
server.Etcd.StorageConfig.CAFile = masterConfig.EtcdClientInfo.CA
133-
server.Etcd.DefaultWatchCacheSize = 0
124+
server.Etcd, err = configprocessing.GetEtcdOptions(masterConfig.KubernetesMasterConfig.APIServerArguments, masterConfig.EtcdClientInfo, masterConfig.EtcdStorageConfig.KubernetesStoragePrefix, nil)
125+
if err != nil {
126+
return nil, err
127+
}
134128

135129
server.GenericServerRunOptions.CorsAllowedOriginList = masterConfig.CORSAllowedOrigins
136130
server.GenericServerRunOptions.MaxRequestsInFlight = masterConfig.ServingInfo.MaxRequestsInFlight

pkg/cmd/server/origin/master_config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
2929
kubernetes "github.com/openshift/origin/pkg/cmd/server/kubernetes/master"
3030
originadmission "github.com/openshift/origin/pkg/cmd/server/origin/admission"
31-
originrest "github.com/openshift/origin/pkg/cmd/server/origin/rest"
3231
imageadmission "github.com/openshift/origin/pkg/image/apiserver/admission/limitrange"
3332
imageinformer "github.com/openshift/origin/pkg/image/generated/informers/internalversion"
3433
_ "github.com/openshift/origin/pkg/printers/internalversion"
@@ -131,7 +130,7 @@ func BuildMasterConfig(
131130
informers = realLoopbackInformers
132131
}
133132

134-
restOptsGetter, err := originrest.StorageOptions(options)
133+
restOptsGetter, err := restoptions.NewConfigGetter(options)
135134
if err != nil {
136135
return nil, err
137136
}

pkg/cmd/server/origin/rest/storage_options.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

pkg/cmd/server/start/master_args.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,6 @@ func (args MasterArgs) BuildSerializeableMasterConfig() (*configapi.MasterConfig
314314
// When creating a new config, use Protobuf
315315
configapi.SetProtobufClientDefaults(config.MasterClients.OpenShiftLoopbackClientConnectionOverrides)
316316

317-
// Default storage backend to etcd3 with protobuf storage for our innate config when starting both
318-
// Kubernetes and etcd.
319-
if config.EtcdConfig != nil {
320-
if len(config.KubernetesMasterConfig.APIServerArguments) == 0 {
321-
config.KubernetesMasterConfig.APIServerArguments = configapi.ExtendedArguments{}
322-
config.KubernetesMasterConfig.APIServerArguments["storage-media-type"] = []string{"application/vnd.kubernetes.protobuf"}
323-
config.KubernetesMasterConfig.APIServerArguments["storage-backend"] = []string{"etcd3"}
324-
}
325-
}
326-
327317
return config, nil
328318
}
329319

pkg/cmd/util/flags/flags.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import (
1212

1313
// Apply stores the provided arguments onto a flag set, reporting any errors
1414
// encountered during the process.
15-
func Apply(args map[string][]string, flags *pflag.FlagSet) []error {
15+
func apply(args map[string][]string, flags *pflag.FlagSet, ignoreMissing bool) []error {
1616
var errs []error
1717
for key, value := range args {
1818
flag := flags.Lookup(key)
1919
if flag == nil {
20-
errs = append(errs, field.Invalid(field.NewPath("flag"), key, "is not a valid flag"))
20+
if !ignoreMissing {
21+
errs = append(errs, field.Invalid(field.NewPath("flag"), key, "is not a valid flag"))
22+
}
2123
continue
2224
}
2325
for _, s := range value {
@@ -33,7 +35,15 @@ func Apply(args map[string][]string, flags *pflag.FlagSet) []error {
3335
func Resolve(args map[string][]string, fn func(*pflag.FlagSet)) []error {
3436
fs := pflag.NewFlagSet("extended", pflag.ContinueOnError)
3537
fn(fs)
36-
return Apply(args, fs)
38+
return apply(args, fs, false)
39+
}
40+
41+
// ResolveIgnoreMissing resolves flags in the args, but does not fail on missing flags. It silently skips those.
42+
// It's useful for building subsets of the full options, but validation should do a normal binding.
43+
func ResolveIgnoreMissing(args map[string][]string, fn func(*pflag.FlagSet)) []error {
44+
fs := pflag.NewFlagSet("extended", pflag.ContinueOnError)
45+
fn(fs)
46+
return apply(args, fs, true)
3747
}
3848

3949
// ComponentFlag represents a set of enabled components used in a command line.

0 commit comments

Comments
 (0)