Skip to content

Commit 216ad12

Browse files
authored
Merge pull request #20 from appuio/ocp-1503/set-root-volume-size
Set disk size in machine set annotations
2 parents 91eb7fd + 18c7e58 commit 216ad12

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

controllers/machineset_controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
memoryKey = "machine.openshift.io/memoryMb"
3232
gpuKey = "machine.openshift.io/GPU"
3333
labelsKey = "capacity.cluster-autoscaler.kubernetes.io/labels"
34+
diskKey = "capacity.cluster-autoscaler.kubernetes.io/ephemeral-disk"
3435

3536
gpuKeyValue = "0"
3637
arch = "kubernetes.io/arch=amd64"
@@ -67,9 +68,15 @@ func (r *MachineSetReconciler) Reconcile(ctx context.Context, req ctrl.Request)
6768
return ctrl.Result{}, fmt.Errorf("failed to parse flavor %q: %w", spec.Flavor, err)
6869
}
6970

71+
if spec.RootVolumeSizeGB == 0 {
72+
return ctrl.Result{}, fmt.Errorf("root volume size is not set")
73+
}
74+
7075
machineSet.Annotations[cpuKey] = strconv.Itoa(flavor.CPU)
7176
machineSet.Annotations[memoryKey] = strconv.Itoa(flavor.MemGB * 1024)
7277
machineSet.Annotations[gpuKey] = gpuKeyValue
78+
// According to https://www.cloudscale.ch/en/api/v1#create-a-server GB here means GiB
79+
machineSet.Annotations[diskKey] = fmt.Sprintf("%dGi", spec.RootVolumeSizeGB)
7380

7481
// We guarantee that any existing labels provided via the capacity annotations are preserved.
7582
// See https://github.com/kubernetes/autoscaler/pull/5382 and https://github.com/kubernetes/autoscaler/pull/5697

controllers/machineset_controller_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
ctrl "sigs.k8s.io/controller-runtime"
1515
"sigs.k8s.io/controller-runtime/pkg/client"
1616
"sigs.k8s.io/controller-runtime/pkg/client/fake"
17+
18+
csv1beta1 "github.com/appuio/machine-api-provider-cloudscale/api/cloudscale/provider/v1beta1"
1719
)
1820

1921
func Test_MachineSetReconciler_Reconcile(t *testing.T) {
@@ -37,7 +39,12 @@ func Test_MachineSetReconciler_Reconcile(t *testing.T) {
3739
Spec: machinev1beta1.MachineSetSpec{},
3840
}
3941

40-
setFlavorOnMachineSet(ms, "plus-4-2")
42+
providerData := csv1beta1.CloudscaleMachineProviderSpec{
43+
Flavor: "plus-4-2",
44+
RootVolumeSizeGB: 50,
45+
}
46+
47+
setMachineSetProviderData(ms, &providerData)
4148

4249
c := fake.NewClientBuilder().
4350
WithScheme(scheme).
@@ -57,10 +64,11 @@ func Test_MachineSetReconciler_Reconcile(t *testing.T) {
5764
assert.Equal(t, "4096", updated.Annotations[memoryKey])
5865
assert.Equal(t, "0", updated.Annotations[gpuKey])
5966
assert.Equal(t, "a=a,b=b,kubernetes.io/arch=amd64", updated.Annotations[labelsKey])
67+
assert.Equal(t, "50Gi", updated.Annotations[diskKey])
6068
}
6169

62-
func setFlavorOnMachineSet(machine *machinev1beta1.MachineSet, flavor string) {
70+
func setMachineSetProviderData(machine *machinev1beta1.MachineSet, providerData *csv1beta1.CloudscaleMachineProviderSpec) {
6371
machine.Spec.Template.Spec.ProviderSpec.Value = &runtime.RawExtension{
64-
Raw: []byte(fmt.Sprintf(`{"flavor": "%s"}`, flavor)),
72+
Raw: []byte(fmt.Sprintf(`{"flavor": "%s", "rootVolumeSizeGB": %d}`, providerData.Flavor, providerData.RootVolumeSizeGB)),
6573
}
6674
}

0 commit comments

Comments
 (0)