Skip to content

Commit 55c44ce

Browse files
committed
feat: allow diskSetup to include partition layout
Signed-off-by: Miltiadis Alexis <[email protected]>
1 parent 608b533 commit 55c44ce

16 files changed

+608
-55
lines changed

api/bootstrap/kubeadm/v1beta1/kubeadmconfig_types.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,23 +774,63 @@ type DiskSetup struct {
774774
Filesystems []Filesystem `json:"filesystems,omitempty"`
775775
}
776776

777+
// PartitionSpec defines the size and optional type for a partition
778+
type PartitionSpec struct {
779+
// percentage of disk that partition will take (1-100)
780+
// +kubebuilder:validation:Minimum=1
781+
// +kubebuilder:validation:Maximum=100
782+
// +required
783+
Percentage int32 `json:"percentage"`
784+
785+
// partitionType is the partition type (optional).
786+
// +optional
787+
PartitionType PartitionType `json:"partitionType,omitempty"`
788+
}
789+
790+
// PartitionType defines the partition type.
791+
// +kubebuilder:validation:Enum="83";"82";"fd";"8e";"0c";"07"
792+
type PartitionType string
793+
794+
const (
795+
// PartitionTypeLinux is the partition type for Linux (83).
796+
PartitionTypeLinux PartitionType = "83"
797+
// PartitionTypeSwap is the partition type for Linux Swap (82).
798+
PartitionTypeSwap PartitionType = "82"
799+
// PartitionTypeLinuxRAID is the partition type for Linux RAID (fd).
800+
PartitionTypeLinuxRAID PartitionType = "fd"
801+
// PartitionTypeLVM is the partition type for LVM (8e).
802+
PartitionTypeLVM PartitionType = "8e"
803+
// PartitionTypeWin95FAT32LBA is the partition type for Win95 FAT32 LBA (0c).
804+
PartitionTypeWin95FAT32LBA PartitionType = "0c"
805+
// PartitionTypeNTFS is the partition type for NTFS (07).
806+
PartitionTypeNTFS PartitionType = "07"
807+
)
808+
777809
// Partition defines how to create and layout a partition.
778810
type Partition struct {
779811
// device is the name of the device.
780812
// +required
781813
// +kubebuilder:validation:MinLength=1
782814
// +kubebuilder:validation:MaxLength=256
783815
Device string `json:"device"`
816+
784817
// layout specifies the device layout.
785818
// If it is true, a single partition will be created for the entire device.
786819
// When layout is false, it means don't partition or ignore existing partitioning.
787820
// +required
788821
Layout bool `json:"layout"`
822+
823+
// diskLayout specifies the percentage of disk space and partition types.
824+
// If specified, this will override the Layout field.
825+
// +optional
826+
DiskLayout []PartitionSpec `json:"diskLayout,omitempty"`
827+
789828
// overwrite describes whether to skip checks and create the partition if a partition or filesystem is found on the device.
790829
// Use with caution. Default is 'false'.
791830
// +optional
792831
Overwrite *bool `json:"overwrite,omitempty"`
793-
// tableType specifies the tupe of partition table. The following are supported:
832+
833+
// tableType specifies the type of partition table. The following are supported:
794834
// 'mbr': default and setups a MS-DOS partition table
795835
// 'gpt': setups a GPT partition table
796836
// +optional

api/bootstrap/kubeadm/v1beta1/zz_generated.conversion.go

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/bootstrap/kubeadm/v1beta1/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/bootstrap/kubeadm/v1beta2/kubeadmconfig_types.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ func (c *KubeadmConfigSpec) Validate(isKCP bool, pathPrefix *field.Path) field.E
149149
allErrs = append(allErrs, c.validateFiles(pathPrefix)...)
150150
allErrs = append(allErrs, c.validateUsers(pathPrefix)...)
151151
allErrs = append(allErrs, c.validateIgnition(pathPrefix)...)
152+
allErrs = append(allErrs, c.validateDiskSetup(pathPrefix)...)
152153

153154
// Validate JoinConfiguration.
154155
if c.JoinConfiguration.IsDefined() {
@@ -407,6 +408,32 @@ func (c *KubeadmConfigSpec) validateIgnition(pathPrefix *field.Path) field.Error
407408
return allErrs
408409
}
409410

411+
func (c *KubeadmConfigSpec) validateDiskSetup(pathPrefix *field.Path) field.ErrorList {
412+
var allErrs field.ErrorList
413+
414+
for i, partition := range c.DiskSetup.Partitions {
415+
if len(partition.DiskLayout) > 0 {
416+
var totalPercentage int32
417+
for _, layout := range partition.DiskLayout {
418+
totalPercentage += layout.Percentage
419+
}
420+
421+
if totalPercentage > 100 {
422+
allErrs = append(
423+
allErrs,
424+
field.Invalid(
425+
pathPrefix.Child("diskSetup", "partitions").Index(i).Child("diskLayout"),
426+
totalPercentage,
427+
"the sum of all partition percentages must not be greater than 100",
428+
),
429+
)
430+
}
431+
}
432+
}
433+
434+
return allErrs
435+
}
436+
410437
// IgnitionSpec contains Ignition specific configuration.
411438
// +kubebuilder:validation:MinProperties=1
412439
type IgnitionSpec struct {
@@ -847,8 +874,46 @@ type Partition struct {
847874
// +optional
848875
// +kubebuilder:validation:Enum=mbr;gpt
849876
TableType string `json:"tableType,omitempty"`
877+
878+
// diskLayout specifies the percentage of disk space and partition types.
879+
// If specified, this will override the Layout field.
880+
// +optional
881+
// +listType=atomic
882+
DiskLayout []PartitionSpec `json:"diskLayout,omitempty"`
883+
}
884+
885+
// PartitionSpec defines the size and optional type for a partition
886+
type PartitionSpec struct {
887+
// percentage of disk that partition will take (1-100)
888+
// +kubebuilder:validation:Minimum=1
889+
// +kubebuilder:validation:Maximum=100
890+
// +required
891+
Percentage int32 `json:"percentage"`
892+
893+
// partitionType is the partition type (optional).
894+
// +optional
895+
PartitionType PartitionType `json:"partitionType,omitempty"`
850896
}
851897

898+
// PartitionType defines the partition type.
899+
// +kubebuilder:validation:Enum="83";"82";"fd";"8e";"0c";"07"
900+
type PartitionType string
901+
902+
const (
903+
// PartitionTypeLinux is the partition type for Linux (83).
904+
PartitionTypeLinux PartitionType = "83"
905+
// PartitionTypeSwap is the partition type for Linux Swap (82).
906+
PartitionTypeSwap PartitionType = "82"
907+
// PartitionTypeLinuxRAID is the partition type for Linux RAID (fd).
908+
PartitionTypeLinuxRAID PartitionType = "fd"
909+
// PartitionTypeLVM is the partition type for LVM (8e).
910+
PartitionTypeLVM PartitionType = "8e"
911+
// PartitionTypeWin95FAT32LBA is the partition type for Win95 FAT32 LBA (0c).
912+
PartitionTypeWin95FAT32LBA PartitionType = "0c"
913+
// PartitionTypeNTFS is the partition type for NTFS (07).
914+
PartitionTypeNTFS PartitionType = "07"
915+
)
916+
852917
// Filesystem defines the file systems to be created.
853918
type Filesystem struct {
854919
// device specifies the device name

api/bootstrap/kubeadm/v1beta2/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml

Lines changed: 60 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)