Skip to content

chore: Helmfile v1 compatibility [TOOLS][MINOR] #2136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"aliases": "shellscript",
"bin/hooks/*": "shellscript",
"helmfile-*.yaml": "helm",
"helmfile-*.yaml.gotmpl": "helm",
"helmfile.yaml": "helm",
"otomi": "shellscript"
},
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM linode/apl-tools:v2.8.8 AS ci
FROM linode/apl-tools:v2.9.0 AS ci

ENV APP_HOME=/home/app/stack

Expand Down Expand Up @@ -26,7 +26,7 @@ FROM ci AS clean
# below command removes the packages specified in devDependencies and set NODE_ENV to production
RUN npm prune --production

FROM linode/apl-tools:v2.8.8 AS prod
FROM linode/apl-tools:v2.9.0 AS prod
ENV APP_HOME=/home/app/stack
ENV ENV_DIR=/home/app/stack/env
ENV VERBOSITY='0'
Expand Down
4 changes: 2 additions & 2 deletions bin/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ function hf_template() {
QUIET=1
if [ -n "$1" ]; then
local out_dir="$1"
[ -z "$FILE_OPT" ] && [ -z "$LABEL_OPT" ] && hf -f helmfile.tpl/helmfile-init.yaml template --skip-deps --output-dir="$out_dir" $SKIP_CLEANUP >/dev/null
[ -z "$FILE_OPT" ] && [ -z "$LABEL_OPT" ] && hf -f helmfile.tpl/helmfile-init.yaml.gotmpl template --skip-deps --output-dir="$out_dir" $SKIP_CLEANUP >/dev/null
hf template --skip-deps --output-dir="$out_dir" $SKIP_CLEANUP >/dev/null
else
[ -z "$FILE_OPT" ] && [ -z "$LABEL_OPT" ] && hf -f helmfile.tpl/helmfile-init.yaml template --skip-deps $SKIP_CLEANUP
[ -z "$FILE_OPT" ] && [ -z "$LABEL_OPT" ] && hf -f helmfile.tpl/helmfile-init.yaml.gotmpl template --skip-deps $SKIP_CLEANUP
hf template --skip-deps $SKIP_CLEANUP
fi
}
Expand Down
4 changes: 2 additions & 2 deletions bin/job-presync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ hf list | grep $release && is_deployed=true
# - Always: remove job

if [ "$run_policy" = 'Always' ]; then
hf -l name=$release destroy --args=--wait
hf -l name=$release destroy --deleteWait
else
# OnSpecChange
has_diff=false
hf -l name=$release diff --skip-deps && has_diff=true
[ -n "$VERBOSE" ] && echo "has_diff: $has_diff"
if $has_diff && $is_deployed; then
hf -l name=$release destroy --args=--wait
hf -l name=$release destroy --deleteWait
fi
fi
2 changes: 1 addition & 1 deletion chart/apl/localtest-minikube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export CUSTOM_NETWORK='--network minikube'
#####
# apply
#####
binzx/otomi otomi apply-as-apps -f helmfile.tpl/helmfile-init.yaml
binzx/otomi otomi apply-as-apps -f helmfile.tpl/helmfile-init.yaml.gotmpl
binzx/otomi otomi apply-as-apps
# minikube tunnel
40 changes: 20 additions & 20 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ Effective development starts with an understanding the code structure and the re

```
apl-core
├── .values # Boilerplate for initializing git repository
├── adr # Architectural Decision Records [read more](https://adr.github.io/madr/)
├── bin # APL CLI entrypoint (deprecated)
├── binzx # APL CLI entrypoint
├── chart # Helm chart for installing APL and upgrading APL Helm charts
├── charts # All other Helm charts that comprise APL
├── docs # Documentation
├── helmfile.d/helmfile-*.yaml # Helmfile specs ordered by name and executed accordingly by otomi commands
├── helmfile.d/snippets # Reusable code snippets
├── helmfile.tpl # Additional Helmfiles that do not have corresponding chart and are not parsed on otomi apply|template command
├── k8s # Kubernetes manifests that before any other chart
├── src # APL CLI source code
├── tests # Values used for testing purposes
├── upgrades.yaml # Upgrade presync hooks
├── values # Value templates that serves as input to corresponding Helm charts
├── values-changes.yaml # Definitions for performing data migrations
├── values-schema.yaml # JSON schema that defines APL interface
└── versions.yaml # Version tags of otomi-api, otomi-console and otomi-tasks
├── .values # Boilerplate for initializing git repository
├── adr # Architectural Decision Records [read more](https://adr.github.io/madr/)
├── bin # APL CLI entrypoint (deprecated)
├── binzx # APL CLI entrypoint
├── chart # Helm chart for installing APL and upgrading APL Helm charts
├── charts # All other Helm charts that comprise APL
├── docs # Documentation
├── helmfile.d/helmfile-*.yaml* # Helmfile specs ordered by name and executed accordingly by otomi commands
├── helmfile.d/snippets # Reusable code snippets
├── helmfile.tpl # Additional Helmfiles that do not have corresponding chart and are not parsed on otomi apply|template command
├── k8s # Kubernetes manifests that before any other chart
├── src # APL CLI source code
├── tests # Values used for testing purposes
├── upgrades.yaml # Upgrade presync hooks
├── values # Value templates that serves as input to corresponding Helm charts
├── values-changes.yaml # Definitions for performing data migrations
├── values-schema.yaml # JSON schema that defines APL interface
└── versions.yaml # Version tags of otomi-api, otomi-console and otomi-tasks
```

