-
Notifications
You must be signed in to change notification settings - Fork 567
OCPBUGS-86238: set limits for aro.openshift.io/swift-nic in request overrides for ARO swift #8552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
|
|
||
| appsv1 "k8s.io/api/apps/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/api/resource" | ||
| runtime "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/utils/ptr" | ||
|
|
||
|
|
@@ -285,6 +286,240 @@ func generateResources() (map[string]*corev1.Secret, map[string]*corev1.ConfigMa | |
| return secrets, configMaps | ||
| } | ||
|
|
||
| func TestApplyRequestsOverrides(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| annotations map[string]string | ||
| containers []corev1.Container | ||
| initContainers []corev1.Container | ||
| expectedContainers []corev1.Container | ||
| expectedInitContainers []corev1.Container | ||
| }{ | ||
| { | ||
| name: "When overriding cpu and memory it should only update requests", | ||
| annotations: map[string]string{ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: these annotation keys are hardcoded as string literals, but the production code uses hyperv1.ResourceRequestOverrideAnnotationPrefix + "/router.router": "cpu=500m,memory=1Gi",
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is intentionally using the literal, I want this tests to break if the value of the constant is changed, to ensure that is a conscious action. |
||
| "resource-request-override.hypershift.openshift.io/router.router": "cpu=500m,memory=1Gi", | ||
| }, | ||
| containers: []corev1.Container{ | ||
| { | ||
| Name: "router", | ||
| Resources: corev1.ResourceRequirements{ | ||
| Requests: corev1.ResourceList{ | ||
| corev1.ResourceCPU: resource.MustParse("100m"), | ||
| corev1.ResourceMemory: resource.MustParse("256Mi"), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| expectedContainers: []corev1.Container{ | ||
| { | ||
| Name: "router", | ||
| Resources: corev1.ResourceRequirements{ | ||
| Requests: corev1.ResourceList{ | ||
| corev1.ResourceCPU: resource.MustParse("500m"), | ||
| corev1.ResourceMemory: resource.MustParse("1Gi"), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "When overriding aro.openshift.io/swift-nic it should set both requests and limits", | ||
| annotations: map[string]string{ | ||
| "resource-request-override.hypershift.openshift.io/router.router": "aro.openshift.io/swift-nic=1", | ||
| }, | ||
| containers: []corev1.Container{ | ||
| { | ||
| Name: "router", | ||
| Resources: corev1.ResourceRequirements{ | ||
| Requests: corev1.ResourceList{}, | ||
| }, | ||
| }, | ||
| }, | ||
| expectedContainers: []corev1.Container{ | ||
| { | ||
| Name: "router", | ||
| Resources: corev1.ResourceRequirements{ | ||
| Requests: corev1.ResourceList{ | ||
| aroSwiftNICResource: resource.MustParse("1"), | ||
| }, | ||
| Limits: corev1.ResourceList{ | ||
| aroSwiftNICResource: resource.MustParse("1"), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "When overriding mixed resources it should set limits only for swift-nic", | ||
| annotations: map[string]string{ | ||
| "resource-request-override.hypershift.openshift.io/router.router": "cpu=500m,aro.openshift.io/swift-nic=1", | ||
| }, | ||
| containers: []corev1.Container{ | ||
| { | ||
| Name: "router", | ||
| Resources: corev1.ResourceRequirements{ | ||
| Requests: corev1.ResourceList{ | ||
| corev1.ResourceCPU: resource.MustParse("100m"), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| expectedContainers: []corev1.Container{ | ||
| { | ||
| Name: "router", | ||
| Resources: corev1.ResourceRequirements{ | ||
| Requests: corev1.ResourceList{ | ||
| corev1.ResourceCPU: resource.MustParse("500m"), | ||
| aroSwiftNICResource: resource.MustParse("1"), | ||
| }, | ||
| Limits: corev1.ResourceList{ | ||
| aroSwiftNICResource: resource.MustParse("1"), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "When overriding an init container with swift-nic it should set both requests and limits", | ||
| annotations: map[string]string{ | ||
| "resource-request-override.hypershift.openshift.io/router.init-router": "aro.openshift.io/swift-nic=2", | ||
| }, | ||
| initContainers: []corev1.Container{ | ||
| { | ||
| Name: "init-router", | ||
| Resources: corev1.ResourceRequirements{ | ||
| Requests: corev1.ResourceList{}, | ||
| }, | ||
| }, | ||
| }, | ||
| expectedInitContainers: []corev1.Container{ | ||
| { | ||
| Name: "init-router", | ||
| Resources: corev1.ResourceRequirements{ | ||
| Requests: corev1.ResourceList{ | ||
| aroSwiftNICResource: resource.MustParse("2"), | ||
| }, | ||
| Limits: corev1.ResourceList{ | ||
| aroSwiftNICResource: resource.MustParse("2"), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "When annotation targets a different deployment it should not apply overrides", | ||
| annotations: map[string]string{ | ||
| "resource-request-override.hypershift.openshift.io/kube-apiserver.kube-apiserver": "cpu=500m", | ||
| }, | ||
| containers: []corev1.Container{ | ||
| { | ||
| Name: "router", | ||
| Resources: corev1.ResourceRequirements{ | ||
| Requests: corev1.ResourceList{ | ||
| corev1.ResourceCPU: resource.MustParse("100m"), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| expectedContainers: []corev1.Container{ | ||
| { | ||
| Name: "router", | ||
| Resources: corev1.ResourceRequirements{ | ||
| Requests: corev1.ResourceList{ | ||
| corev1.ResourceCPU: resource.MustParse("100m"), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| g := NewGomegaWithT(t) | ||
|
|
||
| workload := &controlPlaneWorkload[*appsv1.Deployment]{ | ||
| name: "router", | ||
| workloadProvider: &deploymentProvider{}, | ||
| ComponentOptions: &testComponent{}, | ||
| } | ||
| hcp := &hyperv1.HostedControlPlane{} | ||
| hcp.Annotations = test.annotations | ||
|
|
||
| podTemplate := &corev1.PodTemplateSpec{ | ||
| Spec: corev1.PodSpec{ | ||
| Containers: test.containers, | ||
| InitContainers: test.initContainers, | ||
| }, | ||
| } | ||
|
|
||
| workload.applyRequestsOverrides(podTemplate, hcp) | ||
|
|
||
| if test.expectedContainers != nil { | ||
| g.Expect(podTemplate.Spec.Containers).To(Equal(test.expectedContainers)) | ||
| } | ||
| if test.expectedInitContainers != nil { | ||
| g.Expect(podTemplate.Spec.InitContainers).To(Equal(test.expectedInitContainers)) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestApplyNonOvercommitableResourceLimits(t *testing.T) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't this already covered in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I still want to cover this function in isolation as a consumable piece of code. |
||
| tests := []struct { | ||
| name string | ||
| overrides corev1.ResourceList | ||
| existingLimits corev1.ResourceList | ||
| expectedLimits corev1.ResourceList | ||
| }{ | ||
| { | ||
| name: "When overriding aro.openshift.io/swift-nic it should set the limit to the same value", | ||
| overrides: corev1.ResourceList{ | ||
| aroSwiftNICResource: resource.MustParse("1"), | ||
| }, | ||
| expectedLimits: corev1.ResourceList{ | ||
| aroSwiftNICResource: resource.MustParse("1"), | ||
| }, | ||
| }, | ||
| { | ||
| name: "When overriding standard resources it should not set limits", | ||
| overrides: corev1.ResourceList{ | ||
| corev1.ResourceCPU: resource.MustParse("500m"), | ||
| corev1.ResourceMemory: resource.MustParse("1Gi"), | ||
| }, | ||
| expectedLimits: nil, | ||
| }, | ||
| { | ||
| name: "When overriding a mix of standard and swift-nic resources it should only set limits for swift-nic", | ||
| overrides: corev1.ResourceList{ | ||
| corev1.ResourceCPU: resource.MustParse("500m"), | ||
| aroSwiftNICResource: resource.MustParse("2"), | ||
| }, | ||
| existingLimits: corev1.ResourceList{ | ||
| corev1.ResourceMemory: resource.MustParse("2Gi"), | ||
| }, | ||
| expectedLimits: corev1.ResourceList{ | ||
| corev1.ResourceMemory: resource.MustParse("2Gi"), | ||
| aroSwiftNICResource: resource.MustParse("2"), | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| g := NewGomegaWithT(t) | ||
| container := &corev1.Container{ | ||
| Resources: corev1.ResourceRequirements{ | ||
| Limits: test.existingLimits, | ||
| }, | ||
| } | ||
| applyNonOvercommitableResourceLimits(container, test.overrides) | ||
| g.Expect(container.Resources.Limits).To(Equal(test.expectedLimits)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestSetDefaultOptions(t *testing.T) { | ||
| g := NewGomegaWithT(t) | ||
| scheme := runtime.NewScheme() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.