-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clean up construction to make creating types more obvious #20777
Merged
openshift-merge-robot
merged 4 commits into
openshift:master
from
deads2k:server-22-scrub-start
Aug 29, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bffab1b
UPSTREAM: 67896: expose generic storage factory primitives
deads2k b8be8a7
use a more 'normal' storage factory
deads2k 8708fd5
collapse onto upstream storage RESTOptions
deads2k 3563995
clean up construction to make creating types more obvious
deads2k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intentional removal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, logically the openshift apiserver has no public address