Skip to content

Commit

Permalink
add construct resource requirements
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Yurkov <[email protected]>
  • Loading branch information
yurkov-anton committed Oct 29, 2021
1 parent c5391d2 commit 4b7c5c3
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 41 deletions.
34 changes: 15 additions & 19 deletions charts/csi-baremetal-deployment/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
{{- define "setResources" }}

{{- if .resources }}
{{- if or .resources.requests .resources.limits }}

{{- $requestsValues := .resources.requests | values | compact }}
{{- $limitsValues := .resources.limits | values | compact }}

{{- if or $requestsValues $limitsValues -}}
resources:
{{- if .resources.limits }}
limits:
{{- if .resources.limits.memory }}
memory: {{ .resources.limits.memory }}
{{- end }}
{{- if .resources.limits.cpu }}
cpu: {{ .resources.limits.cpu }}
{{- end }}
{{- if $limitsValues }}
limits:
{{- if .resources.limits.memory }}
memory: {{ .resources.limits.memory }}
{{- end }}
{{- if .resources.limits.cpu }}
cpu: {{ .resources.limits.cpu }}
{{- end }}
{{- end }}

{{- if .resources.requests }}
requests:
{{- if .resources.requests.memory }}
memory: {{ .resources.requests.memory }}
{{- end }}
{{- if .resources.requests.cpu }}
cpu: {{ .resources.requests.cpu }}
{{- end }}
{{- if $requestsValues }}
requests:
{{- if .resources.requests.memory }}
memory: {{ .resources.requests.memory }}
{{- end }}
{{- if .resources.requests.cpu }}
cpu: {{ .resources.requests.cpu }}
{{- end }}
{{- end }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ spec:
image:
name: csi-baremetal-controller
tag: {{ .Values.driver.controller.image.tag | default .Values.image.tag }}
{{- include "setResources" .Values.driver.controller | nindent 6 }}
resources:
{{- include "setResources" .Values.driver.controller | indent 8 }}
log:
format: {{ .Values.driver.log.format }}
level: {{ .Values.driver.log.level }}
Expand All @@ -33,28 +34,33 @@ spec:
image:
name: livenessprobe
tag: {{ .Values.driver.livenessProbe.image.tag }}
{{- include "setResources" .Values.driver.livenessProbe | nindent 10 }}
resources:
{{- include "setResources" .Values.driver.livenessProbe | indent 12 }}
csi-provisioner:
image:
name: csi-provisioner
tag: {{ .Values.driver.provisioner.image.tag }}
{{- include "setResources" .Values.driver.provisioner | nindent 10 }}
resources:
{{- include "setResources" .Values.driver.provisioner | indent 12 }}
csi-resizer:
image:
name: csi-resizer
tag: {{ .Values.driver.resizer.image.tag }}
{{- include "setResources" .Values.driver.resizer | nindent 10 }}
resources:
{{- include "setResources" .Values.driver.resizer | indent 12 }}
node:
driveMgr:
image:
name: csi-baremetal-{{ .Values.driver.drivemgr.type }}
tag: {{ .Values.driver.drivemgr.image.tag | default .Values.image.tag }}
{{- include "setResources" .Values.driver.drivemgr | nindent 8 }}
resources:
{{- include "setResources" .Values.driver.drivemgr | indent 10 }}
endpoint: {{ .Values.driver.drivemgr.grpc.server.endpoint }}
image:
name: csi-baremetal-node
tag: {{ .Values.driver.node.image.tag | default .Values.image.tag }}
{{- include "setResources" .Values.driver.node | nindent 6 }}
resources:
{{- include "setResources" .Values.driver.node | indent 8 }}
log:
format: {{ .Values.driver.log.format }}
level: {{ .Values.driver.log.level }}
Expand All @@ -63,12 +69,14 @@ spec:
image:
name: csi-node-driver-registrar
tag: {{ .Values.driver.nodeDriverRegistrar.image.tag }}
{{- include "setResources" .Values.driver.nodeDriverRegistrar | nindent 10 }}
resources:
{{- include "setResources" .Values.driver.nodeDriverRegistrar | indent 12 }}
livenessprobe:
image:
name: livenessprobe
tag: {{ .Values.driver.livenessProbe.image.tag }}
{{- include "setResources" .Values.driver.livenessProbe | nindent 10 }}
resources:
{{- include "setResources" .Values.driver.livenessProbe | indent 12 }}
metrics:
path: {{ .Values.driver.metrics.path }}
port: {{ .Values.driver.metrics.port }}
Expand All @@ -82,7 +90,8 @@ spec:
image:
name: csi-baremetal-scheduler-extender
tag: {{ .Values.scheduler.image.tag | default .Values.image.tag }}
{{- include "setResources" .Values.scheduler | nindent 4 }}
resources:
{{- include "setResources" .Values.scheduler | indent 6 }}
log:
format: {{ .Values.scheduler.log.format }}
level: {{ .Values.scheduler.log.level }}
Expand All @@ -95,7 +104,8 @@ spec:
image:
name: csi-baremetal-scheduler-patcher
tag: {{ .Values.scheduler.patcher.image.tag | default .Values.image.tag }}
{{- include "setResources" .Values.scheduler.patcher | nindent 6 }}
resources:
{{- include "setResources" .Values.scheduler.patcher | indent 8 }}
interval: {{ .Values.scheduler.patcher.interval }}
restoreOnShutdown: {{ .Values.scheduler.patcher.restore_on_shutdown }}
configMapName: {{ .Values.scheduler.patcher.config_map_name }}
Expand All @@ -106,7 +116,8 @@ spec:
image:
name: csi-baremetal-node-controller
tag: {{ .Values.nodeController.image.tag | default .Values.image.tag }}
{{- include "setResources" .Values.nodeController | nindent 4 }}
resources:
{{- include "setResources" .Values.nodeController | indent 6 }}
log:
format: {{ .Values.nodeController.log.format }}
level: {{ .Values.nodeController.log.level }}
8 changes: 8 additions & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,11 @@ func ConstructSelectorMap(appName string) map[string]string {
constant.SelectorKey: appName,
}
}

