mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #56812 from dims/drop-using-cloud-provider-for-setting-host-address
Automatic merge from submit-queue (batch tested with PRs 56250, 56809, 56812, 56792, 56724). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Drop using cloud provider to set host address feature **What this PR does / why we need it**: Follow up to PR #54516, also see notice to -dev@ : https://groups.google.com/forum/#!topic/kubernetes-dev/2NaxUCSbIw8 **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note kube-apiserver: The external hostname no longer longer use the cloud provider API to select a default. It can be set explicitly using --external-hostname, if needed. ```
This commit is contained in:
commit
b3cbfed4d8
@ -630,8 +630,18 @@ func defaultOptions(s *options.ServerRunOptions) error {
|
|||||||
if err := s.SecureServing.MaybeDefaultWithSelfSignedCerts(s.GenericServerRunOptions.AdvertiseAddress.String(), []string{"kubernetes.default.svc", "kubernetes.default", "kubernetes"}, []net.IP{apiServerServiceIP}); err != nil {
|
if err := s.SecureServing.MaybeDefaultWithSelfSignedCerts(s.GenericServerRunOptions.AdvertiseAddress.String(), []string{"kubernetes.default.svc", "kubernetes.default", "kubernetes"}, []net.IP{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.CloudProvider.DefaultExternalHost(s.GenericServerRunOptions); err != nil {
|
|
||||||
return fmt.Errorf("error setting the external host value: %v", err)
|
if len(s.GenericServerRunOptions.ExternalHost) == 0 {
|
||||||
|
if len(s.GenericServerRunOptions.AdvertiseAddress) > 0 {
|
||||||
|
s.GenericServerRunOptions.ExternalHost = s.GenericServerRunOptions.AdvertiseAddress.String()
|
||||||
|
} else {
|
||||||
|
if hostname, err := os.Hostname(); err == nil {
|
||||||
|
s.GenericServerRunOptions.ExternalHost = hostname
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("error finding host name: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
glog.Infof("external host was not specified, using %v", s.GenericServerRunOptions.ExternalHost)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Authentication.ApplyAuthorization(s.Authorization)
|
s.Authentication.ApplyAuthorization(s.Authorization)
|
||||||
|
@ -21,7 +21,6 @@ go_library(
|
|||||||
deps = [
|
deps = [
|
||||||
"//pkg/api/legacyscheme:go_default_library",
|
"//pkg/api/legacyscheme:go_default_library",
|
||||||
"//pkg/client/informers/informers_generated/internalversion:go_default_library",
|
"//pkg/client/informers/informers_generated/internalversion:go_default_library",
|
||||||
"//pkg/cloudprovider:go_default_library",
|
|
||||||
"//pkg/kubeapiserver/authenticator:go_default_library",
|
"//pkg/kubeapiserver/authenticator:go_default_library",
|
||||||
"//pkg/kubeapiserver/authorizer:go_default_library",
|
"//pkg/kubeapiserver/authorizer:go_default_library",
|
||||||
"//pkg/kubeapiserver/authorizer/modes:go_default_library",
|
"//pkg/kubeapiserver/authorizer/modes:go_default_library",
|
||||||
@ -29,7 +28,6 @@ go_library(
|
|||||||
"//vendor/github.com/golang/glog:go_default_library",
|
"//vendor/github.com/golang/glog:go_default_library",
|
||||||
"//vendor/github.com/pborman/uuid:go_default_library",
|
"//vendor/github.com/pborman/uuid:go_default_library",
|
||||||
"//vendor/github.com/spf13/pflag:go_default_library",
|
"//vendor/github.com/spf13/pflag:go_default_library",
|
||||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
|
||||||
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
|
||||||
"//vendor/k8s.io/apiserver/pkg/server:go_default_library",
|
"//vendor/k8s.io/apiserver/pkg/server:go_default_library",
|
||||||
|
@ -17,15 +17,7 @@ limitations under the License.
|
|||||||
package options
|
package options
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
|
||||||
genericoptions "k8s.io/apiserver/pkg/server/options"
|
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type CloudProviderOptions struct {
|
type CloudProviderOptions struct {
|
||||||
@ -49,44 +41,3 @@ func (s *CloudProviderOptions) AddFlags(fs *pflag.FlagSet) {
|
|||||||
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile,
|
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile,
|
||||||
"The path to the cloud provider configuration file. Empty string for no configuration file.")
|
"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
|
|
||||||
}
|
|
||||||
|
|
||||||
if cloudprovider.IsCloudProvider(s.CloudProvider) {
|
|
||||||
glog.Info("--external-hostname was not specified. Trying to get it from the cloud provider.")
|
|
||||||
|
|
||||||
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
|
|
||||||
glog.Warning("[Deprecated] Getting host address using cloud provider is " +
|
|
||||||
"now deprecated. Please use --external-hostname explicitly")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -338,13 +338,17 @@ type CompletedConfig struct {
|
|||||||
// Complete fills in any fields not set that are required to have valid data and can be derived
|
// Complete fills in any fields not set that are required to have valid data and can be derived
|
||||||
// from other fields. If you're going to `ApplyOptions`, do that first. It's mutating the receiver.
|
// from other fields. If you're going to `ApplyOptions`, do that first. It's mutating the receiver.
|
||||||
func (c *Config) Complete(informers informers.SharedInformerFactory) CompletedConfig {
|
func (c *Config) Complete(informers informers.SharedInformerFactory) CompletedConfig {
|
||||||
if len(c.ExternalAddress) == 0 && c.PublicAddress != nil {
|
host := c.ExternalAddress
|
||||||
hostAndPort := c.PublicAddress.String()
|
if host == "" && c.PublicAddress != nil {
|
||||||
if c.ReadWritePort != 0 {
|
host = c.PublicAddress.String()
|
||||||
hostAndPort = net.JoinHostPort(hostAndPort, strconv.Itoa(c.ReadWritePort))
|
|
||||||
}
|
|
||||||
c.ExternalAddress = hostAndPort
|
|
||||||
}
|
}
|
||||||
|
if !strings.Contains(host, ":") {
|
||||||
|
if c.ReadWritePort != 0 {
|
||||||
|
host = net.JoinHostPort(host, strconv.Itoa(c.ReadWritePort))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.ExternalAddress = host
|
||||||
|
|
||||||
if c.OpenAPIConfig != nil && c.OpenAPIConfig.SecurityDefinitions != nil {
|
if c.OpenAPIConfig != nil && c.OpenAPIConfig.SecurityDefinitions != nil {
|
||||||
// Setup OpenAPI security: all APIs will have the same authentication for now.
|
// Setup OpenAPI security: all APIs will have the same authentication for now.
|
||||||
c.OpenAPIConfig.DefaultSecurity = []map[string][]string{}
|
c.OpenAPIConfig.DefaultSecurity = []map[string][]string{}
|
||||||
|
Loading…
Reference in New Issue
Block a user