Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions api/v1alpha1/sandboxclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,17 @@ type SandboxClaimInplaceUpdateOptions struct {
Resources *SandboxClaimInplaceUpdateResourcesOptions `json:"resources,omitempty"`
}

// SandboxClaimInplaceUpdateResourcesOptions
// TODO: now we only support cpu inplace resize, consider support mem resize in the future.
// SandboxClaimInplaceUpdateResourcesOptions specifies resources for in-place resize.
type SandboxClaimInplaceUpdateResourcesOptions struct {
// Requests specifies the target resource requests for each container.
// Only CPU is supported for now. The container's original request must already be set;
// CPU and memory are supported. The container's original request must already be set;
// otherwise the value is ignored.
// The new value must not change the Pod's QoS class; otherwise the claim will be rejected.
// +optional
Requests corev1.ResourceList `json:"requests,omitempty"`

// Limits specifies the target resource limits for each container.
// Only CPU is supported for now. The container's original limit must already be set;
// CPU and memory are supported. The container's original limit must already be set;
// otherwise the value is ignored.
// The new value must not change the Pod's QoS class; otherwise the claim will be rejected.
// +optional
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/agents.kruise.io_sandboxclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ spec:
x-kubernetes-int-or-string: true
description: |-
Limits specifies the target resource limits for each container.
Only CPU is supported for now. The container's original limit must already be set;
CPU and memory are supported. The container's original limit must already be set;
otherwise the value is ignored.
The new value must not change the Pod's QoS class; otherwise the claim will be rejected.
type: object
Expand All @@ -144,7 +144,7 @@ spec:
x-kubernetes-int-or-string: true
description: |-
Requests specifies the target resource requests for each container.
Only CPU is supported for now. The container's original request must already be set;
CPU and memory are supported. The container's original request must already be set;
otherwise the value is ignored.
The new value must not change the Pod's QoS class; otherwise the claim will be rejected.
type: object
Expand Down
22 changes: 16 additions & 6 deletions pkg/controller/sandboxclaim/core/common_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func TestCommonControl_EnsureClaimClaiming_ClaimedGreaterThanZero(t *testing.T)
assert.Equal(t, int32(1), newStatus.ClaimedReplicas, "ClaimedReplicas should be 1")
}

func TestCommonControl_EnsureClaimClaiming_CPUResizeFeatureGatePrecondition(t *testing.T) {
func TestCommonControl_EnsureClaimClaiming_ResourceResizeFeatureGatePrecondition(t *testing.T) {
scheme := runtime.NewScheme()
_ = agentsv1alpha1.AddToScheme(scheme)

Expand All @@ -557,7 +557,7 @@ func TestCommonControl_EnsureClaimClaiming_CPUResizeFeatureGatePrecondition(t *t
Replicas: int32Ptr(1),
InplaceUpdate: &agentsv1alpha1.SandboxClaimInplaceUpdateOptions{
Resources: &agentsv1alpha1.SandboxClaimInplaceUpdateResourcesOptions{
Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m")},
Requests: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("512Mi")},
},
},
},
Expand Down Expand Up @@ -1031,16 +1031,22 @@ func TestCommonControl_buildClaimOptions(t *testing.T) {
name: "claim with inplaceUpdate resources",
claim: &agentsv1alpha1.SandboxClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "test-claim-cpu-resize",
Name: "test-claim-resource-resize",
Namespace: "default",
UID: "test-uid-cpu-resize",
UID: "test-uid-resource-resize",
},
Spec: agentsv1alpha1.SandboxClaimSpec{
TemplateName: "test-template",
InplaceUpdate: &agentsv1alpha1.SandboxClaimInplaceUpdateOptions{
Resources: &agentsv1alpha1.SandboxClaimInplaceUpdateResourcesOptions{
Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m")},
Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m")},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("512Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
},
},
},
},
Expand All @@ -1060,6 +1066,10 @@ func TestCommonControl_buildClaimOptions(t *testing.T) {
if reqCPU.String() != "500m" {
t.Errorf("InplaceUpdate.Resources.Requests[cpu] = %v, want 500m", reqCPU.String())
}
reqMemory := opts.InplaceUpdate.Resources.Requests[corev1.ResourceMemory]
if reqMemory.String() != "512Mi" {
t.Errorf("InplaceUpdate.Resources.Requests[memory] = %v, want 512Mi", reqMemory.String())
}
},
},
{
Expand Down
12 changes: 8 additions & 4 deletions pkg/sandbox-manager/infra/sandboxcr/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ func ValidateAndInitClaimOptions(opts infra.ClaimSandboxOptions) (infra.ClaimSan
return infra.ClaimSandboxOptions{}, fmt.Errorf("resources must specify at least one of requests or limits")
}
for _, rl := range []corev1.ResourceList{res.Requests, res.Limits} {
if cpu, ok := rl[corev1.ResourceCPU]; ok {
if cpu.IsZero() || cpu.Cmp(resource.Quantity{}) < 0 {
return infra.ClaimSandboxOptions{}, fmt.Errorf("target cpu must be a positive value")
for resourceName, quantity := range rl {
if !supportedResizeResources[resourceName] {
continue
}
if quantity.IsZero() || quantity.Cmp(resource.Quantity{}) < 0 {
return infra.ClaimSandboxOptions{}, fmt.Errorf("target %s must be a positive value", resourceName)
}
}
}
Expand Down Expand Up @@ -679,7 +682,8 @@ func buildResourceResizedPod(pod *corev1.Pod, requests, limits corev1.ResourceLi

// supportedResizeResources defines which resources are allowed for in-place resize.
var supportedResizeResources = map[corev1.ResourceName]bool{
corev1.ResourceCPU: true,
corev1.ResourceCPU: true,
corev1.ResourceMemory: true,
}

// setContainerResources updates the container's requests and limits for resources
Expand Down
Loading
Loading