Skip to content

Commit

Permalink
Conditionally use RBN or ip names in kops-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Markus With committed Nov 30, 2021
1 parent 40e44c5 commit 1545aaf
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 46 deletions.
1 change: 0 additions & 1 deletion nodeup/pkg/model/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 8 additions & 23 deletions nodeup/pkg/model/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (

"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"

v1 "k8s.io/api/core/v1"
"k8s.io/klog/v2"

"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/flagbuilder"
"k8s.io/kops/pkg/nodelabels"
Expand Down Expand Up @@ -59,7 +59,6 @@ var _ fi.ModelBuilder = &KubeletBuilder{}

// Build is responsible for building the kubelet configuration
func (b *KubeletBuilder) Build(c *fi.ModelBuilderContext) error {

err := b.buildKubeletServingCertificate(c)
if err != nil {
return fmt.Errorf("error building kubelet server cert: %v", err)
Expand Down Expand Up @@ -191,6 +190,8 @@ func (b *KubeletBuilder) buildSystemdEnvironmentFile(kubeletConfig *kops.Kubelet
kubeletConfig.BootstrapKubeconfig = ""
}

kubeletConfig.HostnameOverride = ""

// TODO: Dump the separate file for flags - just complexity!
flags, err := flagbuilder.BuildFlags(kubeletConfig)
if err != nil {
Expand Down Expand Up @@ -304,7 +305,6 @@ func (b *KubeletBuilder) buildSystemdService() *nodetasks.Service {
service.InitDefaults()

if b.ConfigurationMode == "Warming" {

service.Running = fi.Bool(false)
}

Expand Down Expand Up @@ -551,7 +551,6 @@ func (b *KubeletBuilder) buildMasterKubeletKubeconfig(c *fi.ModelBuilderContext)
}

func (b *KubeletBuilder) buildKubeletServingCertificate(c *fi.ModelBuilderContext) error {

if b.UseKopsControllerForNodeBootstrap() {
name := "kubelet-server"
dir := b.PathSrvKubernetes()
Expand Down Expand Up @@ -599,29 +598,15 @@ func (b *KubeletBuilder) buildKubeletServingCertificate(c *fi.ModelBuilderContex
}
}
return nil

}

func (b *KubeletBuilder) kubeletNames() ([]string, error) {
if kops.CloudProviderID(b.Cluster.Spec.CloudProvider) != kops.CloudProviderAWS {
name, err := os.Hostname()
if err != nil {
return nil, err
}

addrs, _ := net.LookupHost(name)

return append(addrs, name), nil
}

cloud := b.Cloud.(awsup.AWSCloud)

result, err := cloud.EC2().DescribeInstances(&ec2.DescribeInstancesInput{
InstanceIds: []*string{&b.InstanceID},
})
name, err := os.Hostname()
if err != nil {
return nil, fmt.Errorf("error describing instances: %v", err)
return nil, err
}

return awsup.GetInstanceCertificateNames(result)
addrs, _ := net.LookupHost(name)

return append(addrs, name), nil
}
54 changes: 33 additions & 21 deletions upup/pkg/fi/cloudup/awsup/aws_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import (

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
k8s_aws "k8s.io/legacy-cloud-providers/aws"

"k8s.io/kops/dnsprovider/pkg/dnsprovider"
dnsproviderroute53 "k8s.io/kops/dnsprovider/pkg/dnsprovider/providers/aws/route53"
"k8s.io/kops/pkg/apis/kops"
Expand All @@ -60,7 +62,6 @@ import (
identity_aws "k8s.io/kops/pkg/nodeidentity/aws"
"k8s.io/kops/pkg/resources/spotinst"
"k8s.io/kops/upup/pkg/fi"
k8s_aws "k8s.io/legacy-cloud-providers/aws"
)

// By default, aws-sdk-go only retries 3 times, which doesn't give
Expand All @@ -69,21 +70,29 @@ import (
// backoff along the way.
const ClientMaxRetries = 13

const DescribeTagsMaxAttempts = 120
const DescribeTagsRetryInterval = 2 * time.Second
const DescribeTagsLogInterval = 10 // this is in "retry intervals"
const (
DescribeTagsMaxAttempts = 120
DescribeTagsRetryInterval = 2 * time.Second
DescribeTagsLogInterval = 10 // this is in "retry intervals"
)

const CreateTagsMaxAttempts = 120
const CreateTagsRetryInterval = 2 * time.Second
const CreateTagsLogInterval = 10 // this is in "retry intervals"
const (
CreateTagsMaxAttempts = 120
CreateTagsRetryInterval = 2 * time.Second
CreateTagsLogInterval = 10 // this is in "retry intervals"
)

const DeleteTagsMaxAttempts = 120
const DeleteTagsRetryInterval = 2 * time.Second
const DeleteTagsLogInterval = 10 // this is in "retry intervals"
const (
DeleteTagsMaxAttempts = 120
DeleteTagsRetryInterval = 2 * time.Second
DeleteTagsLogInterval = 10 // this is in "retry intervals"
)

const TagClusterName = "KubernetesCluster"
const TagNameRolePrefix = "k8s.io/role/"
const TagNameEtcdClusterPrefix = "k8s.io/etcd/"
const (
TagClusterName = "KubernetesCluster"
TagNameRolePrefix = "k8s.io/role/"
TagNameEtcdClusterPrefix = "k8s.io/etcd/"
)

const TagRoleMaster = "master"

Expand Down Expand Up @@ -382,7 +391,6 @@ func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
}

func (c *awsCloudImplementation) addHandlers(regionName string, h *request.Handlers) {

delayer := c.getCrossRequestRetryDelay(regionName)
if delayer != nil {
h.Sign.PushFrontNamed(request.NamedHandler{
Expand Down Expand Up @@ -650,7 +658,6 @@ func getCloudGroups(c AWSCloud, cluster *kops.Cluster, instancegroups []*kops.In
}

return groups, nil

}

// FindAutoscalingGroups finds autoscaling groups matching the specified tags
Expand Down Expand Up @@ -715,7 +722,6 @@ func FindAutoscalingGroups(c AWSCloud, tags map[string]string) ([]*autoscaling.G
return nil, fmt.Errorf("error listing autoscaling groups: %v", err)
}
}

}

return asgs, nil
Expand Down Expand Up @@ -771,7 +777,7 @@ func findAutoscalingGroupLaunchConfiguration(c AWSCloud, g *autoscaling.Group) (
}

version := aws.StringValue(launchTemplate.Version)
//Correctly Handle Default and Latest Versions
// Correctly Handle Default and Latest Versions
klog.V(4).Infof("Launch Template Version Specified By ASG: %v", version)
if version == "" || version == "$Default" || version == "$Latest" {
input := &ec2.DescribeLaunchTemplatesInput{
Expand Down Expand Up @@ -949,7 +955,6 @@ func findInstances(c AWSCloud, ig *kops.InstanceGroup) (map[string]*ec2.Instance
}
}
return instances, nil

}

func findDetachedInstances(c AWSCloud, g *autoscaling.Group) ([]*string, error) {
Expand Down Expand Up @@ -1316,6 +1321,7 @@ func removeELBTags(c AWSCloud, loadBalancerName string, tags map[string]string)

return nil
}

func (c *awsCloudImplementation) RemoveELBV2Tags(ResourceArn string, tags map[string]string) error {
return removeELBV2Tags(c, ResourceArn, tags)
}
Expand Down Expand Up @@ -2082,10 +2088,16 @@ func GetInstanceCertificateNames(instances *ec2.DescribeInstancesOutput) (addrs
}

instance := instances.Reservations[0].Instances[0]
{
if *instance.PrivateDnsNameOptions.HostnameType == ec2.HostnameTypeResourceName {
name := *instance.InstanceId
addrs = append(addrs, name)
} else {
name := *instance.PrivateDnsName
addrs = append(addrs, name)

name := *instance.PrivateDnsName

addrs = append(addrs, name)
}
}

// We only use data for the first interface, and only the first IP
for _, iface := range instance.NetworkInterfaces {
Expand Down
1 change: 1 addition & 0 deletions upup/pkg/fi/cloudup/awsup/aws_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/sts"

"k8s.io/kops/pkg/bootstrap"
nodeidentityaws "k8s.io/kops/pkg/nodeidentity/aws"
)
Expand Down
6 changes: 5 additions & 1 deletion upup/pkg/fi/nodeup/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,11 @@ func evaluateHostnameOverride(cloudProvider api.CloudProviderID) (string, error)
if err != nil {
return "", fmt.Errorf("error reading local-hostname from AWS metadata: %v", err)
}
return string(hostnameBytes), nil
hostname := string(hostnameBytes)
if strings.HasPrefix(hostname, "i-") {
return "", nil
}
return hostname, nil
case api.CloudProviderGCE:
// This lets us tolerate broken hostnames (i.e. systemd)
b, err := vfs.Context.ReadFile("metadata://gce/instance/hostname")
Expand Down

0 comments on commit 1545aaf

Please sign in to comment.