-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20777 from deads2k/server-22-scrub-start
clean up construction to make creating types more obvious
- Loading branch information
Showing
47 changed files
with
275 additions
and
510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing/cloud.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
48 changes: 48 additions & 0 deletions
48
pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing/etcd.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
103 changes: 103 additions & 0 deletions
103
pkg/cmd/openshift-apiserver/openshiftapiserver/restoptionsgetter.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
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" | ||
"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" | ||
) | ||
|
||
// NewConfigGetter returns a restoptions.Getter implemented using information from the provided master config. | ||
func NewRESTOptionsGetter(masterOptions configapi.MasterConfig) (genericregistry.RESTOptionsGetter, 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 | ||
} | ||
} | ||
|
||
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, | ||
} | ||
return restOptionsGetter, nil | ||
} | ||
|
||
// newHeuristicWatchCacheSizes returns a map of suggested watch cache sizes based on total | ||
// memory. It reuses the upstream heuristic and adds OpenShift specific resources. | ||
func newHeuristicWatchCacheSizes(expectedRAMCapacityMB int) map[schema.GroupResource]int { | ||
// TODO: Revisit this heuristic, copied from upstream | ||
clusterSize := expectedRAMCapacityMB / 60 | ||
|
||
// default enable watch caches for resources that will have a high number of clients accessing it | ||
// and where the write rate may be significant | ||
watchCacheSizes := make(map[schema.GroupResource]int) | ||
watchCacheSizes[schema.GroupResource{Group: "network.openshift.io", Resource: "hostsubnets"}] = maxInt(5*clusterSize, 100) | ||
watchCacheSizes[schema.GroupResource{Group: "network.openshift.io", Resource: "netnamespaces"}] = maxInt(5*clusterSize, 100) | ||
watchCacheSizes[schema.GroupResource{Group: "network.openshift.io", Resource: "egressnetworkpolicies"}] = maxInt(10*clusterSize, 100) | ||
return watchCacheSizes | ||
} | ||
|
||
func maxInt(a, b int) int { | ||
if a > b { | ||
return a | ||
} | ||
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", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.