Skip to content

Commit

Permalink
Merge pull request #20 from appuio/ocp-1503/set-root-volume-size
Browse files Browse the repository at this point in the history
Set disk size in machine set annotations
  • Loading branch information
thobens authored Dec 5, 2024
2 parents 91eb7fd + 18c7e58 commit 216ad12
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 7 additions & 0 deletions controllers/machineset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
memoryKey = "machine.openshift.io/memoryMb"
gpuKey = "machine.openshift.io/GPU"
labelsKey = "capacity.cluster-autoscaler.kubernetes.io/labels"
diskKey = "capacity.cluster-autoscaler.kubernetes.io/ephemeral-disk"

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

if spec.RootVolumeSizeGB == 0 {
return ctrl.Result{}, fmt.Errorf("root volume size is not set")
}

machineSet.Annotations[cpuKey] = strconv.Itoa(flavor.CPU)
machineSet.Annotations[memoryKey] = strconv.Itoa(flavor.MemGB * 1024)
machineSet.Annotations[gpuKey] = gpuKeyValue
// According to https://www.cloudscale.ch/en/api/v1#create-a-server GB here means GiB
machineSet.Annotations[diskKey] = fmt.Sprintf("%dGi", spec.RootVolumeSizeGB)

// We guarantee that any existing labels provided via the capacity annotations are preserved.
// See https://github.com/kubernetes/autoscaler/pull/5382 and https://github.com/kubernetes/autoscaler/pull/5697
Expand Down
14 changes: 11 additions & 3 deletions controllers/machineset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

csv1beta1 "github.com/appuio/machine-api-provider-cloudscale/api/cloudscale/provider/v1beta1"
)

func Test_MachineSetReconciler_Reconcile(t *testing.T) {
Expand All @@ -37,7 +39,12 @@ func Test_MachineSetReconciler_Reconcile(t *testing.T) {
Spec: machinev1beta1.MachineSetSpec{},
}

setFlavorOnMachineSet(ms, "plus-4-2")
providerData := csv1beta1.CloudscaleMachineProviderSpec{
Flavor: "plus-4-2",
RootVolumeSizeGB: 50,
}

setMachineSetProviderData(ms, &providerData)

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

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

0 comments on commit 216ad12

Please sign in to comment.