You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@yunikorn.apache.org by zh...@apache.org on 2023/12/09 08:01:04 UTC
(yunikorn-k8shim) branch master updated: [YUNIKORN-2205] remove the warning of processing nonexistent "namespace.guaranteed" (#747)
This is an automated email from the ASF dual-hosted git repository.
zhuqi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-k8shim.git
The following commit(s) were added to refs/heads/master by this push:
new a118ba6c [YUNIKORN-2205] remove the warning of processing nonexistent "namespace.guaranteed" (#747)
a118ba6c is described below
commit a118ba6c4d84804e2a407f9d91196ece4690cf09
Author: haser <ha...@gmail.com>
AuthorDate: Sat Dec 9 16:00:50 2023 +0800
[YUNIKORN-2205] remove the warning of processing nonexistent "namespace.guaranteed" (#747)
Shortening the variable name and make the code more Go-like, also add coverage.
Closes: #747
Signed-off-by: qzhu <qz...@cloudera.com>
---
pkg/common/utils/utils.go | 20 +++++++++++---------
pkg/common/utils/utils_test.go | 15 +++++++++++++++
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/pkg/common/utils/utils.go b/pkg/common/utils/utils.go
index 837cd1d1..220b68d1 100644
--- a/pkg/common/utils/utils.go
+++ b/pkg/common/utils/utils.go
@@ -179,16 +179,18 @@ func PodUnderCondition(pod *v1.Pod, condition *v1.PodCondition) bool {
// get namespace guaranteed resource from namespace annotation
func GetNamespaceGuaranteedFromAnnotation(namespaceObj *v1.Namespace) *si.Resource {
// retrieve guaranteed resource info from annotations
- namespaceGuaranteed := GetNameSpaceAnnotationValue(namespaceObj, constants.NamespaceGuaranteed)
- var namespaceGuaranteedMap map[string]string
- err := json.Unmarshal([]byte(namespaceGuaranteed), &namespaceGuaranteedMap)
- if err != nil {
- log.Log(log.ShimUtils).Warn("Unable to process namespace.guaranteed annotation",
- zap.String("namespace", namespaceObj.Name),
- zap.String("namespace.guaranteed is", namespaceGuaranteed))
- return nil
+ if guaranteed := GetNameSpaceAnnotationValue(namespaceObj, constants.NamespaceGuaranteed); guaranteed != "" {
+ var namespaceGuaranteedMap map[string]string
+ err := json.Unmarshal([]byte(guaranteed), &namespaceGuaranteedMap)
+ if err != nil {
+ log.Log(log.ShimUtils).Warn("Unable to process namespace.guaranteed annotation",
+ zap.String("namespace", namespaceObj.Name),
+ zap.String("namespace.guaranteed is", guaranteed))
+ return nil
+ }
+ return common.GetResource(namespaceGuaranteedMap)
}
- return common.GetResource(namespaceGuaranteedMap)
+ return nil
}
func GetNamespaceQuotaFromAnnotation(namespaceObj *v1.Namespace) *si.Resource {
diff --git a/pkg/common/utils/utils_test.go b/pkg/common/utils/utils_test.go
index 77799999..d7307d3c 100644
--- a/pkg/common/utils/utils_test.go
+++ b/pkg/common/utils/utils_test.go
@@ -283,6 +283,21 @@ func TestGetNamespaceGuaranteedFromAnnotation(t *testing.T) {
},
},
}, nil},
+ {&v1.Namespace{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "test",
+ Namespace: "test",
+ Annotations: map[string]string{
+ constants.NamespaceGuaranteed: "error",
+ },
+ },
+ }, nil},
+ {&v1.Namespace{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "test",
+ Namespace: "test",
+ },
+ }, nil},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("namespace: %v", tc.namespace), func(t *testing.T) {
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@yunikorn.apache.org
For additional commands, e-mail: issues-help@yunikorn.apache.org