From bffab1bbdd8e577abe3306a16aa00eb592cc8cfa Mon Sep 17 00:00:00 2001 From: David Eads Date: Mon, 27 Aug 2018 10:39:15 -0400 Subject: [PATCH 1/4] UPSTREAM: 67896: expose generic storage factory primitives --- .../staging/src/k8s.io/apiserver/pkg/server/options/etcd.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vendor/k8s.io/kubernetes/staging/src/k8s.io/apiserver/pkg/server/options/etcd.go b/vendor/k8s.io/kubernetes/staging/src/k8s.io/apiserver/pkg/server/options/etcd.go index 7f7c47d760e1..b6a32f6f161e 100644 --- a/vendor/k8s.io/kubernetes/staging/src/k8s.io/apiserver/pkg/server/options/etcd.go +++ b/vendor/k8s.io/kubernetes/staging/src/k8s.io/apiserver/pkg/server/options/etcd.go @@ -192,7 +192,7 @@ func (s *EtcdOptions) ApplyWithStorageFactoryTo(factory serverstorage.StorageFac if err := s.addEtcdHealthEndpoint(c); err != nil { return err } - c.RESTOptionsGetter = &storageFactoryRestOptionsFactory{Options: *s, StorageFactory: factory} + c.RESTOptionsGetter = &StorageFactoryRestOptionsFactory{Options: *s, StorageFactory: factory} return nil } @@ -234,12 +234,12 @@ func (f *SimpleRestOptionsFactory) GetRESTOptions(resource schema.GroupResource) return ret, nil } -type storageFactoryRestOptionsFactory struct { +type StorageFactoryRestOptionsFactory struct { Options EtcdOptions StorageFactory serverstorage.StorageFactory } -func (f *storageFactoryRestOptionsFactory) GetRESTOptions(resource schema.GroupResource) (generic.RESTOptions, error) { +func (f *StorageFactoryRestOptionsFactory) GetRESTOptions(resource schema.GroupResource) (generic.RESTOptions, error) { storageConfig, err := f.StorageFactory.NewConfig(resource) if err != nil { return generic.RESTOptions{}, fmt.Errorf("unable to find storage destination for %v, due to %v", resource, err.Error()) From b8be8a786a66f95b7995c6e8696d2b1ff0055fa5 Mon Sep 17 00:00:00 2001 From: David Eads Date: Mon, 27 Aug 2018 10:39:22 -0400 Subject: [PATCH 2/4] use a more 'normal' storage factory --- .../openshiftapiserver/config.go | 4 +- .../configprocessing/etcd.go | 48 ++++++ .../server/kubernetes/master/master_config.go | 14 +- pkg/cmd/server/origin/master_config.go | 3 +- pkg/cmd/server/origin/rest/storage_options.go | 59 ------- pkg/cmd/server/start/master_args.go | 10 -- pkg/cmd/util/flags/flags.go | 16 +- .../coreinstall/kubeapiserver/config.go | 2 - pkg/util/restoptions/configgetter.go | 158 +++++++----------- test/integration/etcd_storage_path_test.go | 11 +- 10 files changed, 135 insertions(+), 190 deletions(-) create mode 100644 pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing/etcd.go delete mode 100644 pkg/cmd/server/origin/rest/storage_options.go diff --git a/pkg/cmd/openshift-apiserver/openshiftapiserver/config.go b/pkg/cmd/openshift-apiserver/openshiftapiserver/config.go index b9368bc57c7c..d6b29cb3f038 100644 --- a/pkg/cmd/openshift-apiserver/openshiftapiserver/config.go +++ b/pkg/cmd/openshift-apiserver/openshiftapiserver/config.go @@ -25,10 +25,10 @@ import ( "github.com/openshift/origin/pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing" configapi "github.com/openshift/origin/pkg/cmd/server/apis/config" originadmission "github.com/openshift/origin/pkg/cmd/server/origin/admission" - originrest "github.com/openshift/origin/pkg/cmd/server/origin/rest" "github.com/openshift/origin/pkg/image/apiserver/registryhostname" sccstorage "github.com/openshift/origin/pkg/security/apiserver/registry/securitycontextconstraints/etcd" usercache "github.com/openshift/origin/pkg/user/cache" + "github.com/openshift/origin/pkg/util/restoptions" "github.com/openshift/origin/pkg/version" ) @@ -49,7 +49,7 @@ func NewOpenshiftAPIConfig(openshiftAPIServerConfig *configapi.MasterConfig) (*O if err != nil { return nil, err } - restOptsGetter, err := originrest.StorageOptions(*openshiftAPIServerConfig) + restOptsGetter, err := restoptions.NewConfigGetter(*openshiftAPIServerConfig) if err != nil { return nil, err } diff --git a/pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing/etcd.go b/pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing/etcd.go new file mode 100644 index 000000000000..252cb86ad597 --- /dev/null +++ b/pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing/etcd.go @@ -0,0 +1,48 @@ +package configprocessing + +import ( + configapi "github.com/openshift/origin/pkg/cmd/server/apis/config" + cmdflags "github.com/openshift/origin/pkg/cmd/util/flags" + "k8s.io/apimachinery/pkg/runtime/schema" + utilerrors "k8s.io/apimachinery/pkg/util/errors" + "k8s.io/apiserver/pkg/server/options" + "k8s.io/apiserver/pkg/storage/storagebackend" +) + +// GetEtcdOptions takes configuration information and flag overrides to produce the upstream etcdoptions. +func GetEtcdOptions(startingFlags map[string][]string, etcdConnectionInfo configapi.EtcdConnectionInfo, storagePrefix string, defaultWatchCacheSizes map[schema.GroupResource]int) (*options.EtcdOptions, error) { + storageConfig := storagebackend.NewDefaultConfig(storagePrefix, nil) + storageConfig.Type = "etcd3" + storageConfig.ServerList = etcdConnectionInfo.URLs + storageConfig.KeyFile = etcdConnectionInfo.ClientCert.KeyFile + storageConfig.CertFile = etcdConnectionInfo.ClientCert.CertFile + storageConfig.CAFile = etcdConnectionInfo.CA + + etcdOptions := options.NewEtcdOptions(storageConfig) + etcdOptions.DefaultStorageMediaType = "application/vnd.kubernetes.protobuf" + etcdOptions.DefaultWatchCacheSize = 0 + if err := cmdflags.ResolveIgnoreMissing(startingFlags, etcdOptions.AddFlags); len(err) > 0 { + return nil, utilerrors.NewAggregate(err) + } + + if etcdOptions.EnableWatchCache { + watchCacheSizes := map[schema.GroupResource]int{} + for k, v := range defaultWatchCacheSizes { + watchCacheSizes[k] = v + } + + if userSpecified, err := options.ParseWatchCacheSizes(etcdOptions.WatchCacheSizes); err == nil { + for resource, size := range userSpecified { + watchCacheSizes[resource] = size + } + } + + var err error + etcdOptions.WatchCacheSizes, err = options.WriteWatchCacheSizes(watchCacheSizes) + if err != nil { + return nil, err + } + } + + return etcdOptions, nil +} diff --git a/pkg/cmd/server/kubernetes/master/master_config.go b/pkg/cmd/server/kubernetes/master/master_config.go index 6d04007a4a74..d12e707ffe00 100644 --- a/pkg/cmd/server/kubernetes/master/master_config.go +++ b/pkg/cmd/server/kubernetes/master/master_config.go @@ -121,16 +121,10 @@ func BuildKubeAPIserverOptions(masterConfig configapi.MasterConfig) (*kapiserver } } - server.Etcd.EnableGarbageCollection = true - server.Etcd.StorageConfig.Type = "etcd3" - server.Etcd.DefaultStorageMediaType = "application/json" // TODO(post-1.6.1-rebase): enable protobuf with etcd3 as upstream - server.Etcd.StorageConfig.Quorum = true - server.Etcd.StorageConfig.Prefix = masterConfig.EtcdStorageConfig.KubernetesStoragePrefix - server.Etcd.StorageConfig.ServerList = masterConfig.EtcdClientInfo.URLs - server.Etcd.StorageConfig.KeyFile = masterConfig.EtcdClientInfo.ClientCert.KeyFile - server.Etcd.StorageConfig.CertFile = masterConfig.EtcdClientInfo.ClientCert.CertFile - server.Etcd.StorageConfig.CAFile = masterConfig.EtcdClientInfo.CA - server.Etcd.DefaultWatchCacheSize = 0 + server.Etcd, err = configprocessing.GetEtcdOptions(masterConfig.KubernetesMasterConfig.APIServerArguments, masterConfig.EtcdClientInfo, masterConfig.EtcdStorageConfig.KubernetesStoragePrefix, nil) + if err != nil { + return nil, err + } server.GenericServerRunOptions.CorsAllowedOriginList = masterConfig.CORSAllowedOrigins server.GenericServerRunOptions.MaxRequestsInFlight = masterConfig.ServingInfo.MaxRequestsInFlight diff --git a/pkg/cmd/server/origin/master_config.go b/pkg/cmd/server/origin/master_config.go index d15db0f280b2..6f3f629506b9 100644 --- a/pkg/cmd/server/origin/master_config.go +++ b/pkg/cmd/server/origin/master_config.go @@ -28,7 +28,6 @@ import ( configapi "github.com/openshift/origin/pkg/cmd/server/apis/config" kubernetes "github.com/openshift/origin/pkg/cmd/server/kubernetes/master" originadmission "github.com/openshift/origin/pkg/cmd/server/origin/admission" - originrest "github.com/openshift/origin/pkg/cmd/server/origin/rest" imageadmission "github.com/openshift/origin/pkg/image/apiserver/admission/limitrange" imageinformer "github.com/openshift/origin/pkg/image/generated/informers/internalversion" _ "github.com/openshift/origin/pkg/printers/internalversion" @@ -131,7 +130,7 @@ func BuildMasterConfig( informers = realLoopbackInformers } - restOptsGetter, err := originrest.StorageOptions(options) + restOptsGetter, err := restoptions.NewConfigGetter(options) if err != nil { return nil, err } diff --git a/pkg/cmd/server/origin/rest/storage_options.go b/pkg/cmd/server/origin/rest/storage_options.go deleted file mode 100644 index 852c78363a7d..000000000000 --- a/pkg/cmd/server/origin/rest/storage_options.go +++ /dev/null @@ -1,59 +0,0 @@ -package rest - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - serverstorage "k8s.io/apiserver/pkg/server/storage" - - configapi "github.com/openshift/origin/pkg/cmd/server/apis/config" - "github.com/openshift/origin/pkg/util/restoptions" -) - -// StorageOptions returns the appropriate storage configuration for the origin rest APIs, including -// overiddes. -func StorageOptions(options configapi.MasterConfig) (restoptions.Getter, error) { - return restoptions.NewConfigGetter( - options, - &serverstorage.ResourceConfig{}, - // prefixes: - map[schema.GroupResource]string{ - {Resource: "clusterpolicies"}: "authorization/cluster/policies", - {Resource: "clusterpolicies", Group: "authorization.openshift.io"}: "authorization/cluster/policies", - {Resource: "clusterpolicybindings"}: "authorization/cluster/policybindings", - {Resource: "clusterpolicybindings", Group: "authorization.openshift.io"}: "authorization/cluster/policybindings", - {Resource: "policies"}: "authorization/local/policies", - {Resource: "policies", Group: "authorization.openshift.io"}: "authorization/local/policies", - {Resource: "policybindings"}: "authorization/local/policybindings", - {Resource: "policybindings", Group: "authorization.openshift.io"}: "authorization/local/policybindings", - - {Resource: "oauthaccesstokens"}: "oauth/accesstokens", - {Resource: "oauthaccesstokens", Group: "oauth.openshift.io"}: "oauth/accesstokens", - {Resource: "oauthauthorizetokens"}: "oauth/authorizetokens", - {Resource: "oauthauthorizetokens", Group: "oauth.openshift.io"}: "oauth/authorizetokens", - {Resource: "oauthclients"}: "oauth/clients", - {Resource: "oauthclients", Group: "oauth.openshift.io"}: "oauth/clients", - {Resource: "oauthclientauthorizations"}: "oauth/clientauthorizations", - {Resource: "oauthclientauthorizations", Group: "oauth.openshift.io"}: "oauth/clientauthorizations", - - {Resource: "identities"}: "useridentities", - {Resource: "identities", Group: "user.openshift.io"}: "useridentities", - - {Resource: "clusternetworks"}: "registry/sdnnetworks", - {Resource: "clusternetworks", Group: "network.openshift.io"}: "registry/sdnnetworks", - {Resource: "egressnetworkpolicies"}: "registry/egressnetworkpolicy", - {Resource: "egressnetworkpolicies", Group: "network.openshift.io"}: "registry/egressnetworkpolicy", - {Resource: "hostsubnets"}: "registry/sdnsubnets", - {Resource: "hostsubnets", Group: "network.openshift.io"}: "registry/sdnsubnets", - {Resource: "netnamespaces"}: "registry/sdnnetnamespaces", - {Resource: "netnamespaces", Group: "network.openshift.io"}: "registry/sdnnetnamespaces", - }, - // storage versions: no overrides anymore - map[schema.GroupResource]schema.GroupVersion{}, - // quorum resources: - map[schema.GroupResource]struct{}{ - {Resource: "oauthauthorizetokens"}: {}, - {Resource: "oauthauthorizetokens", Group: "oauth.openshift.io"}: {}, - {Resource: "oauthaccesstokens"}: {}, - {Resource: "oauthaccesstokens", Group: "oauth.openshift.io"}: {}, - }, - ) -} diff --git a/pkg/cmd/server/start/master_args.go b/pkg/cmd/server/start/master_args.go index 081f7b79156e..f341447bb419 100644 --- a/pkg/cmd/server/start/master_args.go +++ b/pkg/cmd/server/start/master_args.go @@ -314,16 +314,6 @@ func (args MasterArgs) BuildSerializeableMasterConfig() (*configapi.MasterConfig // When creating a new config, use Protobuf configapi.SetProtobufClientDefaults(config.MasterClients.OpenShiftLoopbackClientConnectionOverrides) - // Default storage backend to etcd3 with protobuf storage for our innate config when starting both - // Kubernetes and etcd. - if config.EtcdConfig != nil { - if len(config.KubernetesMasterConfig.APIServerArguments) == 0 { - config.KubernetesMasterConfig.APIServerArguments = configapi.ExtendedArguments{} - config.KubernetesMasterConfig.APIServerArguments["storage-media-type"] = []string{"application/vnd.kubernetes.protobuf"} - config.KubernetesMasterConfig.APIServerArguments["storage-backend"] = []string{"etcd3"} - } - } - return config, nil } diff --git a/pkg/cmd/util/flags/flags.go b/pkg/cmd/util/flags/flags.go index 4709477ed714..e22645120dc6 100644 --- a/pkg/cmd/util/flags/flags.go +++ b/pkg/cmd/util/flags/flags.go @@ -12,12 +12,14 @@ import ( // Apply stores the provided arguments onto a flag set, reporting any errors // encountered during the process. -func Apply(args map[string][]string, flags *pflag.FlagSet) []error { +func apply(args map[string][]string, flags *pflag.FlagSet, ignoreMissing bool) []error { var errs []error for key, value := range args { flag := flags.Lookup(key) if flag == nil { - errs = append(errs, field.Invalid(field.NewPath("flag"), key, "is not a valid flag")) + if !ignoreMissing { + errs = append(errs, field.Invalid(field.NewPath("flag"), key, "is not a valid flag")) + } continue } for _, s := range value { @@ -33,7 +35,15 @@ func Apply(args map[string][]string, flags *pflag.FlagSet) []error { func Resolve(args map[string][]string, fn func(*pflag.FlagSet)) []error { fs := pflag.NewFlagSet("extended", pflag.ContinueOnError) fn(fs) - return Apply(args, fs) + return apply(args, fs, false) +} + +// ResolveIgnoreMissing resolves flags in the args, but does not fail on missing flags. It silently skips those. +// It's useful for building subsets of the full options, but validation should do a normal binding. +func ResolveIgnoreMissing(args map[string][]string, fn func(*pflag.FlagSet)) []error { + fs := pflag.NewFlagSet("extended", pflag.ContinueOnError) + fn(fs) + return apply(args, fs, true) } // ComponentFlag represents a set of enabled components used in a command line. diff --git a/pkg/oc/clusterup/coreinstall/kubeapiserver/config.go b/pkg/oc/clusterup/coreinstall/kubeapiserver/config.go index 52f5e0843ed6..c71be57c03e9 100644 --- a/pkg/oc/clusterup/coreinstall/kubeapiserver/config.go +++ b/pkg/oc/clusterup/coreinstall/kubeapiserver/config.go @@ -80,8 +80,6 @@ func (opt KubeAPIServerStartConfig) MakeMasterConfig(dockerClient dockerhelper.I return "", err } - masterconfig.KubernetesMasterConfig.APIServerArguments["feature-gates"] = []string{"CustomResourceSubresources=true"} - if err := componentinstall.WriteMasterConfig(masterconfigFilename, masterconfig); err != nil { return "", err } diff --git a/pkg/util/restoptions/configgetter.go b/pkg/util/restoptions/configgetter.go index 99f1bc991ef6..8c1ec4bcc2d7 100644 --- a/pkg/util/restoptions/configgetter.go +++ b/pkg/util/restoptions/configgetter.go @@ -1,119 +1,50 @@ package restoptions import ( - "sync" - - "github.com/golang/glog" + "strconv" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apiserver/pkg/registry/generic" - "k8s.io/apiserver/pkg/registry/generic/registry" "k8s.io/apiserver/pkg/server/options" + apiserverstorage "k8s.io/apiserver/pkg/server/storage" serverstorage "k8s.io/apiserver/pkg/server/storage" + "k8s.io/kubernetes/pkg/api/legacyscheme" + "github.com/openshift/origin/pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing" configapi "github.com/openshift/origin/pkg/cmd/server/apis/config" - kubernetes "github.com/openshift/origin/pkg/cmd/server/kubernetes/master" ) -// configRESTOptionsGetter provides RESTOptions based on a provided config -type configRESTOptionsGetter struct { - masterOptions configapi.MasterConfig - - restOptionsLock sync.Mutex - restOptionsMap map[schema.GroupResource]generic.RESTOptions - - storageFactory serverstorage.StorageFactory - defaultResourceConfig *serverstorage.ResourceConfig - - cacheEnabled bool - defaultCacheSize int - cacheSizes map[schema.GroupResource]int - quorumResources map[schema.GroupResource]struct{} - - deleteCollectionWorkers int - enableGarbageCollection bool -} - // NewConfigGetter returns a restoptions.Getter implemented using information from the provided master config. // TODO: this class should either not need to know about configapi.MasterConfig, or not be in pkg/util -func NewConfigGetter(masterOptions configapi.MasterConfig, defaultResourceConfig *serverstorage.ResourceConfig, resourcePrefixOverrides map[schema.GroupResource]string, enforcedStorageVersions map[schema.GroupResource]schema.GroupVersion, quorumResources map[schema.GroupResource]struct{}) (Getter, error) { - apiserverOptions, err := kubernetes.BuildKubeAPIserverOptions(masterOptions) - if err != nil { - return nil, err - } - storageFactory, err := kubernetes.BuildStorageFactory(apiserverOptions, enforcedStorageVersions) - if err != nil { - return nil, err - } - storageFactory.DefaultResourcePrefixes = resourcePrefixOverrides - storageFactory.StorageConfig.Prefix = masterOptions.EtcdStorageConfig.OpenShiftStoragePrefix - - // perform watch cache heuristic like upstream - if apiserverOptions.Etcd.EnableWatchCache { - glog.V(2).Infof("Initializing cache sizes based on %dMB limit", apiserverOptions.GenericServerRunOptions.TargetRAMMB) - sizes := newHeuristicWatchCacheSizes(apiserverOptions.GenericServerRunOptions.TargetRAMMB) - if userSpecified, err := options.ParseWatchCacheSizes(apiserverOptions.Etcd.WatchCacheSizes); err == nil { - for resource, size := range userSpecified { - sizes[resource] = size - } - } - apiserverOptions.Etcd.WatchCacheSizes, err = options.WriteWatchCacheSizes(sizes) +func NewConfigGetter(masterOptions configapi.MasterConfig) (Getter, error) { + var err error + targetRAMMB := 0 + if targetRamString := masterOptions.KubernetesMasterConfig.APIServerArguments["target-ram-mb"]; len(targetRamString) == 1 { + targetRAMMB, err = strconv.Atoi(targetRamString[0]) if err != nil { return nil, err } } - cacheSizes, err := options.ParseWatchCacheSizes(apiserverOptions.Etcd.WatchCacheSizes) - if err != nil { - return nil, err - } - - return &configRESTOptionsGetter{ - masterOptions: masterOptions, - cacheEnabled: apiserverOptions.Etcd.EnableWatchCache, - defaultCacheSize: apiserverOptions.Etcd.DefaultWatchCacheSize, - cacheSizes: cacheSizes, - restOptionsMap: map[schema.GroupResource]generic.RESTOptions{}, - defaultResourceConfig: defaultResourceConfig, - quorumResources: quorumResources, - storageFactory: storageFactory, - deleteCollectionWorkers: apiserverOptions.Etcd.DeleteCollectionWorkers, - enableGarbageCollection: apiserverOptions.Etcd.EnableGarbageCollection, - }, nil -} - -func (g *configRESTOptionsGetter) GetRESTOptions(resource schema.GroupResource) (generic.RESTOptions, error) { - g.restOptionsLock.Lock() - defer g.restOptionsLock.Unlock() - if resourceOptions, ok := g.restOptionsMap[resource]; ok { - return resourceOptions, nil - } - - config, err := g.storageFactory.NewConfig(resource) - if err != nil { - return generic.RESTOptions{}, err + etcdOptions, err := configprocessing.GetEtcdOptions( + masterOptions.KubernetesMasterConfig.APIServerArguments, + masterOptions.EtcdClientInfo, + masterOptions.EtcdStorageConfig.OpenShiftStoragePrefix, + newHeuristicWatchCacheSizes(targetRAMMB), + ) + + storageFactory := apiserverstorage.NewDefaultStorageFactory( + etcdOptions.StorageConfig, + etcdOptions.DefaultStorageMediaType, + legacyscheme.Codecs, + apiserverstorage.NewDefaultResourceEncodingConfig(legacyscheme.Scheme), + &serverstorage.ResourceConfig{}, + specialDefaultResourcePrefixes, + ) + restOptionsGetter := &options.StorageFactoryRestOptionsFactory{ + Options: *etcdOptions, + StorageFactory: storageFactory, } - - if _, ok := g.quorumResources[resource]; ok { - config.Quorum = true - } - - cacheSize, ok := g.cacheSizes[resource] - if !ok { - cacheSize = g.defaultCacheSize - } - - resourceOptions := generic.RESTOptions{ - StorageConfig: config, - Decorator: registry.StorageWithCacher(cacheSize), - DeleteCollectionWorkers: g.deleteCollectionWorkers, - EnableGarbageCollection: g.enableGarbageCollection, - ResourcePrefix: g.storageFactory.ResourcePrefix(resource), - CountMetricPollPeriod: config.CountMetricPollPeriod, - } - g.restOptionsMap[resource] = resourceOptions - - return resourceOptions, nil + return restOptionsGetter, nil } // newHeuristicWatchCacheSizes returns a map of suggested watch cache sizes based on total @@ -137,3 +68,36 @@ func maxInt(a, b int) int { } return b } + +// specialDefaultResourcePrefixes are prefixes compiled into Kubernetes. +var specialDefaultResourcePrefixes = map[schema.GroupResource]string{ + {Resource: "clusterpolicies"}: "authorization/cluster/policies", + {Resource: "clusterpolicies", Group: "authorization.openshift.io"}: "authorization/cluster/policies", + {Resource: "clusterpolicybindings"}: "authorization/cluster/policybindings", + {Resource: "clusterpolicybindings", Group: "authorization.openshift.io"}: "authorization/cluster/policybindings", + {Resource: "policies"}: "authorization/local/policies", + {Resource: "policies", Group: "authorization.openshift.io"}: "authorization/local/policies", + {Resource: "policybindings"}: "authorization/local/policybindings", + {Resource: "policybindings", Group: "authorization.openshift.io"}: "authorization/local/policybindings", + + {Resource: "oauthaccesstokens"}: "oauth/accesstokens", + {Resource: "oauthaccesstokens", Group: "oauth.openshift.io"}: "oauth/accesstokens", + {Resource: "oauthauthorizetokens"}: "oauth/authorizetokens", + {Resource: "oauthauthorizetokens", Group: "oauth.openshift.io"}: "oauth/authorizetokens", + {Resource: "oauthclients"}: "oauth/clients", + {Resource: "oauthclients", Group: "oauth.openshift.io"}: "oauth/clients", + {Resource: "oauthclientauthorizations"}: "oauth/clientauthorizations", + {Resource: "oauthclientauthorizations", Group: "oauth.openshift.io"}: "oauth/clientauthorizations", + + {Resource: "identities"}: "useridentities", + {Resource: "identities", Group: "user.openshift.io"}: "useridentities", + + {Resource: "clusternetworks"}: "registry/sdnnetworks", + {Resource: "clusternetworks", Group: "network.openshift.io"}: "registry/sdnnetworks", + {Resource: "egressnetworkpolicies"}: "registry/egressnetworkpolicy", + {Resource: "egressnetworkpolicies", Group: "network.openshift.io"}: "registry/egressnetworkpolicy", + {Resource: "hostsubnets"}: "registry/sdnsubnets", + {Resource: "hostsubnets", Group: "network.openshift.io"}: "registry/sdnsubnets", + {Resource: "netnamespaces"}: "registry/sdnnetnamespaces", + {Resource: "netnamespaces", Group: "network.openshift.io"}: "registry/sdnnetnamespaces", +} diff --git a/test/integration/etcd_storage_path_test.go b/test/integration/etcd_storage_path_test.go index e00990dfa8bd..e605fb7a1040 100644 --- a/test/integration/etcd_storage_path_test.go +++ b/test/integration/etcd_storage_path_test.go @@ -834,6 +834,7 @@ func TestEtcd3StoragePath(t *testing.T) { "storage.k8s.io/v1alpha1=true", "batch/v2alpha1=true", }, + "storage-media-type": {"application/json"}, } masterConfig.AdmissionConfig.PluginConfig["ServiceAccount"] = &serverapi.AdmissionPluginConfig{ Configuration: &serverapi.DefaultAdmissionConfig{Disable: true}, @@ -1158,14 +1159,14 @@ func getEtcdBucket(path string) string { // stable fields to compare as a sanity check type metaObject struct { // all of type meta - Kind string `json:"kind,omitempty" protobuf:"bytes,1,opt,name=kind"` - APIVersion string `json:"apiVersion,omitempty" protobuf:"bytes,2,opt,name=apiVersion"` + Kind string `json:"kind,omitempty"` + APIVersion string `json:"apiVersion,omitempty"` // parts of object meta Metadata struct { - Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"` - Namespace string `json:"namespace,omitempty" protobuf:"bytes,2,opt,name=namespace"` - } `json:"metadata,omitempty" protobuf:"bytes,3,opt,name=metadata"` + Name string `json:"name,omitempty"` + Namespace string `json:"namespace,omitempty"` + } `json:"metadata,omitempty"` } func (obj *metaObject) getGVK() schema.GroupVersionKind { From 8708fd5218c50a1b93b5ebeb451edf8d7bdf52d3 Mon Sep 17 00:00:00 2001 From: David Eads Date: Mon, 27 Aug 2018 11:44:57 -0400 Subject: [PATCH 3/4] collapse onto upstream storage RESTOptions --- .../registry/deployconfig/etcd/etcd.go | 3 +-- .../rolebindingrestriction/etcd/etcd.go | 3 +-- .../apiserver/registry/build/etcd/etcd.go | 3 +-- .../registry/buildconfig/etcd/etcd.go | 3 +-- .../openshiftapiserver/config.go | 3 +-- .../openshiftapiserver/restoptionsgetter.go} | 6 ++--- pkg/cmd/server/origin/master_config.go | 6 ++--- .../apiserver/registry/image/etcd/etcd.go | 3 +-- .../registry/image/etcd/etcd_test.go | 5 ++-- .../registry/imagestream/etcd/etcd.go | 3 +-- .../registry/imagestream/etcd/etcd_test.go | 5 ++-- .../registry/imagestreamimage/rest_test.go | 10 ++++---- .../registry/imagestreammapping/rest_test.go | 10 ++++---- .../registry/imagestreamtag/rest_test.go | 10 ++++---- .../registry/clusternetwork/etcd/etcd.go | 3 +-- .../registry/egressnetworkpolicy/etcd/etcd.go | 3 +-- .../registry/hostsubnet/etcd/etcd.go | 3 +-- .../registry/netnamespace/etcd/etcd.go | 3 +-- .../registry/oauthaccesstoken/etcd/etcd.go | 3 +-- .../registry/oauthauthorizetoken/etcd/etcd.go | 3 +-- .../registry/oauthclient/etcd/etcd.go | 3 +-- .../oauthclientauthorization/etcd/etcd.go | 3 +-- .../clusterresourcequota/etcd/etcd.go | 3 +-- .../apiserver/registry/route/etcd/etcd.go | 3 +-- .../registry/route/etcd/etcd_test.go | 5 ++-- .../brokertemplateinstance/etcd/etcd.go | 3 +-- .../apiserver/registry/template/etcd/etcd.go | 3 +-- .../registry/templateinstance/etcd/etcd.go | 3 +-- .../apiserver/registry/group/etcd/etcd.go | 3 +-- .../apiserver/registry/identity/etcd/etcd.go | 3 +-- pkg/user/apiserver/registry/user/etcd/etcd.go | 3 +-- pkg/util/restoptions/interfaces.go | 10 -------- pkg/util/restoptions/simplegetter.go | 24 ------------------- 33 files changed, 56 insertions(+), 104 deletions(-) rename pkg/{util/restoptions/configgetter.go => cmd/openshift-apiserver/openshiftapiserver/restoptionsgetter.go} (96%) delete mode 100644 pkg/util/restoptions/interfaces.go delete mode 100644 pkg/util/restoptions/simplegetter.go diff --git a/pkg/apps/apiserver/registry/deployconfig/etcd/etcd.go b/pkg/apps/apiserver/registry/deployconfig/etcd/etcd.go index 8ff76b4db033..64786d1379cd 100644 --- a/pkg/apps/apiserver/registry/deployconfig/etcd/etcd.go +++ b/pkg/apps/apiserver/registry/deployconfig/etcd/etcd.go @@ -27,7 +27,6 @@ import ( "github.com/openshift/origin/pkg/apps/apiserver/registry/deployconfig" appsutil "github.com/openshift/origin/pkg/apps/util" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) // REST contains the REST storage for DeploymentConfig objects. @@ -52,7 +51,7 @@ func (r *REST) ShortNames() []string { // NewREST returns a deploymentConfigREST containing the REST storage for DeploymentConfig objects, // a statusREST containing the REST storage for changing the status of a DeploymentConfig, // and a scaleREST containing the REST storage for the Scale subresources of DeploymentConfigs. -func NewREST(optsGetter restoptions.Getter) (*REST, *StatusREST, *ScaleREST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, *StatusREST, *ScaleREST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &appsapi.DeploymentConfig{} }, NewListFunc: func() runtime.Object { return &appsapi.DeploymentConfigList{} }, diff --git a/pkg/authorization/apiserver/registry/rolebindingrestriction/etcd/etcd.go b/pkg/authorization/apiserver/registry/rolebindingrestriction/etcd/etcd.go index 01af2035651b..7575a6853af1 100644 --- a/pkg/authorization/apiserver/registry/rolebindingrestriction/etcd/etcd.go +++ b/pkg/authorization/apiserver/registry/rolebindingrestriction/etcd/etcd.go @@ -12,7 +12,6 @@ import ( authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization" "github.com/openshift/origin/pkg/authorization/apiserver/registry/rolebindingrestriction" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) type REST struct { @@ -22,7 +21,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a RESTStorage object that will work against nodes. -func NewREST(optsGetter restoptions.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &authorizationapi.RoleBindingRestriction{} }, NewListFunc: func() runtime.Object { return &authorizationapi.RoleBindingRestrictionList{} }, diff --git a/pkg/build/apiserver/registry/build/etcd/etcd.go b/pkg/build/apiserver/registry/build/etcd/etcd.go index 7454916cec5a..e171efa5f487 100644 --- a/pkg/build/apiserver/registry/build/etcd/etcd.go +++ b/pkg/build/apiserver/registry/build/etcd/etcd.go @@ -15,7 +15,6 @@ import ( buildapi "github.com/openshift/origin/pkg/build/apis/build" buildregistry "github.com/openshift/origin/pkg/build/apiserver/registry/build" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) type REST struct { @@ -31,7 +30,7 @@ func (r *REST) Categories() []string { } // NewREST returns a RESTStorage object that will work against Build objects. -func NewREST(optsGetter restoptions.Getter) (*REST, *DetailsREST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, *DetailsREST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &buildapi.Build{} }, NewListFunc: func() runtime.Object { return &buildapi.BuildList{} }, diff --git a/pkg/build/apiserver/registry/buildconfig/etcd/etcd.go b/pkg/build/apiserver/registry/buildconfig/etcd/etcd.go index 416fa725cb12..31e1ee87bceb 100644 --- a/pkg/build/apiserver/registry/buildconfig/etcd/etcd.go +++ b/pkg/build/apiserver/registry/buildconfig/etcd/etcd.go @@ -12,7 +12,6 @@ import ( buildapi "github.com/openshift/origin/pkg/build/apis/build" "github.com/openshift/origin/pkg/build/apiserver/registry/buildconfig" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) type REST struct { @@ -34,7 +33,7 @@ func (r *REST) ShortNames() []string { } // NewREST returns a RESTStorage object that will work against BuildConfig. -func NewREST(optsGetter restoptions.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &buildapi.BuildConfig{} }, NewListFunc: func() runtime.Object { return &buildapi.BuildConfigList{} }, diff --git a/pkg/cmd/openshift-apiserver/openshiftapiserver/config.go b/pkg/cmd/openshift-apiserver/openshiftapiserver/config.go index d6b29cb3f038..8de62e28ae53 100644 --- a/pkg/cmd/openshift-apiserver/openshiftapiserver/config.go +++ b/pkg/cmd/openshift-apiserver/openshiftapiserver/config.go @@ -28,7 +28,6 @@ import ( "github.com/openshift/origin/pkg/image/apiserver/registryhostname" sccstorage "github.com/openshift/origin/pkg/security/apiserver/registry/securitycontextconstraints/etcd" usercache "github.com/openshift/origin/pkg/user/cache" - "github.com/openshift/origin/pkg/util/restoptions" "github.com/openshift/origin/pkg/version" ) @@ -49,7 +48,7 @@ func NewOpenshiftAPIConfig(openshiftAPIServerConfig *configapi.MasterConfig) (*O if err != nil { return nil, err } - restOptsGetter, err := restoptions.NewConfigGetter(*openshiftAPIServerConfig) + restOptsGetter, err := NewRESTOptionsGetter(*openshiftAPIServerConfig) if err != nil { return nil, err } diff --git a/pkg/util/restoptions/configgetter.go b/pkg/cmd/openshift-apiserver/openshiftapiserver/restoptionsgetter.go similarity index 96% rename from pkg/util/restoptions/configgetter.go rename to pkg/cmd/openshift-apiserver/openshiftapiserver/restoptionsgetter.go index 8c1ec4bcc2d7..ad7e8659cbcd 100644 --- a/pkg/util/restoptions/configgetter.go +++ b/pkg/cmd/openshift-apiserver/openshiftapiserver/restoptionsgetter.go @@ -1,9 +1,10 @@ -package restoptions +package openshiftapiserver import ( "strconv" "k8s.io/apimachinery/pkg/runtime/schema" + genericregistry "k8s.io/apiserver/pkg/registry/generic" "k8s.io/apiserver/pkg/server/options" apiserverstorage "k8s.io/apiserver/pkg/server/storage" serverstorage "k8s.io/apiserver/pkg/server/storage" @@ -14,8 +15,7 @@ import ( ) // NewConfigGetter returns a restoptions.Getter implemented using information from the provided master config. -// TODO: this class should either not need to know about configapi.MasterConfig, or not be in pkg/util -func NewConfigGetter(masterOptions configapi.MasterConfig) (Getter, error) { +func NewRESTOptionsGetter(masterOptions configapi.MasterConfig) (genericregistry.RESTOptionsGetter, error) { var err error targetRAMMB := 0 if targetRamString := masterOptions.KubernetesMasterConfig.APIServerArguments["target-ram-mb"]; len(targetRamString) == 1 { diff --git a/pkg/cmd/server/origin/master_config.go b/pkg/cmd/server/origin/master_config.go index 6f3f629506b9..e45372b247cb 100644 --- a/pkg/cmd/server/origin/master_config.go +++ b/pkg/cmd/server/origin/master_config.go @@ -8,6 +8,7 @@ import ( "k8s.io/apiserver/pkg/admission" admissionmetrics "k8s.io/apiserver/pkg/admission/metrics" "k8s.io/apiserver/pkg/audit" + genericregistry "k8s.io/apiserver/pkg/registry/generic" genericapiserver "k8s.io/apiserver/pkg/server" cacheddiscovery "k8s.io/client-go/discovery/cached" kinformers "k8s.io/client-go/informers" @@ -39,7 +40,6 @@ import ( "github.com/openshift/origin/pkg/cmd/openshift-apiserver/openshiftapiserver" "github.com/openshift/origin/pkg/image/apiserver/registryhostname" securityinformer "github.com/openshift/origin/pkg/security/generated/informers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) // MasterConfig defines the required parameters for starting the OpenShift master @@ -52,7 +52,7 @@ type MasterConfig struct { additionalPostStartHooks map[string]genericapiserver.PostStartHookFunc // RESTOptionsGetter provides access to storage and RESTOptions for a particular resource - RESTOptionsGetter restoptions.Getter + RESTOptionsGetter genericregistry.RESTOptionsGetter RuleResolver rbacregistryvalidation.AuthorizationRuleResolver SubjectLocator rbacauthorizer.SubjectLocator @@ -130,7 +130,7 @@ func BuildMasterConfig( informers = realLoopbackInformers } - restOptsGetter, err := restoptions.NewConfigGetter(options) + restOptsGetter, err := openshiftapiserver.NewRESTOptionsGetter(options) if err != nil { return nil, err } diff --git a/pkg/image/apiserver/registry/image/etcd/etcd.go b/pkg/image/apiserver/registry/image/etcd/etcd.go index 1466f855c3ee..d9cbd9bbe0e0 100644 --- a/pkg/image/apiserver/registry/image/etcd/etcd.go +++ b/pkg/image/apiserver/registry/image/etcd/etcd.go @@ -12,7 +12,6 @@ import ( imageapi "github.com/openshift/origin/pkg/image/apis/image" imageregistry "github.com/openshift/origin/pkg/image/apiserver/registry/image" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) // REST implements a RESTStorage for images against etcd. @@ -23,7 +22,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a new REST. -func NewREST(optsGetter restoptions.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &imageapi.Image{} }, NewListFunc: func() runtime.Object { return &imageapi.ImageList{} }, diff --git a/pkg/image/apiserver/registry/image/etcd/etcd_test.go b/pkg/image/apiserver/registry/image/etcd/etcd_test.go index cefced32409f..0fdd695595eb 100644 --- a/pkg/image/apiserver/registry/image/etcd/etcd_test.go +++ b/pkg/image/apiserver/registry/image/etcd/etcd_test.go @@ -9,6 +9,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" apirequest "k8s.io/apiserver/pkg/endpoints/request" + "k8s.io/apiserver/pkg/registry/generic" genericregistrytest "k8s.io/apiserver/pkg/registry/generic/testing" "k8s.io/apiserver/pkg/registry/rest" etcdtesting "k8s.io/apiserver/pkg/storage/etcd/testing" @@ -16,7 +17,6 @@ import ( imageapi "github.com/openshift/origin/pkg/image/apis/image" "github.com/openshift/origin/pkg/image/apiserver/registry/image" - "github.com/openshift/origin/pkg/util/restoptions" // install all APIs _ "github.com/openshift/origin/pkg/api/install" ) @@ -24,7 +24,8 @@ import ( func newStorage(t *testing.T) (*REST, *etcdtesting.EtcdTestServer) { server, etcdStorage := etcdtesting.NewUnsecuredEtcd3TestClientServer(t) etcdStorage.Codec = legacyscheme.Codecs.LegacyCodec(schema.GroupVersion{Group: "image.openshift.io", Version: "v1"}) - storage, err := NewREST(restoptions.NewSimpleGetter(etcdStorage)) + imageRESTOptions := generic.RESTOptions{StorageConfig: etcdStorage, Decorator: generic.UndecoratedStorage, DeleteCollectionWorkers: 1, ResourcePrefix: "images"} + storage, err := NewREST(imageRESTOptions) if err != nil { t.Fatal(err) } diff --git a/pkg/image/apiserver/registry/imagestream/etcd/etcd.go b/pkg/image/apiserver/registry/imagestream/etcd/etcd.go index bd201f558469..4de3edb29f32 100644 --- a/pkg/image/apiserver/registry/imagestream/etcd/etcd.go +++ b/pkg/image/apiserver/registry/imagestream/etcd/etcd.go @@ -24,7 +24,6 @@ import ( "github.com/openshift/origin/pkg/image/apiserver/registry/imagestream" "github.com/openshift/origin/pkg/image/apiserver/registryhostname" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) // REST implements a RESTStorage for image streams against etcd. @@ -48,7 +47,7 @@ func (r *REST) ShortNames() []string { // NewREST returns a new REST. func NewREST( - optsGetter restoptions.Getter, + optsGetter generic.RESTOptionsGetter, registryHostname registryhostname.RegistryHostnameRetriever, subjectAccessReviewRegistry authorizationclient.SubjectAccessReviewInterface, limitVerifier imageadmission.LimitVerifier, diff --git a/pkg/image/apiserver/registry/imagestream/etcd/etcd_test.go b/pkg/image/apiserver/registry/imagestream/etcd/etcd_test.go index 53bb9bd60248..ed875d60affe 100644 --- a/pkg/image/apiserver/registry/imagestream/etcd/etcd_test.go +++ b/pkg/image/apiserver/registry/imagestream/etcd/etcd_test.go @@ -6,13 +6,13 @@ import ( imageapi "github.com/openshift/origin/pkg/image/apis/image" "github.com/openshift/origin/pkg/image/apis/image/validation/fake" admfake "github.com/openshift/origin/pkg/image/apiserver/admission/fake" - "github.com/openshift/origin/pkg/util/restoptions" authorizationapi "k8s.io/api/authorization/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apiserver/pkg/authentication/user" apirequest "k8s.io/apiserver/pkg/endpoints/request" + "k8s.io/apiserver/pkg/registry/generic" genericregistrytest "k8s.io/apiserver/pkg/registry/generic/testing" "k8s.io/apiserver/pkg/registry/rest" etcdtesting "k8s.io/apiserver/pkg/storage/etcd/testing" @@ -53,9 +53,10 @@ func (f *fakeSubjectAccessReviewRegistry) Create(subjectAccessReview *authorizat func newStorage(t *testing.T) (*REST, *StatusREST, *InternalREST, *etcdtesting.EtcdTestServer) { server, etcdStorage := etcdtesting.NewUnsecuredEtcd3TestClientServer(t) etcdStorage.Codec = legacyscheme.Codecs.LegacyCodec(schema.GroupVersion{Group: "image.openshift.io", Version: "v1"}) + imagestreamRESTOptions := generic.RESTOptions{StorageConfig: etcdStorage, Decorator: generic.UndecoratedStorage, DeleteCollectionWorkers: 1, ResourcePrefix: "imagestreams"} registry := registryhostname.TestingRegistryHostnameRetriever(noDefaultRegistry, "", "") imageStorage, _, statusStorage, internalStorage, err := NewREST( - restoptions.NewSimpleGetter(etcdStorage), + imagestreamRESTOptions, registry, &fakeSubjectAccessReviewRegistry{}, &admfake.ImageStreamLimitVerifier{}, diff --git a/pkg/image/apiserver/registry/imagestreamimage/rest_test.go b/pkg/image/apiserver/registry/imagestreamimage/rest_test.go index 395cd28a22e6..c6cea6b731b2 100644 --- a/pkg/image/apiserver/registry/imagestreamimage/rest_test.go +++ b/pkg/image/apiserver/registry/imagestreamimage/rest_test.go @@ -11,6 +11,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" apirequest "k8s.io/apiserver/pkg/endpoints/request" + "k8s.io/apiserver/pkg/registry/generic" "k8s.io/apiserver/pkg/storage/etcd/etcdtest" etcdtesting "k8s.io/apiserver/pkg/storage/etcd/testing" "k8s.io/kubernetes/pkg/api/legacyscheme" @@ -23,10 +24,9 @@ import ( imageetcd "github.com/openshift/origin/pkg/image/apiserver/registry/image/etcd" "github.com/openshift/origin/pkg/image/apiserver/registry/imagestream" imagestreametcd "github.com/openshift/origin/pkg/image/apiserver/registry/imagestream/etcd" - "github.com/openshift/origin/pkg/util/restoptions" + "github.com/openshift/origin/pkg/image/apiserver/registryhostname" _ "github.com/openshift/origin/pkg/api/install" - "github.com/openshift/origin/pkg/image/apiserver/registryhostname" ) var testDefaultRegistry = func() (string, bool) { return "defaultregistry:5000", true } @@ -42,13 +42,15 @@ func setup(t *testing.T) (etcd.KV, *etcdtesting.EtcdTestServer, *REST) { server, etcdStorage := etcdtesting.NewUnsecuredEtcd3TestClientServer(t) etcdStorage.Codec = legacyscheme.Codecs.LegacyCodec(schema.GroupVersion{Group: "image.openshift.io", Version: "v1"}) etcdClient := etcd.NewKV(server.V3Client) + imageRESTOptions := generic.RESTOptions{StorageConfig: etcdStorage, Decorator: generic.UndecoratedStorage, DeleteCollectionWorkers: 1, ResourcePrefix: "images"} - imageStorage, err := imageetcd.NewREST(restoptions.NewSimpleGetter(etcdStorage)) + imageStorage, err := imageetcd.NewREST(imageRESTOptions) if err != nil { t.Fatal(err) } defaultRegistry := registryhostname.TestingRegistryHostnameRetriever(testDefaultRegistry, "", "") - imageStreamStorage, _, imageStreamStatus, internalStorage, err := imagestreametcd.NewREST(restoptions.NewSimpleGetter(etcdStorage), defaultRegistry, &fakeSubjectAccessReviewRegistry{}, &admfake.ImageStreamLimitVerifier{}, &fake.RegistryWhitelister{}, imagestreametcd.NewEmptyLayerIndex()) + imagestreamRESTOptions := generic.RESTOptions{StorageConfig: etcdStorage, Decorator: generic.UndecoratedStorage, DeleteCollectionWorkers: 1, ResourcePrefix: "imagestreams"} + imageStreamStorage, _, imageStreamStatus, internalStorage, err := imagestreametcd.NewREST(imagestreamRESTOptions, defaultRegistry, &fakeSubjectAccessReviewRegistry{}, &admfake.ImageStreamLimitVerifier{}, &fake.RegistryWhitelister{}, imagestreametcd.NewEmptyLayerIndex()) if err != nil { t.Fatal(err) } diff --git a/pkg/image/apiserver/registry/imagestreammapping/rest_test.go b/pkg/image/apiserver/registry/imagestreammapping/rest_test.go index 36b48e2689bc..ad427ffe4dc8 100644 --- a/pkg/image/apiserver/registry/imagestreammapping/rest_test.go +++ b/pkg/image/apiserver/registry/imagestreammapping/rest_test.go @@ -20,6 +20,7 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/apiserver/pkg/authentication/user" apirequest "k8s.io/apiserver/pkg/endpoints/request" + "k8s.io/apiserver/pkg/registry/generic" "k8s.io/apiserver/pkg/storage/etcd/etcdtest" etcdtesting "k8s.io/apiserver/pkg/storage/etcd/testing" "k8s.io/kubernetes/pkg/api/legacyscheme" @@ -34,10 +35,9 @@ import ( imageetcd "github.com/openshift/origin/pkg/image/apiserver/registry/image/etcd" "github.com/openshift/origin/pkg/image/apiserver/registry/imagestream" imagestreametcd "github.com/openshift/origin/pkg/image/apiserver/registry/imagestream/etcd" - "github.com/openshift/origin/pkg/util/restoptions" + "github.com/openshift/origin/pkg/image/apiserver/registryhostname" _ "github.com/openshift/origin/pkg/api/install" - "github.com/openshift/origin/pkg/image/apiserver/registryhostname" ) const testDefaultRegistryURL = "defaultregistry:5000" @@ -55,13 +55,15 @@ func setup(t *testing.T) (etcd.KV, *etcdtesting.EtcdTestServer, *REST) { server, etcdStorage := etcdtesting.NewUnsecuredEtcd3TestClientServer(t) etcdStorage.Codec = legacyscheme.Codecs.LegacyCodec(schema.GroupVersion{Group: "image.openshift.io", Version: "v1"}) etcdClient := etcd.NewKV(server.V3Client) + imageRESTOptions := generic.RESTOptions{StorageConfig: etcdStorage, Decorator: generic.UndecoratedStorage, DeleteCollectionWorkers: 1, ResourcePrefix: "images"} - imageStorage, err := imageetcd.NewREST(restoptions.NewSimpleGetter(etcdStorage)) + imageStorage, err := imageetcd.NewREST(imageRESTOptions) if err != nil { t.Fatal(err) } registry := registryhostname.TestingRegistryHostnameRetriever(testDefaultRegistry, "", "") - imageStreamStorage, _, imageStreamStatus, internalStorage, err := imagestreametcd.NewREST(restoptions.NewSimpleGetter(etcdStorage), registry, &fakeSubjectAccessReviewRegistry{}, &admfake.ImageStreamLimitVerifier{}, &fake.RegistryWhitelister{}, imagestreametcd.NewEmptyLayerIndex()) + imagestreamRESTOptions := generic.RESTOptions{StorageConfig: etcdStorage, Decorator: generic.UndecoratedStorage, DeleteCollectionWorkers: 1, ResourcePrefix: "imagestreams"} + imageStreamStorage, _, imageStreamStatus, internalStorage, err := imagestreametcd.NewREST(imagestreamRESTOptions, registry, &fakeSubjectAccessReviewRegistry{}, &admfake.ImageStreamLimitVerifier{}, &fake.RegistryWhitelister{}, imagestreametcd.NewEmptyLayerIndex()) if err != nil { t.Fatal(err) } diff --git a/pkg/image/apiserver/registry/imagestreamtag/rest_test.go b/pkg/image/apiserver/registry/imagestreamtag/rest_test.go index 9c4007a74fec..e30f51165b30 100644 --- a/pkg/image/apiserver/registry/imagestreamtag/rest_test.go +++ b/pkg/image/apiserver/registry/imagestreamtag/rest_test.go @@ -16,6 +16,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apiserver/pkg/authentication/user" apirequest "k8s.io/apiserver/pkg/endpoints/request" + "k8s.io/apiserver/pkg/registry/generic" "k8s.io/apiserver/pkg/storage/etcd/etcdtest" etcdtesting "k8s.io/apiserver/pkg/storage/etcd/testing" "k8s.io/kubernetes/pkg/api/legacyscheme" @@ -29,10 +30,9 @@ import ( imageetcd "github.com/openshift/origin/pkg/image/apiserver/registry/image/etcd" "github.com/openshift/origin/pkg/image/apiserver/registry/imagestream" imagestreametcd "github.com/openshift/origin/pkg/image/apiserver/registry/imagestream/etcd" - "github.com/openshift/origin/pkg/util/restoptions" + "github.com/openshift/origin/pkg/image/apiserver/registryhostname" _ "github.com/openshift/origin/pkg/api/install" - "github.com/openshift/origin/pkg/image/apiserver/registryhostname" ) var testDefaultRegistry = func() (string, bool) { return "defaultregistry:5000", true } @@ -69,15 +69,17 @@ func setup(t *testing.T) (etcd.KV, *etcdtesting.EtcdTestServer, *REST) { server, etcdStorage := etcdtesting.NewUnsecuredEtcd3TestClientServer(t) etcdStorage.Codec = legacyscheme.Codecs.LegacyCodec(schema.GroupVersion{Group: "image.openshift.io", Version: "v1"}) etcdClient := etcd.NewKV(server.V3Client) + imagestreamRESTOptions := generic.RESTOptions{StorageConfig: etcdStorage, Decorator: generic.UndecoratedStorage, DeleteCollectionWorkers: 1, ResourcePrefix: "imagestreams"} rw := &fake.RegistryWhitelister{} - imageStorage, err := imageetcd.NewREST(restoptions.NewSimpleGetter(etcdStorage)) + imageRESTOptions := generic.RESTOptions{StorageConfig: etcdStorage, Decorator: generic.UndecoratedStorage, DeleteCollectionWorkers: 1, ResourcePrefix: "images"} + imageStorage, err := imageetcd.NewREST(imageRESTOptions) if err != nil { t.Fatal(err) } registry := registryhostname.TestingRegistryHostnameRetriever(testDefaultRegistry, "", "") imageStreamStorage, _, imageStreamStatus, internalStorage, err := imagestreametcd.NewREST( - restoptions.NewSimpleGetter(etcdStorage), + imagestreamRESTOptions, registry, &fakeSubjectAccessReviewRegistry{}, &admfake.ImageStreamLimitVerifier{}, diff --git a/pkg/network/apiserver/registry/clusternetwork/etcd/etcd.go b/pkg/network/apiserver/registry/clusternetwork/etcd/etcd.go index ad3a2cbfcbb0..700e4804a2cf 100644 --- a/pkg/network/apiserver/registry/clusternetwork/etcd/etcd.go +++ b/pkg/network/apiserver/registry/clusternetwork/etcd/etcd.go @@ -12,7 +12,6 @@ import ( networkapi "github.com/openshift/origin/pkg/network/apis/network" "github.com/openshift/origin/pkg/network/apiserver/registry/clusternetwork" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) // rest implements a RESTStorage for sdn against etcd @@ -23,7 +22,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a RESTStorage object that will work against subnets -func NewREST(optsGetter restoptions.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &networkapi.ClusterNetwork{} }, NewListFunc: func() runtime.Object { return &networkapi.ClusterNetworkList{} }, diff --git a/pkg/network/apiserver/registry/egressnetworkpolicy/etcd/etcd.go b/pkg/network/apiserver/registry/egressnetworkpolicy/etcd/etcd.go index bb31aef45e81..eae5423e0cd3 100644 --- a/pkg/network/apiserver/registry/egressnetworkpolicy/etcd/etcd.go +++ b/pkg/network/apiserver/registry/egressnetworkpolicy/etcd/etcd.go @@ -12,7 +12,6 @@ import ( networkapi "github.com/openshift/origin/pkg/network/apis/network" "github.com/openshift/origin/pkg/network/apiserver/registry/egressnetworkpolicy" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) // rest implements a RESTStorage for egress network policy against etcd @@ -23,7 +22,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a RESTStorage object that will work against egress network policy -func NewREST(optsGetter restoptions.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &networkapi.EgressNetworkPolicy{} }, NewListFunc: func() runtime.Object { return &networkapi.EgressNetworkPolicyList{} }, diff --git a/pkg/network/apiserver/registry/hostsubnet/etcd/etcd.go b/pkg/network/apiserver/registry/hostsubnet/etcd/etcd.go index 9071a1616951..0d1383bf7f0d 100644 --- a/pkg/network/apiserver/registry/hostsubnet/etcd/etcd.go +++ b/pkg/network/apiserver/registry/hostsubnet/etcd/etcd.go @@ -12,7 +12,6 @@ import ( networkapi "github.com/openshift/origin/pkg/network/apis/network" "github.com/openshift/origin/pkg/network/apiserver/registry/hostsubnet" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) // rest implements a RESTStorage for sdn against etcd @@ -23,7 +22,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a RESTStorage object that will work against subnets -func NewREST(optsGetter restoptions.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &networkapi.HostSubnet{} }, NewListFunc: func() runtime.Object { return &networkapi.HostSubnetList{} }, diff --git a/pkg/network/apiserver/registry/netnamespace/etcd/etcd.go b/pkg/network/apiserver/registry/netnamespace/etcd/etcd.go index b4ba598faae4..0f549b82fbd3 100644 --- a/pkg/network/apiserver/registry/netnamespace/etcd/etcd.go +++ b/pkg/network/apiserver/registry/netnamespace/etcd/etcd.go @@ -12,7 +12,6 @@ import ( networkapi "github.com/openshift/origin/pkg/network/apis/network" "github.com/openshift/origin/pkg/network/apiserver/registry/netnamespace" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) // rest implements a RESTStorage for sdn against etcd @@ -23,7 +22,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a RESTStorage object that will work against netnamespaces -func NewREST(optsGetter restoptions.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &networkapi.NetNamespace{} }, NewListFunc: func() runtime.Object { return &networkapi.NetNamespaceList{} }, diff --git a/pkg/oauth/apiserver/registry/oauthaccesstoken/etcd/etcd.go b/pkg/oauth/apiserver/registry/oauthaccesstoken/etcd/etcd.go index a9cfaf46762c..fc35ac4b10bd 100644 --- a/pkg/oauth/apiserver/registry/oauthaccesstoken/etcd/etcd.go +++ b/pkg/oauth/apiserver/registry/oauthaccesstoken/etcd/etcd.go @@ -14,7 +14,6 @@ import ( "github.com/openshift/origin/pkg/oauth/apiserver/registry/oauthaccesstoken" "github.com/openshift/origin/pkg/oauth/apiserver/registry/oauthclient" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) // rest implements a RESTStorage for access tokens against etcd @@ -25,7 +24,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a RESTStorage object that will work against access tokens -func NewREST(optsGetter restoptions.Getter, clientGetter oauthclient.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter, clientGetter oauthclient.Getter) (*REST, error) { strategy := oauthaccesstoken.NewStrategy(clientGetter) store := ®istry.Store{ NewFunc: func() runtime.Object { return &oauthapi.OAuthAccessToken{} }, diff --git a/pkg/oauth/apiserver/registry/oauthauthorizetoken/etcd/etcd.go b/pkg/oauth/apiserver/registry/oauthauthorizetoken/etcd/etcd.go index 01fa7f193003..f0c19bffdd1b 100644 --- a/pkg/oauth/apiserver/registry/oauthauthorizetoken/etcd/etcd.go +++ b/pkg/oauth/apiserver/registry/oauthauthorizetoken/etcd/etcd.go @@ -14,7 +14,6 @@ import ( "github.com/openshift/origin/pkg/oauth/apiserver/registry/oauthauthorizetoken" "github.com/openshift/origin/pkg/oauth/apiserver/registry/oauthclient" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) // rest implements a RESTStorage for authorize tokens against etcd @@ -25,7 +24,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a RESTStorage object that will work against authorize tokens -func NewREST(optsGetter restoptions.Getter, clientGetter oauthclient.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter, clientGetter oauthclient.Getter) (*REST, error) { strategy := oauthauthorizetoken.NewStrategy(clientGetter) store := ®istry.Store{ NewFunc: func() runtime.Object { return &oauthapi.OAuthAuthorizeToken{} }, diff --git a/pkg/oauth/apiserver/registry/oauthclient/etcd/etcd.go b/pkg/oauth/apiserver/registry/oauthclient/etcd/etcd.go index 494f5d3ed7cd..54b970cd7a16 100644 --- a/pkg/oauth/apiserver/registry/oauthclient/etcd/etcd.go +++ b/pkg/oauth/apiserver/registry/oauthclient/etcd/etcd.go @@ -12,7 +12,6 @@ import ( oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth" "github.com/openshift/origin/pkg/oauth/apiserver/registry/oauthclient" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) // rest implements a RESTStorage for oauth clients against etcd @@ -23,7 +22,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a RESTStorage object that will work against oauth clients -func NewREST(optsGetter restoptions.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &oauthapi.OAuthClient{} }, NewListFunc: func() runtime.Object { return &oauthapi.OAuthClientList{} }, diff --git a/pkg/oauth/apiserver/registry/oauthclientauthorization/etcd/etcd.go b/pkg/oauth/apiserver/registry/oauthclientauthorization/etcd/etcd.go index c4f4925957d2..4e8615ff1d92 100644 --- a/pkg/oauth/apiserver/registry/oauthclientauthorization/etcd/etcd.go +++ b/pkg/oauth/apiserver/registry/oauthclientauthorization/etcd/etcd.go @@ -14,7 +14,6 @@ import ( "github.com/openshift/origin/pkg/oauth/apiserver/registry/oauthclient" "github.com/openshift/origin/pkg/oauth/apiserver/registry/oauthclientauthorization" printersinternal "github.com/openshift/origin/pkg/printers/internalversion" - "github.com/openshift/origin/pkg/util/restoptions" ) // rest implements a RESTStorage for oauth client authorizations against etcd @@ -25,7 +24,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a RESTStorage object that will work against oauth clients -func NewREST(optsGetter restoptions.Getter, clientGetter oauthclient.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter, clientGetter oauthclient.Getter) (*REST, error) { strategy := oauthclientauthorization.NewStrategy(clientGetter) store := ®istry.Store{ diff --git a/pkg/quota/apiserver/registry/clusterresourcequota/etcd/etcd.go b/pkg/quota/apiserver/registry/clusterresourcequota/etcd/etcd.go index 63de32734573..70b1019d65d3 100644 --- a/pkg/quota/apiserver/registry/clusterresourcequota/etcd/etcd.go +++ b/pkg/quota/apiserver/registry/clusterresourcequota/etcd/etcd.go @@ -15,7 +15,6 @@ import ( printersinternal "github.com/openshift/origin/pkg/printers/internalversion" quotaapi "github.com/openshift/origin/pkg/quota/apis/quota" "github.com/openshift/origin/pkg/quota/apiserver/registry/clusterresourcequota" - "github.com/openshift/origin/pkg/util/restoptions" ) type REST struct { @@ -31,7 +30,7 @@ func (r *REST) ShortNames() []string { } // NewREST returns a RESTStorage object that will work against ClusterResourceQuota objects. -func NewREST(optsGetter restoptions.Getter) (*REST, *StatusREST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, *StatusREST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return "aapi.ClusterResourceQuota{} }, NewListFunc: func() runtime.Object { return "aapi.ClusterResourceQuotaList{} }, diff --git a/pkg/route/apiserver/registry/route/etcd/etcd.go b/pkg/route/apiserver/registry/route/etcd/etcd.go index ecece391bb23..92b2a15ebf07 100644 --- a/pkg/route/apiserver/registry/route/etcd/etcd.go +++ b/pkg/route/apiserver/registry/route/etcd/etcd.go @@ -18,7 +18,6 @@ import ( "github.com/openshift/origin/pkg/route" routeapi "github.com/openshift/origin/pkg/route/apis/route" routeregistry "github.com/openshift/origin/pkg/route/apiserver/registry/route" - "github.com/openshift/origin/pkg/util/restoptions" ) type REST struct { @@ -34,7 +33,7 @@ func (r *REST) Categories() []string { } // NewREST returns a RESTStorage object that will work against routes. -func NewREST(optsGetter restoptions.Getter, allocator route.RouteAllocator, sarClient routeregistry.SubjectAccessReviewInterface) (*REST, *StatusREST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter, allocator route.RouteAllocator, sarClient routeregistry.SubjectAccessReviewInterface) (*REST, *StatusREST, error) { strategy := routeregistry.NewStrategy(allocator, sarClient) store := ®istry.Store{ diff --git a/pkg/route/apiserver/registry/route/etcd/etcd_test.go b/pkg/route/apiserver/registry/route/etcd/etcd_test.go index 9fa7868da1d9..7c0e75780216 100644 --- a/pkg/route/apiserver/registry/route/etcd/etcd_test.go +++ b/pkg/route/apiserver/registry/route/etcd/etcd_test.go @@ -19,7 +19,7 @@ import ( routeapi "github.com/openshift/origin/pkg/route/apis/route" _ "github.com/openshift/origin/pkg/route/apis/route/install" "github.com/openshift/origin/pkg/route/apiserver/registry/route" - "github.com/openshift/origin/pkg/util/restoptions" + "k8s.io/apiserver/pkg/registry/generic" ) type testAllocator struct { @@ -56,7 +56,8 @@ func (t *testSAR) Create(subjectAccessReview *authorizationapi.SubjectAccessRevi func newStorage(t *testing.T, allocator routetypes.RouteAllocator) (*REST, *etcdtesting.EtcdTestServer) { server, etcdStorage := etcdtesting.NewUnsecuredEtcd3TestClientServer(t) etcdStorage.Codec = legacyscheme.Codecs.LegacyCodec(schema.GroupVersion{Group: "route.openshift.io", Version: "v1"}) - storage, _, err := NewREST(restoptions.NewSimpleGetter(etcdStorage), allocator, &testSAR{allow: true}) + restOptions := generic.RESTOptions{StorageConfig: etcdStorage, Decorator: generic.UndecoratedStorage, DeleteCollectionWorkers: 1, ResourcePrefix: "routes"} + storage, _, err := NewREST(restOptions, allocator, &testSAR{allow: true}) if err != nil { t.Fatal(err) } diff --git a/pkg/template/apiserver/registry/brokertemplateinstance/etcd/etcd.go b/pkg/template/apiserver/registry/brokertemplateinstance/etcd/etcd.go index 31cc6e1faebd..54a3ff1ef9cf 100644 --- a/pkg/template/apiserver/registry/brokertemplateinstance/etcd/etcd.go +++ b/pkg/template/apiserver/registry/brokertemplateinstance/etcd/etcd.go @@ -12,7 +12,6 @@ import ( printersinternal "github.com/openshift/origin/pkg/printers/internalversion" templateapi "github.com/openshift/origin/pkg/template/apis/template" "github.com/openshift/origin/pkg/template/apiserver/registry/brokertemplateinstance" - "github.com/openshift/origin/pkg/util/restoptions" ) // REST implements a RESTStorage for brokertemplateinstances against etcd @@ -23,7 +22,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a RESTStorage object that will work against brokertemplateinstances. -func NewREST(optsGetter restoptions.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &templateapi.BrokerTemplateInstance{} }, NewListFunc: func() runtime.Object { return &templateapi.BrokerTemplateInstanceList{} }, diff --git a/pkg/template/apiserver/registry/template/etcd/etcd.go b/pkg/template/apiserver/registry/template/etcd/etcd.go index df7ac07b0a0c..a829b1a814aa 100644 --- a/pkg/template/apiserver/registry/template/etcd/etcd.go +++ b/pkg/template/apiserver/registry/template/etcd/etcd.go @@ -12,7 +12,6 @@ import ( printersinternal "github.com/openshift/origin/pkg/printers/internalversion" templateapi "github.com/openshift/origin/pkg/template/apis/template" "github.com/openshift/origin/pkg/template/apiserver/registry/template" - "github.com/openshift/origin/pkg/util/restoptions" ) // REST implements a RESTStorage for templates against etcd @@ -23,7 +22,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a RESTStorage object that will work against templates. -func NewREST(optsGetter restoptions.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &templateapi.Template{} }, NewListFunc: func() runtime.Object { return &templateapi.TemplateList{} }, diff --git a/pkg/template/apiserver/registry/templateinstance/etcd/etcd.go b/pkg/template/apiserver/registry/templateinstance/etcd/etcd.go index 9930727dd585..843961a6bbde 100644 --- a/pkg/template/apiserver/registry/templateinstance/etcd/etcd.go +++ b/pkg/template/apiserver/registry/templateinstance/etcd/etcd.go @@ -16,7 +16,6 @@ import ( printersinternal "github.com/openshift/origin/pkg/printers/internalversion" templateapi "github.com/openshift/origin/pkg/template/apis/template" "github.com/openshift/origin/pkg/template/apiserver/registry/templateinstance" - "github.com/openshift/origin/pkg/util/restoptions" ) // REST implements a RESTStorage for templateinstances against etcd @@ -27,7 +26,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a RESTStorage object that will work against templateinstances. -func NewREST(optsGetter restoptions.Getter, authorizationClient authorizationclient.AuthorizationV1Interface) (*REST, *StatusREST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter, authorizationClient authorizationclient.AuthorizationV1Interface) (*REST, *StatusREST, error) { strategy := templateinstance.NewStrategy(authorizationClient) store := ®istry.Store{ diff --git a/pkg/user/apiserver/registry/group/etcd/etcd.go b/pkg/user/apiserver/registry/group/etcd/etcd.go index 23116858d755..7969655bcccd 100644 --- a/pkg/user/apiserver/registry/group/etcd/etcd.go +++ b/pkg/user/apiserver/registry/group/etcd/etcd.go @@ -11,7 +11,6 @@ import ( printersinternal "github.com/openshift/origin/pkg/printers/internalversion" userapi "github.com/openshift/origin/pkg/user/apis/user" "github.com/openshift/origin/pkg/user/apiserver/registry/group" - "github.com/openshift/origin/pkg/util/restoptions" ) // REST implements a RESTStorage for groups against etcd @@ -20,7 +19,7 @@ type REST struct { } // NewREST returns a RESTStorage object that will work against groups -func NewREST(optsGetter restoptions.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &userapi.Group{} }, NewListFunc: func() runtime.Object { return &userapi.GroupList{} }, diff --git a/pkg/user/apiserver/registry/identity/etcd/etcd.go b/pkg/user/apiserver/registry/identity/etcd/etcd.go index 538d2b331fce..9d46b4269a73 100644 --- a/pkg/user/apiserver/registry/identity/etcd/etcd.go +++ b/pkg/user/apiserver/registry/identity/etcd/etcd.go @@ -13,7 +13,6 @@ import ( printersinternal "github.com/openshift/origin/pkg/printers/internalversion" userapi "github.com/openshift/origin/pkg/user/apis/user" "github.com/openshift/origin/pkg/user/apiserver/registry/identity" - "github.com/openshift/origin/pkg/util/restoptions" ) // REST implements a RESTStorage for identites against etcd @@ -24,7 +23,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a RESTStorage object that will work against identites -func NewREST(optsGetter restoptions.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &userapi.Identity{} }, NewListFunc: func() runtime.Object { return &userapi.IdentityList{} }, diff --git a/pkg/user/apiserver/registry/user/etcd/etcd.go b/pkg/user/apiserver/registry/user/etcd/etcd.go index af9d128dad27..bc0ecd0b20ba 100644 --- a/pkg/user/apiserver/registry/user/etcd/etcd.go +++ b/pkg/user/apiserver/registry/user/etcd/etcd.go @@ -23,7 +23,6 @@ import ( userapi "github.com/openshift/origin/pkg/user/apis/user" "github.com/openshift/origin/pkg/user/apis/user/validation" "github.com/openshift/origin/pkg/user/apiserver/registry/user" - "github.com/openshift/origin/pkg/util/restoptions" ) // rest implements a RESTStorage for users against etcd @@ -34,7 +33,7 @@ type REST struct { var _ rest.StandardStorage = &REST{} // NewREST returns a RESTStorage object that will work against users -func NewREST(optsGetter restoptions.Getter) (*REST, error) { +func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) { store := ®istry.Store{ NewFunc: func() runtime.Object { return &userapi.User{} }, NewListFunc: func() runtime.Object { return &userapi.UserList{} }, diff --git a/pkg/util/restoptions/interfaces.go b/pkg/util/restoptions/interfaces.go deleted file mode 100644 index 7a104df41010..000000000000 --- a/pkg/util/restoptions/interfaces.go +++ /dev/null @@ -1,10 +0,0 @@ -package restoptions - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apiserver/pkg/registry/generic" -) - -type Getter interface { - GetRESTOptions(resource schema.GroupResource) (generic.RESTOptions, error) -} diff --git a/pkg/util/restoptions/simplegetter.go b/pkg/util/restoptions/simplegetter.go deleted file mode 100644 index 299076ee8321..000000000000 --- a/pkg/util/restoptions/simplegetter.go +++ /dev/null @@ -1,24 +0,0 @@ -package restoptions - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apiserver/pkg/registry/generic" - "k8s.io/apiserver/pkg/storage/storagebackend" -) - -type simpleGetter struct { - storage *storagebackend.Config -} - -func NewSimpleGetter(storage *storagebackend.Config) Getter { - return &simpleGetter{storage: storage} -} - -func (s *simpleGetter) GetRESTOptions(resource schema.GroupResource) (generic.RESTOptions, error) { - return generic.RESTOptions{ - StorageConfig: s.storage, - Decorator: generic.UndecoratedStorage, - DeleteCollectionWorkers: 1, - ResourcePrefix: resource.Resource, - }, nil -} From 3563995f484929f73b8ce334347e1c6302a00013 Mon Sep 17 00:00:00 2001 From: David Eads Date: Mon, 27 Aug 2018 11:25:35 -0400 Subject: [PATCH 4/4] clean up construction to make creating types more obvious --- .../configprocessing/cloud.go | 15 +++ pkg/cmd/openshift-apiserver/server.go | 6 -- .../controller_manager.go | 14 +++ .../server/kubernetes/master/master_config.go | 27 +----- .../origin/admission/plugin_initializer.go | 49 ++-------- pkg/cmd/server/origin/master.go | 97 +------------------ pkg/cmd/server/origin/master_config.go | 20 +--- 7 files changed, 48 insertions(+), 180 deletions(-) create mode 100644 pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing/cloud.go diff --git a/pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing/cloud.go b/pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing/cloud.go new file mode 100644 index 000000000000..1399ec4fa15d --- /dev/null +++ b/pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing/cloud.go @@ -0,0 +1,15 @@ +package configprocessing + +import "fmt" + +func GetCloudProviderConfigFile(args map[string][]string) (string, error) { + filenames, ok := args["cloud-config"] + if !ok { + return "", nil + } + if len(filenames) != 1 { + return "", fmt.Errorf(`one or zero "--cloud-config" required, not %v`, filenames) + } + + return filenames[0], nil +} diff --git a/pkg/cmd/openshift-apiserver/server.go b/pkg/cmd/openshift-apiserver/server.go index 3135cacabab2..6f3f2ae7f423 100644 --- a/pkg/cmd/openshift-apiserver/server.go +++ b/pkg/cmd/openshift-apiserver/server.go @@ -14,7 +14,6 @@ import ( configapi "github.com/openshift/origin/pkg/cmd/server/apis/config" "github.com/openshift/origin/pkg/cmd/server/apis/config/validation" "github.com/openshift/origin/pkg/cmd/util" - "github.com/openshift/origin/pkg/cmd/util/variable" ) func RunOpenShiftAPIServer(masterConfig *configapi.MasterConfig) error { @@ -51,11 +50,6 @@ func RunOpenShiftAPIServer(masterConfig *configapi.MasterConfig) error { preparedOpenshiftAPIServer := openshiftAPIServer.GenericAPIServer.PrepareRun() glog.Infof("Starting master on %s (%s)", masterConfig.ServingInfo.BindAddress, version.Get().String()) - glog.Infof("Public master address is %s", masterConfig.MasterPublicURL) - imageTemplate := variable.NewDefaultImageTemplate() - imageTemplate.Format = masterConfig.ImageConfig.Format - imageTemplate.Latest = masterConfig.ImageConfig.Latest - glog.Infof("Using images from %q", imageTemplate.ExpandOrDie("")) if err := preparedOpenshiftAPIServer.Run(utilwait.NeverStop); err != nil { return err diff --git a/pkg/cmd/openshift-controller-manager/controller_manager.go b/pkg/cmd/openshift-controller-manager/controller_manager.go index 96f2b1e9e071..b6b8956bb210 100644 --- a/pkg/cmd/openshift-controller-manager/controller_manager.go +++ b/pkg/cmd/openshift-controller-manager/controller_manager.go @@ -10,6 +10,7 @@ import ( origincontrollers "github.com/openshift/origin/pkg/cmd/openshift-controller-manager/controller" configapi "github.com/openshift/origin/pkg/cmd/server/apis/config" "github.com/openshift/origin/pkg/cmd/util" + "github.com/openshift/origin/pkg/cmd/util/variable" "github.com/openshift/origin/pkg/version" "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/wait" @@ -38,6 +39,19 @@ func RunOpenShiftControllerManager(config *configapi.OpenshiftControllerConfig, } } + { + imageTemplate := variable.NewDefaultImageTemplate() + imageTemplate.Format = config.Deployer.ImageTemplateFormat.Format + imageTemplate.Latest = config.Deployer.ImageTemplateFormat.Latest + glog.Infof("DeploymentConfig controller using images from %q", imageTemplate.ExpandOrDie("")) + } + { + imageTemplate := variable.NewDefaultImageTemplate() + imageTemplate.Format = config.Build.ImageTemplateFormat.Format + imageTemplate.Latest = config.Build.ImageTemplateFormat.Latest + glog.Infof("Build controller using images from %q", imageTemplate.ExpandOrDie("")) + } + originControllerManager := func(stopCh <-chan struct{}) { if err := waitForHealthyAPIServer(kubeClient.Discovery().RESTClient()); err != nil { glog.Fatal(err) diff --git a/pkg/cmd/server/kubernetes/master/master_config.go b/pkg/cmd/server/kubernetes/master/master_config.go index d12e707ffe00..1858d5efe49c 100644 --- a/pkg/cmd/server/kubernetes/master/master_config.go +++ b/pkg/cmd/server/kubernetes/master/master_config.go @@ -30,7 +30,6 @@ import ( apiserverstorage "k8s.io/apiserver/pkg/server/storage" "k8s.io/apiserver/pkg/storage" storagefactory "k8s.io/apiserver/pkg/storage/storagebackend/factory" - utilflag "k8s.io/apiserver/pkg/util/flag" "k8s.io/client-go/rest" "k8s.io/kube-aggregator/pkg/apis/apiregistration" apiregistrationv1beta1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1" @@ -73,15 +72,6 @@ var LegacyAPIGroupPrefixes = sets.NewString(apiserver.DefaultLegacyAPIPrefix, le // BuildKubeAPIserverOptions constructs the appropriate kube-apiserver run options. // It returns an error if no KubernetesMasterConfig was defined. func BuildKubeAPIserverOptions(masterConfig configapi.MasterConfig) (*kapiserveroptions.ServerRunOptions, error) { - host, portString, err := net.SplitHostPort(masterConfig.ServingInfo.BindAddress) - if err != nil { - return nil, err - } - port, err := strconv.Atoi(portString) - if err != nil { - return nil, err - } - portRange, err := knet.ParsePortRange(masterConfig.KubernetesMasterConfig.ServicesNodePortRange) if err != nil { return nil, err @@ -97,11 +87,10 @@ func BuildKubeAPIserverOptions(masterConfig configapi.MasterConfig) (*kapiserver server.ServiceNodePortRange = *portRange server.Features.EnableProfiling = true - server.SecureServing.BindAddress = net.ParseIP(host) - server.SecureServing.BindPort = port - server.SecureServing.BindNetwork = masterConfig.ServingInfo.BindNetwork - server.SecureServing.ServerCert.CertKey.CertFile = masterConfig.ServingInfo.ServerCert.CertFile - server.SecureServing.ServerCert.CertKey.KeyFile = masterConfig.ServingInfo.ServerCert.KeyFile + server.SecureServing, err = configprocessing.ToServingOptions(masterConfig.ServingInfo) + if err != nil { + return nil, err + } server.InsecureServing.BindPort = 0 // disable anonymous authentication @@ -130,14 +119,6 @@ func BuildKubeAPIserverOptions(masterConfig configapi.MasterConfig) (*kapiserver server.GenericServerRunOptions.MaxRequestsInFlight = masterConfig.ServingInfo.MaxRequestsInFlight server.GenericServerRunOptions.MaxMutatingRequestsInFlight = masterConfig.ServingInfo.MaxRequestsInFlight / 2 server.GenericServerRunOptions.MinRequestTimeout = masterConfig.ServingInfo.RequestTimeoutSeconds - for _, nc := range masterConfig.ServingInfo.NamedCertificates { - sniCert := utilflag.NamedCertKey{ - CertFile: nc.CertFile, - KeyFile: nc.KeyFile, - Names: nc.Names, - } - server.SecureServing.SNICertKeys = append(server.SecureServing.SNICertKeys, sniCert) - } server.KubeletConfig.ReadOnlyPort = 0 server.KubeletConfig.Port = masterConfig.KubeletClientInfo.Port diff --git a/pkg/cmd/server/origin/admission/plugin_initializer.go b/pkg/cmd/server/origin/admission/plugin_initializer.go index c9caca43e0b2..dfe682bf7526 100644 --- a/pkg/cmd/server/origin/admission/plugin_initializer.go +++ b/pkg/cmd/server/origin/admission/plugin_initializer.go @@ -23,9 +23,9 @@ import ( "k8s.io/kubernetes/pkg/quota/install" userinformer "github.com/openshift/client-go/user/informers/externalversions" + "github.com/openshift/origin/pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing" oadmission "github.com/openshift/origin/pkg/cmd/server/admission" configapi "github.com/openshift/origin/pkg/cmd/server/apis/config" - kubernetes "github.com/openshift/origin/pkg/cmd/server/kubernetes/master" "github.com/openshift/origin/pkg/image/apiserver/registryhostname" imageinformer "github.com/openshift/origin/pkg/image/generated/informers/internalversion" imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset" @@ -46,7 +46,7 @@ type InformerAccess interface { } func NewPluginInitializer( - options configapi.MasterConfig, + masterConfig configapi.MasterConfig, privilegedLoopbackConfig *rest.Config, informers InformerAccess, authorizer authorizer.Authorizer, @@ -77,24 +77,21 @@ func NewPluginInitializer( quotaRegistry.Add(imageEvaluators[i]) } - registryHostnameRetriever, err := registryhostname.DefaultRegistryHostnameRetriever(privilegedLoopbackConfig, options.ImagePolicyConfig.ExternalRegistryHostname, options.ImagePolicyConfig.InternalRegistryHostname) + registryHostnameRetriever, err := registryhostname.DefaultRegistryHostnameRetriever(privilegedLoopbackConfig, masterConfig.ImagePolicyConfig.ExternalRegistryHostname, masterConfig.ImagePolicyConfig.InternalRegistryHostname) if err != nil { return nil, err } - // punch through layers to build this in order to get a string for a cloud provider file - // TODO refactor us into a forward building flow with a side channel like this - kubeOptions, err := kubernetes.BuildKubeAPIserverOptions(options) + var cloudConfig []byte + cloudConfigFile, err := configprocessing.GetCloudProviderConfigFile(masterConfig.KubernetesMasterConfig.APIServerArguments) if err != nil { return nil, err } - - var cloudConfig []byte - if kubeOptions.CloudProvider.CloudConfigFile != "" { + if len(cloudConfigFile) != 0 { var err error - cloudConfig, err = ioutil.ReadFile(kubeOptions.CloudProvider.CloudConfigFile) + cloudConfig, err = ioutil.ReadFile(cloudConfigFile) if err != nil { - return nil, fmt.Errorf("Error reading from cloud configuration file %s: %v", kubeOptions.CloudProvider.CloudConfigFile, err) + return nil, fmt.Errorf("error reading from cloud configuration file %s: %v", cloudConfigFile, err) } } // note: we are passing a combined quota registry here... @@ -136,7 +133,7 @@ func NewPluginInitializer( openshiftPluginInitializer := &oadmission.PluginInitializer{ ProjectCache: projectCache, OriginQuotaRegistry: quotaRegistry, - JenkinsPipelineConfig: options.JenkinsPipelineConfig, + JenkinsPipelineConfig: masterConfig.JenkinsPipelineConfig, RESTClientConfig: *privilegedLoopbackConfig, ClusterResourceQuotaInformer: informers.GetInternalOpenshiftQuotaInformers().Quota().InternalVersion().ClusterResourceQuotas(), ClusterQuotaMapper: clusterQuotaMappingController.GetClusterQuotaMapper(), @@ -147,31 +144,3 @@ func NewPluginInitializer( return admission.PluginInitializers{genericInitializer, webhookInitializer, kubePluginInitializer, openshiftPluginInitializer}, nil } - -type DefaultInformerAccess struct { - InternalKubernetesInformers kinternalinformers.SharedInformerFactory - KubernetesInformers kexternalinformers.SharedInformerFactory - InternalOpenshiftImageInformers imageinformer.SharedInformerFactory - InternalOpenshiftQuotaInformers quotainformer.SharedInformerFactory - InternalOpenshiftSecurityInformers securityinformer.SharedInformerFactory - OpenshiftUserInformers userinformer.SharedInformerFactory -} - -func (i *DefaultInformerAccess) GetInternalKubernetesInformers() kinternalinformers.SharedInformerFactory { - return i.InternalKubernetesInformers -} -func (i *DefaultInformerAccess) GetKubernetesInformers() kexternalinformers.SharedInformerFactory { - return i.KubernetesInformers -} -func (i *DefaultInformerAccess) GetInternalOpenshiftImageInformers() imageinformer.SharedInformerFactory { - return i.InternalOpenshiftImageInformers -} -func (i *DefaultInformerAccess) GetInternalOpenshiftQuotaInformers() quotainformer.SharedInformerFactory { - return i.InternalOpenshiftQuotaInformers -} -func (i *DefaultInformerAccess) GetInternalOpenshiftSecurityInformers() securityinformer.SharedInformerFactory { - return i.InternalOpenshiftSecurityInformers -} -func (i *DefaultInformerAccess) GetOpenshiftUserInformers() userinformer.SharedInformerFactory { - return i.OpenshiftUserInformers -} diff --git a/pkg/cmd/server/origin/master.go b/pkg/cmd/server/origin/master.go index 38d04e54a253..568e0d742717 100644 --- a/pkg/cmd/server/origin/master.go +++ b/pkg/cmd/server/origin/master.go @@ -14,16 +14,13 @@ import ( aggregatorapiserver "k8s.io/kube-aggregator/pkg/apiserver" kubeapiserver "k8s.io/kubernetes/pkg/master" kcorestorage "k8s.io/kubernetes/pkg/registry/core/rest" - rbacrest "k8s.io/kubernetes/pkg/registry/rbac/rest" "github.com/openshift/origin/pkg/cmd/openshift-apiserver/openshiftapiserver" "github.com/openshift/origin/pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing" "github.com/openshift/origin/pkg/cmd/openshift-kube-apiserver/openshiftkubeapiserver" - "github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" kubernetes "github.com/openshift/origin/pkg/cmd/server/kubernetes/master" cmdutil "github.com/openshift/origin/pkg/cmd/util" sccstorage "github.com/openshift/origin/pkg/security/apiserver/registry/securitycontextconstraints/etcd" - "k8s.io/apimachinery/pkg/util/wait" kapiserveroptions "k8s.io/kubernetes/cmd/kube-apiserver/app/options" ) @@ -35,8 +32,11 @@ func (c *MasterConfig) newOpenshiftAPIConfig(kubeAPIServerConfig apiserver.Confi // make a shallow copy to let us twiddle a few things // most of the config actually remains the same. We only need to mess with a couple items genericConfig := kubeAPIServerConfig - // TODO try to stop special casing these. We should all agree on them. - genericConfig.RESTOptionsGetter = c.RESTOptionsGetter + var err error + genericConfig.RESTOptionsGetter, err = openshiftapiserver.NewRESTOptionsGetter(c.Options) + if err != nil { + return nil, err + } var caData []byte if len(c.Options.ImagePolicyConfig.AdditionalTrustedCA) != 0 { @@ -237,90 +237,3 @@ func (c *MasterConfig) Run(stopCh <-chan struct{}) error { // Attempt to verify the server came up for 20 seconds (100 tries * 100ms, 100ms timeout per try) return cmdutil.WaitForSuccessfulDial(true, c.Options.ServingInfo.BindNetwork, c.Options.ServingInfo.BindAddress, 100*time.Millisecond, 100*time.Millisecond, 100) } - -func (c *MasterConfig) RunKubeAPIServer(stopCh <-chan struct{}) error { - var err error - var apiExtensionsInformers apiextensionsinformers.SharedInformerFactory - var delegateAPIServer apiserver.DelegationTarget - var extraPostStartHooks map[string]apiserver.PostStartHookFunc - - c.kubeAPIServerConfig.GenericConfig.BuildHandlerChainFunc, extraPostStartHooks, err = openshiftkubeapiserver.BuildHandlerChain(c.kubeAPIServerConfig.GenericConfig, c.ClientGoKubeInformers, &c.Options) - if err != nil { - return err - } - - kubeAPIServerOptions, err := kubernetes.BuildKubeAPIserverOptions(c.Options) - if err != nil { - return err - } - - delegateAPIServer = apiserver.NewEmptyDelegate() - delegateAPIServer, apiExtensionsInformers, err = c.withAPIExtensions(delegateAPIServer, kubeAPIServerOptions, *c.kubeAPIServerConfig.GenericConfig) - if err != nil { - return err - } - delegateAPIServer, err = c.withNonAPIRoutes(delegateAPIServer, *c.kubeAPIServerConfig.GenericConfig) - if err != nil { - return err - } - delegateAPIServer, err = c.withKubeAPI(delegateAPIServer, *c.kubeAPIServerConfig) - if err != nil { - return err - } - aggregatedAPIServer, err := c.withAggregator(delegateAPIServer, kubeAPIServerOptions, *c.kubeAPIServerConfig.GenericConfig, apiExtensionsInformers) - if err != nil { - return err - } - - // Start the audit backend before any request comes in. This means we cannot turn it into a - // post start hook because without calling Backend.Run the Backend.ProcessEvents call might block. - if c.AuditBackend != nil { - if err := c.AuditBackend.Run(stopCh); err != nil { - return fmt.Errorf("failed to run the audit backend: %v", err) - } - } - - aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie("authorization.openshift.io-bootstrapclusterroles", bootstrapData(bootstrappolicy.Policy()).EnsureRBACPolicy()) - aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie("openshift.io-startinformers", func(context apiserver.PostStartHookContext) error { - c.InformerStart(context.StopCh) - return nil - }) - aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie("openshift.io-restmapperupdater", func(context apiserver.PostStartHookContext) error { - c.RESTMapper.Reset() - go func() { - wait.Until(func() { - c.RESTMapper.Reset() - }, 10*time.Second, context.StopCh) - }() - return nil - }) - aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie("quota.openshift.io-clusterquotamapping", func(context apiserver.PostStartHookContext) error { - go c.ClusterQuotaMappingController.Run(5, context.StopCh) - return nil - }) - - // add post-start hooks - for name, fn := range c.additionalPostStartHooks { - aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie(name, fn) - } - for name, fn := range extraPostStartHooks { - aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie(name, fn) - } - - go aggregatedAPIServer.GenericAPIServer.PrepareRun().Run(stopCh) - - // Attempt to verify the server came up for 20 seconds (100 tries * 100ms, 100ms timeout per try) - return cmdutil.WaitForSuccessfulDial(true, c.Options.ServingInfo.BindNetwork, c.Options.ServingInfo.BindAddress, 100*time.Millisecond, 100*time.Millisecond, 100) -} - -// bootstrapData casts our policy data to the rbacrest helper that can -// materialize the policy. -func bootstrapData(data *bootstrappolicy.PolicyData) *rbacrest.PolicyData { - return &rbacrest.PolicyData{ - ClusterRoles: data.ClusterRoles, - ClusterRoleBindings: data.ClusterRoleBindings, - Roles: data.Roles, - RoleBindings: data.RoleBindings, - ClusterRolesToAggregate: data.ClusterRolesToAggregate, - } -} diff --git a/pkg/cmd/server/origin/master_config.go b/pkg/cmd/server/origin/master_config.go index e45372b247cb..5274db78a3c1 100644 --- a/pkg/cmd/server/origin/master_config.go +++ b/pkg/cmd/server/origin/master_config.go @@ -8,7 +8,6 @@ import ( "k8s.io/apiserver/pkg/admission" admissionmetrics "k8s.io/apiserver/pkg/admission/metrics" "k8s.io/apiserver/pkg/audit" - genericregistry "k8s.io/apiserver/pkg/registry/generic" genericapiserver "k8s.io/apiserver/pkg/server" cacheddiscovery "k8s.io/client-go/discovery/cached" kinformers "k8s.io/client-go/informers" @@ -51,9 +50,6 @@ type MasterConfig struct { kubeAPIServerConfig *kubeapiserver.Config additionalPostStartHooks map[string]genericapiserver.PostStartHookFunc - // RESTOptionsGetter provides access to storage and RESTOptions for a particular resource - RESTOptionsGetter genericregistry.RESTOptionsGetter - RuleResolver rbacregistryvalidation.AuthorizationRuleResolver SubjectLocator rbacauthorizer.SubjectLocator @@ -71,12 +67,6 @@ type MasterConfig struct { // To apply different access control to a system component, create a client config specifically for that component. PrivilegedLoopbackClientConfig restclient.Config - // PrivilegedLoopbackKubernetesClientsetExternal is the client used to call Kubernetes APIs from system components, - // built from KubeClientConfig. It should only be accessed via the *TestingClient() helper methods. To apply - // different access control to a system component, create a separate client/config specifically for - // that component. - PrivilegedLoopbackKubernetesClientsetExternal kclientsetexternal.Interface - AuditBackend audit.Backend // TODO inspect uses to eliminate them @@ -130,11 +120,6 @@ func BuildMasterConfig( informers = realLoopbackInformers } - restOptsGetter, err := openshiftapiserver.NewRESTOptionsGetter(options) - if err != nil { - return nil, err - } - privilegedLoopbackConfig, err := configapi.GetClientConfig(options.MasterClients.OpenShiftLoopbackKubeConfig, options.MasterClients.OpenShiftLoopbackClientConnectionOverrides) if err != nil { return nil, err @@ -199,8 +184,6 @@ func BuildMasterConfig( kubeAPIServerConfig: kubeAPIServerConfig, additionalPostStartHooks: map[string]genericapiserver.PostStartHookFunc{}, - RESTOptionsGetter: restOptsGetter, - RuleResolver: openshiftapiserver.NewRuleResolver(informers.GetKubernetesInformers().Rbac().V1()), SubjectLocator: subjectLocator, @@ -215,8 +198,7 @@ func BuildMasterConfig( RegistryHostnameRetriever: registryHostnameRetriever, - PrivilegedLoopbackClientConfig: *privilegedLoopbackConfig, - PrivilegedLoopbackKubernetesClientsetExternal: privilegedLoopbackKubeClientsetExternal, + PrivilegedLoopbackClientConfig: *privilegedLoopbackConfig, InternalKubeInformers: informers.GetInternalKubernetesInformers(), ClientGoKubeInformers: informers.GetKubernetesInformers(),