Skip to content
Open
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
3 changes: 3 additions & 0 deletions helmfile.d/helmfile-03.databases.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bases:
- snippets/defaults.yaml
---
bases:
- snippets/defaults.gotmpl
---
bases:
- snippets/env.gotmpl
---
Expand Down
3 changes: 3 additions & 0 deletions helmfile.d/helmfile-03.init.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bases:
- snippets/defaults.yaml
---
bases:
- snippets/defaults.gotmpl
---
bases:
- snippets/env.gotmpl
---
Expand Down
3 changes: 3 additions & 0 deletions helmfile.d/helmfile-04.init.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bases:
- snippets/defaults.yaml
---
bases:
- snippets/defaults.gotmpl
---
bases:
- snippets/env.gotmpl
---
Expand Down
3 changes: 3 additions & 0 deletions helmfile.d/helmfile-05.init.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bases:
- snippets/defaults.yaml
---
bases:
- snippets/defaults.gotmpl
---
bases:
- snippets/env.gotmpl
---
Expand Down
3 changes: 3 additions & 0 deletions helmfile.d/helmfile-06.init.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bases:
- snippets/defaults.yaml
---
bases:
- snippets/defaults.gotmpl
---
bases:
- snippets/env.gotmpl
---
Expand Down
3 changes: 3 additions & 0 deletions helmfile.d/helmfile-07.init.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bases:
- snippets/defaults.yaml
---
bases:
- snippets/defaults.gotmpl
---
bases:
- snippets/env.gotmpl
---
Expand Down
3 changes: 3 additions & 0 deletions helmfile.d/helmfile-08.init.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bases:
- snippets/defaults.yaml
---
bases:
- snippets/defaults.gotmpl
---
bases:
- snippets/env.gotmpl
---
Expand Down
3 changes: 3 additions & 0 deletions helmfile.d/helmfile-09.init.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bases:
- snippets/defaults.yaml
---
bases:
- snippets/defaults.gotmpl
---
bases:
- snippets/env.gotmpl
---
Expand Down
3 changes: 3 additions & 0 deletions helmfile.d/helmfile-10.monitoring.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bases:
- snippets/defaults.yaml
---
bases:
- snippets/defaults.gotmpl
---
bases:
- snippets/env.gotmpl
---
Expand Down
3 changes: 3 additions & 0 deletions helmfile.d/helmfile-20.ingress.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bases:
- snippets/defaults.yaml
---
bases:
- snippets/defaults.gotmpl
---
bases:
- snippets/env.gotmpl
---
Expand Down
3 changes: 3 additions & 0 deletions helmfile.d/helmfile-50.services.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bases:
- snippets/defaults.yaml
---
bases:
- snippets/defaults.gotmpl
---
bases:
- snippets/env.gotmpl
---
Expand Down
3 changes: 3 additions & 0 deletions helmfile.d/helmfile-70.shared.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bases:
- snippets/defaults.yaml
---
bases:
- snippets/defaults.gotmpl
---
bases:
- snippets/env.gotmpl
---
Expand Down
5 changes: 4 additions & 1 deletion helmfile.d/helmfile-90.artifacts.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bases:
- snippets/defaults.yaml
---
bases:
- snippets/defaults.gotmpl
---
bases:
- snippets/env.gotmpl
---
Expand All @@ -27,4 +30,4 @@ releases:
namespace: otel
labels:
pkg: otel-operator
<<: *raw
<<: *raw
5 changes: 4 additions & 1 deletion helmfile.d/helmfile-91.artifacts.yaml.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bases:
- snippets/defaults.yaml
---
bases:
- snippets/defaults.gotmpl
---
bases:
- snippets/env.gotmpl
---
Expand All @@ -18,4 +21,4 @@ releases:
labels:
pkg: istio
app: core
<<: *raw
<<: *raw
3 changes: 3 additions & 0 deletions helmfile.d/snippets/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ environments:
keycloak:
imageName: null
size: 5Gi
storageClass: ''
walStorageSize: 5Gi
replicas: 2
recovery: {}
Expand Down Expand Up @@ -1039,6 +1040,7 @@ environments:
harbor:
imageName: null
size: 5Gi
storageClass: ''
walStorageSize: 5Gi
replicas: 2
coreDatabase: registry
Expand Down Expand Up @@ -1068,6 +1070,7 @@ environments:
gitea:
imageName: null
size: 5Gi
storageClass: ''
walStorageSize: 5Gi
replicas: 2
recovery: {}
Expand Down
141 changes: 140 additions & 1 deletion src/cmd/migrate.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { globSync } from 'glob'
import {
applyChanges,
Changes,
filterChanges,
preservePvcStorageClassInRawValues,
processDeletionEntry,
removeSopsArtifacts,
sopsMigration,
Expand Down Expand Up @@ -442,3 +442,142 @@ describe('processDeletionEntry', () => {
expect(mockDeleteFile).not.toHaveBeenCalled()
})
})

