core: fix empty string bug
This function was always using an empty string, instead of the extracted resources
Closes: #9867
Signed-off-by: Tom Hellier <me@tomhellier.com>
(cherry picked from commit 59b4c57406)
This commit is contained in:
1 parent
2aa3978df5
commit
1cef5ea75d
2 files changed
+37
-2
No files matched your search
@@ -99,10 +99,9 @@ func applyResourcesToContainers(opConfig map[string]string, key string, podspec
|
||||
func getComputeResource(opConfig map[string]string, key string) []k8sutil.ContainerResource {
|
||||
// Add Resource list if any
|
||||
resource := []k8sutil.ContainerResource{}
|
||||
resourceRaw := ""
|
||||
var err error
|
||||
|
||||
if k8sutil.GetValue(opConfig, key, "") != "" {
|
||||
if resourceRaw := k8sutil.GetValue(opConfig, key, ""); resourceRaw != "" {
|
||||
resource, err = k8sutil.YamlToContainerResource(resourceRaw)
|
||||
if err != nil {
|
||||
logger.Warningf("failed to parse %q. %v", resourceRaw, err)
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func TestDaemonSetTemplate(t *testing.T) {
|
||||
@@ -80,3 +81,38 @@ func TestGetPortFromConfig(t *testing.T) {
|
||||
err = os.Unsetenv(key)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestApplyingResourcesToRBDPlugin(t *testing.T) {
|
||||
tp := templateParam{}
|
||||
rbdPlugin, err := templateToDaemonSet("rbdplugin", RBDPluginTemplatePath, tp)
|
||||
assert.Nil(t, err)
|
||||
params := make(map[string]string)
|
||||
|
||||
// need to build using map[string]interface{} because the following resource
|
||||
// doesn't serialise nicely
|
||||
// https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity
|
||||
resource := []map[string]interface{}{
|
||||
{
|
||||
"name": "driver-registrar",
|
||||
"resource": map[string]interface{}{
|
||||
"limits": map[string]interface{}{
|
||||
"cpu": "200m",
|
||||
"memory": "256Mi",
|
||||
},
|
||||
"requests": map[string]interface{}{
|
||||
"cpu": "100m",
|
||||
"memory": "128Mi",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
resourceRaw, err := yaml.Marshal(resource)
|
||||
assert.Nil(t, err)
|
||||
params[rbdPluginResource] = string(resourceRaw)
|
||||
applyResourcesToContainers(params, rbdPluginResource, &rbdPlugin.Spec.Template.Spec)
|
||||
assert.Equal(t, rbdPlugin.Spec.Template.Spec.Containers[0].Resources.Requests.Memory().String(), "128Mi")
|
||||
assert.Equal(t, rbdPlugin.Spec.Template.Spec.Containers[0].Resources.Limits.Memory().String(), "256Mi")
|
||||
assert.Equal(t, rbdPlugin.Spec.Template.Spec.Containers[0].Resources.Requests.Cpu().String(), "100m")
|
||||
assert.Equal(t, rbdPlugin.Spec.Template.Spec.Containers[0].Resources.Limits.Cpu().String(), "200m")
|
||||
}
|
||||
Reference in new issue
Block a user