Skip to content

Commit

Permalink
[YUNIKORN-2205] remove the warning of processing nonexistent "namespa…
Browse files Browse the repository at this point in the history
…ce.guaranteed" (#747)

Shortening the variable name and make the code more Go-like, also add coverage.

Closes: #747

Signed-off-by: qzhu <[email protected]>
  • Loading branch information
Haser0305 authored and zhuqi-lucas committed Dec 9, 2023
1 parent dc98af0 commit a118ba6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pkg/common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions pkg/common/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a118ba6

Please sign in to comment.