This is an automated email from the ASF dual-hosted git repository.
xianjin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git
The following commit(s) were added to refs/heads/master by this push:
new 8c443838 [operator] infer resource request/limit from spec for init
container (#521)
8c443838 is described below
commit 8c443838cdaf484b0faef1db7dd51e4e0f60c422
Author: advancedxy <[email protected]>
AuthorDate: Tue Jan 31 15:12:26 2023 +0800
[operator] infer resource request/limit from spec for init container (#521)
### What changes were proposed in this pull request?
passing RSS resource spec to init-container's
### Why are the changes needed?
This pr fixes #496.
Without this pr, RSS operator cannot work correctly with resource quota
enabled namespace
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
added UT
---
deploy/kubernetes/operator/go.mod | 2 +
.../operator/pkg/controller/util/util.go | 2 +
.../operator/pkg/controller/util/util_test.go | 61 ++++++++++++++++++++++
3 files changed, 65 insertions(+)
diff --git a/deploy/kubernetes/operator/go.mod
b/deploy/kubernetes/operator/go.mod
index 2d7500ee..f98ebb85 100644
--- a/deploy/kubernetes/operator/go.mod
+++ b/deploy/kubernetes/operator/go.mod
@@ -5,6 +5,7 @@ go 1.17
require (
github.com/onsi/ginkgo/v2 v2.1.4
github.com/onsi/gomega v1.20.0
+ github.com/stretchr/testify v1.7.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
gomodules.xyz/jsonpatch/v2 v2.2.0
k8s.io/api v0.22.2
@@ -46,6 +47,7 @@ require (
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
+ github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
diff --git a/deploy/kubernetes/operator/pkg/controller/util/util.go
b/deploy/kubernetes/operator/pkg/controller/util/util.go
index bc1f3ccb..a1404038 100644
--- a/deploy/kubernetes/operator/pkg/controller/util/util.go
+++ b/deploy/kubernetes/operator/pkg/controller/util/util.go
@@ -175,6 +175,7 @@ func GenerateInitContainers(rssPodSpec
*v1alpha1.RSSPodSpec) []corev1.Container
Privileged: pointer.Bool(true),
},
VolumeMounts:
GenerateHostPathVolumeMounts(rssPodSpec.HostPathMounts),
+ Resources: rssPodSpec.Resources,
})
if len(rssPodSpec.LogHostPath) > 0 {
initContainers = append(initContainers,
corev1.Container{
@@ -193,6 +194,7 @@ func GenerateInitContainers(rssPodSpec
*v1alpha1.RSSPodSpec) []corev1.Container
VolumeMounts: []corev1.VolumeMount{
*generateLogVolumeMount(rssPodSpec),
},
+ Resources: rssPodSpec.Resources,
})
}
}
diff --git a/deploy/kubernetes/operator/pkg/controller/util/util_test.go
b/deploy/kubernetes/operator/pkg/controller/util/util_test.go
index 5a49c5ef..4db5beb3 100644
--- a/deploy/kubernetes/operator/pkg/controller/util/util_test.go
+++ b/deploy/kubernetes/operator/pkg/controller/util/util_test.go
@@ -21,7 +21,9 @@ import (
"sort"
"testing"
+ "github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
+ "k8s.io/apimachinery/pkg/api/resource"
"k8s.io/utils/pointer"
"github.com/apache/incubator-uniffle/deploy/kubernetes/operator/api/uniffle/v1alpha1"
@@ -84,6 +86,65 @@ func TestGenerateMakeDataDirCommand(t *testing.T) {
}
}
+func TestGenerateInitContainers(t *testing.T) {
+ // first check resource request
+ for _, tt := range []struct {
+ name string
+ rssPodSpec *v1alpha1.RSSPodSpec
+ resources *corev1.ResourceRequirements
+ }{
+ {
+ name: "without security context",
+ rssPodSpec: &v1alpha1.RSSPodSpec{},
+ resources: nil,
+ },
+ {
+ name: "security context with host path mapping",
+ rssPodSpec: &v1alpha1.RSSPodSpec{
+ HostPathMounts: map[string]string{
+ "/data3": "/mnt/data3",
+ },
+ SecurityContext: &corev1.PodSecurityContext{
+ RunAsUser: pointer.Int64(2000),
+ FSGroup: pointer.Int64(1000),
+ },
+ MainContainer: &v1alpha1.MainContainer{
+ Resources: corev1.ResourceRequirements{
+ Limits:
map[corev1.ResourceName]resource.Quantity{
+ corev1.ResourceCPU:
resource.MustParse("1"),
+ corev1.ResourceMemory:
resource.MustParse("1G"),
+ },
+ Requests:
map[corev1.ResourceName]resource.Quantity{
+ corev1.ResourceCPU:
resource.MustParse("1"),
+ corev1.ResourceMemory:
resource.MustParse("1G"),
+ },
+ },
+ },
+ },
+ resources: &corev1.ResourceRequirements{
+ Limits:
map[corev1.ResourceName]resource.Quantity{
+ corev1.ResourceCPU:
resource.MustParse("1"),
+ corev1.ResourceMemory:
resource.MustParse("1G"),
+ },
+ Requests:
map[corev1.ResourceName]resource.Quantity{
+ corev1.ResourceCPU:
resource.MustParse("1"),
+ corev1.ResourceMemory:
resource.MustParse("1G"),
+ },
+ },
+ },
+ } {
+ t.Run(tt.name, func(t *testing.T) {
+ assertion := assert.New(t)
+ containers := GenerateInitContainers(tt.rssPodSpec)
+ if len(containers) == 0 {
+ assertion.Nil(tt.resources)
+ } else {
+ assertion.Equal(tt.resources,
&containers[0].Resources)
+ }
+ })
+ }
+}
+
func isEqualStringSlice(a, b []string) bool {
if len(a) != len(b) {
return false