本文整理匯總了Golang中k8s/io/kubernetes/pkg/api/resource.Quantity.Cmp方法的典型用法代碼示例。如果您正苦於以下問題:Golang Quantity.Cmp方法的具體用法?Golang Quantity.Cmp怎麽用?Golang Quantity.Cmp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/kubernetes/pkg/api/resource.Quantity
的用法示例。
在下文中一共展示了Quantity.Cmp方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ValidateNonnegativeQuantity
// Validates that a Quantity is not negative
func ValidateNonnegativeQuantity(value resource.Quantity, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if value.Cmp(resource.Quantity{}) < 0 {
allErrs = append(allErrs, field.Invalid(fldPath, value.String(), isNegativeErrorMsg))
}
return allErrs
}
示例2: formatImageStreamQuota
func formatImageStreamQuota(out *tabwriter.Writer, c client.Interface, kc kclient.Interface, stream *imageapi.ImageStream) {
quotas, err := kc.ResourceQuotas(stream.Namespace).List(api.ListOptions{})
if err != nil {
return
}
var limit *resource.Quantity
for _, item := range quotas.Items {
// search for smallest ImageStream quota
if value, ok := item.Spec.Hard[imageapi.ResourceImageStreamSize]; ok {
if limit == nil || limit.Cmp(value) > 0 {
limit = &value
}
}
}
if limit != nil {
quantity := imagequota.GetImageStreamSize(c, stream, make(map[string]*imageapi.Image))
scale := mega
if quantity.Value() >= (1<<giga.scale) || limit.Value() >= (1<<giga.scale) {
scale = giga
}
formatString(out, "Quota Usage", fmt.Sprintf("%s / %s",
formatQuantity(quantity, scale), formatQuantity(limit, scale)))
}
}
示例3: InternalExtractContainerResourceValue
// TODO: remove this duplicate
// InternalExtractContainerResourceValue extracts the value of a resource
// in an already known container
func InternalExtractContainerResourceValue(fs *api.ResourceFieldSelector, container *api.Container) (string, error) {
divisor := resource.Quantity{}
if divisor.Cmp(fs.Divisor) == 0 {
divisor = resource.MustParse("1")
} else {
divisor = fs.Divisor
}
switch fs.Resource {
case "limits.cpu":
return convertResourceCPUToString(container.Resources.Limits.Cpu(), divisor)
case "limits.memory":
return convertResourceMemoryToString(container.Resources.Limits.Memory(), divisor)
case "requests.cpu":
return convertResourceCPUToString(container.Resources.Requests.Cpu(), divisor)
case "requests.memory":
return convertResourceMemoryToString(container.Resources.Requests.Memory(), divisor)
}
return "", fmt.Errorf("Unsupported container resource : %v", fs.Resource)
}