## Reusable code snippets
Expand Down Expand Up @@ -65,7 +65,7 @@ While rendering kubernetes manifests APL leverages Helmfile.
In APL, all Helmfile specs are defined in the `helmfile.d/` directory and executed in alphabetical order. The majority of Helmfile specs has the following structure:

```go-template
#helmfiled./999-helmfile.yaml
#helmfile.d/999-helmfile.yaml.gotmpl
bases:
- snippets/defaults.yaml
---
Expand All @@ -80,7 +80,7 @@ releases:
- <helmfile release>
```

From the above code snippet, the `base` statements define loading and merging values from various sources. If we would execute `otomi apply|template -f helmfiled./999-helmfile.yaml` then the following data flow would take place:
From the above code snippet, the `base` statements define loading and merging values from various sources. If we would execute `otomi apply|template -f helmfile.d/999-helmfile.yaml.gotmpl` then the following data flow would take place:

```mermaid
flowchart LR
Expand Down
1 change: 1 addition & 0 deletions helmfile.tpl/helmfile-connectivity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ environments:
- namespace: team-a2
labels:
otomi.io/app: c7
---
releases:
- name: inter-team-connectivity
installed: true
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/apply-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const applyE2e = async (): Promise<void> => {

await hf(
{
fileOpts: `${rootDir}/helmfile.tpl/helmfile-e2e.yaml`,
fileOpts: `${rootDir}/helmfile.tpl/helmfile-e2e.yaml.gotmpl`,
logLevel: logLevelString(),
args: ['apply'],
},
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const applyAll = async () => {
await writeValuesToFile(`${env.ENV_DIR}/env/status.yaml`, { status: { otomi: state, helm: releases } }, true)

const output: ProcessOutputTrimmed = await hf(
{ fileOpts: 'helmfile.tpl/helmfile-init.yaml', args: 'template' },
{ fileOpts: 'helmfile.tpl/helmfile-init.yaml.gotmpl', args: 'template' },
{ streams: { stderr: d.stream.error } },
)
if (output.exitCode > 0) {
Expand All @@ -78,7 +78,7 @@ const applyAll = async () => {
await hf(
{
// 'fileOpts' limits the hf scope and avoids parse errors (we only have basic values in this statege):
fileOpts: 'helmfile.d/helmfile-02.init.yaml',
fileOpts: 'helmfile.d/helmfile-02.init.yaml.gotmpl',
labelOpts: ['stage=prep'],
logLevel: logLevelString(),
args: hfArgs,
Expand Down Expand Up @@ -117,7 +117,7 @@ const applyAll = async () => {
await hf(
{
// 'fileOpts' limits the hf scope and avoids parse errors (we only have basic values in this statege):
fileOpts: `${rootDir}/helmfile.tpl/helmfile-e2e.yaml`,
fileOpts: `${rootDir}/helmfile.tpl/helmfile-e2e.yaml.gotmpl`,
logLevel: logLevelString(),
args: hfArgs,
},
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const destroyAll = async () => {
d.info('Uninstalled all charts.')
d.info('Uninstalling applied manifests...')
const output: ProcessOutputTrimmed = await hf(
{ fileOpts: 'helmfile.tpl/helmfile-init.yaml', args: 'template' },
{ fileOpts: 'helmfile.tpl/helmfile-init.yaml.gotmpl', args: 'template' },
{ streams: debugStream },
)
if (output.exitCode > 0 || output.stderr.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ function renameKeyDeep(obj: any, oldKey: string, newKey: string): any {

export const migrateLegacyValues = async (envDir: string, deps = { writeFile }): Promise<boolean> => {
const output = await hf(
{ fileOpts: `${rootDir}/helmfile.tpl/helmfile-dump-files-old.yaml`, args: 'build' },
{ fileOpts: `${rootDir}/helmfile.tpl/helmfile-dump-files-old.yaml.gotmpl`, args: 'build' },
undefined,
envDir,
)
Expand Down
25 changes: 10 additions & 15 deletions src/common/hf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,22 @@ export const hfValues = async (
let output: ProcessOutputTrimmed
if (filesOnly)
output = await hf(
{ fileOpts: `${rootDir}/helmfile.tpl/helmfile-dump-files.yaml`, args: 'build' },
{ fileOpts: `${rootDir}/helmfile.tpl/helmfile-dump-files.yaml.gotmpl`, args: 'build' },
undefined,
envDir,
)
else if (defaultValues)
output = await hf(
{ fileOpts: `${rootDir}/helmfile.tpl/helmfile-dump-defaults.yaml`, args: 'build' },
{ fileOpts: `${rootDir}/helmfile.tpl/helmfile-dump-defaults.yaml.gotmpl`, args: 'build' },
undefined,
envDir,
)
else
output = await hf({ fileOpts: `${rootDir}/helmfile.tpl/helmfile-dump-all.yaml`, args: 'build' }, undefined, envDir)
output = await hf(
{ fileOpts: `${rootDir}/helmfile.tpl/helmfile-dump-all.yaml.gotmpl`, args: 'build' },
undefined,
envDir,
)
const res = parse(replaceHFPaths(output.stdout, envDir)).renderedvalues
if (excludeSecrets) {
// strip secrets
Expand Down Expand Up @@ -135,13 +139,6 @@ export const getStandaloneFiles = async (envDir: string): Promise<Record<string,
return files
}

export const getHelmArgs = (argv: HelmArguments, args: string[] = []): string[] => {
const argsArr: string[] = args
if (argv.args) argsArr.push(argv.args)
if (argv.kubeVersion) argsArr.push(`--kube-version=${argv.kubeVersion}`)
return ['--args', argsArr.join(' ')]
}

export const hfTemplate = async (
argv: HelmArguments,
outDir?: string,
Expand All @@ -150,16 +147,14 @@ export const hfTemplate = async (
): Promise<string> => {
const d = terminal('common:hf:hfTemplate')
process.env.QUIET = '1'
// const args = ['template', '--validate']
const args = ['template', '--include-needs']
const args = ['template', '--include-needs', '--skip-tests']
if (outDir) args.push(`--output-dir=${outDir}`)
if (argv.skipCleanup || isCore) args.push('--skip-cleanup')
const helmArgs = getHelmArgs(argv, ['--skip-tests'])
args.push(...helmArgs)
if (argv.kubeVersion) args.push(`--kube-version=${argv.kubeVersion}`)
let template = ''
const params: HFParams = { args, fileOpts: argv.file, labelOpts: argv.label, logLevel: argv.logLevel }
if (!argv.f && !argv.l) {
const file = 'helmfile.tpl/helmfile-init.yaml'
const file = 'helmfile.tpl/helmfile-init.yaml.gotmpl'
d.debug(`# Templating ${file} started`)
const outInit = await hf({ ...params, fileOpts: file }, { streams }, envDir)
d.debug(`# Templating ${file} done`)
Expand Down
2 changes: 1 addition & 1 deletion src/common/yargs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const helmOpts: { [key: string]: Options } = {
file: {
alias: 'f',
array: true,
describe: "Select helmfiles by filename, e.g. '-f helmfile.d/helmfile-15.ingress-core.yaml'",
describe: "Select helmfiles by filename, e.g. '-f helmfile.d/helmfile-15.ingress-core.yaml.gotmpl'",
nargs: 1,
coerce: (files: string[]) => {
if (!files || files.length === 0) return files
Expand Down
2 changes: 1 addition & 1 deletion src/dev/addApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const generateAppsFile = async (projectDir: string, name: string): Promise<void>
}

const generateHelmfileFile = async (projectDir: string, name: string): Promise<void> => {
const helmfilePath = `${projectDir}/helmfile-${name}.yaml`
const helmfilePath = `${projectDir}/helmfile-${name}.yaml.gotmpl`
const helmfileChunkPath = `${helmfilePath}.chunk`
const helmfileReleaseChunk = {
releases: [
Expand Down
2 changes: 1 addition & 1 deletion src/dev/bootstrapCoreApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const generateAppsFile = async (projectDir: string, name: string): Promise<void>
}

const generateHelmfileFile = async (projectDir: string, name: string): Promise<void> => {
const helmfilePath = `${projectDir}/helmfile-${name}.yaml`
const helmfilePath = `${projectDir}/helmfile-${name}.yaml.gotmpl`
const helmfileChunkPath = `${helmfilePath}.chunk`
const helmfileReleaseChunk = {
releases: [
Expand Down
2 changes: 1 addition & 1 deletion tests/network-policies/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The Pod status 'Error' means that connection did not succeded thus network polic
Delete connectivity test Pods

```
helmfile -f tests/network-policies/helmfile-connectivity.yaml destroy --args=--wait
helmfile -f tests/network-policies/helmfile-connectivity.yaml destroy --deleteWait
```

# Tests
Expand Down
1 change: 1 addition & 0 deletions tests/network-policies/helmfile-connectivity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ environments:
- https://apl-docs.net
- https://116.203.255.68
- https://httpbin.org/headers
---
releases:
- name: inter-team-connectivity
installed: true
Expand Down
2 changes: 1 addition & 1 deletion tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ARG AGE_VERSION=1.2.0
# https://github.com/noqcks/gucci/releases
ARG GUCCI_VERSION=1.6.13
# https://github.com/helmfile/helmfile/releases
ARG HELMFILE_VERSION=0.171.0
ARG HELMFILE_VERSION=1.0.0
# https://nodejs.org/en/download/
ARG NODE_VERSION=20

Expand Down
1 change: 0 additions & 1 deletion values/harbor/harbor.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ redis:
priorityClassName: otomi-critical
image:
tag: {{ $tag }}
internal:
resources: {{- $h.resources.redis | toYaml | nindent 6 }}

registry:
Expand Down
Loading