Skip to content

Commit fadb8b7

Browse files
Add partition number annotation (#1890)
* add partition number annotation * fix lint
1 parent 049efb4 commit fadb8b7

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

pkg/cloudprovider/provider/baremetal/plugins/tinkerbell/client/template.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const (
6060
hardwareDisk1 = "{{ index .Hardware.Disks 0 }}"
6161
hardwareName = "{{.hardware_name}}"
6262
ProvisionWorkerNodeTemplate = "provision-worker-node"
63+
PartitionNumber = "{{.partition_number}}"
6364
)
6465

6566
// TemplateClient handles interactions with the Tinkerbell Templates in the Tinkerbell cluster.
@@ -195,11 +196,11 @@ func createGrowPartitionAction(destDisk string) Action {
195196
Image: "quay.io/tinkerbell/actions/cexec:c5bde803d9f6c90f1a9d5e06930d856d1481854c",
196197
Timeout: 90,
197198
Environment: map[string]string{
198-
"BLOCK_DEVICE": "{{ index .Hardware.Disks 0 }}3",
199+
"BLOCK_DEVICE": fmt.Sprintf("{{ index .Hardware.Disks 0 }}%s", PartitionNumber),
199200
"FS_TYPE": fsType,
200201
"CHROOT": "y",
201202
"DEFAULT_INTERPRETER": defaultInterpreter,
202-
"CMD_LINE": fmt.Sprintf("growpart %s 3 && resize2fs %s3", destDisk, destDisk),
203+
"CMD_LINE": fmt.Sprintf("growpart %s %s && resize2fs %s%s", destDisk, PartitionNumber, destDisk, PartitionNumber),
203204
},
204205
}
205206
}
@@ -225,7 +226,7 @@ network:
225226
Image: "quay.io/tinkerbell-actions/writefile:v1.0.0",
226227
Timeout: 90,
227228
Environment: map[string]string{
228-
"DEST_DISK": "{{ index .Hardware.Disks 0 }}3",
229+
"DEST_DISK": fmt.Sprintf("{{ index .Hardware.Disks 0 }}%s", PartitionNumber),
229230
"FS_TYPE": fsType,
230231
"DEST_PATH": "/etc/netplan/config.yaml",
231232
"CONTENTS": netplaneConfig,
@@ -250,7 +251,7 @@ echo 'local-hostname: {{.hardware_name}}' >> /var/lib/cloud/seed/nocloud/meta-da
250251
Image: "quay.io/tinkerbell-actions/cexec:v1.0.0",
251252
Timeout: 90,
252253
Environment: map[string]string{
253-
"BLOCK_DEVICE": "{{ index .Hardware.Disks 0 }}3",
254+
"BLOCK_DEVICE": fmt.Sprintf("{{ index .Hardware.Disks 0 }}%s", PartitionNumber),
254255
"FS_TYPE": fsType,
255256
"CHROOT": "y",
256257
"DEFAULT_INTERPRETER": defaultInterpreter,
@@ -265,7 +266,7 @@ func decodeCloudInitFile(hardwareName string) Action {
265266
Image: "quay.io/tinkerbell/actions/cexec:latest",
266267
Timeout: 90,
267268
Environment: map[string]string{
268-
"BLOCK_DEVICE": "{{ index .Hardware.Disks 0 }}3",
269+
"BLOCK_DEVICE": fmt.Sprintf("{{ index .Hardware.Disks 0 }}%s", PartitionNumber),
269270
"FS_TYPE": fsType,
270271
"CHROOT": "y",
271272
"DEFAULT_INTERPRETER": "/bin/sh -c",

pkg/cloudprovider/provider/baremetal/plugins/tinkerbell/client/workflow.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ import (
3131
"sigs.k8s.io/controller-runtime/pkg/client"
3232
)
3333

34+
// DefaultPartitionNumber defines the default value for the "partition_number" field.
35+
const DefaultPartitionNumber = "3"
36+
37+
// PartitionNumberAnnotation is used to specify the main partition number of the disk device.
38+
const PartitionNumberAnnotation = "hardware.kubermatic.io/partition-number"
39+
3440
// WorkflowClient handles interactions with the Tinkerbell Workflows.
3541
type WorkflowClient struct {
3642
tinkclient client.Client
@@ -73,6 +79,7 @@ func (w *WorkflowClient) CreateWorkflow(ctx context.Context, userData, templateR
7379
"cidr": convertNetmaskToCIDR(ifaceConfig.IP),
7480
"ns": dnsNameservers,
7581
"default_route": ifaceConfig.IP.Gateway,
82+
"partition_number": w.getPartitionNumber(hardware),
7683
},
7784
},
7885
}
@@ -124,3 +131,11 @@ func (w *WorkflowClient) CleanupWorkflows(ctx context.Context, hardwareName, nam
124131

125132
return nil
126133
}
134+
135+
func (w *WorkflowClient) getPartitionNumber(hardware tink.Hardware) string {
136+
partitionNumber, exists := hardware.Annotations[PartitionNumberAnnotation]
137+
if !exists {
138+
partitionNumber = DefaultPartitionNumber // Use the default value
139+
}
140+
return partitionNumber
141+
}

0 commit comments

Comments
 (0)