Skip to content

Commit

Permalink
feat - Add option to provide resources requests/limits to controller
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Doussin <guillaume.doussin@gmail.com>
  • Loading branch information
OpenGuidou authored and jgwest committed Jul 31, 2024
1 parent b8dae39 commit 3992ad3
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 5 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/argorollouts_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type RolloutManagerSpec struct {

// Metadata to apply to the generated resources
AdditionalMetadata *ResourceMetadata `json:"additionalMetadata,omitempty"`

// Resources requests/limits for Argo Rollout controller
ControllerResources *corev1.ResourceRequirements `json:"controllerResources,omitempty"`
}

// ArgoRolloutsNodePlacementSpec is used to specify NodeSelector and Tolerations for Rollouts workloads
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions config/crd/bases/argoproj.io_rolloutmanagers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,61 @@ spec:
description: Labels to add to the resources during its creation.
type: object
type: object
controllerResources:
description: Resources requests/limits for Argo Rollout controller
properties:
claims:
description: |-
Claims lists the names of resources, defined in spec.resourceClaims,
that are used by this container.
This is an alpha field and requires enabling the
DynamicResourceAllocation feature gate.
This field is immutable. It can only be set for containers.
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
name:
description: |-
Name must match the name of one entry in pod.spec.resourceClaims of
the Pod where this field is used. It makes that resource available
inside a container.
type: string
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: |-
Limits describes the maximum amount of compute resources allowed.
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: |-
Requests describes the minimum amount of compute resources required.
If Requests is omitted for a container, it defaults to Limits if that is explicitly specified,
otherwise to an implementation-defined value. Requests cannot exceed Limits.
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
type: object
env:
description: Env lets you specify environment for Rollouts pods
items:
Expand Down
15 changes: 10 additions & 5 deletions controllers/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ func rolloutsContainer(cr rolloutsmanagerv1alpha1.RolloutManager) corev1.Contain
// Environment specified in the CR take precedence over everything else
rolloutsEnv = envMerge(rolloutsEnv, proxyEnvVars(), false)

containerResources := cr.Spec.ControllerResources
if containerResources == nil {
containerResources = &corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceEphemeralStorage: resource.MustParse("1Gi"),
},
}
}

return corev1.Container{
Args: getRolloutsCommandArgs(cr),
Env: rolloutsEnv,
Expand Down Expand Up @@ -291,11 +300,6 @@ func rolloutsContainer(cr rolloutsmanagerv1alpha1.RolloutManager) corev1.Contain
SuccessThreshold: int32(1),
TimeoutSeconds: int32(4),
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceEphemeralStorage: resource.MustParse("1Gi"),
},
},
SecurityContext: &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{
Expand All @@ -319,6 +323,7 @@ func rolloutsContainer(cr rolloutsmanagerv1alpha1.RolloutManager) corev1.Contain
Name: "tmp",
},
},
Resources: *containerResources,
}

}
Expand Down
23 changes: 23 additions & 0 deletions controllers/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ var _ = Describe("Deployment Test", func() {
fetchedDeployment := &appsv1.Deployment{}
Expect(fetchObject(ctx, r.Client, a.Namespace, DefaultArgoRolloutsResourceName, fetchedDeployment)).To(Succeed())

a.Spec.ControllerResources = &corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("100m"),
corev1.ResourceMemory: resource.MustParse("100Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("500Mi"),
},
}
expectedDeployment := deploymentCR(DefaultArgoRolloutsResourceName, a.Namespace, DefaultArgoRolloutsResourceName, []string{"plugin-bin", "tmp"}, "linux", DefaultArgoRolloutsResourceName, a)

By("verify that the fetched Deployment matches the desired one")
Expand Down Expand Up @@ -96,6 +106,7 @@ var _ = Describe("Deployment Test", func() {
Expect(fetchedDeployment.Spec.Template.Spec.Tolerations).To(Equal(expectedDeployment.Spec.Template.Spec.Tolerations))
Expect(fetchedDeployment.Spec.Template.Spec.SecurityContext).To(Equal(expectedDeployment.Spec.Template.Spec.SecurityContext))
Expect(fetchedDeployment.Spec.Template.Spec.Volumes).To(Equal(expectedDeployment.Spec.Template.Spec.Volumes))
Expect(fetchedDeployment.Spec.Template.Spec.Containers[0].Resources).To(Equal(expectedDeployment.Spec.Template.Spec.Containers[0].Resources))

})
})
Expand Down Expand Up @@ -315,6 +326,18 @@ var _ = Describe("Deployment Test", func() {
Entry(".spec.template.spec.volumes", func(deployment *appsv1.Deployment) {
deployment.Spec.Template.Spec.Volumes = []corev1.Volume{{Name: "my-volume"}}
}),
Entry(".spec.template.spec.containes.resources", func(deployment *appsv1.Deployment) {
deployment.Spec.Template.Spec.Containers[0].Resources = corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("100m"),
corev1.ResourceMemory: resource.MustParse("100Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("500Mi"),
},
}
}),
)

})
Expand Down
21 changes: 21 additions & 0 deletions docs/crd_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,24 @@ spec:
myannotation: "myvalue"
```
### RolloutManager example with resources requests/limits for the Argo Rollouts controller
You can provide resources requests and limits for the Argo Rollouts controller.
``` yaml
apiVersion: argoproj.io/v1alpha1
kind: RolloutManager
metadata:
name: argo-rollout
labels:
example: with-resources-example
spec:
controllerResources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
```
15 changes: 15 additions & 0 deletions examples/custom_resources_rolloutmanager.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
apiVersion: argoproj.io/v1alpha1
kind: RolloutManager
metadata:
name: argo-rollout
labels:
example: with-resources-example
spec:
controllerResources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
38 changes: 38 additions & 0 deletions tests/e2e/rollout_tests_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -443,5 +444,42 @@ func RunRolloutsTests(namespaceScopedParam bool) {
expectMetadataOnObjectMeta(&service.ObjectMeta, rolloutsManager.Spec.AdditionalMetadata)
})
})

When("A RolloutManager specifies controller resources", func() {

It("should create the controller with the correct resources requests/limits", func() {

rolloutsManager := rolloutsmanagerv1alpha1.RolloutManager{
ObjectMeta: metav1.ObjectMeta{
Name: "basic-rollouts-manager-with-resources",
Namespace: fixture.TestE2ENamespace,
},
Spec: rolloutsmanagerv1alpha1.RolloutManagerSpec{
ControllerResources: &corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("100m"),
corev1.ResourceMemory: resource.MustParse("100Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("500Mi"),
},
},
NamespaceScoped: namespaceScopedParam,
},
}

Expect(k8sClient.Create(ctx, &rolloutsManager)).To(Succeed())

Eventually(rolloutsManager, "1m", "1s").Should(rolloutManagerFixture.HavePhase(rolloutsmanagerv1alpha1.PhaseAvailable))

deployment := appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: controllers.DefaultArgoRolloutsResourceName, Namespace: rolloutManager.Namespace},
}
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(&deployment), &deployment)).To(Succeed())

Expect(deployment.Spec.Template.Spec.Containers[0].Resources).To(Equal(*rolloutsManager.Spec.ControllerResources))
})
})
})
}

0 comments on commit 3992ad3

Please sign in to comment.