From ff437289dd28a3b56e01afc55a1a964510227be5 Mon Sep 17 00:00:00 2001 From: Martin Fleurke Date: Tue, 7 Jan 2025 14:31:00 +0100 Subject: [PATCH] fix for Bug #117073 - Cannot specify resource requests/limits for backup job, resulting in OOM Killed --- .../templates/deployment_cluster.yaml | 7 ++++ helm/mysql-innodbcluster/values.yaml | 35 ++++++++++++++++++- helm/mysql-operator/crds/crd.yaml | 9 +++++ mysqloperator/controller/backup/backup_api.py | 5 ++- .../controller/backup/backup_objects.py | 4 +++ 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/helm/mysql-innodbcluster/templates/deployment_cluster.yaml b/helm/mysql-innodbcluster/templates/deployment_cluster.yaml index 1668794e..1ed41973 100644 --- a/helm/mysql-innodbcluster/templates/deployment_cluster.yaml +++ b/helm/mysql-innodbcluster/templates/deployment_cluster.yaml @@ -280,6 +280,9 @@ spec: {{- end }} {{- if hasKey $profile "podLabels" }} podLabels: {{ toYaml $profile.podLabels | nindent 6 }} + {{- end }} + {{- if hasKey $profile "podLabels" }} + podSpec: {{ toYaml $profile.podSpec | nindent 6 }} {{- end }} {{- $isDumpInstance = hasKey $profile "dumpInstance" }} {{- $isSnapshot = hasKey $profile "snapshot" }} @@ -362,6 +365,10 @@ spec: {{- end }} {{- if hasKey $schedule.backupProfile "podLabels" }} podLabels: {{ toYaml $schedule.backupProfile.podLabels | nindent 8 }} + {{- end }} + # Pod Spec + {{- if hasKey $schedule.backupProfile "podSpec" }} + podSpec: {{ toYaml $schedule.backupProfile.podSpec | nindent 8 }} {{- end }} {{- if $isDumpInstance }} dumpInstance: diff --git a/helm/mysql-innodbcluster/values.yaml b/helm/mysql-innodbcluster/values.yaml index f790d8e9..178c0f5b 100644 --- a/helm/mysql-innodbcluster/values.yaml +++ b/helm/mysql-innodbcluster/values.yaml @@ -26,6 +26,11 @@ baseServerId: 1000 # instances: 1 # certAndPKsecretName: # podSpec: +# containers: +# - name: router +# resources: +# requests: +# limits: # podAnnotations: # podLabels: @@ -123,7 +128,15 @@ baseServerId: 1000 # limits: # memory: "8192Mi" # adapt to your needs # cpu: "3600m" # adapt to your needs -# +# initContainers: +# - name: initmysql +# resources: +# requests: +# memory: "2048Mi" # adapt to your needs +# cpu: "1000m" # adapt to your needs +# limits: +# memory: "2048Mi" # adapt to your needs +# cpu: "3000m" # adapt to your needs #podAnnotations: #podLabels: @@ -169,6 +182,20 @@ baseServerId: 1000 #backupProfiles: #- name: dump-instance-profile-pvc +# podLabels: +# podAnnotations: +# podSpec: +# containers: +# - name: operator-backup-job +# resources: +# requests: +# memory: "512Mi" # adapt to your needs +# cpu: "200m" # adapt to your needs +# ephemeral-storage: "160Mi" # adapt to your needs +# limits: +# memory: "512Mi" # adapt to your needs +# cpu: "900m" # adapt to your needs +# ephemeral-storage: "160Mi" # dumpInstance: # dumpOptions: # excludeSchemas: ["excludeme"] @@ -176,6 +203,9 @@ baseServerId: 1000 # persistentVolumeClaim: # claimName: backup-volume-claim-1 #- name: dump-instance-profile-oci +# podLabels: +# podAnnotations: +# podSpec: # dumpInstance: # dumpOptions: # excludeSchemas: ["excludeme"] @@ -186,6 +216,9 @@ baseServerId: 1000 # credentials: oci-credentials # #- name: snapshot-profile-oci +# podLabels: +# podAnnotations: +# podSpec: # snapshot: # storage: # ociObjectStorage: diff --git a/helm/mysql-operator/crds/crd.yaml b/helm/mysql-operator/crds/crd.yaml index 25ad6ffa..583c01d4 100644 --- a/helm/mysql-operator/crds/crd.yaml +++ b/helm/mysql-operator/crds/crd.yaml @@ -423,6 +423,9 @@ spec: podLabels: type: object x-kubernetes-preserve-unknown-fields: true + podSpec: + type: object + x-kubernetes-preserve-unknown-fields: true dumpInstance: type: object properties: @@ -570,6 +573,9 @@ spec: podLabels: type: object x-kubernetes-preserve-unknown-fields: true + podSpec: + type: object + x-kubernetes-preserve-unknown-fields: true dumpInstance: type: object properties: @@ -948,6 +954,9 @@ spec: podLabels: type: object x-kubernetes-preserve-unknown-fields: true + podSpec: + type: object + x-kubernetes-preserve-unknown-fields: true dumpInstance: type: object properties: diff --git a/mysqloperator/controller/backup/backup_api.py b/mysqloperator/controller/backup/backup_api.py index 1cbd3ecc..6719f5e9 100644 --- a/mysqloperator/controller/backup/backup_api.py +++ b/mysqloperator/controller/backup/backup_api.py @@ -67,6 +67,7 @@ def __init__(self): self.snapshot: Optional[Snapshot] = None self.podAnnotations: Optional[dict] = None self.podLabels: Optional[dict] = None + self.podSpec: Optional[dict] = None def add_to_pod_spec(self, pod_spec: dict, container_name: str) -> None: assert self.snapshot or self.dumpInstance @@ -82,6 +83,8 @@ def parse(self, spec: dict, prefix: str, name_required: bool = True) -> None: self.podAnnotations = dget_dict(spec, "podAnnotations", prefix) if "podLabels" in spec: self.podLabels = dget_dict(spec, "podLabels", prefix) + if "podSpec" in spec: + self.podSpec = dget_dict(spec, "podSpec", prefix) prefix += "." + self.name method_spec = dget_dict(spec, "dumpInstance", prefix, {}) @@ -102,7 +105,7 @@ def parse(self, spec: dict, prefix: str, name_required: bool = True) -> None: f"One of dumpInstance or snapshot must be set in a {prefix}") def __str__(self) -> str: - return f"Object BackupProfile name={self.name} dumpInstance={self.dumpInstance} snapshot={self.snapshot} podAnnotations={self.podAnnotations} podLabels={self.podLabels}" + return f"Object BackupProfile name={self.name} dumpInstance={self.dumpInstance} snapshot={self.snapshot} podAnnotations={self.podAnnotations} podLabels={self.podLabels} podSpec={self.podSpec}" def __eq__(self, other: 'BackupProfile') -> bool: assert other is None or isinstance(other, BackupProfile) diff --git a/mysqloperator/controller/backup/backup_objects.py b/mysqloperator/controller/backup/backup_objects.py index 3bea181f..d87a179d 100644 --- a/mysqloperator/controller/backup/backup_objects.py +++ b/mysqloperator/controller/backup/backup_objects.py @@ -116,6 +116,10 @@ def prepare_backup_job(jobname: str, spec: MySQLBackupSpec) -> dict: spec.add_to_pod_spec(job["spec"]["template"], "operator-backup-job") + if spec.backupProfile.podSpec: + utils.merge_patch_object(job["spec"]["template"]["spec"], + spec.backupProfile.podSpec, "spec.podSpec") + return job