describe('preservePvcStorageClassInRawValues', () => {
const makeDeps = (overrides: Partial<any> = {}) => ({
readPvc: jest.fn(async () => undefined),
listPvcs: jest.fn(async () => []),
getParsedArgs: jest.fn(() => ({ dryRun: false, local: false })),
terminal,
...overrides,
})

it('should set app _rawValues and databases.storageClass when pvc storageClass differs from cluster default', async () => {
const values: Record<string, any> = {
cluster: { defaultStorageClass: 'linode-block-storage' },
databases: {
gitea: {},
harbor: {},
keycloak: {},
},
apps: {
gitea: { _rawValues: {} },
harbor: { _rawValues: {} },
keycloak: { _rawValues: {} },
prometheus: { _rawValues: {} },
'kubeflow-pipelines': { _rawValues: {} },
'git-server': { _rawValues: {} },
},
}

const readPvc = jest.fn(async (namespace: string, name: string) => {
const byName: Record<string, any> = {
'git-server/git-server-data': { spec: { storageClassName: 'legacy-sc' } },
'gitea/data-gitea-0': { spec: { storageClassName: 'legacy-sc' } },
'gitea/gitea-backup': { spec: { storageClassName: 'legacy-sc' } },
'kfp/mysql-pv-claim': { spec: { storageClassName: 'legacy-sc' } },
}
return byName[`${namespace}/${name}`]
})

const listPvcs = jest.fn(async (namespace: string, labelSelector: string) => {
const bySelector: Record<string, any[]> = {
'gitea/cnpg.io/cluster=gitea-db': [
{ metadata: { labels: { 'cnpg.io/pvcRole': 'PG_DATA' } }, spec: { storageClassName: 'legacy-sc' } },
{ metadata: { labels: { 'cnpg.io/pvcRole': 'PG_WAL' } }, spec: { storageClassName: 'legacy-wal-sc' } },
],
'harbor/app.kubernetes.io/instance=harbor,component=redis': [{ spec: { storageClassName: 'legacy-sc' } }],
'harbor/app.kubernetes.io/instance=harbor,component=trivy': [{ spec: { storageClassName: 'legacy-sc' } }],
'harbor/cnpg.io/cluster=harbor-otomi-db': [
{ metadata: { labels: { 'cnpg.io/pvcRole': 'PG_DATA' } }, spec: { storageClassName: 'legacy-sc' } },
],
'keycloak/cnpg.io/cluster=keycloak-db': [
{ metadata: { labels: { 'cnpg.io/pvcRole': 'PG_DATA' } }, spec: { storageClassName: 'legacy-sc' } },
],
'monitoring/operator.prometheus.io/name=po-prometheus': [{ spec: { storageClassName: 'legacy-sc' } }],
}
return bySelector[`${namespace}/${labelSelector}`] || []
})

await preservePvcStorageClassInRawValues(values, makeDeps({ readPvc, listPvcs }))

expect(values.apps['git-server']._rawValues.persistence.storageClass).toBe('legacy-sc')
expect(values.apps.gitea._rawValues.global.storageClass).toBe('legacy-sc')
expect(values.apps.gitea._rawValues.giteaBackup.storageClassName).toBe('legacy-sc')
expect(values.databases.gitea.storageClass).toBe('legacy-sc')
expect(values.apps.harbor._rawValues.persistence.persistentVolumeClaim.redis.storageClass).toBe('legacy-sc')
expect(values.apps.harbor._rawValues.persistence.persistentVolumeClaim.trivy.storageClass).toBe('legacy-sc')
expect(values.databases.harbor.storageClass).toBe('legacy-sc')
expect(values.databases.keycloak.storageClass).toBe('legacy-sc')
expect(values.apps['kubeflow-pipelines']._rawValues.mysql.storage.storageClass).toBe('legacy-sc')
expect(
values.apps.prometheus._rawValues.prometheus.prometheusSpec.storageSpec.volumeClaimTemplate.spec.storageClassName,
).toBe('legacy-sc')
})

it('should not set overrides when pvc storageClass equals cluster default', async () => {
const values: Record<string, any> = {
cluster: { defaultStorageClass: 'linode-block-storage' },
databases: {
gitea: {},
harbor: {},
keycloak: {},
},
apps: {
gitea: { _rawValues: {} },
harbor: { _rawValues: {} },
keycloak: { _rawValues: {} },
prometheus: { _rawValues: {} },
'kubeflow-pipelines': { _rawValues: {} },
'git-server': { _rawValues: {} },
},
}

const readPvc = jest.fn(async () => ({ spec: { storageClassName: 'linode-block-storage' } }))
const listPvcs = jest.fn(async () => [{ spec: { storageClassName: 'linode-block-storage' } }])

await preservePvcStorageClassInRawValues(values, makeDeps({ readPvc, listPvcs }))

expect(values.apps['git-server']._rawValues).toEqual({})
expect(values.apps.gitea._rawValues).toEqual({})
expect(values.apps.harbor._rawValues).toEqual({})
expect(values.apps.keycloak._rawValues).toEqual({})
expect(values.apps['kubeflow-pipelines']._rawValues).toEqual({})
expect(values.apps.prometheus._rawValues).toEqual({})
expect(values.databases.gitea).toEqual({})
expect(values.databases.harbor).toEqual({})
expect(values.databases.keycloak).toEqual({})
})

it('should keep existing databases.storageClass overrides', async () => {
const values: Record<string, any> = {
cluster: { defaultStorageClass: 'linode-block-storage' },
databases: {
gitea: { storageClass: 'preset-db-sc' },
harbor: { storageClass: 'preset-db-sc' },
keycloak: { storageClass: 'preset-db-sc' },
},
}

const listPvcs = jest.fn(async (namespace: string, labelSelector: string) => {
const bySelector: Record<string, any[]> = {
'gitea/cnpg.io/cluster=gitea-db': [
{ metadata: { labels: { 'cnpg.io/pvcRole': 'PG_DATA' } }, spec: { storageClassName: 'legacy-sc' } },
],
'harbor/cnpg.io/cluster=harbor-otomi-db': [
{ metadata: { labels: { 'cnpg.io/pvcRole': 'PG_DATA' } }, spec: { storageClassName: 'legacy-sc' } },
],
'keycloak/cnpg.io/cluster=keycloak-db': [
{ metadata: { labels: { 'cnpg.io/pvcRole': 'PG_DATA' } }, spec: { storageClassName: 'legacy-sc' } },
],
}
return bySelector[`${namespace}/${labelSelector}`] || []
})

await preservePvcStorageClassInRawValues(values, makeDeps({ listPvcs }))

expect(values.databases.gitea.storageClass).toBe('preset-db-sc')
expect(values.databases.harbor.storageClass).toBe('preset-db-sc')
expect(values.databases.keycloak.storageClass).toBe('preset-db-sc')
})
})
Loading
Loading