1
0
mirror of https://github.com/rancher/rke.git synced 2025-07-14 15:46:03 +00:00

Merge pull request #3136 from kinarashah/fix

[v1.3] changes around hostname-override for aws cloud provider
This commit is contained in:
Kinara Shah 2023-01-12 09:22:27 -08:00 committed by GitHub
commit 0dc41477c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 11 deletions

View File

@ -157,6 +157,7 @@ var (
} }
DefaultClusterProportionalAutoscalerLinearParams = v3.LinearAutoscalerParams{CoresPerReplica: 128, NodesPerReplica: 4, Min: 1, PreventSinglePointFailure: true} DefaultClusterProportionalAutoscalerLinearParams = v3.LinearAutoscalerParams{CoresPerReplica: 128, NodesPerReplica: 4, Min: 1, PreventSinglePointFailure: true}
DefaultMonitoringAddonReplicas = int32(1) DefaultMonitoringAddonReplicas = int32(1)
defaultUseInstanceMetadataHostname = false
) )
type ExternalFlags struct { type ExternalFlags struct {
@ -263,6 +264,10 @@ func (c *Cluster) setClusterDefaults(ctx context.Context, flags ExternalFlags) e
c.ForceDeployCerts = true c.ForceDeployCerts = true
} }
if c.CloudProvider.Name == k8s.AWSCloudProvider && c.CloudProvider.UseInstanceMetadataHostname == nil {
c.CloudProvider.UseInstanceMetadataHostname = &defaultUseInstanceMetadataHostname
}
// enable cri-dockerd for k8s >= 1.24 // enable cri-dockerd for k8s >= 1.24
err = c.setCRIDockerd() err = c.setCRIDockerd()
if err != nil { if err != nil {

View File

@ -458,11 +458,12 @@ func (c *Cluster) BuildKubeletProcess(host *hosts.Host, serviceOptions v3.Kubern
kubelet := &c.Services.Kubelet kubelet := &c.Services.Kubelet
Command := c.getRKEToolsEntryPoint(host.OS(), "kubelet") Command := c.getRKEToolsEntryPoint(host.OS(), "kubelet")
CommandArgs := map[string]string{ CommandArgs := map[string]string{
"client-ca-file": pki.GetCertPath(pki.CACertName), "client-ca-file": pki.GetCertPath(pki.CACertName),
"cloud-provider": c.CloudProvider.Name, "cloud-provider": c.CloudProvider.Name,
"cluster-dns": c.ClusterDNSServer, "cluster-dns": c.ClusterDNSServer,
"cluster-domain": c.ClusterDomain, "cluster-domain": c.ClusterDomain,
"fail-swap-on": strconv.FormatBool(kubelet.FailSwapOn), "fail-swap-on": strconv.FormatBool(kubelet.FailSwapOn),
// overrides kubernetes.io/hostname label on node, rke uses it to find node (services/node_util.go)
"hostname-override": host.HostnameOverride, "hostname-override": host.HostnameOverride,
"kubeconfig": pki.GetConfigPath(pki.KubeNodeCertName), "kubeconfig": pki.GetConfigPath(pki.KubeNodeCertName),
"pod-infra-container-image": kubelet.InfraContainerImage, "pod-infra-container-image": kubelet.InfraContainerImage,
@ -490,9 +491,6 @@ func (c *Cluster) BuildKubeletProcess(host *hosts.Host, serviceOptions v3.Kubern
if host.IsWindows() { // compatible with Windows if host.IsWindows() { // compatible with Windows
CommandArgs["cloud-config"] = path.Join(host.PrefixPath, cloudConfigFileName) CommandArgs["cloud-config"] = path.Join(host.PrefixPath, cloudConfigFileName)
} }
if c.CloudProvider.Name == k8s.AWSCloudProvider {
delete(CommandArgs, "hostname-override")
}
} }
if c.IsKubeletGenerateServingCertificateEnabled() { if c.IsKubeletGenerateServingCertificateEnabled() {
@ -690,7 +688,8 @@ func (c *Cluster) BuildKubeProxyProcess(host *hosts.Host, serviceOptions v3.Kube
} else { } else {
CommandArgs["bind-address"] = host.Address CommandArgs["bind-address"] = host.Address
} }
if c.CloudProvider.Name == k8s.AWSCloudProvider { if c.CloudProvider.Name == k8s.AWSCloudProvider && c.CloudProvider.UseInstanceMetadataHostname != nil && *c.CloudProvider.UseInstanceMetadataHostname {
// rke-tools will inject hostname-override from ec2 instance metadata to match with the spec.nodeName set by cloud provider https://github.com/rancher/rke-tools/blob/3eab4f07aa97a8aeeaaef55b1b7bbc82e2a3374a/entrypoint.sh#L17
delete(CommandArgs, "hostname-override") delete(CommandArgs, "hostname-override")
} }
} }

View File

@ -2,7 +2,7 @@
// +build !ignore_autogenerated // +build !ignore_autogenerated
/* /*
Copyright 2022 Rancher Labs, Inc. Copyright 2023 Rancher Labs, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -554,6 +554,8 @@ type PortCheck struct {
type CloudProvider struct { type CloudProvider struct {
// Name of the Cloud Provider // Name of the Cloud Provider
Name string `yaml:"name" json:"name,omitempty"` Name string `yaml:"name" json:"name,omitempty"`
// Only configured for AWS currently, add for other providers as needed
UseInstanceMetadataHostname *bool ` yaml:"useInstanceMetadataHostname,omitempty" json:"useInstanceMetadataHostname,omitempty"`
// AWSCloudProvider // AWSCloudProvider
AWSCloudProvider *AWSCloudProvider `yaml:"awsCloudProvider,omitempty" json:"awsCloudProvider,omitempty"` AWSCloudProvider *AWSCloudProvider `yaml:"awsCloudProvider,omitempty" json:"awsCloudProvider,omitempty"`
// AzureCloudProvider // AzureCloudProvider

View File

@ -2,7 +2,7 @@
// +build !ignore_autogenerated // +build !ignore_autogenerated
/* /*
Copyright 2022 Rancher Labs, Inc. Copyright 2023 Rancher Labs, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -400,6 +400,11 @@ func (in *CanalNetworkProvider) DeepCopy() *CanalNetworkProvider {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CloudProvider) DeepCopyInto(out *CloudProvider) { func (in *CloudProvider) DeepCopyInto(out *CloudProvider) {
*out = *in *out = *in
if in.UseInstanceMetadataHostname != nil {
in, out := &in.UseInstanceMetadataHostname, &out.UseInstanceMetadataHostname
*out = new(bool)
**out = **in
}
if in.AWSCloudProvider != nil { if in.AWSCloudProvider != nil {
in, out := &in.AWSCloudProvider, &out.AWSCloudProvider in, out := &in.AWSCloudProvider, &out.AWSCloudProvider
*out = new(AWSCloudProvider) *out = new(AWSCloudProvider)