mirror of https://github.com/k3s-io/k3s
Merge pull request #39435 from sttts/sttts-cloudprovider-to-master
Automatic merge from submit-queue Move apiserver cloudprovider dep into kubeapiserverpull/6/head
commit
f76fba0da0
|
@ -43,6 +43,7 @@ type ServerRunOptions struct {
|
|||
InsecureServing *genericoptions.ServingOptions
|
||||
Authentication *kubeoptions.BuiltInAuthenticationOptions
|
||||
Authorization *kubeoptions.BuiltInAuthorizationOptions
|
||||
CloudProvider *kubeoptions.CloudProviderOptions
|
||||
|
||||
AllowPrivileged bool
|
||||
EventTTL time.Duration
|
||||
|
@ -65,6 +66,7 @@ func NewServerRunOptions() *ServerRunOptions {
|
|||
InsecureServing: genericoptions.NewInsecureServingOptions(),
|
||||
Authentication: kubeoptions.NewBuiltInAuthenticationOptions().WithAll(),
|
||||
Authorization: kubeoptions.NewBuiltInAuthorizationOptions(),
|
||||
CloudProvider: kubeoptions.NewCloudProviderOptions(),
|
||||
|
||||
EventTTL: 1 * time.Hour,
|
||||
MasterCount: 1,
|
||||
|
@ -96,6 +98,7 @@ func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) {
|
|||
s.InsecureServing.AddDeprecatedFlags(fs)
|
||||
s.Authentication.AddFlags(fs)
|
||||
s.Authorization.AddFlags(fs)
|
||||
s.CloudProvider.AddFlags(fs)
|
||||
|
||||
// Note: the weird ""+ in below lines seems to be the only way to get gofmt to
|
||||
// arrange these text blocks sensibly. Grrr.
|
||||
|
|
|
@ -91,7 +91,7 @@ func Run(s *options.ServerRunOptions) error {
|
|||
if err := s.SecureServing.MaybeDefaultWithSelfSignedCerts(s.GenericServerRunOptions.AdvertiseAddress.String(), apiServerServiceIP); err != nil {
|
||||
return fmt.Errorf("error creating self-signed certificates: %v", err)
|
||||
}
|
||||
if err := s.GenericServerRunOptions.DefaultExternalHost(); err != nil {
|
||||
if err := s.CloudProvider.DefaultExternalHost(s.GenericServerRunOptions); err != nil {
|
||||
return fmt.Errorf("error setting the external host value: %v", err)
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ func Run(s *options.ServerRunOptions) error {
|
|||
if len(s.SSHUser) > 0 {
|
||||
// Get ssh key distribution func, if supported
|
||||
var installSSH genericapiserver.InstallSSHKey
|
||||
cloud, err := cloudprovider.InitCloudProvider(s.GenericServerRunOptions.CloudProvider, s.GenericServerRunOptions.CloudConfigFile)
|
||||
cloud, err := cloudprovider.InitCloudProvider(s.CloudProvider.CloudProvider, s.CloudProvider.CloudConfigFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cloud provider could not be initialized: %v", err)
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ type ServerRunOptions struct {
|
|||
SecureServing *genericoptions.SecureServingOptions
|
||||
InsecureServing *genericoptions.ServingOptions
|
||||
Authentication *kubeoptions.BuiltInAuthenticationOptions
|
||||
CloudProvider *kubeoptions.CloudProviderOptions
|
||||
}
|
||||
|
||||
func NewServerRunOptions() *ServerRunOptions {
|
||||
|
@ -71,6 +72,7 @@ func NewServerRunOptions() *ServerRunOptions {
|
|||
SecureServing: genericoptions.NewSecureServingOptions(),
|
||||
InsecureServing: genericoptions.NewInsecureServingOptions(),
|
||||
Authentication: kubeoptions.NewBuiltInAuthenticationOptions().WithAll(),
|
||||
CloudProvider: kubeoptions.NewCloudProviderOptions(),
|
||||
}
|
||||
s.InsecureServing.BindPort = InsecurePort
|
||||
s.SecureServing.ServingOptions.BindPort = SecurePort
|
||||
|
@ -82,7 +84,7 @@ func (serverOptions *ServerRunOptions) Run(stopCh <-chan struct{}) error {
|
|||
serverOptions.Etcd.StorageConfig.ServerList = []string{"http://127.0.0.1:2379"}
|
||||
|
||||
// set defaults
|
||||
if err := serverOptions.GenericServerRunOptions.DefaultExternalHost(); err != nil {
|
||||
if err := serverOptions.CloudProvider.DefaultExternalHost(serverOptions.GenericServerRunOptions); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := serverOptions.SecureServing.MaybeDefaultWithSelfSignedCerts(serverOptions.GenericServerRunOptions.AdvertiseAddress.String()); err != nil {
|
||||
|
|
|
@ -34,6 +34,7 @@ type ServerRunOptions struct {
|
|||
InsecureServing *genericoptions.ServingOptions
|
||||
Authentication *kubeoptions.BuiltInAuthenticationOptions
|
||||
Authorization *kubeoptions.BuiltInAuthorizationOptions
|
||||
CloudProvider *kubeoptions.CloudProviderOptions
|
||||
|
||||
EventTTL time.Duration
|
||||
}
|
||||
|
@ -47,6 +48,7 @@ func NewServerRunOptions() *ServerRunOptions {
|
|||
InsecureServing: genericoptions.NewInsecureServingOptions(),
|
||||
Authentication: kubeoptions.NewBuiltInAuthenticationOptions().WithAll(),
|
||||
Authorization: kubeoptions.NewBuiltInAuthorizationOptions(),
|
||||
CloudProvider: kubeoptions.NewCloudProviderOptions(),
|
||||
|
||||
EventTTL: 1 * time.Hour,
|
||||
}
|
||||
|
@ -62,6 +64,7 @@ func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) {
|
|||
s.InsecureServing.AddFlags(fs)
|
||||
s.Authentication.AddFlags(fs)
|
||||
s.Authorization.AddFlags(fs)
|
||||
s.CloudProvider.AddFlags(fs)
|
||||
|
||||
fs.DurationVar(&s.EventTTL, "event-ttl", s.EventTTL,
|
||||
"Amount of time to retain events. Default is 1h.")
|
||||
|
|
|
@ -74,7 +74,7 @@ func Run(s *options.ServerRunOptions) error {
|
|||
if err := s.SecureServing.MaybeDefaultWithSelfSignedCerts(s.GenericServerRunOptions.AdvertiseAddress.String()); err != nil {
|
||||
return fmt.Errorf("error creating self-signed certificates: %v", err)
|
||||
}
|
||||
if err := s.GenericServerRunOptions.DefaultExternalHost(); err != nil {
|
||||
if err := s.CloudProvider.DefaultExternalHost(s.GenericServerRunOptions); err != nil {
|
||||
return fmt.Errorf("error setting the external host value: %v", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -21,13 +21,11 @@ go_library(
|
|||
deps = [
|
||||
"//pkg/admission:go_default_library",
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/v1:go_default_library",
|
||||
"//pkg/apimachinery/registered:go_default_library",
|
||||
"//pkg/client/clientset_generated/clientset/typed/authentication/v1beta1:go_default_library",
|
||||
"//pkg/client/clientset_generated/clientset/typed/authorization/v1beta1:go_default_library",
|
||||
"//pkg/client/restclient:go_default_library",
|
||||
"//pkg/client/unversioned/clientcmd:go_default_library",
|
||||
"//pkg/cloudprovider:go_default_library",
|
||||
"//pkg/genericapiserver/authenticator:go_default_library",
|
||||
"//pkg/genericapiserver/authorizer:go_default_library",
|
||||
"//pkg/runtime/schema:go_default_library",
|
||||
|
|
|
@ -19,14 +19,11 @@ package options
|
|||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/pkg/admission"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||
"k8s.io/kubernetes/pkg/util/config"
|
||||
|
||||
|
@ -39,8 +36,6 @@ type ServerRunOptions struct {
|
|||
AdmissionControlConfigFile string
|
||||
AdvertiseAddress net.IP
|
||||
|
||||
CloudConfigFile string
|
||||
CloudProvider string
|
||||
CorsAllowedOriginList []string
|
||||
DefaultStorageMediaType string
|
||||
DeleteCollectionWorkers int
|
||||
|
@ -109,44 +104,6 @@ func (s *ServerRunOptions) DefaultAdvertiseAddress(secure *SecureServingOptions,
|
|||
return nil
|
||||
}
|
||||
|
||||
func (options *ServerRunOptions) DefaultExternalHost() error {
|
||||
if len(options.ExternalHost) != 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: extend for other providers
|
||||
if options.CloudProvider == "gce" || options.CloudProvider == "aws" {
|
||||
cloud, err := cloudprovider.InitCloudProvider(options.CloudProvider, options.CloudConfigFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%q cloud provider could not be initialized: %v", options.CloudProvider, err)
|
||||
}
|
||||
instances, supported := cloud.Instances()
|
||||
if !supported {
|
||||
return fmt.Errorf("%q cloud provider has no instances", options.CloudProvider)
|
||||
}
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get hostname: %v", err)
|
||||
}
|
||||
nodeName, err := instances.CurrentNodeName(hostname)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get NodeName from %q cloud provider: %v", options.CloudProvider, err)
|
||||
}
|
||||
addrs, err := instances.NodeAddresses(nodeName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get external host address from %q cloud provider: %v", options.CloudProvider, err)
|
||||
} else {
|
||||
for _, addr := range addrs {
|
||||
if addr.Type == v1.NodeExternalIP {
|
||||
options.ExternalHost = addr.Address
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// StorageGroupsToEncodingVersion returns a map from group name to group version,
|
||||
// computed from s.StorageVersions flag.
|
||||
func (s *ServerRunOptions) StorageGroupsToEncodingVersion() (map[string]schema.GroupVersion, error) {
|
||||
|
@ -211,12 +168,6 @@ func (s *ServerRunOptions) AddUniversalFlags(fs *pflag.FlagSet) {
|
|||
"will be used. If --bind-address is unspecified, the host's default interface will "+
|
||||
"be used.")
|
||||
|
||||
fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider,
|
||||
"The provider for cloud services. Empty string for no provider.")
|
||||
|
||||
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile,
|
||||
"The path to the cloud provider configuration file. Empty string for no configuration file.")
|
||||
|
||||
fs.StringSliceVar(&s.CorsAllowedOriginList, "cors-allowed-origins", s.CorsAllowedOriginList, ""+
|
||||
"List of allowed origins for CORS, comma separated. An allowed origin can be a regular "+
|
||||
"expression to support subdomain matching. If this list is empty CORS will not be enabled.")
|
||||
|
|
|
@ -12,9 +12,12 @@ go_library(
|
|||
srcs = [
|
||||
"authentication.go",
|
||||
"authorization.go",
|
||||
"cloudprovider.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api/v1:go_default_library",
|
||||
"//pkg/cloudprovider:go_default_library",
|
||||
"//pkg/controller/informers:go_default_library",
|
||||
"//pkg/genericapiserver:go_default_library",
|
||||
"//pkg/genericapiserver/options:go_default_library",
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package options
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||
genericoptions "k8s.io/kubernetes/pkg/genericapiserver/options"
|
||||
)
|
||||
|
||||
type CloudProviderOptions struct {
|
||||
CloudConfigFile string
|
||||
CloudProvider string
|
||||
}
|
||||
|
||||
func NewCloudProviderOptions() *CloudProviderOptions {
|
||||
return &CloudProviderOptions{}
|
||||
}
|
||||
|
||||
func (s *CloudProviderOptions) Validate() []error {
|
||||
allErrors := []error{}
|
||||
return allErrors
|
||||
}
|
||||
|
||||
func (s *CloudProviderOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider,
|
||||
"The provider for cloud services. Empty string for no provider.")
|
||||
|
||||
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile,
|
||||
"The path to the cloud provider configuration file. Empty string for no configuration file.")
|
||||
}
|
||||
|
||||
func (s *CloudProviderOptions) DefaultExternalHost(genericoptions *genericoptions.ServerRunOptions) error {
|
||||
if len(genericoptions.ExternalHost) != 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: extend for other providers
|
||||
if s.CloudProvider == "gce" || s.CloudProvider == "aws" {
|
||||
cloud, err := cloudprovider.InitCloudProvider(s.CloudProvider, s.CloudConfigFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%q cloud provider could not be initialized: %v", s.CloudProvider, err)
|
||||
}
|
||||
instances, supported := cloud.Instances()
|
||||
if !supported {
|
||||
return fmt.Errorf("%q cloud provider has no instances", s.CloudProvider)
|
||||
}
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get hostname: %v", err)
|
||||
}
|
||||
nodeName, err := instances.CurrentNodeName(hostname)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get NodeName from %q cloud provider: %v", s.CloudProvider, err)
|
||||
}
|
||||
addrs, err := instances.NodeAddresses(nodeName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get external host address from %q cloud provider: %v", s.CloudProvider, err)
|
||||
} else {
|
||||
for _, addr := range addrs {
|
||||
if addr.Type == v1.NodeExternalIP {
|
||||
genericoptions.ExternalHost = addr.Address
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue