8000 feat: static team settings page by dennisvankekem · Pull Request #2024 · linode/apl-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: static team settings page #2024

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 27 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
826c8b5
feat: replaced regex patterns for strings
dennisvankekem Mar 27, 2025
f0830ce
fix: debug versions
dennisvankekem Mar 31, 2025
c0b93eb
Merge branch 'main' into APL-540
dennisvankekem Mar 31, 2025
16b42b5
Merge branch 'main' into APL-540
dennisvankekem Apr 4, 2025
60adb9d
feat: setup value changes
ElderMatt Apr 7, 2025
7afe342
ci: change values-migrate env dir
j-zimnowoda Apr 8, 2025
f255729
Merge remote-tracking branch 'origin/main' into APL-540
j-zimnowoda Apr 8, 2025
76728fd
feat: migrate team settings
ElderMatt Apr 8, 2025
b638b35
fix: values schema changes
dennisvankekem Apr 8, 2025
2a30a93
fix: teamSettings migration
ferruhcihan Apr 8, 2025
2c0317c
fix: cspell lint errors
ferruhcihan Apr 8, 2025
76ef1f2
Merge branch 'main' into APL-540
j-zimnowoda Apr 8, 2025
2cfd4dd
fix: values changes version
dennisvankekem Apr 8, 2025
f70c8f1
fix: remove opsgenie and email migration
dennisvankekem Apr 9, 2025
272798f
fix: teamSettingsMigration test
dennisvankekem Apr 9, 2025
0550987
Merge branch 'main' into APL-540
dennisvankekem Apr 9, 2025
c19cc9c
fix: test fixtures
dennisvankekem Apr 9, 2025
5b03f32
Merge branch 'main' into APL-540
dennisvankekem Apr 10, 2025
c8ee5b9
fix: reverted resourceQuota
dennisvankekem Apr 14, 2025
9c729e9
Merge branch 'main' into APL-540
dennisvankekem Apr 15, 2025
0c8beae
fix: added specVersion
dennisvankekem Apr 15, 2025
e514737
fix: removed duplicated slack key
dennisvankekem Apr 15, 2025
5152107
fix: removed email from secret settings
dennisvankekem Apr 15, 2025
d4664fb
Merge branch 'main' into APL-540
dennisvankekem Apr 16, 2025
6a93249
fix: removed async from teamSettingsMigration
dennisvankekem Apr 16, 2025
e8999dd
fix: auto migrate oopsie
dennisvankekem Apr 16, 2025
85b47d2
fix: reverted versions to main
dennisvankekem Apr 16, 2025
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
103 changes: 101 additions & 2 deletions 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, getBuildName, policiesMigration } from 'src/cmd/migrate'< 8000 /td>
import stubs from 'src/test-stubs'
import { globSync } from 'glob'
import { getFileMap } from '../common/repo'
import { env } from '../common/envalid'
import { getFileMap } from '../common/repo'

