Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/controller/worker/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error {
// specifying the volume type requires a custom volume size to be specified too.
if pool.Volume != nil && pool.Volume.Type != nil {
machineClassSpec["rootDiskType"] = *pool.Volume.Type
} else if machineTypeFromCloudProfile != nil &&
machineTypeFromCloudProfile.Storage != nil &&
machineTypeFromCloudProfile.Storage.Type != "" &&
machineTypeFromCloudProfile.Storage.Type != "default" {
// Use the storage type from the cloud profile as the default if not explicitly set in the shoot spec.
machineClassSpec["rootDiskType"] = machineTypeFromCloudProfile.Storage.Type
if machineTypeFromCloudProfile.Storage.StorageSize != nil {
cloudProfileVolumeSize, err := worker.DiskSize(machineTypeFromCloudProfile.Storage.StorageSize.String())
if err == nil && cloudProfileVolumeSize > 0 {
if _, alreadySet := machineClassSpec["rootDiskSize"]; !alreadySet {
machineClassSpec["rootDiskSize"] = cloudProfileVolumeSize
}
}
}
}

if machineImage.ID != "" {
Expand Down
67 changes: 67 additions & 0 deletions pkg/controller/worker/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package worker_test

import (
"context"
"embed"
"encoding/json"
"fmt"
"maps"
Expand Down Expand Up @@ -1139,6 +1140,72 @@ var _ = Describe("Machines", func() {
Expect(result[0].AutoPreserveFailedMachineMax).To(Equal(int32(0)))
Expect(result[1].AutoPreserveFailedMachineMax).To(Equal(int32(0)))
})
It("should use storage type and size from cloud profile machine type as default when no pool volume is specified", func() {
premiumStorageSize := resource.MustParse("64Gi")
clusterWithPremiumMachineType := &extensionscontroller.Cluster{
CloudProfile: cluster.CloudProfile.DeepCopy(),
Shoot: cluster.Shoot,
Seed: cluster.Seed,
}
clusterWithPremiumMachineType.CloudProfile.Spec.MachineTypes = []gardencorev1beta1.MachineType{
{
Name: machineType,
Capabilities: capabilitiesAmd,
Storage: &gardencorev1beta1.MachineTypeStorage{
Class: "standard",
StorageSize: &premiumStorageSize,
Type: "premium",
},
},
{
Name: machineTypeArm,
Architecture: new(archARM),
Capabilities: capabilitiesArm,
},
}

machineClassPath := filepath.Join("internal", "machineclass")
if useStackitMCM {
machineClassPath = filepath.Join("internal", "machineclass-stackit")
}

workerDelegate, _ = NewWorkerDelegate(c, scheme, chartApplier, "", w, clusterWithPremiumMachineType, customLabelDomain)

var capturedMachineClasses []map[string]any
chartApplier.
EXPECT().
ApplyFromEmbeddedFS(
ctx,
charts.InternalChart,
machineClassPath,
namespace,
"machineclass",
gomock.AssignableToTypeOf(kubernetes.Values(nil)),
).
DoAndReturn(func(_ context.Context, _ embed.FS, _, _, _ string, opts ...kubernetes.ApplyOption) error {
applyOpts := &kubernetes.ApplyOptions{}
for _, o := range opts {
o.MutateApplyOptions(applyOpts)
}
if values, ok := applyOpts.Values.(map[string]any); ok {
if classes, ok := values["machineClasses"].([]map[string]any); ok {
capturedMachineClasses = classes
}
}
return nil
})

err := workerDelegate.DeployMachineClasses(ctx)
Expect(err).NotTo(HaveOccurred())

Expect(capturedMachineClasses).NotTo(BeEmpty())
for _, class := range capturedMachineClasses {
if class["machineType"] == machineType {
Expect(class).To(HaveKeyWithValue("rootDiskType", "premium"), "expected rootDiskType to be set from cloud profile storage type")
Expect(class).To(HaveKeyWithValue("rootDiskSize", 64), "expected rootDiskSize to be set from cloud profile storage size")
}
}
})
},
Entry("with capabilities and using imageIDs", true, false, false),
Entry("with capabilities and using imageIDs with STACKIT mcm", true, false, true),
Expand Down