Downward API hugepages
Kubernetes-commit: 45bd6cb186c05eb3a6cdb2cc4927bbcb50a8ff74
This commit is contained in:
parent
2c52ab8913
commit
74ecab5f7e
|
@ -199,7 +199,20 @@ func extractContainerResourceValue(fs *corev1.ResourceFieldSelector, container *
|
|||
case "requests.ephemeral-storage":
|
||||
return convertResourceEphemeralStorageToString(container.Resources.Requests.StorageEphemeral(), divisor)
|
||||
}
|
||||
|
||||
// handle extended standard resources with dynamic names
|
||||
// example: requests.hugepages-<pageSize> or limits.hugepages-<pageSize>
|
||||
if strings.HasPrefix(fs.Resource, "requests.") {
|
||||
resourceName := corev1.ResourceName(strings.TrimPrefix(fs.Resource, "requests."))
|
||||
if IsHugePageResourceName(resourceName) {
|
||||
return convertResourceHugePagesToString(container.Resources.Requests.Name(resourceName, resource.BinarySI), divisor)
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(fs.Resource, "limits.") {
|
||||
resourceName := corev1.ResourceName(strings.TrimPrefix(fs.Resource, "limits."))
|
||||
if IsHugePageResourceName(resourceName) {
|
||||
return convertResourceHugePagesToString(container.Resources.Limits.Name(resourceName, resource.BinarySI), divisor)
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("Unsupported container resource : %v", fs.Resource)
|
||||
}
|
||||
|
||||
|
@ -217,6 +230,13 @@ func convertResourceMemoryToString(memory *resource.Quantity, divisor resource.Q
|
|||
return strconv.FormatInt(m, 10), nil
|
||||
}
|
||||
|
||||
// convertResourceHugePagesToString converts hugepages value to the format of divisor and returns
|
||||
// ceiling of the value.
|
||||
func convertResourceHugePagesToString(hugePages *resource.Quantity, divisor resource.Quantity) (string, error) {
|
||||
m := int64(math.Ceil(float64(hugePages.Value()) / float64(divisor.Value())))
|
||||
return strconv.FormatInt(m, 10), nil
|
||||
}
|
||||
|
||||
// convertResourceEphemeralStorageToString converts ephemeral storage value to the format of divisor and returns
|
||||
// ceiling of the value.
|
||||
func convertResourceEphemeralStorageToString(ephemeralStorage *resource.Quantity, divisor resource.Quantity) (string, error) {
|
||||
|
@ -269,3 +289,9 @@ func GetEnvVarRefString(from *corev1.EnvVarSource) string {
|
|||
|
||||
return "invalid valueFrom"
|
||||
}
|
||||
|
||||
// IsHugePageResourceName returns true if the resource name has the huge page
|
||||
// resource prefix.
|
||||
func IsHugePageResourceName(name corev1.ResourceName) bool {
|
||||
return strings.HasPrefix(string(name), corev1.ResourceHugePagesPrefix)
|
||||
}
|
||||
|
|
|
@ -108,7 +108,20 @@ func ExtractContainerResourceValue(fs *corev1.ResourceFieldSelector, container *
|
|||
case "requests.ephemeral-storage":
|
||||
return convertResourceEphemeralStorageToString(container.Resources.Requests.StorageEphemeral(), divisor)
|
||||
}
|
||||
|
||||
// handle extended standard resources with dynamic names
|
||||
// example: requests.hugepages-<pageSize> or limits.hugepages-<pageSize>
|
||||
if strings.HasPrefix(fs.Resource, "requests.") {
|
||||
resourceName := corev1.ResourceName(strings.TrimPrefix(fs.Resource, "requests."))
|
||||
if IsHugePageResourceName(resourceName) {
|
||||
return convertResourceHugePagesToString(container.Resources.Requests.Name(resourceName, resource.BinarySI), divisor)
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(fs.Resource, "limits.") {
|
||||
resourceName := corev1.ResourceName(strings.TrimPrefix(fs.Resource, "limits."))
|
||||
if IsHugePageResourceName(resourceName) {
|
||||
return convertResourceHugePagesToString(container.Resources.Limits.Name(resourceName, resource.BinarySI), divisor)
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("Unsupported container resource : %v", fs.Resource)
|
||||
}
|
||||
|
||||
|
@ -126,6 +139,13 @@ func convertResourceMemoryToString(memory *resource.Quantity, divisor resource.Q
|
|||
return strconv.FormatInt(m, 10), nil
|
||||
}
|
||||
|
||||
// convertResourceHugePagesToString converts hugepages value to the format of divisor and returns
|
||||
// ceiling of the value.
|
||||
func convertResourceHugePagesToString(hugePages *resource.Quantity, divisor resource.Quantity) (string, error) {
|
||||
m := int64(math.Ceil(float64(hugePages.Value()) / float64(divisor.Value())))
|
||||
return strconv.FormatInt(m, 10), nil
|
||||
}
|
||||
|
||||
// convertResourceEphemeralStorageToString converts ephemeral storage value to the format of divisor and returns
|
||||
// ceiling of the value.
|
||||
func convertResourceEphemeralStorageToString(ephemeralStorage *resource.Quantity, divisor resource.Quantity) (string, error) {
|
||||
|
|
Loading…
Reference in New Issue