diff --git a/pkg/common/utils/utils.go b/pkg/common/utils/utils.go index 837cd1d1b..220b68d14 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 77799999c..d7307d3cc 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) {