Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds auto scale padding #362

Merged
merged 2 commits into from
Oct 16, 2023
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: 12 additions & 2 deletions internal/fullnode/pvc_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ import (
cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1"
"github.com/strangelove-ventures/cosmos-operator/internal/diff"
"github.com/strangelove-ventures/cosmos-operator/internal/kube"
"gopkg.in/inf.v0"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
snapshotGrowthFactor = 102
)

var (
defaultAccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
)
Expand Down Expand Up @@ -79,9 +85,13 @@ func pvcResources(crd *cosmosv1.CosmosFullNode) corev1.ResourceRequirements {
reqs = crd.Spec.VolumeClaimTemplate.Resources
size = reqs.Requests[corev1.ResourceStorage]
)

if autoScale := crd.Status.SelfHealing.PVCAutoScale; autoScale != nil {
if autoScale.RequestedSize.Cmp(size) > 0 {
reqs.Requests[corev1.ResourceStorage] = autoScale.RequestedSize
requestedSize := autoScale.RequestedSize.DeepCopy()
newSize := requestedSize.AsDec()
AntiTyping marked this conversation as resolved.
Show resolved Hide resolved
sizeWithPadding := resource.NewDecimalQuantity(*newSize.Mul(newSize, inf.NewDec(snapshotGrowthFactor, 2)), resource.DecimalSI)
if sizeWithPadding.Cmp(size) > 0 {
reqs.Requests[corev1.ResourceStorage] = *sizeWithPadding
}
}
return reqs
Expand Down
94 changes: 73 additions & 21 deletions internal/fullnode/pvc_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestBuildPVCs(t *testing.T) {
Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse("100G")},
},
}

crd.Spec.InstanceOverrides = map[string]cosmosv1.InstanceOverridesSpec{
"juno-0": {},
}
Expand Down Expand Up @@ -148,30 +149,81 @@ func TestBuildPVCs(t *testing.T) {
}
})

t.Run("pvc auto scale", func(t *testing.T) {
for _, tt := range []struct {
SpecQuant, AutoScaleQuant, WantQuant string
}{
{"100G", "99G", "100G"},
{"100G", "101G", "101G"},
} {
crd := defaultCRD()
crd.Spec.Replicas = 1
crd.Spec.VolumeClaimTemplate = cosmosv1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(tt.SpecQuant)},
},
}
crd.Status.SelfHealing.PVCAutoScale = &cosmosv1.PVCAutoScaleStatus{
RequestedSize: resource.MustParse(tt.AutoScaleQuant),
t.Run("pvc auto scale with padding", func(t *testing.T) {
AntiTyping marked this conversation as resolved.
Show resolved Hide resolved
t.Run("given auto scale size less then current size", func(t *testing.T) {
for _, tt := range []struct {
SpecQuant, AutoScaleQuant, WantQuant string
}{
{"100G", "97G", "100G"},
} {
crd := defaultCRD()
crd.Spec.Replicas = 1
crd.Spec.VolumeClaimTemplate = cosmosv1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(tt.SpecQuant)},
},
}
crd.Status.SelfHealing.PVCAutoScale = &cosmosv1.PVCAutoScaleStatus{
RequestedSize: resource.MustParse(tt.AutoScaleQuant),
}

pvcs := BuildPVCs(&crd)
require.Len(t, pvcs, 1, tt)

want := corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(tt.WantQuant)}
require.Equal(t, want.Storage().Value(), pvcs[0].Object().Spec.Resources.Requests.Storage().Value(), tt)
}
AntiTyping marked this conversation as resolved.
Show resolved Hide resolved
})

pvcs := BuildPVCs(&crd)
require.Len(t, pvcs, 1, tt)
t.Run("given auto scale size equal to current size", func(t *testing.T) {
for _, tt := range []struct {
SpecQuant, AutoScaleQuant, WantQuant string
}{
{"102G", "100G", "102G"},
} {
crd := defaultCRD()
crd.Spec.Replicas = 1
crd.Spec.VolumeClaimTemplate = cosmosv1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(tt.SpecQuant)},
},
}
crd.Status.SelfHealing.PVCAutoScale = &cosmosv1.PVCAutoScaleStatus{
RequestedSize: resource.MustParse(tt.AutoScaleQuant),
}

pvcs := BuildPVCs(&crd)
require.Len(t, pvcs, 1, tt)

want := corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(tt.WantQuant)}
require.Equal(t, want, pvcs[0].Object().Spec.Resources.Requests, tt)
}
})

want := corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(tt.WantQuant)}
require.Equal(t, want, pvcs[0].Object().Spec.Resources.Requests, tt)
}
t.Run("given auto scale size greater then current size", func(t *testing.T) {
for _, tt := range []struct {
SpecQuant, AutoScaleQuant, WantQuant string
}{
{"100G", "100G", "102G"},
} {
crd := defaultCRD()
crd.Spec.Replicas = 1
crd.Spec.VolumeClaimTemplate = cosmosv1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(tt.SpecQuant)},
},
}
crd.Status.SelfHealing.PVCAutoScale = &cosmosv1.PVCAutoScaleStatus{
RequestedSize: resource.MustParse(tt.AutoScaleQuant),
}

pvcs := BuildPVCs(&crd)
require.Len(t, pvcs, 1, tt)

want := corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(tt.WantQuant)}
require.Equal(t, want.Storage().Value(), pvcs[0].Object().Spec.Resources.Requests.Storage().Value(), tt)
}
})
})

test.HasTypeLabel(t, func(crd cosmosv1.CosmosFullNode) []map[string]string {
Expand Down
Loading