Skip to content

Commit 4f8d041

Browse files
committed
cloud init isn't widely available on other GCE OS, default to using startup-script unless its an Ubuntu/COS OS
1 parent 3440db0 commit 4f8d041

File tree

8 files changed

+68
-65
lines changed

8 files changed

+68
-65
lines changed

cmd/kops/integration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ func TestManyAddonsCCMIRSA(t *testing.T) {
855855

856856
func TestManyAddonsGCE(t *testing.T) {
857857
newIntegrationTest("minimal.example.com", "many-addons-gce").
858+
withStartupScript().
858859
withAddons(
859860
certManagerAddon,
860861
clusterAutoscalerAddon,

pkg/model/gcemodel/autoscalinggroup.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,16 @@ func (b *AutoscalingGroupModelBuilder) buildInstanceTemplate(c *fi.CloudupModelB
132132
}
133133

134134
if startupScript != nil {
135-
if !fi.ValueOf(b.Cluster.Spec.CloudProvider.GCE.UseStartupScript) {
136-
// Use "user-data" instead of "startup-script", for compatibility with cloud-init
135+
// GCE doesn't bundle cloud-init on every OS unless cloud-init is present in the upstream distribution
136+
// So far, thats only true for COS and Ubuntu
137+
switch {
138+
case fi.ValueOf(b.Cluster.Spec.CloudProvider.GCE.UseStartupScript):
139+
t.Metadata["startup-script"] = startupScript
140+
case strings.HasPrefix(ig.Spec.Image, "cos-cloud/"):
141+
t.Metadata["user-data"] = startupScript
142+
case strings.HasPrefix(ig.Spec.Image, "ubuntu-os-cloud/"):
137143
t.Metadata["user-data"] = startupScript
138-
} else {
144+
default:
139145
t.Metadata["startup-script"] = startupScript
140146
}
141147
}

tests/integration/update_cluster/many-addons-gce/in-v1alpha2.yaml

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,45 @@ spec:
1818
cloudProvider: gce
1919
configBase: memfs://tests/minimal.example.com
2020
etcdClusters:
21-
- cpuRequest: 200m
22-
etcdMembers:
23-
- instanceGroup: master-us-test1-a
24-
name: a
25-
memoryRequest: 100Mi
26-
name: main
27-
- cpuRequest: 100m
28-
etcdMembers:
29-
- instanceGroup: master-us-test1-a
30-
name: a
31-
memoryRequest: 100Mi
32-
name: events
21+
- cpuRequest: 200m
22+
etcdMembers:
23+
- instanceGroup: master-us-test1-a
24+
name: a
25+
memoryRequest: 100Mi
26+
name: main
27+
- cpuRequest: 100m
28+
etcdMembers:
29+
- instanceGroup: master-us-test1-a
30+
name: a
31+
memoryRequest: 100Mi
32+
name: events
3333
iam:
3434
allowContainerRegistry: true
3535
legacy: false
3636
kubelet:
3737
anonymousAuth: false
3838
kubernetesApiAccess:
39-
- 0.0.0.0/0
40-
- ::/0
39+
- 0.0.0.0/0
40+
- ::/0
4141
kubernetesVersion: v1.32.0
4242
masterPublicName: api.minimal.example.com
4343
networking:
4444
cni: {}
4545
nonMasqueradeCIDR: 100.64.0.0/10
4646
project: testproject
4747
sshAccess:
48-
- 0.0.0.0/0
49-
- ::/0
48+
- 0.0.0.0/0
49+
- ::/0
5050
subnets:
51-
- cidr: 10.0.16.0/20
52-
name: us-test1
53-
region: us-test1
54-
type: Public
51+
- cidr: 10.0.16.0/20
52+
name: us-test1
53+
region: us-test1
54+
type: Public
5555
topology:
5656
dns:
5757
type: Public
5858

5959
---
60-
6160
apiVersion: kops.k8s.io/v1alpha2
6261
kind: InstanceGroup
6362
metadata:
@@ -66,18 +65,17 @@ metadata:
6665
kops.k8s.io/cluster: minimal.example.com
6766
name: master-us-test1-a
6867
spec:
69-
image: ubuntu-os-cloud/ubuntu-2004-focal-v20221018
68+
image: debian-cloud/debian-12-bookworm-v20251014
7069
machineType: e2-medium
7170
maxSize: 1
7271
minSize: 1
7372
role: Master
7473
subnets:
75-
- us-test1
74+
- us-test1
7675
zones:
77-
- us-test1-a
76+
- us-test1-a
7877

7978
---
80-
8179
apiVersion: kops.k8s.io/v1alpha2
8280
kind: InstanceGroup
8381
metadata:
@@ -86,12 +84,12 @@ metadata:
8684
kops.k8s.io/cluster: minimal.example.com
8785
name: nodes
8886
spec:
89-
image: ubuntu-os-cloud/ubuntu-2004-focal-v20221018
87+
image: debian-cloud/debian-12-bookworm-v20251014
9088
machineType: e2-medium
9189
maxSize: 1
9290
minSize: 1
9391
role: Node
9492
subnets:
95-
- us-test1
93+
- us-test1
9694
zones:
97-
- us-test1-a
95+
- us-test1-a

tests/integration/update_cluster/many-addons-gce/kubernetes.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ resource "google_compute_instance_template" "master-us-test1-a-minimal-example-c
470470
provisioned_iops = 0
471471
provisioned_throughput = 0
472472
source = ""
473-
source_image = "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221018"
473+
source_image = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-12-bookworm-v20251014"
474474
type = "PERSISTENT"
475475
}
476476
labels = {
@@ -487,7 +487,7 @@ resource "google_compute_instance_template" "master-us-test1-a-minimal-example-c
487487
"cluster-name" = "minimal.example.com"
488488
"kops-k8s-io-instance-group-name" = "master-us-test1-a"
489489
"ssh-keys" = "admin: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCtWu40XQo8dczLsCq0OWV+hxm9uV3WxeH9Kgh4sMzQxNtoU1pvW0XdjpkBesRKGoolfWeCLXWxpyQb1IaiMkKoz7MdhQ/6UKjMjP66aFWWp3pwD0uj0HuJ7tq4gKHKRYGTaZIRWpzUiANBrjugVgA+Sd7E/mYwc/DMXkIyRZbvhQ=="
490-
"user-data" = file("${path.module}/data/google_compute_instance_template_master-us-test1-a-minimal-example-com_metadata_user-data")
490+
"startup-script" = file("${path.module}/data/google_compute_instance_template_master-us-test1-a-minimal-example-com_metadata_startup-script")
491491
}
492492
name_prefix = "master-us-test1-a-minimal-e8ua4m-"
493493
network_interface {
@@ -524,7 +524,7 @@ resource "google_compute_instance_template" "nodes-minimal-example-com" {
524524
provisioned_iops = 0
525525
provisioned_throughput = 0
526526
source = ""
527-
source_image = "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221018"
527+
source_image = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-12-bookworm-v20251014"
528528
type = "PERSISTENT"
529529
}
530530
labels = {
@@ -541,7 +541,7 @@ resource "google_compute_instance_template" "nodes-minimal-example-com" {
541541
"kops-k8s-io-instance-group-name" = "nodes"
542542
"kube-env" = "AUTOSCALER_ENV_VARS: os_distribution=ubuntu;arch=amd64;os=linux"
543543
"ssh-keys" = "admin: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCtWu40XQo8dczLsCq0OWV+hxm9uV3WxeH9Kgh4sMzQxNtoU1pvW0XdjpkBesRKGoolfWeCLXWxpyQb1IaiMkKoz7MdhQ/6UKjMjP66aFWWp3pwD0uj0HuJ7tq4gKHKRYGTaZIRWpzUiANBrjugVgA+Sd7E/mYwc/DMXkIyRZbvhQ=="
544-
"user-data" = file("${path.module}/data/google_compute_instance_template_nodes-minimal-example-com_metadata_user-data")
544+
"startup-script" = file("${path.module}/data/google_compute_instance_template_nodes-minimal-example-com_metadata_startup-script")
545545
}
546546
name_prefix = "nodes-minimal-example-com-"
547547
network_interface {

tests/integration/update_cluster/minimal_gce_dns-none/in-v1alpha2.yaml

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,43 @@ spec:
1616
cloudProvider: gce
1717
configBase: memfs://tests/minimal-gce.example.com
1818
etcdClusters:
19-
- cpuRequest: 200m
20-
etcdMembers:
21-
- instanceGroup: master-us-test1-a
22-
name: a
23-
memoryRequest: 100Mi
24-
name: main
25-
- cpuRequest: 100m
26-
etcdMembers:
27-
- instanceGroup: master-us-test1-a
28-
name: a
29-
memoryRequest: 100Mi
30-
name: events
19+
- cpuRequest: 200m
20+
etcdMembers:
21+
- instanceGroup: master-us-test1-a
22+
name: a
23+
memoryRequest: 100Mi
24+
name: main
25+
- cpuRequest: 100m
26+
etcdMembers:
27+
- instanceGroup: master-us-test1-a
28+
name: a
29+
memoryRequest: 100Mi
30+
name: events
3131
iam:
3232
legacy: false
3333
kubelet:
3434
anonymousAuth: false
3535
kubernetesApiAccess:
36-
- 0.0.0.0/0
37-
- ::/0
36+
- 0.0.0.0/0
37+
- ::/0
3838
kubernetesVersion: v1.32.0
3939
masterPublicName: api.minimal-gce.example.com
4040
networking:
4141
cni: {}
4242
nonMasqueradeCIDR: 100.64.0.0/10
4343
project: testproject
4444
sshAccess:
45-
- 0.0.0.0/0
46-
- ::/0
45+
- 0.0.0.0/0
46+
- ::/0
4747
subnets:
48-
- name: us-test1
49-
region: us-test1
50-
type: Private
48+
- name: us-test1
49+
region: us-test1
50+
type: Private
5151
topology:
5252
dns:
5353
type: None
5454

5555
---
56-
5756
apiVersion: kops.k8s.io/v1alpha2
5857
kind: InstanceGroup
5958
metadata:
@@ -62,18 +61,17 @@ metadata:
6261
kops.k8s.io/cluster: minimal-gce.example.com
6362
name: master-us-test1-a
6463
spec:
65-
image: ubuntu-os-cloud/ubuntu-2004-focal-v20221018
64+
image: cos-cloud/cos-121-18867-294-2
6665
machineType: e2-medium
6766
maxSize: 1
6867
minSize: 1
6968
role: Master
7069
subnets:
71-
- us-test1
70+
- us-test1
7271
zones:
73-
- us-test1-a
72+
- us-test1-a
7473

7574
---
76-
7775
apiVersion: kops.k8s.io/v1alpha2
7876
kind: InstanceGroup
7977
metadata:
@@ -82,12 +80,12 @@ metadata:
8280
kops.k8s.io/cluster: minimal-gce.example.com
8381
name: nodes
8482
spec:
85-
image: ubuntu-os-cloud/ubuntu-2004-focal-v20221018
83+
image: cos-cloud/cos-121-18867-294-2
8684
machineType: e2-medium
8785
maxSize: 2
8886
minSize: 2
8987
role: Node
9088
subnets:
91-
- us-test1
89+
- us-test1
9290
zones:
93-
- us-test1-a
91+
- us-test1-a

tests/integration/update_cluster/minimal_gce_dns-none/kubernetes.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ resource "google_compute_instance_template" "master-us-test1-a-minimal-gce-examp
510510
provisioned_iops = 0
511511
provisioned_throughput = 0
512512
source = ""
513-
source_image = "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221018"
513+
source_image = "https://www.googleapis.com/compute/v1/projects/cos-cloud/global/images/cos-121-18867-294-2"
514514
type = "PERSISTENT"
515515
}
516516
labels = {
@@ -562,7 +562,7 @@ resource "google_compute_instance_template" "nodes-minimal-gce-example-com" {
562562
provisioned_iops = 0
563563
provisioned_throughput = 0
564564
source = ""
565-
source_image = "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221018"
565+
source_image = "https://www.googleapis.com/compute/v1/projects/cos-cloud/global/images/cos-121-18867-294-2"
566566
type = "PERSISTENT"
567567
}
568568
labels = {
@@ -577,7 +577,7 @@ resource "google_compute_instance_template" "nodes-minimal-gce-example-com" {
577577
metadata = {
578578
"cluster-name" = "minimal-gce.example.com"
579579
"kops-k8s-io-instance-group-name" = "nodes"
580-
"kube-env" = "AUTOSCALER_ENV_VARS: os_distribution=ubuntu;arch=amd64;os=linux"
580+
"kube-env" = "AUTOSCALER_ENV_VARS: os_distribution=cos;arch=amd64;os=linux"
581581
"ssh-keys" = "admin: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCtWu40XQo8dczLsCq0OWV+hxm9uV3WxeH9Kgh4sMzQxNtoU1pvW0XdjpkBesRKGoolfWeCLXWxpyQb1IaiMkKoz7MdhQ/6UKjMjP66aFWWp3pwD0uj0HuJ7tq4gKHKRYGTaZIRWpzUiANBrjugVgA+Sd7E/mYwc/DMXkIyRZbvhQ=="
582582
"user-data" = file("${path.module}/data/google_compute_instance_template_nodes-minimal-gce-example-com_metadata_user-data")
583583
}

0 commit comments

Comments
 (0)