// ConstructResourceRequirements creates the ResourceRequirements contains Limits and Requests lists
func ConstructResourceRequirements(resources *components.ResourceRequirements) corev1.ResourceRequirements {
if resources != nil {
return corev1.ResourceRequirements(*resources)
}
return corev1.ResourceRequirements{}
}
8 changes: 4 additions & 4 deletions pkg/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func createControllerContainers(csi *csibaremetalv1.Deployment) []corev1.Contain
},
TerminationMessagePath: constant.TerminationMessagePath,
TerminationMessagePolicy: constant.TerminationMessagePolicy,
Resources: corev1.ResourceRequirements(*c.Resources),
Resources: common.ConstructResourceRequirements(c.Resources),
},
{
Name: constant.ProvisionerName,
Expand All @@ -206,7 +206,7 @@ func createControllerContainers(csi *csibaremetalv1.Deployment) []corev1.Contain
},
TerminationMessagePath: constant.TerminationMessagePath,
TerminationMessagePolicy: constant.TerminationMessagePolicy,
Resources: corev1.ResourceRequirements(*provisioner.Resources),
Resources: common.ConstructResourceRequirements(provisioner.Resources),
},
{
Name: constant.ResizerName,
Expand All @@ -227,7 +227,7 @@ func createControllerContainers(csi *csibaremetalv1.Deployment) []corev1.Contain
},
TerminationMessagePath: constant.TerminationMessagePath,
TerminationMessagePolicy: constant.TerminationMessagePolicy,
Resources: corev1.ResourceRequirements(*resizer.Resources),
Resources: common.ConstructResourceRequirements(resizer.Resources),
},
{
Name: constant.LivenessProbeName,
Expand All @@ -243,7 +243,7 @@ func createControllerContainers(csi *csibaremetalv1.Deployment) []corev1.Contain
},
TerminationMessagePath: constant.TerminationMessagePath,
TerminationMessagePolicy: constant.TerminationMessagePolicy,
Resources: corev1.ResourceRequirements(*liveness.Resources),
Resources: common.ConstructResourceRequirements(liveness.Resources),
},
}
}
8 changes: 4 additions & 4 deletions pkg/node/node_daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func createNodeContainers(csi *csibaremetalv1.Deployment, platform *PlatformDesc
},
TerminationMessagePath: constant.TerminationMessagePath,
TerminationMessagePolicy: constant.TerminationMessagePolicy,
Resources: corev1.ResourceRequirements(*lp.Resources),
Resources: common.ConstructResourceRequirements(lp.Resources),
},
{
Name: constant.DriverRegistrarName,
Expand All @@ -228,7 +228,7 @@ func createNodeContainers(csi *csibaremetalv1.Deployment, platform *PlatformDesc
},
TerminationMessagePath: constant.TerminationMessagePath,
TerminationMessagePolicy: constant.TerminationMessagePolicy,
Resources: corev1.ResourceRequirements(*dr.Resources),
Resources: common.ConstructResourceRequirements(dr.Resources),
},
{
Name: "node",
Expand Down Expand Up @@ -287,7 +287,7 @@ func createNodeContainers(csi *csibaremetalv1.Deployment, platform *PlatformDesc
VolumeMounts: nodeMounts,
TerminationMessagePath: constant.TerminationMessagePath,
TerminationMessagePolicy: constant.TerminationMessagePolicy,
Resources: corev1.ResourceRequirements(*node.Resources),
Resources: common.ConstructResourceRequirements(node.Resources),
},
{
Name: "drivemgr",
Expand All @@ -304,7 +304,7 @@ func createNodeContainers(csi *csibaremetalv1.Deployment, platform *PlatformDesc
VolumeMounts: driveMgrMounts,
TerminationMessagePath: constant.TerminationMessagePath,
TerminationMessagePolicy: constant.TerminationMessagePolicy,
Resources: corev1.ResourceRequirements(*driveMgr.Resources),
Resources: common.ConstructResourceRequirements(driveMgr.Resources),
},
}
}
2 changes: 1 addition & 1 deletion pkg/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func createNodeControllerContainers(csi *csibaremetalv1.Deployment) []corev1.Con
TerminationMessagePath: constant.TerminationMessagePath,
TerminationMessagePolicy: constant.TerminationMessagePolicy,
VolumeMounts: []corev1.VolumeMount{constant.CrashMountVolume},
Resources: corev1.ResourceRequirements(*resources),
Resources: common.ConstructResourceRequirements(resources),
},
}
}
2 changes: 1 addition & 1 deletion pkg/patcher/scheduler_patcher_vanilla.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (p patcherConfiguration) createPatcherContainers() []corev1.Container {
},
TerminationMessagePath: constant.TerminationMessagePath,
TerminationMessagePolicy: constant.TerminationMessagePolicy,
Resources: corev1.ResourceRequirements(*p.resources),
Resources: common.ConstructResourceRequirements(p.resources),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler_extender.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func createExtenderContainers(csi *csibaremetalv1.Deployment, isPatchingEnabled
TerminationMessagePath: constant.TerminationMessagePath,
TerminationMessagePolicy: constant.TerminationMessagePolicy,
VolumeMounts: volumeMounts,
Resources: corev1.ResourceRequirements(*csi.Spec.Scheduler.Resources),
Resources: common.ConstructResourceRequirements(csi.Spec.Scheduler.Resources),
},
}
}

0 comments on commit 4b7c5c3

Please sign in to comment.