1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] Allow to pass EphemeralStorage Resource to the Pods (#1401)

This commit is contained in:
Adam Janikowski 2023-09-05 18:09:10 +02:00 committed by GitHub
parent fc7bc29f83
commit 7def39ed6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 13 deletions

View file

@ -14,6 +14,7 @@
- (Feature) Reconciliation Loop Interval option
- (Bugfix) Fix GZIP encoding in case of small responses
- (Bugfix) Fix PVC Rotation Discovery
- (Feature) Allow to pass EphemeralStorage Resource to the Pods
## [1.2.32](https://github.com/arangodb/kube-arangodb/tree/1.2.32) (2023-08-07)
- (Feature) Backup lifetime - remove Backup once its lifetime has been reached

View file

@ -534,21 +534,33 @@ func operatorInitContainer(name, operatorImage string, command []string, securit
// ExtractPodResourceRequirement filters resource requirements for Pods.
func ExtractPodResourceRequirement(resources core.ResourceRequirements) core.ResourceRequirements {
filterStorage := func(list core.ResourceList) core.ResourceList {
newlist := make(core.ResourceList)
if q, ok := list[core.ResourceCPU]; ok {
newlist[core.ResourceCPU] = q
}
if q, ok := list[core.ResourceMemory]; ok {
newlist[core.ResourceMemory] = q
}
return newlist
}
filter := PodResourceRequirementsFilter(core.ResourceCPU, core.ResourceMemory, core.ResourceEphemeralStorage)
return core.ResourceRequirements{
Limits: filterStorage(resources.Limits),
Requests: filterStorage(resources.Requests),
Limits: filter(resources.Limits),
Requests: filter(resources.Requests),
}
}
func PodResourceRequirementsFilter(filters ...core.ResourceName) func(in core.ResourceList) core.ResourceList {
return func(in core.ResourceList) core.ResourceList {
filtered := map[core.ResourceName]bool{}
for _, k := range filters {
filtered[k] = true
}
n := core.ResourceList{}
for k, v := range in {
if _, ok := filtered[k]; !ok {
continue
}
n[k] = v
}
return n
}
}

View file

@ -22,14 +22,17 @@ package k8sutil
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
core "k8s.io/api/core/v1"
resource "k8s.io/apimachinery/pkg/api/resource"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/arangodb/kube-arangodb/pkg/handlers/utils"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
)
@ -416,3 +419,61 @@ func Test_EnsureFinalizer(t *testing.T) {
require.NotContains(t, pod.Finalizers, f)
})
}
func Test_ExtractPodResourceRequirement(t *testing.T) {
v, err := resource.ParseQuantity("1Gi")
require.NoError(t, err)
t.Run("Filter Storage", func(t *testing.T) {
in := core.ResourceRequirements{
Limits: map[core.ResourceName]resource.Quantity{
core.ResourceCPU: v,
core.ResourceStorage: v,
},
}
require.Len(t, in.Limits, 2)
require.Len(t, in.Requests, 0)
out := ExtractPodResourceRequirement(in)
require.Len(t, out.Limits, 1)
require.Contains(t, out.Limits, core.ResourceCPU)
require.NotContains(t, out.Limits, core.ResourceStorage)
require.Len(t, out.Requests, 0)
})
t.Run("Ensure that all required Resources are filtered", func(t *testing.T) {
resources := map[core.ResourceName]bool{
core.ResourceCPU: true,
core.ResourceMemory: true,
core.ResourceStorage: false,
core.ResourceEphemeralStorage: true,
}
in := core.ResourceRequirements{
Limits: core.ResourceList{},
Requests: core.ResourceList{},
}
for k := range resources {
in.Limits[k] = v
in.Requests[k] = v
}
out := ExtractPodResourceRequirement(in)
for k, v := range resources {
t.Run(fmt.Sprintf("Resource %s should be %s", k, util.BoolSwitch(v, "present", "missing")), func(t *testing.T) {
require.Contains(t, in.Requests, k)
require.Contains(t, in.Limits, k)
if v {
require.Contains(t, out.Requests, k)
require.Contains(t, out.Limits, k)
} else {
require.NotContains(t, out.Requests, k)
require.NotContains(t, out.Limits, k)
}
})
}
})
}