Skip to content

Commit

Permalink
feat: project values diff
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Sep 18, 2023
1 parent c7b2698 commit 4ece6fb
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/kontinuous/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const cloneDeep = require("lodash.clonedeep")
const beforeMergeChartValues = require("./before-merge-chart-values")

module.exports = (values) => {
Expand All @@ -10,5 +11,6 @@ module.exports = (values) => {
continue
}
subValues._isProjectValues = true
subValues._ProjectValues = cloneDeep(subValues)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 6 additions & 0 deletions plugins/contrib/values-compilers/01-unfold-charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -26,6 +29,9 @@ const findAliasOf = async (
}
}
for (const [k, value] of entries) {
if (k.startsWith("_")) {
continue
}
const found = await findAliasOf(
search,
value,
Expand Down
6 changes: 6 additions & 0 deletions plugins/contrib/values-compilers/03-resolve-alias-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions plugins/contrib/values-compilers/04-implicit-enabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const implicitEnabled = (values, scope = []) => {
}
}
for (const key of Object.keys(values)) {
if (key.startsWith("_")) {
continue
}
implicitEnabled(values[key], [...scope, key])
}
}
Expand Down
3 changes: 3 additions & 0 deletions plugins/contrib/values-compilers/05-jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions plugins/contrib/values-compilers/10-tpl-meta-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions plugins/fabrique/charts/pg/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4ece6fb

Please sign in to comment.