Skip to content

Commit 05dba13

Browse files
authored
Merge pull request #17821 from rramkumar1/master
gce: Support cloudLabels for InstanceGroup
2 parents 584d67e + cfafeee commit 05dba13

File tree

5 files changed

+26
-18
lines changed

5 files changed

+26
-18
lines changed

pkg/model/context.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"k8s.io/kops/upup/pkg/fi"
3434
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks"
3535
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
36+
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
3637
"k8s.io/kops/upup/pkg/fi/cloudup/hetzner"
3738
"k8s.io/kops/upup/pkg/fi/cloudup/scaleway"
3839

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

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

@@ -178,6 +181,8 @@ func (b *KopsModelContext) CloudTagsForInstanceGroup(ig *kops.InstanceGroup) (ma
178181
switch b.Cluster.GetCloudProvider() {
179182
case kops.CloudProviderHetzner:
180183
labels[hetzner.TagKubernetesNodeLabelPrefix+k] = v
184+
case kops.CloudProviderGCE:
185+
// TODO: Do nothing for now while we figure out how to address GCE label length limit of 63
181186
default:
182187
labels[nodeidentityaws.ClusterAutoscalerNodeTemplateLabel+k] = v
183188
}
@@ -196,6 +201,15 @@ func (b *KopsModelContext) CloudTagsForInstanceGroup(ig *kops.InstanceGroup) (ma
196201
labels[hetzner.TagKubernetesInstanceRole] = string(ig.Spec.Role)
197202
labels[hetzner.TagKubernetesClusterName] = b.ClusterName()
198203
labels[hetzner.TagKubernetesInstanceGroup] = ig.Name
204+
case kops.CloudProviderGCE:
205+
clusterLabel := gce.LabelForCluster(b.ClusterName())
206+
roleLabel := gce.GceLabelNameRolePrefix + ig.Spec.Role.ToLowerString()
207+
labels[clusterLabel.Key] = clusterLabel.Value
208+
labels[roleLabel] = ig.Spec.Role.ToLowerString()
209+
labels[gce.GceLabelNameInstanceGroup] = ig.ObjectMeta.Name
210+
if ig.Spec.Role == kops.InstanceGroupRoleControlPlane {
211+
labels[gce.GceLabelNameRolePrefix+"master"] = "master"
212+
}
199213
default:
200214
// The system tags take priority because the cluster likely breaks without them...
201215

pkg/model/gcemodel/autoscalinggroup.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,6 @@ func (b *AutoscalingGroupModelBuilder) buildInstanceTemplate(c *fi.CloudupModelB
220220
case kops.InstanceGroupRoleBastion:
221221
t.Tags = append(t.Tags, b.GCETagForRole(kops.InstanceGroupRoleBastion))
222222
}
223-
clusterLabel := gce.LabelForCluster(b.ClusterName())
224-
roleLabel := gce.GceLabelNameRolePrefix + ig.Spec.Role.ToLowerString()
225-
t.Labels = map[string]string{
226-
clusterLabel.Key: clusterLabel.Value,
227-
roleLabel: ig.Spec.Role.ToLowerString(),
228-
gce.GceLabelNameInstanceGroup: ig.ObjectMeta.Name,
229-
}
230-
if ig.Spec.Role == kops.InstanceGroupRoleControlPlane {
231-
t.Labels[gce.GceLabelNameRolePrefix+"master"] = "master"
232-
}
233223

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

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

251-
// labels, err := b.CloudTagsForInstanceGroup(ig)
252-
// if err != nil {
253-
// return fmt.Errorf("error building cloud tags: %v", err)
254-
// }
255-
// t.Labels = labels
241+
labels, err := b.CloudTagsForInstanceGroup(ig)
242+
if err != nil {
243+
return nil, fmt.Errorf("error building cloud tags: %v", err)
244+
}
245+
t.Labels = labels
256246

257247
t.GuestAccelerators = []gcetasks.AcceleratorConfig{}
258248
for _, accelerator := range ig.Spec.GuestAccelerators {

tests/integration/update_cluster/ha_gce/kubernetes.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,10 @@ resource "google_compute_instance_template" "nodes-ha-gce-example-com" {
780780
type = "PERSISTENT"
781781
}
782782
labels = {
783-
"k8s-io-cluster-name" = "ha-gce-example-com"
784-
"k8s-io-instance-group" = "nodes"
785-
"k8s-io-role-node" = "node"
783+
"k8s-io-cluster-name" = "ha-gce-example-com"
784+
"k8s-io-instance-group" = "nodes"
785+
"k8s-io-role-node" = "node"
786+
"k8s.io/cluster-autoscaler/node-template/taint/a" = "b:c"
786787
}
787788
lifecycle {
788789
create_before_destroy = true

tests/integration/update_cluster/minimal_gce/in-v1alpha2.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ metadata:
6262
name: master-us-test1-a
6363
spec:
6464
image: ubuntu-os-cloud/ubuntu-2004-focal-v20221018
65+
cloudLabels:
66+
testCloudLabel: foobar
6567
machineType: e2-medium
6668
maxSize: 1
6769
minSize: 1

tests/integration/update_cluster/minimal_gce/kubernetes.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ resource "google_compute_instance_template" "master-us-test1-a-minimal-gce-examp
446446
"k8s-io-instance-group" = "master-us-test1-a"
447447
"k8s-io-role-control-plane" = "control-plane"
448448
"k8s-io-role-master" = "master"
449+
"testCloudLabel" = "foobar"
449450
}
450451
lifecycle {
451452
create_before_destroy = true

0 commit comments

Comments
 (0)