Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/model/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks"
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
"k8s.io/kops/upup/pkg/fi/cloudup/hetzner"
"k8s.io/kops/upup/pkg/fi/cloudup/scaleway"

Expand Down Expand Up @@ -145,6 +146,8 @@ func (b *KopsModelContext) NodeInstanceGroups() []*kops.InstanceGroup {
}

// CloudTagsForInstanceGroup computes the tags to apply to instances in the specified InstanceGroup
//
// TODO: The cloud provider specific logic should be moved to relevant model packages.
func (b *KopsModelContext) CloudTagsForInstanceGroup(ig *kops.InstanceGroup) (map[string]string, error) {
labels := b.CloudTags(b.AutoscalingGroupName(ig), false)

Expand Down Expand Up @@ -178,6 +181,8 @@ func (b *KopsModelContext) CloudTagsForInstanceGroup(ig *kops.InstanceGroup) (ma
switch b.Cluster.GetCloudProvider() {
case kops.CloudProviderHetzner:
labels[hetzner.TagKubernetesNodeLabelPrefix+k] = v
case kops.CloudProviderGCE:
// TODO: Do nothing for now while we figure out how to address GCE label length limit of 63
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the label is too long for GCE, and the cluster-autoscaler doesn't look at this label anyway on GCE?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I was not aware that the labels might be a no-op on GCE. Does that need to be looked into more or are you sure on that fact? If so, I can just change the comment.

default:
labels[nodeidentityaws.ClusterAutoscalerNodeTemplateLabel+k] = v
}
Expand All @@ -196,6 +201,15 @@ func (b *KopsModelContext) CloudTagsForInstanceGroup(ig *kops.InstanceGroup) (ma
labels[hetzner.TagKubernetesInstanceRole] = string(ig.Spec.Role)
labels[hetzner.TagKubernetesClusterName] = b.ClusterName()
labels[hetzner.TagKubernetesInstanceGroup] = ig.Name
case kops.CloudProviderGCE:
clusterLabel := gce.LabelForCluster(b.ClusterName())
roleLabel := gce.GceLabelNameRolePrefix + ig.Spec.Role.ToLowerString()
labels[clusterLabel.Key] = clusterLabel.Value
labels[roleLabel] = ig.Spec.Role.ToLowerString()
labels[gce.GceLabelNameInstanceGroup] = ig.ObjectMeta.Name
if ig.Spec.Role == kops.InstanceGroupRoleControlPlane {
labels[gce.GceLabelNameRolePrefix+"master"] = "master"
}
default:
// The system tags take priority because the cluster likely breaks without them...

Expand Down
20 changes: 5 additions & 15 deletions pkg/model/gcemodel/autoscalinggroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,6 @@ func (b *AutoscalingGroupModelBuilder) buildInstanceTemplate(c *fi.CloudupModelB
case kops.InstanceGroupRoleBastion:
t.Tags = append(t.Tags, b.GCETagForRole(kops.InstanceGroupRoleBastion))
}
clusterLabel := gce.LabelForCluster(b.ClusterName())
roleLabel := gce.GceLabelNameRolePrefix + ig.Spec.Role.ToLowerString()
t.Labels = map[string]string{
clusterLabel.Key: clusterLabel.Value,
roleLabel: ig.Spec.Role.ToLowerString(),
gce.GceLabelNameInstanceGroup: ig.ObjectMeta.Name,
}
if ig.Spec.Role == kops.InstanceGroupRoleControlPlane {
t.Labels[gce.GceLabelNameRolePrefix+"master"] = "master"
}

if gce.UsesIPAliases(b.Cluster) {
t.CanIPForward = fi.PtrTo(false)
Expand All @@ -248,11 +238,11 @@ func (b *AutoscalingGroupModelBuilder) buildInstanceTemplate(c *fi.CloudupModelB

t.ServiceAccounts = append(t.ServiceAccounts, b.LinkToServiceAccount(ig))

// labels, err := b.CloudTagsForInstanceGroup(ig)
// if err != nil {
// return fmt.Errorf("error building cloud tags: %v", err)
// }
// t.Labels = labels
labels, err := b.CloudTagsForInstanceGroup(ig)
if err != nil {
return nil, fmt.Errorf("error building cloud tags: %v", err)
}
t.Labels = labels

t.GuestAccelerators = []gcetasks.AcceleratorConfig{}
for _, accelerator := range ig.Spec.GuestAccelerators {
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/update_cluster/ha_gce/kubernetes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,10 @@ resource "google_compute_instance_template" "nodes-ha-gce-example-com" {
type = "PERSISTENT"
}
labels = {
"k8s-io-cluster-name" = "ha-gce-example-com"
"k8s-io-instance-group" = "nodes"
"k8s-io-role-node" = "node"
"k8s-io-cluster-name" = "ha-gce-example-com"
"k8s-io-instance-group" = "nodes"
"k8s-io-role-node" = "node"
"k8s.io/cluster-autoscaler/node-template/taint/a" = "b:c"
}
lifecycle {
create_before_destroy = true
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/update_cluster/minimal_gce/in-v1alpha2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ metadata:
name: master-us-test1-a
spec:
image: ubuntu-os-cloud/ubuntu-2004-focal-v20221018
cloudLabels:
testCloudLabel: foobar
machineType: e2-medium
maxSize: 1
minSize: 1
Expand Down
1 change: 1 addition & 0 deletions tests/integration/update_cluster/minimal_gce/kubernetes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ resource "google_compute_instance_template" "master-us-test1-a-minimal-gce-examp
"k8s-io-instance-group" = "master-us-test1-a"
"k8s-io-role-control-plane" = "control-plane"
"k8s-io-role-master" = "master"
"testCloudLabel" = "foobar"
}
lifecycle {
create_before_destroy = true
Expand Down
Loading