diff --git a/src/otomi-stack.ts b/src/otomi-stack.ts index 9a724a02..7462223b 100644 --- a/src/otomi-stack.ts +++ b/src/otomi-stack.ts @@ -72,6 +72,7 @@ import { getValuesSchema, removeBlankAttributes, } from 'src/utils' +import { deepQuote } from 'src/utils/yamlUtils' import { cleanEnv, CUSTOM_ROOT_CA, @@ -1853,9 +1854,11 @@ export default class OtomiStack { } async editWorkloadValues(teamId: string, name: string, data: WorkloadValues): Promise { - const workload = this.repoService - .getTeamConfigService(teamId) - .patchWorkload(name, { spec: { values: stringifyYaml(data.values) } }) + const workload = this.repoService.getTeamConfigService(teamId).patchWorkload(name, { + spec: { + values: stringifyYaml(deepQuote(data.values)), + }, + }) await this.saveTeamWorkloadValues(workload) await this.doTeamDeployment( teamId, diff --git a/src/utils/yamlUtils.ts b/src/utils/yamlUtils.ts new file mode 100644 index 00000000..2407e252 --- /dev/null +++ b/src/utils/yamlUtils.ts @@ -0,0 +1,18 @@ +import YAML from 'yaml' + +export function quoteIfDangerous(value: unknown) { + if (typeof value === 'string' && ['yes', 'no', 'on', 'off'].includes(value.toLowerCase())) { + const scalar = new YAML.Scalar(value) + scalar.type = YAML.Scalar.QUOTE_DOUBLE + return scalar + } + return value +} + +export function deepQuote(obj: any): any { + if (Array.isArray(obj)) return obj.map(deepQuote) + if (obj && typeof obj === 'object') { + return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, deepQuote(v)])) + } + return quoteIfDangerous(obj) +}