jest.mock('uuid', () => ({
v4: jest.fn(() => 'my-fixed-uuid'),
Expand Down Expand Up @@ -571,6 +571,105 @@ describe('Build image name migration', () => {
}, 20000)
})

describe('teamSettingsMigration', () => {
// Create a mock values object representing teams with settings that need migration.
const getTeamSettingsMockValues = (): any => ({
versions: { specVersion: 1 },
teamConfig: {
team1: {
settings: {
alerts: {
email: 'test@example.com',
opsgenie: 'ops_value',
teams: 'keep this alert',
},
selfService: {
service: ['ingress'],
access: ['downloadKubeConfig', 'shell'],
policies: ['edit policies'],
apps: ['argocd', 'gitea'],
},
},
},
team2: {
settings: {
alerts: {
teams: 'team2 alert',
},
selfService: {
service: [],
access: [],
policies: [],
apps: ['argocd'],
},
},
},
},
})

// Expected values after migration:
// - The alerts block should have the 'email' and 'opsgenie' keys removed.
// - The selfService arrays ('service', 'access', 'policies', 'apps') are replaced with a new
// teamMembers object with the correct 8000 boolean values.
const getTeamSettingsExpectedValues = (): any => ({
versions: { specVersion: 2 },
teamConfig: {
team1: {
settings: {
alerts: {
teams: 'keep this alert',
},
selfService: {
teamMembers: {
createServices: true, // 'ingress' was present in service.
editSecurityPolicies: true, // 'edit policies' was present in policies.
useCloudShell: true, // 'shell' was present in access.
downloadKubeconfig: true, // 'downloadKubeConfig' was present in access.
downloadDockerLogin: false, // 'downloadDockerConfig' was not provided.
},
},
},
},
team2: {
settings: {
alerts: {
teams: 'team2 alert',
},
selfService: {
teamMembers: {
createServices: false,
editSecurityPolicies: false,
useCloudShell: false,
downloadKubeconfig: false,
downloadDockerLogin: false,
},
},
},
},
},
})

// Set up the values and changes flag to trigger the teamSettingsMigration.
const teamSettingValues: any = getTeamSettingsMockValues()
const valuesChanges: any = {
version: 2,
teamSettingsMigration: true,
}
const deps: any = {
cd: jest.fn(),
rename: jest.fn(),
hfValues: jest.fn().mockReturnValue(teamSettingValues),
terminal,
writeValues: jest.fn(),
}

it('should migrate team settings correctly', async () => {
await applyChanges([valuesChanges], false, deps)
const expectedValues = getTeamSettingsExpectedValues()
expect(deps.writeValues).toBeCalledWith(expectedValues, true)
}, 20000)
})

jest.mock('glob')
describe('Policies migration', () => {
const mockFilePaths = ['/path/to/env/teams/admin/policies.yaml', '/path/to/env/teams/alpha/policies.yaml']
Expand Down
63 changes: 63 additions & 0 deletions src/cmd/migrate.ts
6D40
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ interface Change {
[mutation: string]: string
}>
networkPoliciesMigration?: boolean
teamSettingsMigration?: boolean
teamResourceQuotaMigration?: boolean
buildImageNameMigration?: boolean
policiesMigration?: boolean
Expand Down Expand Up @@ -303,6 +304,67 @@ const networkPoliciesMigration = async (values: Record<string, any>): Promise<vo
)
}

const teamSettingsMigration = (values: Record<string, any>): void => {
const teams: Array<string> = Object.keys(values?.teamConfig as Record<string, any>)

teams.map((teamName) => {
// Get the alerts block for the team and remove email and opsgenie
const alerts = get(values, `teamConfig.${teamName}.settings.alerts`)
if (alerts?.email) unset(alerts, 'email')
if (alerts?.opsgenie) unset(alerts, 'opsgenie')
// Get the selfService block for the team
const selfService = get(values, `teamConfig.${teamName}.settings.selfService`)
if (!selfService) return

// Initialize the new teamMembers structure with default boolean values
const teamMembers = {
createServices: false,
editSecurityPolicies: false,
useCloudShell: false,
downloadKubeconfig: false,
downloadDockerLogin: false,
}

// Map selfService.service.ingress -> teamMembers.createServices
const servicePermissions = get(selfService, 'service', [])
if (Array.isArray(servicePermissions) && servicePermissions.includes('ingress')) {
teamMembers.createServices = true
}

// Map selfService.access keys to corresponding teamMembers fields
// - downloadKubeConfig -> downloadKubeconfig
// - downloadDockerConfig -> downloadDockerLogin
// - shell -> useCloudShell
const accessPermissions = get(selfService, 'access', [])
if (Array.isArray(accessPermissions)) {
if (accessPermissions.includes('downloadKubeConfig')) {
teamMembers.downloadKubeconfig = true
}
if (accessPermissions.includes('downloadDockerConfig')) {
teamMembers.downloadDockerLogin = true
}
if (accessPermissions.includes('shell')) {
teamMembers.useCloudShell = true
}
}

// Map selfService.policies.edit_policies -> teamMembers.editSecurityPolicies.
// Note: In the source schema, the string "edit policies" is used.
const policies = get(selfService, 'policies', [])
if (Array.isArray(policies) && policies.includes('edit policies')) {
teamMembers.editSecurityPolicies = true
}

// Set the new teamMembers object on selfService
set(selfService, 'teamMembers', teamMembers)

unset(selfService, 'service')
unset(selfService, 'access')
unset(selfService, 'policies')
unset(selfService, 'apps')
})
}

export const getBuildName = (name: string, tag: string): string => {
return `${name}-${tag}`
.toLowerCase()
Expand Down Expand Up @@ -437,6 +499,7 @@ export const applyChanges = async (
}

if (c.networkPoliciesMigration) await networkPoliciesMigration(values)
if (c.teamSettingsMigration) teamSettingsMigration(values)
if (c.teamResourceQuotaMigration) teamResourceQuotaMigration(values)
if (c.buildImageNameMigration) await buildImageNameMigration(values)
if (c.policiesMigration) await policiesMigration()
Expand Down
6 changes: 4 additions & 2 deletions src/common/values.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { pathExists } from 'fs-extra'
import { mkdir, unlink, writeFile } from 'fs/promises'
import { cloneDeep, get, isEmpty, isEqual, merge, omit, pick, set } from 'lodash'
import { cloneDeep, get, isEmpty, isEqual, merge, mergeWith, omit, pick, set } from 'lodash'
import path from 'path'
import { supportedK8sVersions } from 'src/supportedK8sVersions.json'
import { stringify } from 'yaml'
Expand Down Expand Up @@ -121,7 +121,9 @@ export const writeValuesToFile = async (
const values = cloneDeep(inValues)
const originalValues = (await loadYaml(targetPath + suffix, { noError: true })) ?? {}
d.debug('originalValues: ', JSON.stringify(originalValues, null, 2))
const mergeResult = merge(cloneDeep(originalValues), values)
const mergeResult = mergeWith(cloneDeep(originalValues), values, (prev, next) => {
return next
})
const cleanedValues = removeBlankAttributes(values)
const cleanedMergeResult = removeBlankAttributes(mergeResult)
if (((overwrite && isEmpty(cleanedValues)) || (!overwrite && isEmpty(cleanedMergeResult))) && isSecretsFile) {
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/env/settings/alerts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ metadata:
name: alerts
labels: {}
spec:
email: {}
msteams: {}
receivers:
- slack
- msteams
msteams: {}
slack: {}
7 changes: 2 additions & 5 deletions tests/fixtures/env/settings/secrets.alerts.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
kind: AplAlertSet
spec:
email:
critical: admins@yourdoma.in
nonCritical: admins@yourdoma.in
slack:
url: https://hooks.slack.com/services/id
msteams:
highPrio: https://xxxxxxx.com
lowPrio: https://xxxxxxxx.com
slack:
url: https://hooks.slack.com/services/id
name: alerts
metadata:
name: alerts
14 changes: 6 additions & 8 deletions tests/fixtures/env/teams/admin/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ spec:
alertmanager: true
grafana: true
selfService:
access:
- shell
- downloadCertificateAuthority
policies:
- edit policies
apps: []
service:
- ingress
teamMembers:
createServices: false
editSecurityPolicies: true
useCloudShell: true
downloadKubeconfig: false
downloadDockerLogin: false
alerts:
groupInterval: 5m
receivers:
Expand Down
3 changes: 0 additions & 3 deletions tests/fixtures/env/teams/demo/secrets.settings.yaml
10000
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ kind: AplTeamSettingSet
spec:
password: somesecretvalue
alerts:
email:
critical: admins@yourdoma.in
nonCritical: admins@yourdoma.in
slack:
url: https://slack.con
name: demo
Expand Down
20 changes: 6 additions & 14 deletions tests/fixtures/env/teams/demo/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ metadata:
apl.io/teamId: demo
spec:
alerts:
email:
critical: admins@yourdoma.in
nonCritical: admins@yourdoma.in
receivers:
- slack
repeatInterval: 3h
Expand All @@ -30,14 +27,9 @@ spec:
- name: services.loadbalancers
value: '0'
selfService:
access:
- shell
- downloadCertificateAuthority
apps: []
policies:
- edit policies
service:
- ingress
team:
- alerts
password: somesecretvalue
teamMembers:
createServices: true
editSecurityPolicies: true
useCloudShell: true
downloadKubeconfig: false
downloadDockerLogin: false
14 changes: 6 additions & 8 deletions tests/fixtures/env/teams/dev/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ spec:
egressPublic: false
ingressPrivate: true
selfService:
access:
- shell
- downloadCertificateAuthority
policies:
- edit policies
apps: []
service:
- ingress
teamMembers:
createServices: false
editSecurityPolicies: true
useCloudShell: true
downloadKubeconfig: false
downloadDockerLogin: false
password: IkdUsKPcGAdanjas
alerts:
groupInterval: 5m
Expand Down
2 changes: 2 additions & 0 deletions values-changes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ changes:
- 'databases.keycloak.imported'
- 'databases.gitea.imported'
- 'databases.gitea.useOtomiDB'
- version: 34
teamSettingsMigration: true
- version: 35
teamResourceQuotaMigration: true
- version: 36
Expand Down
Loading
0