Skip to content

Commit 3ced964

Browse files
committed
permit specifying daemonset and deployment resources
closes #853 Signed-off-by: Clément Nussbaumer <clement.nussbaumer@postfinance.ch>
1 parent adf8832 commit 3ced964

File tree

7 files changed

+198
-94
lines changed

7 files changed

+198
-94
lines changed

cli/k8s_client/types.go

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -167,33 +167,35 @@ type DeploymentYAMLArguments struct {
167167
CloudProvider string `json:"cloudProvider"`
168168
IdentityLabel bool `json:"identityLabel"`
169169
K8sAPIQPS int `json:"k8sAPIQPS"`
170+
Resources *v1.ResourceRequirements `json:"resources"`
170171
}
171172

172173
type DaemonsetYAMLArguments struct {
173-
DaemonsetName string `json:"daemonsetName"`
174-
TridentImage string `json:"tridentImage"`
175-
ImageRegistry string `json:"imageRegistry"`
176-
KubeletDir string `json:"kubeletDir"`
177-
LogFormat string `json:"logFormat"`
178-
LogLevel string `json:"logLevel"`
179-
LogWorkflows string `json:"logWorkflows"`
180-
LogLayers string `json:"logLayers"`
181-
ProbePort string `json:"probePort"`
182-
ImagePullSecrets []string `json:"imagePullSecrets"`
183-
Labels map[string]string `json:"labels"`
184-
ControllingCRDetails map[string]string `json:"controllingCRDetails"`
185-
EnableForceDetach bool `json:"enableForceDetach"`
186-
DisableAuditLog bool `json:"disableAuditLog"`
187-
Debug bool `json:"debug"`
188-
Version *versionutils.Version `json:"version"`
189-
HTTPRequestTimeout string `json:"httpRequestTimeout"`
190-
NodeSelector map[string]string `json:"nodeSelector"`
191-
Tolerations []map[string]string `json:"tolerations"`
192-
ServiceAccountName string `json:"serviceAccountName"`
193-
ImagePullPolicy string `json:"imagePullPolicy"`
194-
ISCSISelfHealingInterval string `json:"iscsiSelfHealingInterval"`
195-
ISCSISelfHealingWaitTime string `json:"iscsiSelfHealingWaitTime"`
196-
NodePrep []string `json:"nodePrep"`
174+
DaemonsetName string `json:"daemonsetName"`
175+
TridentImage string `json:"tridentImage"`
176+
ImageRegistry string `json:"imageRegistry"`
177+
KubeletDir string `json:"kubeletDir"`
178+
LogFormat string `json:"logFormat"`
179+
LogLevel string `json:"logLevel"`
180+
LogWorkflows string `json:"logWorkflows"`
181+
LogLayers string `json:"logLayers"`
182+
ProbePort string `json:"probePort"`
183+
ImagePullSecrets []string `json:"imagePullSecrets"`
184+
Labels map[string]string `json:"labels"`
185+
ControllingCRDetails map[string]string `json:"controllingCRDetails"`
186+
EnableForceDetach bool `json:"enableForceDetach"`
187+
DisableAuditLog bool `json:"disableAuditLog"`
188+
Debug bool `json:"debug"`
189+
Version *versionutils.Version `json:"version"`
190+
HTTPRequestTimeout string `json:"httpRequestTimeout"`
191+
NodeSelector map[string]string `json:"nodeSelector"`
192+
Tolerations []map[string]string `json:"tolerations"`
193+
ServiceAccountName string `json:"serviceAccountName"`
194+
ImagePullPolicy string `json:"imagePullPolicy"`
195+
ISCSISelfHealingInterval string `json:"iscsiSelfHealingInterval"`
196+
ISCSISelfHealingWaitTime string `json:"iscsiSelfHealingWaitTime"`
197+
NodePrep []string `json:"nodePrep"`
198+
Resources *v1.ResourceRequirements `json:"resources"`
197199
}
198200

199201
type TridentVersionPodYAMLArguments struct {

cli/k8s_client/yaml_factory.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
commonconfig "github.com/netapp/trident/config"
1212
. "github.com/netapp/trident/logging"
1313
"github.com/netapp/trident/utils"
14+
v1 "k8s.io/api/core/v1"
15+
"sigs.k8s.io/yaml"
1416
)
1517

