mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Move apiserver cloudprovider dep into kubeapiserver
This commit is contained in:
parent
5e9f39b5fb
commit
f96fa748d8
@ -43,6 +43,7 @@ type ServerRunOptions struct {
|
|||||||
InsecureServing *genericoptions.ServingOptions
|
InsecureServing *genericoptions.ServingOptions
|
||||||
Authentication *kubeoptions.BuiltInAuthenticationOptions
|
Authentication *kubeoptions.BuiltInAuthenticationOptions
|
||||||
Authorization *kubeoptions.BuiltInAuthorizationOptions
|
Authorization *kubeoptions.BuiltInAuthorizationOptions
|
||||||
|
CloudProvider *kubeoptions.CloudProviderOptions
|
||||||
|
|
||||||
AllowPrivileged bool
|
AllowPrivileged bool
|
||||||
EventTTL time.Duration
|
EventTTL time.Duration
|
||||||
@ -65,6 +66,7 @@ func NewServerRunOptions() *ServerRunOptions {
|
|||||||
InsecureServing: genericoptions.NewInsecureServingOptions(),
|
InsecureServing: genericoptions.NewInsecureServingOptions(),
|
||||||
Authentication: kubeoptions.NewBuiltInAuthenticationOptions().WithAll(),
|
Authentication: kubeoptions.NewBuiltInAuthenticationOptions().WithAll(),
|
||||||
Authorization: kubeoptions.NewBuiltInAuthorizationOptions(),
|
Authorization: kubeoptions.NewBuiltInAuthorizationOptions(),
|
||||||
|
CloudProvider: kubeoptions.NewCloudProviderOptions(),
|
||||||
|
|
||||||
EventTTL: 1 * time.Hour,
|
EventTTL: 1 * time.Hour,
|
||||||
MasterCount: 1,
|
MasterCount: 1,
|
||||||
@ -96,6 +98,7 @@ func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) {
|
|||||||
s.InsecureServing.AddDeprecatedFlags(fs)
|
s.InsecureServing.AddDeprecatedFlags(fs)
|
||||||
s.Authentication.AddFlags(fs)
|
s.Authentication.AddFlags(fs)
|
||||||
s.Authorization.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
|
// Note: the weird ""+ in below lines seems to be the only way to get gofmt to
|
||||||
// arrange these text blocks sensibly. Grrr.
|
// arrange these text blocks sensibly. Grrr.
|
||||||
|
@ -90,7 +90,7 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
if err := s.SecureServing.MaybeDefaultWithSelfSignedCerts(s.GenericServerRunOptions.AdvertiseAddress.String(), apiServerServiceIP); err != nil {
|
if err := s.SecureServing.MaybeDefaultWithSelfSignedCerts(s.GenericServerRunOptions.AdvertiseAddress.String(), apiServerServiceIP); err != nil {
|
||||||
return fmt.Errorf("error creating self-signed certificates: %v", err)
|
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)
|
return fmt.Errorf("error setting the external host value: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
if len(s.SSHUser) > 0 {
|
if len(s.SSHUser) > 0 {
|
||||||
// Get ssh key distribution func, if supported
|
// Get ssh key distribution func, if supported
|
||||||
var installSSH genericapiserver.InstallSSHKey
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("cloud provider could not be initialized: %v", err)
|
return fmt.Errorf("cloud provider could not be initialized: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,7 @@ type ServerRunOptions struct {
|
|||||||
SecureServing *genericoptions.SecureServingOptions
|
SecureServing *genericoptions.SecureServingOptions
|
||||||
InsecureServing *genericoptions.ServingOptions
|
InsecureServing *genericoptions.ServingOptions
|
||||||
Authentication *kubeoptions.BuiltInAuthenticationOptions
|
Authentication *kubeoptions.BuiltInAuthenticationOptions
|
||||||
|
CloudProvider *kubeoptions.CloudProviderOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServerRunOptions() *ServerRunOptions {
|
func NewServerRunOptions() *ServerRunOptions {
|
||||||
@ -71,6 +72,7 @@ func NewServerRunOptions() *ServerRunOptions {
|
|||||||
SecureServing: genericoptions.NewSecureServingOptions(),
|
SecureServing: genericoptions.NewSecureServingOptions(),
|
||||||
InsecureServing: genericoptions.NewInsecureServingOptions(),
|
InsecureServing: genericoptions.NewInsecureServingOptions(),
|
||||||
Authentication: kubeoptions.NewBuiltInAuthenticationOptions().WithAll(),
|
Authentication: kubeoptions.NewBuiltInAuthenticationOptions().WithAll(),
|
||||||
|
CloudProvider: kubeoptions.NewCloudProviderOptions(),
|
||||||
}
|
}
|
||||||
s.InsecureServing.BindPort = InsecurePort
|
s.InsecureServing.BindPort = InsecurePort
|
||||||
s.SecureServing.ServingOptions.BindPort = SecurePort
|
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"}
|
serverOptions.Etcd.StorageConfig.ServerList = []string{"http://127.0.0.1:2379"}
|
||||||
|
|
||||||
// set defaults
|
// set defaults
|
||||||
if err := serverOptions.GenericServerRunOptions.DefaultExternalHost(); err != nil {
|
if err := serverOptions.CloudProvider.DefaultExternalHost(serverOptions.GenericServerRunOptions); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := serverOptions.SecureServing.MaybeDefaultWithSelfSignedCerts(serverOptions.GenericServerRunOptions.AdvertiseAddress.String()); err != nil {
|
if err := serverOptions.SecureServing.MaybeDefaultWithSelfSignedCerts(serverOptions.GenericServerRunOptions.AdvertiseAddress.String()); err != nil {
|
||||||
|
@ -34,6 +34,7 @@ type ServerRunOptions struct {
|
|||||||
InsecureServing *genericoptions.ServingOptions
|
InsecureServing *genericoptions.ServingOptions
|
||||||
Authentication *kubeoptions.BuiltInAuthenticationOptions
|
Authentication *kubeoptions.BuiltInAuthenticationOptions
|
||||||
Authorization *kubeoptions.BuiltInAuthorizationOptions
|
Authorization *kubeoptions.BuiltInAuthorizationOptions
|
||||||
|
CloudProvider *kubeoptions.CloudProviderOptions
|
||||||
|
|
||||||
EventTTL time.Duration
|
EventTTL time.Duration
|
||||||
}
|
}
|
||||||
@ -47,6 +48,7 @@ func NewServerRunOptions() *ServerRunOptions {
|
|||||||
InsecureServing: genericoptions.NewInsecureServingOptions(),
|
InsecureServing: genericoptions.NewInsecureServingOptions(),
|
||||||
Authentication: kubeoptions.NewBuiltInAuthenticationOptions().WithAll(),
|
Authentication: kubeoptions.NewBuiltInAuthenticationOptions().WithAll(),
|
||||||
Authorization: kubeoptions.NewBuiltInAuthorizationOptions(),
|
Authorization: kubeoptions.NewBuiltInAuthorizationOptions(),
|
||||||
|
CloudProvider: kubeoptions.NewCloudProviderOptions(),
|
||||||
|
|
||||||
EventTTL: 1 * time.Hour,
|
EventTTL: 1 * time.Hour,
|
||||||
}
|
}
|
||||||
@ -62,6 +64,7 @@ func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) {
|
|||||||
s.InsecureServing.AddFlags(fs)
|
s.InsecureServing.AddFlags(fs)
|
||||||
s.Authentication.AddFlags(fs)
|
s.Authentication.AddFlags(fs)
|
||||||
s.Authorization.AddFlags(fs)
|
s.Authorization.AddFlags(fs)
|
||||||
|
s.CloudProvider.AddFlags(fs)
|
||||||
|
|
||||||
fs.DurationVar(&s.EventTTL, "event-ttl", s.EventTTL,
|
fs.DurationVar(&s.EventTTL, "event-ttl", s.EventTTL,
|
||||||
"Amount of time to retain events. Default is 1h.")
|
"Amount of time to retain events. Default is 1h.")
|
||||||
|
@ -73,7 +73,7 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
if err := s.SecureServing.MaybeDefaultWithSelfSignedCerts(s.GenericServerRunOptions.AdvertiseAddress.String()); err != nil {
|
if err := s.SecureServing.MaybeDefaultWithSelfSignedCerts(s.GenericServerRunOptions.AdvertiseAddress.String()); err != nil {
|
||||||
return fmt.Errorf("error creating self-signed certificates: %v", err)
|
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)
|
return fmt.Errorf("error setting the external host value: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,13 +21,11 @@ go_library(
|
|||||||
deps = [
|
deps = [
|
||||||
"//pkg/admission:go_default_library",
|
"//pkg/admission:go_default_library",
|
||||||
"//pkg/api:go_default_library",
|
"//pkg/api:go_default_library",
|
||||||
"//pkg/api/v1:go_default_library",
|
|
||||||
"//pkg/apimachinery/registered: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/authentication/v1beta1:go_default_library",
|
||||||
"//pkg/client/clientset_generated/clientset/typed/authorization/v1beta1:go_default_library",
|
"//pkg/client/clientset_generated/clientset/typed/authorization/v1beta1:go_default_library",
|
||||||
"//pkg/client/restclient:go_default_library",
|
"//pkg/client/restclient:go_default_library",
|
||||||
"//pkg/client/unversioned/clientcmd:go_default_library",
|
"//pkg/client/unversioned/clientcmd:go_default_library",
|
||||||
"//pkg/cloudprovider:go_default_library",
|
|
||||||
"//pkg/genericapiserver/authenticator:go_default_library",
|
"//pkg/genericapiserver/authenticator:go_default_library",
|
||||||
"//pkg/genericapiserver/authorizer:go_default_library",
|
"//pkg/genericapiserver/authorizer:go_default_library",
|
||||||
"//pkg/runtime/schema:go_default_library",
|
"//pkg/runtime/schema:go_default_library",
|
||||||
|
@ -19,14 +19,11 @@ package options
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/admission"
|
"k8s.io/kubernetes/pkg/admission"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
|
||||||
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
|
||||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||||
"k8s.io/kubernetes/pkg/util/config"
|
"k8s.io/kubernetes/pkg/util/config"
|
||||||
|
|
||||||
@ -39,8 +36,6 @@ type ServerRunOptions struct {
|
|||||||
AdmissionControlConfigFile string
|
AdmissionControlConfigFile string
|
||||||
AdvertiseAddress net.IP
|
AdvertiseAddress net.IP
|
||||||
|
|
||||||
CloudConfigFile string
|
|
||||||
CloudProvider string
|
|
||||||
CorsAllowedOriginList []string
|
CorsAllowedOriginList []string
|
||||||
DefaultStorageMediaType string
|
DefaultStorageMediaType string
|
||||||
DeleteCollectionWorkers int
|
DeleteCollectionWorkers int
|
||||||
@ -109,44 +104,6 @@ func (s *ServerRunOptions) DefaultAdvertiseAddress(secure *SecureServingOptions,
|
|||||||
return nil
|
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,
|
// StorageGroupsToEncodingVersion returns a map from group name to group version,
|
||||||
// computed from s.StorageVersions flag.
|
// computed from s.StorageVersions flag.
|
||||||
func (s *ServerRunOptions) StorageGroupsToEncodingVersion() (map[string]schema.GroupVersion, error) {
|
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 "+
|
"will be used. If --bind-address is unspecified, the host's default interface will "+
|
||||||
"be used.")
|
"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, ""+
|
fs.StringSliceVar(&s.CorsAllowedOriginList, "cors-allowed-origins", s.CorsAllowedOriginList, ""+
|
||||||
"List of allowed origins for CORS, comma separated. An allowed origin can be a regular "+
|
"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.")
|
"expression to support subdomain matching. If this list is empty CORS will not be enabled.")
|
||||||
|
@ -12,9 +12,12 @@ go_library(
|
|||||||
srcs = [
|
srcs = [
|
||||||
"authentication.go",
|
"authentication.go",
|
||||||
"authorization.go",
|
"authorization.go",
|
||||||
|
"cloudprovider.go",
|
||||||
],
|
],
|
||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
deps = [
|
deps = [
|
||||||
|
"//pkg/api/v1:go_default_library",
|
||||||
|
"//pkg/cloudprovider:go_default_library",
|
||||||
"//pkg/controller/informers:go_default_library",
|
"//pkg/controller/informers:go_default_library",
|
||||||
"//pkg/genericapiserver:go_default_library",
|
"//pkg/genericapiserver:go_default_library",
|
||||||
"//pkg/genericapiserver/options:go_default_library",
|
"//pkg/genericapiserver/options:go_default_library",
|
||||||
|
88
pkg/kubeapiserver/options/cloudprovider.go
Normal file
88
pkg/kubeapiserver/options/cloudprovider.go
Normal file
@ -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
Block a user