diff --git a/pkg/model/context.go b/pkg/model/context.go index 90990d183a98f..aade9c9e055eb 100644 --- a/pkg/model/context.go +++ b/pkg/model/context.go @@ -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" @@ -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) @@ -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 default: labels[nodeidentityaws.ClusterAutoscalerNodeTemplateLabel+k] = v } @@ -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... diff --git a/pkg/model/gcemodel/autoscalinggroup.go b/pkg/model/gcemodel/autoscalinggroup.go index f36eb49d98954..788e974404860 100644 --- a/pkg/model/gcemodel/autoscalinggroup.go +++ b/pkg/model/gcemodel/autoscalinggroup.go @@ -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) @@ -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 { diff --git a/tests/integration/update_cluster/ha_gce/kubernetes.tf b/tests/integration/update_cluster/ha_gce/kubernetes.tf index 790f077a6bd2b..3703551febde9 100644 --- a/tests/integration/update_cluster/ha_gce/kubernetes.tf +++ b/tests/integration/update_cluster/ha_gce/kubernetes.tf @@ -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 diff --git a/tests/integration/update_cluster/minimal_gce/in-v1alpha2.yaml b/tests/integration/update_cluster/minimal_gce/in-v1alpha2.yaml index cdd1b578726e0..cb0341b8b8b42 100644 --- a/tests/integration/update_cluster/minimal_gce/in-v1alpha2.yaml +++ b/tests/integration/update_cluster/minimal_gce/in-v1alpha2.yaml @@ -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 diff --git a/tests/integration/update_cluster/minimal_gce/kubernetes.tf b/tests/integration/update_cluster/minimal_gce/kubernetes.tf index 3cc206ee153eb..7112abd9be46d 100644 --- a/tests/integration/update_cluster/minimal_gce/kubernetes.tf +++ b/tests/integration/update_cluster/minimal_gce/kubernetes.tf @@ -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