Skip to content

Commit

Permalink
feat: Enable config of sidecar resources
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Aug 9, 2021
1 parent 00c3178 commit d3a7a72
Show file tree
Hide file tree
Showing 11 changed files with 664 additions and 262 deletions.
784 changes: 527 additions & 257 deletions api/v1alpha1/generated.pb.go

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions api/v1alpha1/generated.proto

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

1 change: 1 addition & 0 deletions api/v1alpha1/get_pod_req.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ type GetPodSpecReq struct {
PullPolicy corev1.PullPolicy `protobuf:"bytes,6,opt,name=pullPolicy,casttype=k8s.io/api/core/v1.PullPolicy"`
UpdateInterval time.Duration `protobuf:"varint,7,opt,name=updateInterval,casttype=time.Duration"`
StepStatus StepStatus `protobuf:"bytes,8,opt,name=stepStatus"`
Sidecar Sidecar `protobuf:"bytes,10,opt,name=sidecar"`
}
8 changes: 8 additions & 0 deletions api/v1alpha1/sidecar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package v1alpha1

import corev1 "k8s.io/api/core/v1"

type Sidecar struct {
// +kubebuilder:default={limits: {"cpu": "500m", "memory": "256Mi"}, requests: {"cpu": "100m", "memory": "64Mi"}}
Resources corev1.ResourceRequirements `json:"resources,omitempty" protobuf:"bytes,1,opt,name=resources"`
}
2 changes: 2 additions & 0 deletions api/v1alpha1/step_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type StepSpec struct {
NodeSelector map[string]string `json:"nodeSelector,omitempty" protobuf:"bytes,17,rep,name=nodeSelector"`
Affinity *corev1.Affinity `json:"affinity,omitempty" protobuf:"bytes,18,opt,name=affinity"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty" protobuf:"bytes,19,rep,name=tolerations"`
// +kubebuilder:default={resources: {limits: {"cpu": "500m", "memory": "256Mi"}, requests: {"cpu": "100m", "memory": "64Mi"}}}
Sidecar Sidecar `json:"sidecar,omitempty" protobuf:"bytes,28,opt,name=sidecar"`
}

func (in StepSpec) GetIn() *Interface {
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/step_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (in Step) GetPodSpec(req GetPodSpecReq) corev1.PodSpec {
Args: []string{"sidecar"},
Env: envVars,
VolumeMounts: volumeMounts,
Resources: standardResources,
Resources: req.Sidecar.Resources,
Ports: []corev1.ContainerPort{
{ContainerPort: 3570},
},
Expand Down
9 changes: 5 additions & 4 deletions api/v1alpha1/step_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestStep_GetPodSpec(t *testing.T) {
{Name: "ARGO_DATAFLOW_NAMESPACE", Value: "my-ns"},
{Name: "ARGO_DATAFLOW_PIPELINE_NAME", Value: "my-pl"},
{Name: "ARGO_DATAFLOW_REPLICA", Value: "1"},
{Name: "ARGO_DATAFLOW_STEP", Value: `{"metadata":{"creationTimestamp":null},"spec":{"name":"main","cat":{}},"status":{"phase":"","replicas":0,"lastScaledAt":null}}`},
{Name: "ARGO_DATAFLOW_STEP", Value: `{"metadata":{"creationTimestamp":null},"spec":{"name":"main","cat":{},"sidecar":{"resources":{}}},"status":{"phase":"","replicas":0,"lastScaledAt":null}}`},
{Name: "ARGO_DATAFLOW_UPDATE_INTERVAL", Value: "1m0s"},
{Name: "GODEBUG"},
}
Expand Down Expand Up @@ -54,6 +54,7 @@ func TestStep_GetPodSpec(t *testing.T) {
PullPolicy: corev1.PullAlways,
StepStatus: StepStatus{Phase: StepRunning},
UpdateInterval: time.Minute,
Sidecar: Sidecar{Resources: standardResources},
},
corev1.PodSpec{
Containers: []corev1.Container{
Expand Down Expand Up @@ -134,9 +135,9 @@ func TestStep_GetPodSpec(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a, _ := json.MarshalIndent(tt.step.GetPodSpec(tt.req), "", " ")
b, _ := json.MarshalIndent(tt.want, "", " ")
assert.Equal(t, string(b), string(a))
got, _ := json.MarshalIndent(tt.step.GetPodSpec(tt.req), "", " ")
want, _ := json.MarshalIndent(tt.want, "", " ")
assert.Equal(t, string(want), string(got))
})
}
}
Expand Down
18 changes: 18 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.

46 changes: 46 additions & 0 deletions config/crd/bases/dataflow.argoproj.io_pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,52 @@ spec:
serviceAccountName:
default: pipeline
type: string
sidecar:
default:
resources:
limits:
cpu: 500m
memory: 256Mi
requests:
cpu: 100m
memory: 64Mi
properties:
resources:
default:
limits:
cpu: 500m
memory: 256Mi
requests:
cpu: 100m
memory: 64Mi
description: ResourceRequirements describes the compute
resource requirements.
properties:
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-compute-resources-container/'
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. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
type: object
sinks:
items:
properties:
Expand Down
45 changes: 45 additions & 0 deletions config/crd/bases/dataflow.argoproj.io_steps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,51 @@ spec:
serviceAccountName:
default: pipeline
type: string
sidecar:
default:
resources:
limits:
cpu: 500m
memory: 256Mi
requests:
cpu: 100m
memory: 64Mi
properties:
resources:
default:
limits:
cpu: 500m
memory: 256Mi
requests:
cpu: 100m
memory: 64Mi
description: ResourceRequirements describes the compute resource
requirements.
properties:
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-compute-resources-container/'
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. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
type: object
sinks:
items:
properties:
Expand Down
1 change: 1 addition & 0 deletions manager/controllers/step_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func (r *StepReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
PullPolicy: pullPolicy,
UpdateInterval: updateInterval,
StepStatus: step.Status,
Sidecar: step.Spec.Sidecar,
},
),
},
Expand Down

0 comments on commit d3a7a72

Please sign in to comment.