k8s/io/kubernetes/pkg/api/resource.Quantity 示例代码

2022-03-03

以下示例是关于golang中包含resource.Quantity用法的示例代码,想了解resource.Quantity的具体用法?resource.Quantity怎么用?resource.Quantity使用的例子?那么可以参考以下10个相关示例代码来学习它的具体使用方法。

示例1:
conversion.go开发语言: Go项目名称: kubernetes代码行数: 1293
524			}
525			quantity := resource.Quantity{}
526			if err := s.Convert(in, &quantity, 0); err != nil {
537			}
538			quantity := resource.Quantity{}
539			if err := s.Convert(in, &quantity, 0); err != nil {
962		// This is triggered for the Memory field of Container.
963		func(in *int64, out *resource.Quantity, s conversion.Scope) error {
964			out.Set(*in)
967		},
968		func(in *resource.Quantity, out *int64, s conversion.Scope) error {
969			*out = in.Value()
975		// simple hack (int64=Value(), int=MilliValue()) here won't work.
976		func(in *int, out *resource.Quantity, s conversion.Scope) error {
977			out.SetMilli(int64(*in))
示例2:
validation.go开发语言: Go项目名称: kubernetes代码行数: 938
875
876func validateBasicResource(quantity resource.Quantity) errs.ValidationErrorList {
877	if quantity.Value() < 0 {
示例3:
horizontal_test.go开发语言: Go项目名称: ddysher代码行数: 1694
103	reportedLevels       []uint64
104	reportedCPURequests  []resource.Quantity
105	reportedPodReadiness []v1.ConditionStatus
636		reportedLevels:      []uint64{300, 500, 700},
637		reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
638		useMetricsApi:       true,
652		reportedLevels:       []uint64{300, 500, 700},
653		reportedCPURequests:  []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
654		reportedPodReadiness: []v1.ConditionStatus{v1.ConditionFalse, v1.ConditionTrue, v1.ConditionTrue},
669		reportedLevels:       []uint64{400, 500, 700},
670		reportedCPURequests:  []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
671		reportedPodReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse},
690		reportedLevels:      []uint64{300, 500, 700},
691		reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
692		useMetricsApi:       true,
示例4:
horizontal_test.go开发语言: Go项目名称: detiber代码行数: 1675
103	reportedLevels       []uint64
104	reportedCPURequests  []resource.Quantity
105	reportedPodReadiness []v1.ConditionStatus
636		reportedLevels:      []uint64{300, 500, 700},
637		reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
638		useMetricsApi:       true,
652		reportedLevels:       []uint64{300, 500, 700},
653		reportedCPURequests:  []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
654		reportedPodReadiness: []v1.ConditionStatus{v1.ConditionFalse, v1.ConditionTrue, v1.ConditionTrue},
669		reportedLevels:       []uint64{400, 500, 700},
670		reportedCPURequests:  []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
671		reportedPodReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse},
690		reportedLevels:      []uint64{300, 500, 700},
691		reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
692		useMetricsApi:       true,
示例5:
legacy_horizontal_test.go开发语言: Go项目名称: ddysher代码行数: 1054
83	reportedLevels       []uint64
84	reportedCPURequests  []resource.Quantity
85	reportedPodReadiness []v1.ConditionStatus
532		reportedLevels:      []uint64{300, 500, 700},
533		reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
534		useMetricsApi:       true,
548		reportedLevels:       []uint64{300, 500, 700},
549		reportedCPURequests:  []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
550		reportedPodReadiness: []v1.ConditionStatus{v1.ConditionFalse, v1.ConditionTrue, v1.ConditionTrue},
565		reportedLevels:       []uint64{400, 500, 700},
566		reportedCPURequests:  []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
567		reportedPodReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse},
581		reportedLevels:      []uint64{300, 500, 700},
582		reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
583		useMetricsApi:       true,
示例6:
helpers.go开发语言: Go项目名称: ddysher代码行数: 1064
357// diskUsage converts used bytes into a resource quantity.
358func diskUsage(fsStats *statsapi.FsStats) *resource.Quantity {
359	if fsStats == nil || fsStats.UsedBytes == nil {
360		return &resource.Quantity{Format: resource.BinarySI}
361	}
366// inodeUsage converts inodes consumed into a resource quantity.
367func inodeUsage(fsStats *statsapi.FsStats) *resource.Quantity {
368	if fsStats == nil || fsStats.InodesUsed == nil {
369		return &resource.Quantity{Format: resource.BinarySI}
370	}
375// memoryUsage converts working set into a resource quantity.
376func memoryUsage(memStats *statsapi.MemoryStats) *resource.Quantity {
377	if memStats == nil || memStats.WorkingSetBytes == nil {
示例7:
legacy_horizontal_test.go开发语言: Go项目名称: detiber代码行数: 1054
83	reportedLevels       []uint64
84	reportedCPURequests  []resource.Quantity
85	reportedPodReadiness []v1.ConditionStatus
532		reportedLevels:      []uint64{300, 500, 700},
533		reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
534		useMetricsApi:       true,
548		reportedLevels:       []uint64{300, 500, 700},
549		reportedCPURequests:  []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
550		reportedPodReadiness: []v1.ConditionStatus{v1.ConditionFalse, v1.ConditionTrue, v1.ConditionTrue},
565		reportedLevels:       []uint64{400, 500, 700},
566		reportedCPURequests:  []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
567		reportedPodReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse},
581		reportedLevels:      []uint64{300, 500, 700},
582		reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
583		useMetricsApi:       true,
示例8:
helpers.go开发语言: Go项目名称: detiber代码行数: 1064
357// diskUsage converts used bytes into a resource quantity.
358func diskUsage(fsStats *statsapi.FsStats) *resource.Quantity {
359	if fsStats == nil || fsStats.UsedBytes == nil {
360		return &resource.Quantity{Format: resource.BinarySI}
361	}
366// inodeUsage converts inodes consumed into a resource quantity.
367func inodeUsage(fsStats *statsapi.FsStats) *resource.Quantity {
368	if fsStats == nil || fsStats.InodesUsed == nil {
369		return &resource.Quantity{Format: resource.BinarySI}
370	}
375// memoryUsage converts working set into a resource quantity.
376func memoryUsage(memStats *statsapi.MemoryStats) *resource.Quantity {
377	if memStats == nil || memStats.WorkingSetBytes == nil {
示例9:
helpers.go开发语言: Go项目名称: ddysher代码行数: 203
29// containers of the pod.
30func PodRequestsAndLimits(pod *v1.Pod) (reqs map[v1.ResourceName]resource.Quantity, limits map[v1.ResourceName]resource.Quantity) {
31	reqs, limits = map[v1.ResourceName]resource.Quantity{}, map[v1.ResourceName]resource.Quantity{}
143func ExtractContainerResourceValue(fs *v1.ResourceFieldSelector, container *v1.Container) (string, error) {
144	divisor := resource.Quantity{}
145	if divisor.Cmp(fs.Divisor) == 0 {
166// ceiling of the value.
167func convertResourceCPUToString(cpu *resource.Quantity, divisor resource.Quantity) (string, error) {
168	c := int64(math.Ceil(float64(cpu.MilliValue()) / float64(divisor.MilliValue())))
173// ceiling of the value.
174func convertResourceMemoryToString(memory *resource.Quantity, divisor resource.Quantity) (string, error) {
175	m := int64(math.Ceil(float64(memory.Value()) / float64(divisor.Value())))
示例10:
legacy_replica_calculator_test.go开发语言: Go项目名称: ddysher代码行数: 663
235			name:     v1.ResourceCPU,
236			requests: []resource.Quantity{resource.MustParse("1.0")},
237			levels:   []int64{100},
251			name:     v1.ResourceCPU,
252			requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
253			levels:   []int64{300, 500, 700},
269			name:     v1.ResourceCPU,
270			requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
271			levels:   []int64{300, 500, 700},
287			name:     v1.ResourceCPU,
288			requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
289			levels:   []int64{400, 500, 700},
348			name:     v1.ResourceCPU,
349			requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
350			levels:   []int64{100, 300, 500, 250, 250},

本文地址:https://www.itbaoku.cn/snippets/415750.html