1618
const (
@@ -502,6 +504,7 @@ func GetCSIDeploymentYAML(args *DeploymentYAMLArguments) string {
502504
deploymentYAML = utils.ReplaceMultilineYAMLTag(deploymentYAML, "OWNER_REF", constructOwnerRef(args.ControllingCRDetails))
503505
deploymentYAML = utils.ReplaceMultilineYAMLTag(deploymentYAML, "NODE_SELECTOR", constructNodeSelector(args.NodeSelector))
504506
deploymentYAML = utils.ReplaceMultilineYAMLTag(deploymentYAML, "NODE_TOLERATIONS", constructTolerations(args.Tolerations))
507+
deploymentYAML = utils.ReplaceMultilineYAMLTag(deploymentYAML, "RESOURCES", constructResources(args.Resources))
505508
deploymentYAML = strings.ReplaceAll(deploymentYAML, "{ENABLE_FORCE_DETACH}", strconv.FormatBool(args.EnableForceDetach))
506509
deploymentYAML = strings.ReplaceAll(deploymentYAML, "{ENABLE_ACP}", enableACP)
507510
deploymentYAML = strings.ReplaceAll(deploymentYAML, "{K8S_API_CLIENT_TRIDENT_THROTTLE}", K8sAPITridentThrottle)
@@ -572,6 +575,7 @@ spec:
572575
{ENABLE_ACP}
573576
{DEBUG}
574577
{K8S_API_CLIENT_TRIDENT_THROTTLE}
578+
{RESOURCES}
575579
livenessProbe:
576580
exec:
577581
command:
@@ -625,9 +629,7 @@ spec:
625629
{AUTOSUPPORT_HOSTNAME}
626630
{AUTOSUPPORT_DEBUG}
627631
{AUTOSUPPORT_INSECURE}
628-
resources:
629-
limits:
630-
memory: 1Gi
632+
{RESOURCES}
631633
volumeMounts:
632634
- name: asup-dir
633635
mountPath: /asup
@@ -645,6 +647,7 @@ spec:
645647
- "--retry-interval-start=8s"
646648
- "--retry-interval-max=30s"
647649
{K8S_API_CLIENT_SIDECAR_THROTTLE}
650+
{RESOURCES}
648651
env:
649652
- name: ADDRESS
650653
value: /var/lib/csi/sockets/pluginproxy/csi.sock
@@ -664,6 +667,7 @@ spec:
664667
- "--retry-interval-start=10s"
665668
- "--csi-address=$(ADDRESS)"
666669
{K8S_API_CLIENT_SIDECAR_THROTTLE}
670+
{RESOURCES}
667671
env:
668672
- name: ADDRESS
669673
value: /var/lib/csi/sockets/pluginproxy/csi.sock
@@ -678,6 +682,7 @@ spec:
678682
- "--timeout=300s"
679683
- "--csi-address=$(ADDRESS)"
680684
{K8S_API_CLIENT_SIDECAR_THROTTLE}
685+
{RESOURCES}
681686
env:
682687
- name: ADDRESS
683688
value: /var/lib/csi/sockets/pluginproxy/csi.sock
@@ -696,6 +701,7 @@ spec:
696701
- "--timeout=300s"
697702
- "--csi-address=$(ADDRESS)"
698703
{K8S_API_CLIENT_SIDECAR_THROTTLE}
704+
{RESOURCES}
699705
env:
700706
- name: ADDRESS
701707
value: /var/lib/csi/sockets/pluginproxy/csi.sock
@@ -886,6 +892,7 @@ func GetCSIDaemonSetYAMLLinux(args *DaemonsetYAMLArguments) string {
886892
daemonSetYAML = utils.ReplaceMultilineYAMLTag(daemonSetYAML, "NODE_TOLERATIONS", constructTolerations(tolerations))
887893
daemonSetYAML = utils.ReplaceMultilineYAMLTag(daemonSetYAML, "LABELS", constructLabels(args.Labels))
888894
daemonSetYAML = utils.ReplaceMultilineYAMLTag(daemonSetYAML, "OWNER_REF", constructOwnerRef(args.ControllingCRDetails))
895+
daemonSetYAML = utils.ReplaceMultilineYAMLTag(daemonSetYAML, "RESOURCES", constructResources(args.Resources))
889896

890897
// Log before secrets are inserted into YAML.
891898
Log().WithField("yaml", daemonSetYAML).Trace("CSI Daemonset Linux YAML.")
@@ -1033,6 +1040,7 @@ spec:
10331040
timeoutSeconds: 5
10341041
periodSeconds: 10
10351042
initialDelaySeconds: 15
1043+
{RESOURCES}
10361044
env:
10371045
- name: KUBE_NODE_NAME
10381046
valueFrom:
@@ -1074,6 +1082,7 @@ spec:
10741082
- "--v={SIDECAR_LOG_LEVEL}"
10751083
- "--csi-address=$(ADDRESS)"
10761084
- "--kubelet-registration-path=$(REGISTRATION_PATH)"
1085+
{RESOURCES}
10771086
env:
10781087
- name: ADDRESS
10791088
value: /plugin/csi.sock
@@ -2654,6 +2663,16 @@ func constructOwnerRef(ownerRef map[string]string) string {
26542663
return ownerRefData
26552664
}
26562665

2666+
func constructResources(res *v1.ResourceRequirements) string {
2667+
r := struct {
2668+
Resources *v1.ResourceRequirements `json:"resources"`
2669+
}{
2670+
Resources: res,
2671+
}
2672+
bytes, _ := yaml.Marshal(r)
2673+
return string(bytes)
2674+
}
2675+
26572676
func constructImagePullSecrets(imagePullSecrets []string) string {
26582677
var imagePullSecretsData string
26592678
if len(imagePullSecrets) > 0 {

cli/k8s_client/yaml_factory_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
v1 "k8s.io/api/core/v1"
1616
csiv1 "k8s.io/api/storage/v1"
1717
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
18+
"k8s.io/apimachinery/pkg/api/resource"
1819
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1920

2021
"github.com/netapp/trident/config"
@@ -513,6 +514,30 @@ func TestGetCSIDeploymentYAML_K8sAPIQPS(t *testing.T) {
513514
}
514515
}
515516

517+
func TestGetCSIDeploymentYAML_Resources(t *testing.T) {
518+
args := &DeploymentYAMLArguments{Resources: &v1.ResourceRequirements{
519+
Limits: v1.ResourceList{v1.ResourceCPU: resource.MustParse("114m"), v1.ResourceMemory: resource.MustParse("256Mi")},
520+
Requests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("200m"), v1.ResourceMemory: resource.MustParse("512Mi")},
521+
}}
522+
523+
expectedResourcesString := `
524+
resources:
525+
limits:
526+
cpu: 114m
527+
memory: 256Mi
528+
requests:
529+
cpu: 200m
530+
memory: 512Mi
531+
`
532+
yamlData := GetCSIDeploymentYAML(args)
533+
_, err := yaml.YAMLToJSON([]byte(yamlData))
534+
if err != nil {
535+
t.Fatalf("expected valid YAML, got %s", yamlData)
536+
}
537+
assert.Contains(t, yamlData, expectedResourcesString,
538+
fmt.Sprintf("expected resources in final YAML: %s", yamlData))
539+
}
540+
516541
func TestGetCSIDaemonSetYAMLLinux(t *testing.T) {
517542
versions := []string{"1.21.0", "1.23.0", "1.25.0"}
518543

@@ -858,6 +883,30 @@ func TestGetCSIDaemonSetYAMLLinux_Tolerations(t *testing.T) {
858883
fmt.Sprintf("expected default tolerations to not appear in final YAML: %s", yamlData))
859884
}
860885

886+
func TestGetCSIDaemonSetYAMLLinux_Resources(t *testing.T) {
887+
args := &DaemonsetYAMLArguments{Resources: &v1.ResourceRequirements{
888+
Limits: v1.ResourceList{v1.ResourceCPU: resource.MustParse("114m"), v1.ResourceMemory: resource.MustParse("256Mi")},
889+
Requests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("200m"), v1.ResourceMemory: resource.MustParse("512Mi")},
890+
}}
891+
892+
expectedResourcesString := `
893+
resources:
894+
limits:
895+
cpu: 114m
896+
memory: 256Mi
897+
requests:
898+
cpu: 200m
899+
memory: 512Mi
900+
`
901+
yamlData := GetCSIDaemonSetYAMLLinux(args)
902+
_, err := yaml.YAMLToJSON([]byte(yamlData))
903+
if err != nil {
904+
t.Fatalf("expected valid YAML, got %s", yamlData)
905+
}
906+
assert.Contains(t, yamlData, expectedResourcesString,
907+
fmt.Sprintf("expected resources in final YAML: %s", yamlData))
908+
}
909+
861910
func TestGetCSIDaemonSetYAMLWindows(t *testing.T) {
862911
versions := []string{"1.21.0", "1.23.0", "1.25.0"}
863912

helm/trident-operator/templates/tridentorchestrator.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ spec:
1717
{{- if .Values.tridentDebug }}
1818
debug: {{ .Values.tridentDebug }}
1919
{{- end }}
20+
daemonsetResources:
21+
{{- toYaml .Values.tridentDaemonsetResources | nindent 4 }}
22+
deploymentResources:
23+
{{- toYaml .Values.tridentDeploymentResources | nindent 4 }}
2024
{{- if .Values.tridentLogLevel }}
2125
logLevel: {{ .Values.tridentLogLevel }}
2226
{{- end }}

helm/trident-operator/values.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ tridentDisableAuditLog: true
112112
# tridentDebug allows the log level of Trident to be set to debug
113113
tridentDebug: false
114114

115+
# tridentDaemonsetResources permits specifying the resources for all containers of the trident-node daemonset. example:
116+
# tridentDaemonsetResources:
117+
# requests:
118+
# cpu: 250m
119+
# limits:
120+
# cpu: 100m
121+
# memory: 1Gi
122+
tridentDaemonsetResources: {}
123+
124+
# tridentDeploymentResources permits specifying the resources for all containers of the trident-controller deployment.
125+
tridentDeploymentResources:
126+
115127
# tridentLogWorkflows allows specific Trident workflows to be enabled for trace logging or log suppression.
116128
tridentLogWorkflows: ""
117129

operator/controllers/orchestrator/installer/installer.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ var (
103103

104104
nodePrep []string
105105

106+
daemonsetResources *v1.ResourceRequirements
107+
deploymentResources *v1.ResourceRequirements
108+
106109
CRDnames = []string{
107110
ActionMirrorUpdateCRDName,
108111
ActionSnapshotRestoreCRDName,
@@ -394,6 +397,14 @@ func (i *Installer) setInstallationParams(
394397

395398
nodePrep = protocol.FormatProtocols(cr.Spec.NodePrep)
396399

400+
if cr.Spec.DaemonsetResources != nil {
401+
daemonsetResources = cr.Spec.DaemonsetResources
402+
}
403+
404+
if cr.Spec.DeploymentResources != nil {
405+
deploymentResources = cr.Spec.DeploymentResources
406+
}
407+
397408
if cr.Spec.ProbePort != nil {
398409
probePort = strconv.FormatInt(*cr.Spec.ProbePort, 10)
399410
}
@@ -1415,6 +1426,7 @@ func (i *Installer) createOrPatchTridentDeployment(
14151426
EnableACP: enableACP,
14161427
IdentityLabel: identityLabel,
14171428
K8sAPIQPS: k8sAPIQPS,
1429+
Resources: deploymentResources,
14181430
}
14191431

14201432
newDeploymentYAML := k8sclient.GetCSIDeploymentYAML(deploymentArgs)
@@ -1495,6 +1507,7 @@ func (i *Installer) createOrPatchTridentDaemonSet(
14951507
ISCSISelfHealingInterval: iscsiSelfHealingInterval,
14961508
ISCSISelfHealingWaitTime: iscsiSelfHealingWaitTime,
14971509
NodePrep: nodePrep,
1510+
Resources: daemonsetResources,
14981511
}
14991512

15001513
var newDaemonSetYAML string

0 commit comments

Comments
 (0)