Skip to content

Commit 001154a

Browse files
committed
Add --control-plane-volume-type flag to kops create cluster
1 parent 6889d48 commit 001154a

File tree

5 files changed

+131
-0
lines changed

5 files changed

+131
-0
lines changed

cmd/kops/create_cluster.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type CreateClusterOptions struct {
6868

6969
ControlPlaneVolumeSize int32
7070
NodeVolumeSize int32
71+
ControlPlaneVolumeType string
7172
ContainerRuntime string
7273
OutDir string
7374
DisableSubnetTags bool
@@ -301,6 +302,9 @@ func NewCmdCreateCluster(f *util.Factory, out io.Writer) *cobra.Command {
301302
cmd.Flags().Int32Var(&options.ControlPlaneVolumeSize, "control-plane-volume-size", options.ControlPlaneVolumeSize, "Instance volume size (in GB) for control-plane nodes")
302303
cmd.Flags().Int32Var(&options.NodeVolumeSize, "node-volume-size", options.NodeVolumeSize, "Instance volume size (in GB) for worker nodes")
303304

305+
cmd.Flags().StringVar(&options.ControlPlaneVolumeType, "control-plane-volume-type", options.ControlPlaneVolumeType, "Instance volume type for control-plane nodes")
306+
cmd.RegisterFlagCompletionFunc("control-plane-volume-type", completeStorageType)
307+
304308
cmd.Flags().StringVar(&options.NetworkID, "vpc", options.NetworkID, "Shared Network or VPC to use")
305309
cmd.Flags().MarkDeprecated("vpc", "use --network-id instead")
306310
cmd.RegisterFlagCompletionFunc("vpc", completeNetworkID)
@@ -616,6 +620,15 @@ func RunCreateCluster(ctx context.Context, f *util.Factory, out io.Writer, c *Cr
616620
}
617621
}
618622

623+
if c.ControlPlaneVolumeType != "" {
624+
for _, group := range controlPlanes {
625+
if group.Spec.RootVolume == nil {
626+
group.Spec.RootVolume = &api.InstanceRootVolumeSpec{}
627+
}
628+
group.Spec.RootVolume.Type = fi.PtrTo(c.ControlPlaneVolumeType)
629+
}
630+
}
631+
619632
if c.NodeVolumeSize != 0 {
620633
for _, group := range nodes {
621634
if group.Spec.RootVolume == nil {

cmd/kops/create_cluster_integration_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ func TestCreateClusterCilium(t *testing.T) {
8181
runCreateClusterIntegrationTest(t, "../../tests/integration/create_cluster/cilium-eni", "v1alpha2")
8282
}
8383

84+
// TestCreateClusterVolumeType tests the control plane volume type flag
85+
func TestCreateClusterVolumeType(t *testing.T) {
86+
runCreateClusterIntegrationTest(t, "../../tests/integration/create_cluster/volume_type", "v1alpha2")
87+
}
88+
8489
// TestCreateClusterOverride tests the override flag
8590
func TestCreateClusterOverride(t *testing.T) {
8691
runCreateClusterIntegrationTest(t, "../../tests/integration/create_cluster/overrides", "v1alpha2")

pkg/apis/kops/validation/instancegroup.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ func CrossValidateInstanceGroup(g *kops.InstanceGroup, cluster *kops.Cluster, cl
287287
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "warmPool", "minSize"), warmPool.MinSize, "warm pool minSize cannot be negative"))
288288
}
289289
}
290+
//TODO: Add RootVolume validation for other cloud providers ex. GCE
290291

291292
if g.Spec.Containerd != nil {
292293
allErrs = append(allErrs, validateContainerdConfig(cluster, g.Spec.Containerd, field.NewPath("spec", "containerd"), false)...)
@@ -312,6 +313,10 @@ func ValidateControlPlaneInstanceGroup(g *kops.InstanceGroup, cluster *kops.Clus
312313
return allErrs
313314
}
314315

316+
func validateRootVolumeType(g *kops.InstanceGroup) {
317+
318+
}
319+
315320
var validUserDataTypes = []string{
316321
"text/x-include-once-url",
317322
"text/x-include-url",
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
apiVersion: kops.k8s.io/v1alpha2
2+
kind: Cluster
3+
metadata:
4+
creationTimestamp: "2017-01-01T00:00:00Z"
5+
name: volume-types.example.com
6+
spec:
7+
api:
8+
loadBalancer:
9+
type: Public
10+
authorization:
11+
rbac: {}
12+
channel: stable
13+
cloudConfig: {}
14+
cloudProvider: gce
15+
configBase: memfs://tests/volume-types.example.com
16+
etcdClusters:
17+
- cpuRequest: 200m
18+
etcdMembers:
19+
- instanceGroup: control-plane-us-test-1a
20+
name: a
21+
manager:
22+
backupRetentionDays: 90
23+
memoryRequest: 100Mi
24+
name: main
25+
- cpuRequest: 100m
26+
etcdMembers:
27+
- instanceGroup: control-plane-us-test-1a
28+
name: a
29+
manager:
30+
backupRetentionDays: 90
31+
memoryRequest: 100Mi
32+
name: events
33+
iam:
34+
allowContainerRegistry: true
35+
legacy: false
36+
kubelet:
37+
anonymousAuth: false
38+
kubernetesApiAccess:
39+
- 0.0.0.0/0
40+
- ::/0
41+
kubernetesVersion: v1.32.0
42+
networking:
43+
cni: {}
44+
nonMasqueradeCIDR: 100.64.0.0/10
45+
project: camilabustos-gke-dev-new
46+
sshAccess:
47+
- 0.0.0.0/0
48+
- ::/0
49+
subnets:
50+
- cidr: 10.0.16.0/20
51+
name: us-test
52+
region: us-test
53+
type: Public
54+
topology:
55+
dns:
56+
type: None
57+
58+
---
59+
60+
apiVersion: kops.k8s.io/v1alpha2
61+
kind: InstanceGroup
62+
metadata:
63+
creationTimestamp: "2017-01-01T00:00:00Z"
64+
labels:
65+
kops.k8s.io/cluster: volume-types.example.com
66+
name: control-plane-us-test-1a
67+
spec:
68+
image: ubuntu-os-cloud/ubuntu-2404-noble-amd64-v20250606
69+
machineType: e2-medium
70+
maxSize: 1
71+
minSize: 1
72+
role: Master
73+
rootVolumeSize: 32
74+
rootVolumeType: pd-balanced
75+
subnets:
76+
- us-test
77+
zones:
78+
- us-test-1a
79+
80+
---
81+
82+
apiVersion: kops.k8s.io/v1alpha2
83+
kind: InstanceGroup
84+
metadata:
85+
creationTimestamp: "2017-01-01T00:00:00Z"
86+
labels:
87+
kops.k8s.io/cluster: volume-types.example.com
88+
name: nodes-us-test-1a
89+
spec:
90+
image: ubuntu-os-cloud/ubuntu-2404-noble-amd64-v20250606
91+
machineType: e2-medium
92+
maxSize: 1
93+
minSize: 1
94+
role: Node
95+
rootVolumeSize: 64
96+
subnets:
97+
- us-test
98+
zones:
99+
- us-test-1a
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ClusterName: volume-types.example.com
2+
Zones:
3+
- us-test-1a
4+
CloudProvider: gce
5+
Networking: cni
6+
KubernetesVersion: v1.32.0
7+
ControlPlaneVolumeSize: 32
8+
ControlPlaneVolumeType: pd-balanced
9+
NodeVolumeSize: 64

0 commit comments

Comments
 (0)