From 4ece6fba853017eb6de98018f89d7430b44e5498 Mon Sep 17 00:00:00 2001 From: devthejo Date: Mon, 18 Sep 2023 15:33:36 +0200 Subject: [PATCH] feat: project values diff --- packages/kontinuous/package.json | 1 + .../build/load-dependencies/before-merge-project-values.js | 2 ++ .../src/build/load-dependencies/compile-values.js | 4 ++-- .../src/build/load-dependencies/merge-yaml-file-values.js | 7 +++++-- plugins/contrib/values-compilers/01-unfold-charts.js | 6 ++++++ plugins/contrib/values-compilers/03-resolve-alias-of.js | 6 ++++++ plugins/contrib/values-compilers/04-implicit-enabled.js | 3 +++ plugins/contrib/values-compilers/05-jobs.js | 3 +++ plugins/contrib/values-compilers/10-tpl-meta-values.js | 3 +++ plugins/fabrique/charts/pg/values.yaml | 4 ++-- yarn.lock | 1 + 11 files changed, 34 insertions(+), 6 deletions(-) diff --git a/packages/kontinuous/package.json b/packages/kontinuous/package.json index e59dcb3abd..8ffaa903a3 100644 --- a/packages/kontinuous/package.json +++ b/packages/kontinuous/package.json @@ -25,6 +25,7 @@ "launch-editor": "^2.4.0", "link-module-alias": "^1.2.0", "lodash.camelcase": "^4.3.0", + "lodash.clonedeep": "^4.5.0", "lodash.defaults": "^4.2.0", "lodash.defaultsdeep": "^4.6.1", "lodash.get": "^4.4.2", diff --git a/packages/kontinuous/src/build/load-dependencies/before-merge-project-values.js b/packages/kontinuous/src/build/load-dependencies/before-merge-project-values.js index 85a91c8480..79d297e507 100644 --- a/packages/kontinuous/src/build/load-dependencies/before-merge-project-values.js +++ b/packages/kontinuous/src/build/load-dependencies/before-merge-project-values.js @@ -1,3 +1,4 @@ +const cloneDeep = require("lodash.clonedeep") const beforeMergeChartValues = require("./before-merge-chart-values") module.exports = (values) => { @@ -10,5 +11,6 @@ module.exports = (values) => { continue } subValues._isProjectValues = true + subValues._ProjectValues = cloneDeep(subValues) } } diff --git a/packages/kontinuous/src/build/load-dependencies/compile-values.js b/packages/kontinuous/src/build/load-dependencies/compile-values.js index 6974e2ddf2..6e8887247b 100644 --- a/packages/kontinuous/src/build/load-dependencies/compile-values.js +++ b/packages/kontinuous/src/build/load-dependencies/compile-values.js @@ -8,7 +8,7 @@ const pluginFunction = require("~/plugins/context/function") const valuesEnableStandaloneCharts = require("./values-enable-standalone-charts") const beforeMergeProjectValues = require("./before-merge-project-values") -const cleanMetaValues = require("./clean-meta-values") +// const cleanMetaValues = require("./clean-meta-values") const removeNotEnabledValues = require("./remove-not-enabled-values") const mergeYamlFileValues = require("./merge-yaml-file-values") const writeChartsAlias = require("./write-charts-alias") @@ -83,7 +83,7 @@ module.exports = async (config, logger) => { await writeChartsAlias(chartsAliasMap, config) removeNotEnabledValues(values) - cleanMetaValues(values) + // cleanMetaValues(values) const projectValuesFile = await getYamlPath(`${buildProjectPath}/values`) if (projectValuesFile) { diff --git a/packages/kontinuous/src/build/load-dependencies/merge-yaml-file-values.js b/packages/kontinuous/src/build/load-dependencies/merge-yaml-file-values.js index 36786f3457..7e846a9b7c 100644 --- a/packages/kontinuous/src/build/load-dependencies/merge-yaml-file-values.js +++ b/packages/kontinuous/src/build/load-dependencies/merge-yaml-file-values.js @@ -9,9 +9,12 @@ const expandDotNotation = require("./expand-dot-notation") module.exports = async (valuesFileBasename, subValues, beforeMerge) => { const val = (await loadYamlFile(valuesFileBasename)) || {} - await yamlExtends({ dir: path.dirname(valuesFileBasename), values: val }) + await yamlExtends({ + dir: path.dirname(valuesFileBasename), + values: val, + }) - beforeMerge(val) expandDotNotation(val) + beforeMerge(val) deepmerge(subValues, val) } diff --git a/plugins/contrib/values-compilers/01-unfold-charts.js b/plugins/contrib/values-compilers/01-unfold-charts.js index 29bb5512f7..616c902d29 100644 --- a/plugins/contrib/values-compilers/01-unfold-charts.js +++ b/plugins/contrib/values-compilers/01-unfold-charts.js @@ -12,6 +12,9 @@ const findAliasOf = async ( ([_, value]) => !!value?._isChartValues ) for (const [k, value] of entries) { + if (k.startsWith("_")) { + continue + } if (k === search) { const foundScope = [...scope, k] if (searchingSubkeys.length > 0) { @@ -26,6 +29,9 @@ const findAliasOf = async ( } } for (const [k, value] of entries) { + if (k.startsWith("_")) { + continue + } const found = await findAliasOf( search, value, diff --git a/plugins/contrib/values-compilers/03-resolve-alias-of.js b/plugins/contrib/values-compilers/03-resolve-alias-of.js index 91434fead3..e184c5cb89 100644 --- a/plugins/contrib/values-compilers/03-resolve-alias-of.js +++ b/plugins/contrib/values-compilers/03-resolve-alias-of.js @@ -6,12 +6,18 @@ const resolveAliasOf = (values, context, rootValues = values, scope = []) => { const { utils, chartsAliasMap, defaultValuesCache } = context const { deepmerge } = utils for (const [key, val] of Object.entries(values)) { + if (key.startsWith("_")) { + continue + } if (typeof val !== "object" || val === null || val["~chart"]) { continue } resolveAliasOf(values[key], context, rootValues, [...scope, key]) } for (const [key, val] of Object.entries(values)) { + if (key.startsWith("_")) { + continue + } if (typeof val !== "object" || val === null || !val["~chart"]) { continue } diff --git a/plugins/contrib/values-compilers/04-implicit-enabled.js b/plugins/contrib/values-compilers/04-implicit-enabled.js index ba2e1467a8..63064a9dae 100644 --- a/plugins/contrib/values-compilers/04-implicit-enabled.js +++ b/plugins/contrib/values-compilers/04-implicit-enabled.js @@ -8,6 +8,9 @@ const implicitEnabled = (values, scope = []) => { } } for (const key of Object.keys(values)) { + if (key.startsWith("_")) { + continue + } implicitEnabled(values[key], [...scope, key]) } } diff --git a/plugins/contrib/values-compilers/05-jobs.js b/plugins/contrib/values-compilers/05-jobs.js index ca731f369c..8cfbf9c817 100644 --- a/plugins/contrib/values-compilers/05-jobs.js +++ b/plugins/contrib/values-compilers/05-jobs.js @@ -444,6 +444,9 @@ const compileValues = async (values, context, chartScope = []) => { ) { return } + if (key.startsWith("_")) { + return + } const childChartScope = [...chartScope, key] const isJob = subValues._pluginValuesCompilerContribJob const isJobs = subValues._pluginValuesCompilerContribJobs diff --git a/plugins/contrib/values-compilers/10-tpl-meta-values.js b/plugins/contrib/values-compilers/10-tpl-meta-values.js index dda91b36e8..1e995a6c4b 100644 --- a/plugins/contrib/values-compilers/10-tpl-meta-values.js +++ b/plugins/contrib/values-compilers/10-tpl-meta-values.js @@ -19,6 +19,9 @@ const renderTplRecurse = async ( } for (const key of Object.keys(values)) { + if (key.startsWith("_")) { + continue + } const isTplCast = key.startsWith("~tpl:") if (key.startsWith("~tpl~") || isTplCast) { const tpl = values[key] diff --git a/plugins/fabrique/charts/pg/values.yaml b/plugins/fabrique/charts/pg/values.yaml index 19e1752d6b..6626244700 100644 --- a/plugins/fabrique/charts/pg/values.yaml +++ b/plugins/fabrique/charts/pg/values.yaml @@ -13,7 +13,7 @@ cnpg-cluster: - {{ .Values.kontinuous.parentChart }}.jobs-pg ~tpl~dbOwner: "{{ .Values.global.pgUser }}" ~tpl~dbName: "{{ .Values.global.pgDatabase }}" - ~tpl~instances: "{{ or .Values.instances ((or .Values.global.isProd .Values.global.isPreProd) | ternary `3` `1`) }}" + ~tpl~instances: "{{ or (and .Values.Parent._ProjectValues (index .Values.Parent._ProjectValues `cnpg-cluster`).instances) ((or .Values.global.isProd .Values.global.isPreProd) | ternary `3` `1`) }}" postgresqlParameters: TimeZone: "Europe/Paris" extensions: @@ -35,7 +35,7 @@ cnpg-cluster: tag: "14" poolers: rw: - ~tpl~instances: "{{ (or .Values.global.isProd .Values.global.isPreProd) | ternary `3` `1` }}" + ~tpl~instances: "{{ or (and .Values.Parent._ProjectValues (index .Values.Parent._ProjectValues `cnpg-cluster`).instances) ((or .Values.global.isProd .Values.global.isPreProd) | ternary `3` `1`) }}" type: rw pgbouncer: poolMode: session diff --git a/yarn.lock b/yarn.lock index 5d407b756f..3f48b7185e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10798,6 +10798,7 @@ __metadata: launch-editor: "npm:^2.4.0" link-module-alias: "npm:^1.2.0" lodash.camelcase: "npm:^4.3.0" + lodash.clonedeep: "npm:^4.5.0" lodash.defaults: "npm:^4.2.0" lodash.defaultsdeep: "npm:^4.6.1" lodash.get: "npm:^4.4.2"