Skip to content

Commit 837f5fc

Browse files
allow resource specification in MCAD CR
1 parent 938e70f commit 837f5fc

File tree

6 files changed

+91
-19
lines changed

6 files changed

+91
-19
lines changed

api/v1alpha1/mcad_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
v1 "k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

@@ -47,6 +48,11 @@ type MCADSpec struct {
4748
// PodCreationTimeout TODO: Add details and confirm values
4849
// +kubebuilder:default=-1
4950
PodCreationTimeout int `json:"podCreationTimeout,omitempty"`
51+
//podCreationTimeout: //int (default blank)
52+
53+
// ControllerResources TODO: Add details
54+
// +kubebuilder:default={}
55+
ControllerResources v1.ResourceRequirements `json:"controllerResources,omitempty" protobuf:"bytes,8,opt"`
5056
}
5157

5258
// MCADStatus defines the observed state of MCAD

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/codeflare.codeflare.dev_mcads.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,52 @@ spec:
3838
agentConfigs:
3939
description: 'AgentConfigs TODO: Add details'
4040
type: string
41+
controllerResources:
42+
description: 'ControllerResources TODO: Add details'
43+
properties:
44+
claims:
45+
description: "Claims lists the names of resources, defined in
46+
spec.resourceClaims, that are used by this container. \n This
47+
is an alpha field and requires enabling the DynamicResourceAllocation
48+
feature gate. \n This field is immutable."
49+
items:
50+
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
51+
properties:
52+
name:
53+
description: Name must match the name of one entry in pod.spec.resourceClaims
54+
of the Pod where this field is used. It makes that resource
55+
available inside a container.
56+
type: string
57+
required:
58+
- name
59+
type: object
60+
type: array
61+
x-kubernetes-list-map-keys:
62+
- name
63+
x-kubernetes-list-type: map
64+
limits:
65+
additionalProperties:
66+
anyOf:
67+
- type: integer
68+
- type: string
69+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
70+
x-kubernetes-int-or-string: true
71+
description: 'Limits describes the maximum amount of compute resources
72+
allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
73+
type: object
74+
requests:
75+
additionalProperties:
76+
anyOf:
77+
- type: integer
78+
- type: string
79+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
80+
x-kubernetes-int-or-string: true
81+
description: 'Requests describes the minimum amount of compute
82+
resources required. If Requests is omitted for a container,
83+
it defaults to Limits if that is explicitly specified, otherwise
84+
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
85+
type: object
86+
type: object
4187
dispatcherMode:
4288
default: false
4389
description: DispatcherMode determines whether the MCAD Controller

config/internal/mcad/deployment.yaml.tmpl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ spec:
3434
- name: http
3535
containerPort: 8080
3636
protocol: TCP
37-
resources:
38-
limits:
39-
cpu: '2'
40-
memory: 2Gi
41-
requests:
42-
cpu: '2'
43-
memory: 2Gi
37+
resources: {{.ControllerResources}}
4438
terminationMessagePath: /dev/termination-log
4539
terminationMessagePolicy: File
4640
volumeMounts:

controllers/mcad_params.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
package controllers
22

33
import (
4+
"encoding/json"
5+
46
mf "github.com/manifestival/manifestival"
57
mcadv1alpha1 "github.com/project-codeflare/codeflare-operator/api/v1alpha1"
8+
v1 "k8s.io/api/core/v1"
69
)
710

811
type MCADParams struct {
9-
Name string
10-
Namespace string
11-
Owner mf.Owner
12-
EnableMonitoring bool
13-
MultiCluster bool
14-
DispatcherMode bool
15-
PreemptionEnabled bool
16-
AgentConfigs string
17-
QuotaRestURL string
18-
PodCreationTimeout int
12+
Name string
13+
Namespace string
14+
Owner mf.Owner
15+
EnableMonitoring bool
16+
MultiCluster bool
17+
DispatcherMode bool
18+
PreemptionEnabled bool
19+
AgentConfigs string
20+
QuotaRestURL string
21+
PodCreationTimeout int
22+
ControllerResources ControllerResources
23+
}
24+
25+
type ControllerResources struct {
26+
v1.ResourceRequirements
27+
}
28+
29+
func (c *ControllerResources) String() string {
30+
raw, err := json.Marshal(c)
31+
if err != nil {
32+
return "{}"
33+
} else {
34+
return string(raw)
35+
}
1936
}
2037

2138
// ExtractParams is currently a straight-up copy. We can add in more complex validation at a later date
@@ -30,6 +47,7 @@ func (p *MCADParams) ExtractParams(mcad *mcadv1alpha1.MCAD) error {
3047
p.AgentConfigs = mcad.Spec.AgentConfigs
3148
p.QuotaRestURL = mcad.Spec.QuotaRestURL
3249
p.PodCreationTimeout = mcad.Spec.PodCreationTimeout
50+
p.ControllerResources = ControllerResources{mcad.Spec.ControllerResources}
3351

3452
return nil
3553
}

controllers/testdata/mcad_test_cases/case_1.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@ apiVersion: codeflare.codeflare.dev/v1alpha1
22
kind: MCAD
33
metadata:
44
name: blank-custom-resource
5-
spec: {}
5+
spec:
6+
controllerResources:
7+
limits:
8+
cpu: '2'
9+
memory: 2G
10+
requests:
11+
cpu: '2'
12+
memory: 2G

0 commit comments

Comments
 (0)