diff --git a/packages/kontinuous/tests/__snapshots__/extends-ovh.prod.yaml b/packages/kontinuous/tests/__snapshots__/extends-ovh.prod.yaml index 6475aa614..d45ebade9 100644 --- a/packages/kontinuous/tests/__snapshots__/extends-ovh.prod.yaml +++ b/packages/kontinuous/tests/__snapshots__/extends-ovh.prod.yaml @@ -158,6 +158,21 @@ spec: value: pg-hasura-r - name: RETENTION_DAYS value: \\"60\\" + affinity: + nodeAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + preference: + matchExpressions: + - key: nodepool + operator: In + values: + - prod-build + tolerations: + - key: pool + operator: Equal + value: ci + effect: NoSchedule --- apiVersion: batch/v1 kind: CronJob @@ -239,6 +254,21 @@ spec: value: pg-keycloak-r - name: RETENTION_DAYS value: \\"60\\" + affinity: + nodeAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + preference: + matchExpressions: + - key: nodepool + operator: In + values: + - prod-build + tolerations: + - key: pool + operator: Equal + value: ci + effect: NoSchedule --- apiVersion: batch/v1 kind: Job diff --git a/packages/kontinuous/tests/__snapshots__/override-env-default.dev.yaml b/packages/kontinuous/tests/__snapshots__/override-env-default.dev.yaml index fa0a824e9..1235e642c 100644 --- a/packages/kontinuous/tests/__snapshots__/override-env-default.dev.yaml +++ b/packages/kontinuous/tests/__snapshots__/override-env-default.dev.yaml @@ -158,6 +158,21 @@ spec: value: pg-r - name: RETENTION_DAYS value: \\"60\\" + affinity: + nodeAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + preference: + matchExpressions: + - key: nodepool + operator: In + values: + - prod-build + tolerations: + - key: pool + operator: Equal + value: ci + effect: NoSchedule --- apiVersion: batch/v1 kind: Job diff --git a/packages/kontinuous/tests/__snapshots__/pg.prod.yaml b/packages/kontinuous/tests/__snapshots__/pg.prod.yaml index 81eea6c0e..b3dbb2e3b 100644 --- a/packages/kontinuous/tests/__snapshots__/pg.prod.yaml +++ b/packages/kontinuous/tests/__snapshots__/pg.prod.yaml @@ -158,6 +158,21 @@ spec: value: cnpg-r - name: RETENTION_DAYS value: \\"60\\" + affinity: + nodeAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + preference: + matchExpressions: + - key: nodepool + operator: In + values: + - prod-build + tolerations: + - key: pool + operator: Equal + value: ci + effect: NoSchedule --- apiVersion: batch/v1 kind: Job diff --git a/plugins/contrib/patches/40-add-jobs-affinity-and-tolerations.js b/plugins/contrib/patches/40-add-jobs-affinity-and-tolerations.js index 1264ca336..1fd655376 100644 --- a/plugins/contrib/patches/40-add-jobs-affinity-and-tolerations.js +++ b/plugins/contrib/patches/40-add-jobs-affinity-and-tolerations.js @@ -1,20 +1,25 @@ module.exports = (manifests, options) => { - const { affinityToAdd = {}, tolerationsToAdd = [] } = options + const { + affinityToAdd = {}, + tolerationsToAdd = [], + cronjobEnabled = true, + } = options for (const manifest of manifests) { - if (manifest.kind !== "Job") { + const { kind } = manifest + if (!(kind === "Job" || (kind === "CronJob" && cronjobEnabled))) { continue } - manifest.spec.template.spec = manifest.spec.template.spec || {} - const templateSpec = manifest.spec.template.spec + const parentSpec = kind === "CronJob" ? manifest.spec.jobTemplate : manifest + + parentSpec.spec.template.spec ||= {} + const templateSpec = parentSpec.spec.template.spec // Add or merge affinity - templateSpec.affinity = templateSpec.affinity || {} - templateSpec.affinity.nodeAffinity = - templateSpec.affinity.nodeAffinity || {} - templateSpec.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution = - templateSpec.affinity.nodeAffinity - .preferredDuringSchedulingIgnoredDuringExecution || [] + templateSpec.affinity ||= {} + templateSpec.affinity.nodeAffinity ||= {} + templateSpec.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution ||= + [] const existingPreferences = templateSpec.affinity.nodeAffinity .preferredDuringSchedulingIgnoredDuringExecution @@ -31,7 +36,7 @@ module.exports = (manifests, options) => { } // Add or merge tolerations - templateSpec.tolerations = templateSpec.tolerations || [] + templateSpec.tolerations ||= [] const newTolerations = tolerationsToAdd.filter( (tolerationToAdd) => !templateSpec.tolerations.some(