func ValidateResourceRequirements()

in operator/pkg/operator/injector/validate.go [141:165]


func ValidateResourceRequirements(annotation, value string) error {
	if value == "nil" {
		return nil
	}

	resource := make(corev1.ResourceList)
	err := json.Unmarshal([]byte(value), &resource)
	if err != nil {
		return fmt.Errorf("%s unmarshal error:%s", annotation, err.Error())
	}

	for resourceName, quantity := range resource {
		//validate resource name
		if !standardContainerResources.Has(string(resourceName)) && !strings.HasPrefix(string(resourceName), HugePagesPrefix) {
			return fmt.Errorf("%s error:%s isn't a standard resource type", annotation, string(resourceName))
		}

		//validate resource quantity value
		if quantity.MilliValue() <= int64(0) {
			return fmt.Errorf("%s error:%d must be greater than 0", annotation, quantity.MilliValue())
		}
	}

	return nil
}