mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
api: add resource claims to core API
The resource.k8s.io/ClaimTemplate only gets referenced by name, therefore the changes to the core API are limited.
This commit is contained in:
@@ -550,6 +550,42 @@ func dropDisabledFields(
|
||||
dropDisabledTopologySpreadConstraintsFields(podSpec, oldPodSpec)
|
||||
dropDisabledNodeInclusionPolicyFields(podSpec, oldPodSpec)
|
||||
dropDisabledMatchLabelKeysField(podSpec, oldPodSpec)
|
||||
dropDisabledDynamicResourceAllocationFields(podSpec, oldPodSpec)
|
||||
}
|
||||
|
||||
// dropDisabledDynamicResourceAllocationFields removes pod claim references from
|
||||
// container specs and pod-level resource claims unless they are already used
|
||||
// by the old pod spec.
|
||||
func dropDisabledDynamicResourceAllocationFields(podSpec, oldPodSpec *api.PodSpec) {
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.DynamicResourceAllocation) && !dynamicResourceAllocationInUse(oldPodSpec) {
|
||||
dropResourceClaimRequests(podSpec.Containers)
|
||||
dropResourceClaimRequests(podSpec.InitContainers)
|
||||
dropEphemeralResourceClaimRequests(podSpec.EphemeralContainers)
|
||||
podSpec.ResourceClaims = nil
|
||||
}
|
||||
}
|
||||
|
||||
func dynamicResourceAllocationInUse(podSpec *api.PodSpec) bool {
|
||||
if podSpec == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// We only need to check this field because the containers cannot have
|
||||
// resource requirements entries for claims without a corresponding
|
||||
// entry at the pod spec level.
|
||||
return len(podSpec.ResourceClaims) > 0
|
||||
}
|
||||
|
||||
func dropResourceClaimRequests(containers []api.Container) {
|
||||
for i := range containers {
|
||||
containers[i].Resources.Claims = nil
|
||||
}
|
||||
}
|
||||
|
||||
func dropEphemeralResourceClaimRequests(containers []api.EphemeralContainer) {
|
||||
for i := range containers {
|
||||
containers[i].Resources.Claims = nil
|
||||
}
|
||||
}
|
||||
|
||||
// dropDisabledTopologySpreadConstraintsFields removes disabled fields from PodSpec related
|
||||
|
||||
Reference in New Issue
Block a user