mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-17 02:55:11 +00:00
feat: Merge master (#1260)
* chore(site): dependabot deps (#1148) * chore(deps): bump highlight.js from 10.4.1 to 10.5.0 in /site (#1143) Bumps [highlight.js](https://github.com/highlightjs/highlight.js) from 10.4.1 to 10.5.0. - [Release notes](https://github.com/highlightjs/highlight.js/releases) - [Changelog](https://github.com/highlightjs/highlight.js/blob/master/CHANGES.md) - [Commits](https://github.com/highlightjs/highlight.js/compare/10.4.1...10.5.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @babel/plugin-transform-runtime in /site (#1144) Bumps [@babel/plugin-transform-runtime](https://github.com/babel/babel/tree/HEAD/packages/babel-plugin-transform-runtime) from 7.12.1 to 7.12.10. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.12.10/packages/babel-plugin-transform-runtime) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump sirv from 1.0.7 to 1.0.10 in /site (#1145) Bumps [sirv](https://github.com/lukeed/sirv) from 1.0.7 to 1.0.10. - [Release notes](https://github.com/lukeed/sirv/releases) - [Commits](https://github.com/lukeed/sirv/compare/v1.0.7...v1.0.10) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump rollup from 2.34.0 to 2.35.1 in /site (#1142) Bumps [rollup](https://github.com/rollup/rollup) from 2.34.0 to 2.35.1. - [Release notes](https://github.com/rollup/rollup/releases) - [Changelog](https://github.com/rollup/rollup/blob/master/CHANGELOG.md) - [Commits](https://github.com/rollup/rollup/compare/v2.34.0...v2.35.1) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @rollup/plugin-node-resolve in /site (#1141) Bumps [@rollup/plugin-node-resolve](https://github.com/rollup/plugins) from 10.0.0 to 11.0.1. - [Release notes](https://github.com/rollup/plugins/releases) - [Commits](https://github.com/rollup/plugins/compare/node-resolve-v10.0.0...commonjs-v11.0.1) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump marked from 1.2.5 to 1.2.7 in /site (#1140) Bumps [marked](https://github.com/markedjs/marked) from 1.2.5 to 1.2.7. - [Release notes](https://github.com/markedjs/marked/releases) - [Changelog](https://github.com/markedjs/marked/blob/master/release.config.js) - [Commits](https://github.com/markedjs/marked/compare/v1.2.5...v1.2.7) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @babel/core from 7.12.9 to 7.12.10 in /site (#1139) Bumps [@babel/core](https://github.com/babel/babel/tree/HEAD/packages/babel-core) from 7.12.9 to 7.12.10. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.12.10/packages/babel-core) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump rollup-plugin-svelte from 6.1.1 to 7.0.0 in /site (#1138) Bumps [rollup-plugin-svelte](https://github.com/sveltejs/rollup-plugin-svelte) from 6.1.1 to 7.0.0. - [Release notes](https://github.com/sveltejs/rollup-plugin-svelte/releases) - [Changelog](https://github.com/sveltejs/rollup-plugin-svelte/blob/master/CHANGELOG.md) - [Commits](https://github.com/sveltejs/rollup-plugin-svelte/compare/v6.1.1...v7.0.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @babel/preset-env from 7.12.1 to 7.12.11 in /site (#1137) Bumps [@babel/preset-env](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env) from 7.12.1 to 7.12.11. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.12.11/packages/babel-preset-env) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * downgrade svelte plugin Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(console): dependabot deps (#1147) * chore(deps-dev): bump @types/node from 14.14.13 to 14.14.19 in /console (#1146) Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.13 to 14.14.19. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump ts-protoc-gen from 0.13.0 to 0.14.0 in /console (#1129) Bumps [ts-protoc-gen](https://github.com/improbable-eng/ts-protoc-gen) from 0.13.0 to 0.14.0. - [Release notes](https://github.com/improbable-eng/ts-protoc-gen/releases) - [Changelog](https://github.com/improbable-eng/ts-protoc-gen/blob/master/CHANGELOG.md) - [Commits](https://github.com/improbable-eng/ts-protoc-gen/compare/0.13.0...0.14.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @angular/language-service in /console (#1128) Bumps [@angular/language-service](https://github.com/angular/angular/tree/HEAD/packages/language-service) from 11.0.4 to 11.0.5. - [Release notes](https://github.com/angular/angular/releases) - [Changelog](https://github.com/angular/angular/blob/master/CHANGELOG.md) - [Commits](https://github.com/angular/angular/commits/11.0.5/packages/language-service) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @angular/cli from 11.0.4 to 11.0.5 in /console (#1127) Bumps [@angular/cli](https://github.com/angular/angular-cli) from 11.0.4 to 11.0.5. - [Release notes](https://github.com/angular/angular-cli/releases) - [Commits](https://github.com/angular/angular-cli/compare/v11.0.4...v11.0.5) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @angular-devkit/build-angular in /console (#1126) Bumps [@angular-devkit/build-angular](https://github.com/angular/angular-cli) from 0.1100.4 to 0.1100.5. - [Release notes](https://github.com/angular/angular-cli/releases) - [Commits](https://github.com/angular/angular-cli/commits) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Max Peintner <[email protected]> * audit Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat: e-mail templates (#1158) * View definition added * Get templates and texts from the database. * Fill in texts in templates * Fill in texts in templates * Client API added * Weekly backup * Weekly backup * Daily backup * Weekly backup * Tests added * Corrections from merge branch * Fixes from pull request review * chore(console): dependencies (#1189) * chore(deps-dev): bump @angular/language-service in /console (#1187) Bumps [@angular/language-service](https://github.com/angular/angular/tree/HEAD/packages/language-service) from 11.0.5 to 11.0.9. - [Release notes](https://github.com/angular/angular/releases) - [Changelog](https://github.com/angular/angular/blob/master/CHANGELOG.md) - [Commits](https://github.com/angular/angular/commits/11.0.9/packages/language-service) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump google-proto-files from 2.3.0 to 2.4.0 in /console (#1186) Bumps [google-proto-files](https://github.com/googleapis/nodejs-proto-files) from 2.3.0 to 2.4.0. - [Release notes](https://github.com/googleapis/nodejs-proto-files/releases) - [Changelog](https://github.com/googleapis/nodejs-proto-files/blob/master/CHANGELOG.md) - [Commits](https://github.com/googleapis/nodejs-proto-files/compare/v2.3.0...v2.4.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @types/node from 14.14.19 to 14.14.21 in /console (#1185) Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.19 to 14.14.21. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @angular/cli from 11.0.5 to 11.0.7 in /console (#1184) Bumps [@angular/cli](https://github.com/angular/angular-cli) from 11.0.5 to 11.0.7. - [Release notes](https://github.com/angular/angular-cli/releases) - [Commits](https://github.com/angular/angular-cli/compare/v11.0.5...v11.0.7) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump karma from 5.2.3 to 6.0.0 in /console (#1183) Bumps [karma](https://github.com/karma-runner/karma) from 5.2.3 to 6.0.0. - [Release notes](https://github.com/karma-runner/karma/releases) - [Changelog](https://github.com/karma-runner/karma/blob/master/CHANGELOG.md) - [Commits](https://github.com/karma-runner/karma/compare/v5.2.3...v6.0.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @angular-devkit/build-angular in /console (#1182) Bumps [@angular-devkit/build-angular](https://github.com/angular/angular-cli) from 0.1100.5 to 0.1100.7. - [Release notes](https://github.com/angular/angular-cli/releases) - [Commits](https://github.com/angular/angular-cli/commits) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Max Peintner <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix(console): trigger unauthenticated dialog only once (#1170) * fix: trigger dialog once * remove log * typed trigger * chore(console): dependencies (#1205) * chore(deps-dev): bump stylelint from 13.8.0 to 13.9.0 in /console (#1204) Bumps [stylelint](https://github.com/stylelint/stylelint) from 13.8.0 to 13.9.0. - [Release notes](https://github.com/stylelint/stylelint/releases) - [Changelog](https://github.com/stylelint/stylelint/blob/master/CHANGELOG.md) - [Commits](https://github.com/stylelint/stylelint/compare/13.8.0...13.9.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @angular/language-service in /console (#1203) Bumps [@angular/language-service](https://github.com/angular/angular/tree/HEAD/packages/language-service) from 11.0.9 to 11.1.0. - [Release notes](https://github.com/angular/angular/releases) - [Changelog](https://github.com/angular/angular/blob/master/CHANGELOG.md) - [Commits](https://github.com/angular/angular/commits/11.1.0/packages/language-service) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump karma from 6.0.0 to 6.0.1 in /console (#1202) Bumps [karma](https://github.com/karma-runner/karma) from 6.0.0 to 6.0.1. - [Release notes](https://github.com/karma-runner/karma/releases) - [Changelog](https://github.com/karma-runner/karma/blob/master/CHANGELOG.md) - [Commits](https://github.com/karma-runner/karma/compare/v6.0.0...v6.0.1) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @angular/cli from 11.0.7 to 11.1.1 in /console (#1201) Bumps [@angular/cli](https://github.com/angular/angular-cli) from 11.0.7 to 11.1.1. - [Release notes](https://github.com/angular/angular-cli/releases) - [Commits](https://github.com/angular/angular-cli/compare/v11.0.7...v11.1.1) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @types/jasmine from 3.6.2 to 3.6.3 in /console (#1200) Bumps [@types/jasmine](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jasmine) from 3.6.2 to 3.6.3. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jasmine) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Max Peintner <[email protected]> * chore(deps-dev): bump @types/node from 14.14.21 to 14.14.22 in /console (#1199) Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.21 to 14.14.22. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @angular-devkit/build-angular in /console (#1198) Bumps [@angular-devkit/build-angular](https://github.com/angular/angular-cli) from 0.1100.7 to 0.1101.1. - [Release notes](https://github.com/angular/angular-cli/releases) - [Commits](https://github.com/angular/angular-cli/commits) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Max Peintner <[email protected]> * chore(deps): bump angularx-qrcode from 10.0.11 to 11.0.0 in /console (#1197) Bumps [angularx-qrcode](https://github.com/cordobo/angularx-qrcode) from 10.0.11 to 11.0.0. - [Release notes](https://github.com/cordobo/angularx-qrcode/releases) - [Commits](https://github.com/cordobo/angularx-qrcode/compare/10.0.11...11.0.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix pack lock Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: handle sequence correctly in subscription (#1209) * fix: correct master after merges again (#1230) * chore(docs): correct `iss` claim of jwt profile (#1229) * core(docs): correct `iss` claim of jwt profile * fix: correct master after merges again (#1230) * feat(login): new palette based styles (#1149) * chore(deps-dev): bump rollup from 2.33.2 to 2.34.0 in /site (#1040) Bumps [rollup](https://github.com/rollup/rollup) from 2.33.2 to 2.34.0. - [Release notes](https://github.com/rollup/rollup/releases) - [Changelog](https://github.com/rollup/rollup/blob/master/CHANGELOG.md) - [Commits](https://github.com/rollup/rollup/compare/v2.33.2...v2.34.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump svelte-i18n from 3.2.5 to 3.3.0 in /site (#1039) Bumps [svelte-i18n](https://github.com/kaisermann/svelte-i18n) from 3.2.5 to 3.3.0. - [Release notes](https://github.com/kaisermann/svelte-i18n/releases) - [Changelog](https://github.com/kaisermann/svelte-i18n/blob/main/CHANGELOG.md) - [Commits](https://github.com/kaisermann/svelte-i18n/compare/v3.2.5...v3.3.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @rollup/plugin-url from 5.0.1 to 6.0.0 in /site (#1038) Bumps [@rollup/plugin-url](https://github.com/rollup/plugins) from 5.0.1 to 6.0.0. - [Release notes](https://github.com/rollup/plugins/releases) - [Commits](https://github.com/rollup/plugins/compare/url-v5.0.1...url-v6.0.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump svelte from 3.29.7 to 3.30.1 in /site (#1037) Bumps [svelte](https://github.com/sveltejs/svelte) from 3.29.7 to 3.30.1. - [Release notes](https://github.com/sveltejs/svelte/releases) - [Changelog](https://github.com/sveltejs/svelte/blob/master/CHANGELOG.md) - [Commits](https://github.com/sveltejs/svelte/compare/v3.29.7...v3.30.1) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump marked from 1.2.4 to 1.2.5 in /site (#1036) Bumps [marked](https://github.com/markedjs/marked) from 1.2.4 to 1.2.5. - [Release notes](https://github.com/markedjs/marked/releases) - [Changelog](https://github.com/markedjs/marked/blob/master/release.config.js) - [Commits](https://github.com/markedjs/marked/compare/v1.2.4...v1.2.5) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @babel/core from 7.12.3 to 7.12.9 in /site (#1035) Bumps [@babel/core](https://github.com/babel/babel/tree/HEAD/packages/babel-core) from 7.12.3 to 7.12.9. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.12.9/packages/babel-core) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump rollup-plugin-svelte from 6.1.1 to 7.0.0 in /site (#1034) Bumps [rollup-plugin-svelte](https://github.com/sveltejs/rollup-plugin-svelte) from 6.1.1 to 7.0.0. - [Release notes](https://github.com/sveltejs/rollup-plugin-svelte/releases) - [Changelog](https://github.com/sveltejs/rollup-plugin-svelte/blob/master/CHANGELOG.md) - [Commits](https://github.com/sveltejs/rollup-plugin-svelte/compare/v6.1.1...v7.0.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @rollup/plugin-commonjs in /site (#1033) Bumps [@rollup/plugin-commonjs](https://github.com/rollup/plugins) from 15.1.0 to 17.0.0. - [Release notes](https://github.com/rollup/plugins/releases) - [Commits](https://github.com/rollup/plugins/compare/commonjs-v15.1.0...commonjs-v17.0.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @rollup/plugin-node-resolve in /site (#1032) Bumps [@rollup/plugin-node-resolve](https://github.com/rollup/plugins) from 10.0.0 to 11.0.0. - [Release notes](https://github.com/rollup/plugins/releases) - [Commits](https://github.com/rollup/plugins/compare/node-resolve-v10.0.0...commonjs-v11.0.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @babel/preset-env from 7.12.1 to 7.12.7 in /site (#1031) Bumps [@babel/preset-env](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env) from 7.12.1 to 7.12.7. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.12.7/packages/babel-preset-env) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * go * bundle files, lgn-color, legacy theme * remove old references * light dark context, button styles, zitadel brand * button theme, edit templates * typography theme mixins * input styles, container, extend light dark palette * footer, palette, container * container, label, assets, header * action container, input, typography label, adapt button theme * a and footer styles, adapt palette * user log profile, resourcetempurl * postinstall againnn * wrochage * rm local grpc * button elevation, helper for components * radio * radio button mixins, bundle * qr code styles, secret clipboard, icon pack * stroked buttons, icon buttons, header action, typography * fix password policy styles * account selection * account selection, lgn avatar * mocks * template fixes, animations scss * checkbox, register temp * checkbox appr * fix checkbox, remove input interference * select theme * avatar script, user selection, password policy validation fix * fix formfield state for register and change pwd * footer, main style, qr code fix, mfa type fix, account sel, checkbox * fotter tos, user select * reverse buttons for intial submit action * theme script, themed error messages, header img source * content wrapper, i18n, mobile * emptyline * idp mixins, fix unstyled html * register container * register layout, list themes, policy theme, register org * massive asset cleanup * fix source path, add missing icon, fix complexity refs, prefix * remove material icons, unused assets, fix icon font * move icon pack * avatar, contrast theme, error fix * zitadel css map * revert go mod * fix mfa verify actions * add idp styles * fix google colors, idp styles * fix: bugs * fix register options, google * fix script, mobile layout * precompile font selection * go mod tidy * assets and cleanup * input suffix, fix alignment, actions, add progress bar themes * progress bar mixins, layout fixes * remove test from loginname * cleanup comments, scripts * clear comments * fix external back button * fix mfa alignment * fix actions layout, on dom change listener for suffix * free tier change, success label * fix: button font line-height * remove tabindex * remove comment * remove comment * Update internal/ui/login/handler/password_handler.go Co-authored-by: Livio Amstutz <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Maximilian Peintner <[email protected]> Co-authored-by: Livio Amstutz <[email protected]> * chore(console): dependencies (#1233) * chore(deps-dev): bump @angular-devkit/build-angular in /console (#1214) Bumps [@angular-devkit/build-angular](https://github.com/angular/angular-cli) from 0.1101.1 to 0.1101.2. - [Release notes](https://github.com/angular/angular-cli/releases) - [Commits](https://github.com/angular/angular-cli/commits) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump karma from 6.0.1 to 6.0.3 in /console (#1215) Bumps [karma](https://github.com/karma-runner/karma) from 6.0.1 to 6.0.3. - [Release notes](https://github.com/karma-runner/karma/releases) - [Changelog](https://github.com/karma-runner/karma/blob/master/CHANGELOG.md) - [Commits](https://github.com/karma-runner/karma/compare/v6.0.1...v6.0.3) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @angular/language-service in /console (#1216) Bumps [@angular/language-service](https://github.com/angular/angular/tree/HEAD/packages/language-service) from 11.1.0 to 11.1.1. - [Release notes](https://github.com/angular/angular/releases) - [Changelog](https://github.com/angular/angular/blob/master/CHANGELOG.md) - [Commits](https://github.com/angular/angular/commits/11.1.1/packages/language-service) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @angular/cli from 11.1.1 to 11.1.2 in /console (#1217) Bumps [@angular/cli](https://github.com/angular/angular-cli) from 11.1.1 to 11.1.2. - [Release notes](https://github.com/angular/angular-cli/releases) - [Commits](https://github.com/angular/angular-cli/compare/v11.1.1...v11.1.2) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Max Peintner <[email protected]> * lock * site deps Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: get email texts with default language (#1238) * fix(login): mail verification (#1237) * fix: mail verification * not block, stroked * fix: issues of new login ui (#1241) * fix: i18n of register * fix: autofocus * feat(operator): zitadel and database operator (#1208) * feat(operator): add base for zitadel operator * fix(operator): changed pipeline to release operator * fix(operator): fmt with only one parameter * fix(operator): corrected workflow job name * fix(zitadelctl): added restore and backuplist command * fix(zitadelctl): scale for restore * chore(container): use scratch for deploy container * fix(zitadelctl): limit image to scratch * fix(migration): added migration scripts for newer version * fix(operator): changed handling of kubeconfig in operator logic * fix(operator): changed handling of secrets in operator logic * fix(operator): use new version of zitadel * fix(operator): added path for migrations * fix(operator): delete doublets of migration scripts * fix(operator): delete subpaths and integrate logic into init container * fix(operator): corrected path in dockerfile for local migrations * fix(operator): added migrations for cockroachdb-secure * fix(operator): delete logic for ambassador module * fix(operator): added read and write secret commands * fix(operator): correct and align operator pipeline with zitadel pipeline * fix(operator): correct yaml error in operator pipeline * fix(operator): correct action name in operator pipeline * fix(operator): correct case-sensitive filename in operator pipeline * fix(operator): upload artifacts from buildx output * fix(operator): corrected attribute spelling error * fix(operator): combined jobs for operator binary and image * fix(operator): added missing comma in operator pipeline * fix(operator): added codecov for operator image * fix(operator): added codecov for operator image * fix(testing): code changes for testing and several unit-tests (#1009) * fix(operator): usage of interface of kubernetes client for testing and several unit-tests * fix(operator): several unit-tests * fix(operator): several unit-tests * fix(operator): changed order for the operator logic * fix(operator): added version of zitadelctl from semantic release * fix(operator): corrected function call with version of zitadelctl * fix(operator): corrected function call with version of zitadelctl * fix(operator): add check output to operator release pipeline * fix(operator): set --short length everywhere to 12 * fix(operator): zitadel setup in job instead of exec with several unit tests * fix(operator): fixes to combine newest zitadel and testing branch * fix(operator): corrected path in Dockerfile * fix(operator): fixed unit-test that was ignored during changes * fix(operator): fixed unit-test that was ignored during changes * fix(operator): corrected Dockerfile to correctly use env variable * fix(operator): quickfix takeoff deployment * fix(operator): corrected the clusterrolename in the applied artifacts * fix: update secure migrations * fix(operator): migrations (#1057) * fix(operator): copied migrations from orbos repository * fix(operator): newest migrations * chore: use cockroach-secure * fix: rename migration * fix: remove insecure cockroach migrations Co-authored-by: Stefan Benz <[email protected]> * fix: finalize labels * fix(operator): cli logging concurrent and fixe deployment of operator during restore * fix: finalize labels and cli commands * fix: restore * chore: cockroachdb is always secure * chore: use orbos consistent-labels latest commit * test: make tests compatible with new labels * fix: default to sa token for start command * fix: use cockroachdb v12.02 * fix: don't delete flyway user * test: fix migration test * fix: use correct table qualifiers * fix: don't alter sequence ownership * fix: upgrade flyway * fix: change ownership of all dbs and tables to admin user * fix: change defaultdb user * fix: treat clientid status codes >= 400 as errors * fix: reconcile specified ZITADEL version, not binary version * fix: add ca-certs * fix: use latest orbos code * fix: use orbos with fixed race condition * fix: use latest ORBOS code * fix: use latest ORBOS code * fix: make migration and scaling around restoring work * fix(operator): move zitadel operator * chore(migrations): include owner change migration * feat(db): add code base for database operator * fix(db): change used image registry for database operator * fix(db): generated mock * fix(db): add accidentally ignored file * fix(db): add cockroachdb backup image to pipeline * fix(db): correct pipeline and image versions * fix(db): correct version of used orbos * fix(db): correct database import * fix(db): go mod tidy * fix(db): use new version for orbos * fix(migrations): include migrations into zitadelctl binary (#1211) * fix(db): use statik to integrate migrations into binary * fix(migrations): corrections unit tests and pipeline for integrated migrations into zitadelctl binary * fix(migrations): correction in dockerfile for pipeline build * fix(migrations): correction in dockerfile for pipeline build * fix(migrations): dockerfile changes for cache optimization * fix(database): correct used part-of label in database operator * fix(database): correct used selectable label in zitadel operator * fix(operator): correct lables for user secrets in zitadel operator * fix(operator): correct lables for service test in zitadel operator * fix: don't enable database features for user operations (#1227) * fix: don't enable database features for user operations * fix: omit database feature for connection info adapter * fix: use latest orbos version * fix: update ORBOS (#1240) Co-authored-by: Florian Forster <[email protected]> Co-authored-by: Elio Bischof <[email protected]> * Merge branch 'new-eventstore' into cascades # Conflicts: # internal/auth/repository/auth_request.go # internal/auth/repository/eventsourcing/eventstore/auth_request.go # internal/management/repository/eventsourcing/eventstore/user_grant.go # internal/management/repository/user_grant.go # internal/ui/login/handler/external_login_handler.go # internal/ui/login/handler/external_register_handler.go # internal/ui/login/handler/init_password_handler.go # internal/ui/login/handler/register_handler.go # internal/user/repository/view/model/notify_user.go # internal/v2/command/org_policy_login.go # internal/v2/command/project.go # internal/v2/command/user.go # internal/v2/command/user_human.go # internal/v2/command/user_human_externalidp.go # internal/v2/command/user_human_init.go # internal/v2/command/user_human_password.go # internal/v2/command/user_human_webauthn.go # internal/v2/domain/next_step.go # internal/v2/domain/policy_login.go # internal/v2/domain/request.go * chore: add local migrate_local.go again (#1261) Co-authored-by: Max Peintner <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Michael Waeger <[email protected]> Co-authored-by: Livio Amstutz <[email protected]> Co-authored-by: Maximilian Peintner <[email protected]> Co-authored-by: Stefan Benz <[email protected]> Co-authored-by: Florian Forster <[email protected]> Co-authored-by: Elio Bischof <[email protected]>
This commit is contained in:
co-authored by
Max Peintner
dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Michael Waeger
Livio Amstutz
Maximilian Peintner
Stefan Benz
Florian Forster
Elio Bischof
parent
320679467b
commit
db11cf1da3
@@ -0,0 +1,49 @@
|
||||
package iam
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/orbos/pkg/orb"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/secret"
|
||||
"github.com/caos/orbos/pkg/tree"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel"
|
||||
"github.com/pkg/errors"
|
||||
core "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
func GetQueryAndDestroyFuncs(
|
||||
monitor mntr.Monitor,
|
||||
operatorLabels *labels.Operator,
|
||||
desiredTree *tree.Tree,
|
||||
currentTree *tree.Tree,
|
||||
nodeselector map[string]string,
|
||||
tolerations []core.Toleration,
|
||||
orbconfig *orb.Orb,
|
||||
action string,
|
||||
version *string,
|
||||
features []string,
|
||||
) (
|
||||
query operator.QueryFunc,
|
||||
destroy operator.DestroyFunc,
|
||||
secrets map[string]*secret.Secret,
|
||||
err error,
|
||||
) {
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("adapting %s failed: %w", desiredTree.Common.Kind, err)
|
||||
}
|
||||
}()
|
||||
|
||||
switch desiredTree.Common.Kind {
|
||||
case "zitadel.caos.ch/ZITADEL":
|
||||
apiLabels := labels.MustForAPI(operatorLabels, "ZITADEL", desiredTree.Common.Version)
|
||||
return zitadel.AdaptFunc(apiLabels, nodeselector, tolerations, orbconfig, action, version, features)(monitor, desiredTree, currentTree)
|
||||
default:
|
||||
return nil, nil, nil, errors.Errorf("unknown iam kind %s", desiredTree.Common.Kind)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
package zitadel
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/orbos/pkg/orb"
|
||||
"github.com/caos/orbos/pkg/secret"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/setup"
|
||||
|
||||
core "k8s.io/api/core/v1"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/kubernetes/resources/namespace"
|
||||
"github.com/caos/orbos/pkg/tree"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/ambassador"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/configuration"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/deployment"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/migration"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/services"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func AdaptFunc(
|
||||
apiLabels *labels.API,
|
||||
nodeselector map[string]string,
|
||||
tolerations []core.Toleration,
|
||||
orbconfig *orb.Orb,
|
||||
action string,
|
||||
version *string,
|
||||
features []string,
|
||||
) operator.AdaptFunc {
|
||||
return func(
|
||||
monitor mntr.Monitor,
|
||||
desired *tree.Tree,
|
||||
current *tree.Tree,
|
||||
) (
|
||||
operator.QueryFunc,
|
||||
operator.DestroyFunc,
|
||||
map[string]*secret.Secret,
|
||||
error,
|
||||
) {
|
||||
|
||||
allSecrets := make(map[string]*secret.Secret)
|
||||
internalMonitor := monitor.WithField("kind", "iam")
|
||||
|
||||
desiredKind, err := parseDesiredV0(desired)
|
||||
if err != nil {
|
||||
return nil, nil, allSecrets, errors.Wrap(err, "parsing desired state failed")
|
||||
}
|
||||
desired.Parsed = desiredKind
|
||||
secret.AppendSecrets("", allSecrets, getSecretsMap(desiredKind))
|
||||
|
||||
if !monitor.IsVerbose() && desiredKind.Spec.Verbose {
|
||||
internalMonitor.Verbose()
|
||||
}
|
||||
|
||||
namespaceStr := "caos-zitadel"
|
||||
// shared elements
|
||||
cmName := "zitadel-vars"
|
||||
secretName := "zitadel-secret"
|
||||
consoleCMName := "console-config"
|
||||
secretVarsName := "zitadel-secrets-vars"
|
||||
secretPasswordName := "zitadel-passwords"
|
||||
//paths which are used in the configuration and also are used for mounting the used files
|
||||
certPath := "/home/zitadel/dbsecrets-zitadel"
|
||||
secretPath := "/secret"
|
||||
//services which are kubernetes resources and are used in the ambassador elements
|
||||
grpcServiceName := "grpc-v1"
|
||||
var grpcPort uint16 = 80
|
||||
httpServiceName := "http-v1"
|
||||
var httpPort uint16 = 80
|
||||
uiServiceName := "ui-v1"
|
||||
var uiPort uint16 = 80
|
||||
|
||||
// labels := getLabels()
|
||||
users := getAllUsers(desiredKind)
|
||||
allZitadelUsers := getZitadelUserList()
|
||||
dbClient, err := database.NewClient(monitor, orbconfig.URL, orbconfig.Repokey)
|
||||
if err != nil {
|
||||
return nil, nil, allSecrets, err
|
||||
}
|
||||
|
||||
queryNS, err := namespace.AdaptFuncToEnsure(namespaceStr)
|
||||
if err != nil {
|
||||
return nil, nil, allSecrets, err
|
||||
}
|
||||
destroyNS, err := namespace.AdaptFuncToDestroy(namespaceStr)
|
||||
if err != nil {
|
||||
return nil, nil, allSecrets, err
|
||||
}
|
||||
|
||||
zitadelComponent := labels.MustForComponent(apiLabels, "ZITADEL")
|
||||
zitadelDeploymentName := labels.MustForName(zitadelComponent, "zitadel")
|
||||
zitadelPodSelector := labels.DeriveNameSelector(zitadelDeploymentName, false)
|
||||
queryS, destroyS, err := services.AdaptFunc(
|
||||
internalMonitor,
|
||||
zitadelComponent,
|
||||
zitadelPodSelector,
|
||||
namespaceStr,
|
||||
grpcServiceName,
|
||||
grpcPort,
|
||||
httpServiceName,
|
||||
httpPort,
|
||||
uiServiceName,
|
||||
uiPort)
|
||||
if err != nil {
|
||||
return nil, nil, allSecrets, err
|
||||
}
|
||||
|
||||
queryC, destroyC, getConfigurationHashes, err := configuration.AdaptFunc(
|
||||
internalMonitor,
|
||||
zitadelComponent,
|
||||
namespaceStr,
|
||||
desiredKind.Spec.Configuration,
|
||||
cmName,
|
||||
certPath,
|
||||
secretName,
|
||||
secretPath,
|
||||
consoleCMName,
|
||||
secretVarsName,
|
||||
secretPasswordName,
|
||||
users,
|
||||
services.GetClientIDFunc(namespaceStr, httpServiceName, httpPort),
|
||||
dbClient,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, allSecrets, err
|
||||
}
|
||||
|
||||
queryDB, err := database.AdaptFunc(
|
||||
monitor,
|
||||
dbClient,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, allSecrets, err
|
||||
}
|
||||
|
||||
queryM, destroyM, err := migration.AdaptFunc(
|
||||
internalMonitor,
|
||||
labels.MustForComponent(apiLabels, "database"),
|
||||
namespaceStr,
|
||||
action,
|
||||
secretPasswordName,
|
||||
migrationUser,
|
||||
allZitadelUsers,
|
||||
nodeselector,
|
||||
tolerations,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, allSecrets, err
|
||||
}
|
||||
|
||||
querySetup, destroySetup, err := setup.AdaptFunc(
|
||||
internalMonitor,
|
||||
zitadelComponent,
|
||||
namespaceStr,
|
||||
action,
|
||||
desiredKind.Spec.NodeSelector,
|
||||
desiredKind.Spec.Tolerations,
|
||||
desiredKind.Spec.Resources,
|
||||
version,
|
||||
cmName,
|
||||
certPath,
|
||||
secretName,
|
||||
secretPath,
|
||||
consoleCMName,
|
||||
secretVarsName,
|
||||
secretPasswordName,
|
||||
allZitadelUsers,
|
||||
migration.GetDoneFunc(monitor, namespaceStr, action),
|
||||
configuration.GetReadyFunc(monitor, namespaceStr, secretName, secretVarsName, secretPasswordName, cmName, consoleCMName),
|
||||
getConfigurationHashes,
|
||||
)
|
||||
|
||||
queryD, destroyD, err := deployment.AdaptFunc(
|
||||
internalMonitor,
|
||||
zitadelDeploymentName,
|
||||
zitadelPodSelector,
|
||||
desiredKind.Spec.Force,
|
||||
version,
|
||||
namespaceStr,
|
||||
desiredKind.Spec.ReplicaCount,
|
||||
desiredKind.Spec.Affinity,
|
||||
cmName,
|
||||
certPath,
|
||||
secretName,
|
||||
secretPath,
|
||||
consoleCMName,
|
||||
secretVarsName,
|
||||
secretPasswordName,
|
||||
allZitadelUsers,
|
||||
desiredKind.Spec.NodeSelector,
|
||||
desiredKind.Spec.Tolerations,
|
||||
desiredKind.Spec.Resources,
|
||||
migration.GetDoneFunc(monitor, namespaceStr, action),
|
||||
configuration.GetReadyFunc(monitor, namespaceStr, secretName, secretVarsName, secretPasswordName, cmName, consoleCMName),
|
||||
setup.GetDoneFunc(monitor, namespaceStr, action),
|
||||
getConfigurationHashes,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, allSecrets, err
|
||||
}
|
||||
|
||||
queryAmbassador, destroyAmbassador, err := ambassador.AdaptFunc(
|
||||
internalMonitor,
|
||||
labels.MustForComponent(apiLabels, "apiGateway"),
|
||||
namespaceStr,
|
||||
grpcServiceName+"."+namespaceStr+":"+strconv.Itoa(int(grpcPort)),
|
||||
"http://"+httpServiceName+"."+namespaceStr+":"+strconv.Itoa(int(httpPort)),
|
||||
"http://"+uiServiceName+"."+namespaceStr,
|
||||
desiredKind.Spec.Configuration.DNS,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, allSecrets, err
|
||||
}
|
||||
|
||||
destroyers := make([]operator.DestroyFunc, 0)
|
||||
queriers := make([]operator.QueryFunc, 0)
|
||||
for _, feature := range features {
|
||||
switch feature {
|
||||
case "migration":
|
||||
queriers = append(queriers,
|
||||
queryDB,
|
||||
//configuration
|
||||
queryC,
|
||||
//migration
|
||||
queryM,
|
||||
//wait until migration is completed
|
||||
operator.EnsureFuncToQueryFunc(migration.GetDoneFunc(monitor, namespaceStr, action)),
|
||||
)
|
||||
destroyers = append(destroyers,
|
||||
destroyM,
|
||||
)
|
||||
case "iam":
|
||||
queriers = append(queriers,
|
||||
operator.ResourceQueryToZitadelQuery(queryNS),
|
||||
queryDB,
|
||||
//configuration
|
||||
queryC,
|
||||
//migration
|
||||
queryM,
|
||||
//services
|
||||
queryS,
|
||||
querySetup,
|
||||
queryD,
|
||||
operator.EnsureFuncToQueryFunc(deployment.GetReadyFunc(monitor, namespaceStr, zitadelDeploymentName)),
|
||||
queryAmbassador,
|
||||
)
|
||||
destroyers = append(destroyers,
|
||||
destroyAmbassador,
|
||||
destroyS,
|
||||
destroyM,
|
||||
destroyD,
|
||||
destroySetup,
|
||||
destroyC,
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyNS),
|
||||
)
|
||||
case "scaledown":
|
||||
queriers = append(queriers,
|
||||
operator.EnsureFuncToQueryFunc(deployment.GetScaleFunc(monitor, namespaceStr, zitadelDeploymentName)(0)),
|
||||
)
|
||||
case "scaleup":
|
||||
queriers = append(queriers,
|
||||
operator.EnsureFuncToQueryFunc(deployment.GetScaleFunc(monitor, namespaceStr, zitadelDeploymentName)(desiredKind.Spec.ReplicaCount)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (operator.EnsureFunc, error) {
|
||||
return operator.QueriersToEnsureFunc(internalMonitor, true, queriers, k8sClient, queried)
|
||||
},
|
||||
operator.DestroyersToDestroyFunc(monitor, destroyers),
|
||||
allSecrets,
|
||||
nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package ambassador
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/ambassador/grpc"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/ambassador/hosts"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/ambassador/http"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/ambassador/ui"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/configuration"
|
||||
)
|
||||
|
||||
func AdaptFunc(
|
||||
monitor mntr.Monitor,
|
||||
componentLabels *labels.Component,
|
||||
namespace string,
|
||||
grpcURL string,
|
||||
httpURL string,
|
||||
uiURL string,
|
||||
dns *configuration.DNS,
|
||||
) (
|
||||
operator.QueryFunc,
|
||||
operator.DestroyFunc,
|
||||
error,
|
||||
) {
|
||||
internalMonitor := monitor.WithField("type", "ambassador")
|
||||
|
||||
queryGRPC, destroyGRPC, err := grpc.AdaptFunc(internalMonitor, componentLabels, namespace, grpcURL, dns)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
queryUI, destroyHTTP, err := ui.AdaptFunc(internalMonitor, componentLabels, namespace, uiURL, dns)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
queryHTTP, destroyUI, err := http.AdaptFunc(internalMonitor, componentLabels, namespace, httpURL, dns)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
queryHosts, destroyHosts, err := hosts.AdaptFunc(internalMonitor, componentLabels, namespace, dns)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyers := []operator.DestroyFunc{
|
||||
destroyGRPC,
|
||||
destroyHTTP,
|
||||
destroyUI,
|
||||
destroyHosts,
|
||||
}
|
||||
|
||||
queriers := []operator.QueryFunc{
|
||||
queryHosts,
|
||||
queryGRPC,
|
||||
queryUI,
|
||||
queryHTTP,
|
||||
}
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (operator.EnsureFunc, error) {
|
||||
return operator.QueriersToEnsureFunc(internalMonitor, true, queriers, k8sClient, queried)
|
||||
},
|
||||
operator.DestroyersToDestroyFunc(internalMonitor, destroyers),
|
||||
nil
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package ambassador
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/caos/orbos/pkg/labels/mocklabels"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/ambassador/grpc"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/ambassador/hosts"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/ambassador/http"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/ambassador/ui"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/configuration"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
apixv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
func SetReturnResourceVersion(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
group,
|
||||
version,
|
||||
kind,
|
||||
namespace,
|
||||
name string,
|
||||
resourceVersion string,
|
||||
) {
|
||||
ret := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"resourceVersion": resourceVersion,
|
||||
},
|
||||
},
|
||||
}
|
||||
k8sClient.EXPECT().GetNamespacedCRDResource(group, version, kind, namespace, name).Return(ret, nil)
|
||||
}
|
||||
|
||||
func SetMappingsUI(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
namespace string,
|
||||
) {
|
||||
group := "getambassador.io"
|
||||
version := "v2"
|
||||
kind := "Mapping"
|
||||
k8sClient.EXPECT().CheckCRD("mappings.getambassador.io").Times(1).Return(&apixv1beta1.CustomResourceDefinition{}, nil)
|
||||
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, ui.AccountsName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, ui.AccountsName, gomock.Any()).Times(1)
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, ui.ConsoleName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, ui.ConsoleName, gomock.Any()).Times(1)
|
||||
}
|
||||
|
||||
func SetMappingsHTTP(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
namespace string,
|
||||
) {
|
||||
group := "getambassador.io"
|
||||
version := "v2"
|
||||
kind := "Mapping"
|
||||
k8sClient.EXPECT().CheckCRD("mappings.getambassador.io").Times(1).Return(&apixv1beta1.CustomResourceDefinition{}, nil)
|
||||
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, http.AdminRName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, http.AdminRName, gomock.Any()).Times(1)
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, http.AuthorizeName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, http.AuthorizeName, gomock.Any()).Times(1)
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, http.AuthRName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, http.AuthRName, gomock.Any()).Times(1)
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, http.EndsessionName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, http.EndsessionName, gomock.Any()).Times(1)
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, http.IssuerName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, http.IssuerName, gomock.Any()).Times(1)
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, http.MgmtName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, http.MgmtName, gomock.Any()).Times(1)
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, http.OauthName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, http.OauthName, gomock.Any()).Times(1)
|
||||
}
|
||||
|
||||
func SetMappingsGRPC(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
namespace string,
|
||||
) {
|
||||
group := "getambassador.io"
|
||||
version := "v2"
|
||||
kind := "Mapping"
|
||||
k8sClient.EXPECT().CheckCRD("mappings.getambassador.io").Times(1).Return(&apixv1beta1.CustomResourceDefinition{}, nil)
|
||||
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, grpc.AdminMName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, grpc.AdminMName, gomock.Any()).Times(1)
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, grpc.AuthMName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, grpc.AuthMName, gomock.Any()).Times(1)
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, grpc.MgmtMName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, grpc.MgmtMName, gomock.Any()).Times(1)
|
||||
}
|
||||
|
||||
func SetHosts(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
namespace string,
|
||||
) {
|
||||
group := "getambassador.io"
|
||||
version := "v2"
|
||||
kind := "Host"
|
||||
k8sClient.EXPECT().CheckCRD("hosts.getambassador.io").Times(1).Return(&apixv1beta1.CustomResourceDefinition{}, nil)
|
||||
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, hosts.AccountsHostName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, hosts.AccountsHostName, gomock.Any()).Times(1)
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, hosts.ApiHostName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, hosts.ApiHostName, gomock.Any()).Times(1)
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, hosts.ConsoleHostName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, hosts.ConsoleHostName, gomock.Any()).Times(1)
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, hosts.IssuerHostName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, hosts.IssuerHostName, gomock.Any()).Times(1)
|
||||
|
||||
}
|
||||
|
||||
func TestAmbassador_Adapt(t *testing.T) {
|
||||
|
||||
monitor := mntr.Monitor{}
|
||||
namespace := "test"
|
||||
grpcURL := "grpc"
|
||||
httpURL := "http"
|
||||
uiURL := "ui"
|
||||
dns := &configuration.DNS{
|
||||
Domain: "",
|
||||
TlsSecret: "",
|
||||
Subdomains: &configuration.Subdomains{
|
||||
Accounts: "",
|
||||
API: "",
|
||||
Console: "",
|
||||
Issuer: "",
|
||||
},
|
||||
}
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
SetMappingsUI(k8sClient, namespace)
|
||||
SetMappingsHTTP(k8sClient, namespace)
|
||||
SetMappingsGRPC(k8sClient, namespace)
|
||||
SetHosts(k8sClient, namespace)
|
||||
|
||||
query, _, err := AdaptFunc(monitor, mocklabels.Component, namespace, grpcURL, httpURL, uiURL, dns)
|
||||
assert.NoError(t, err)
|
||||
queried := map[string]interface{}{}
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, ensure(k8sClient))
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/kubernetes/resources/ambassador/mapping"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/configuration"
|
||||
)
|
||||
|
||||
const (
|
||||
AdminMName = "admin-grpc-v1"
|
||||
AuthMName = "auth-grpc-v1"
|
||||
MgmtMName = "mgmt-grpc-v1"
|
||||
)
|
||||
|
||||
func AdaptFunc(
|
||||
monitor mntr.Monitor,
|
||||
componentLabels *labels.Component,
|
||||
namespace string,
|
||||
grpcURL string,
|
||||
dns *configuration.DNS,
|
||||
) (
|
||||
operator.QueryFunc,
|
||||
operator.DestroyFunc,
|
||||
error,
|
||||
) {
|
||||
internalMonitor := monitor.WithField("part", "grpc")
|
||||
|
||||
destroyAdminG, err := mapping.AdaptFuncToDestroy(namespace, AdminMName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
destroyAuthG, err := mapping.AdaptFuncToDestroy(namespace, AuthMName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
destroyMgmtGRPC, err := mapping.AdaptFuncToDestroy(namespace, MgmtMName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyers := []operator.DestroyFunc{
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyAdminG),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyAuthG),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyMgmtGRPC),
|
||||
}
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (operator.EnsureFunc, error) {
|
||||
crd, err := k8sClient.CheckCRD("mappings.getambassador.io")
|
||||
if crd == nil || err != nil {
|
||||
return func(k8sClient kubernetes.ClientInt) error { return nil }, nil
|
||||
}
|
||||
|
||||
apiDomain := dns.Subdomains.API + "." + dns.Domain
|
||||
consoleDomain := dns.Subdomains.Console + "." + dns.Domain
|
||||
_ = consoleDomain
|
||||
|
||||
cors := &mapping.CORS{
|
||||
Origins: "*",
|
||||
Methods: "POST, GET, OPTIONS, DELETE, PUT",
|
||||
Headers: "*",
|
||||
Credentials: true,
|
||||
ExposedHeaders: "*",
|
||||
MaxAge: "86400",
|
||||
}
|
||||
|
||||
queryAdminG, err := mapping.AdaptFuncToEnsure(
|
||||
namespace,
|
||||
labels.MustForName(componentLabels, AdminMName),
|
||||
true,
|
||||
apiDomain,
|
||||
"/caos.zitadel.admin.api.v1.AdminService/",
|
||||
"",
|
||||
grpcURL,
|
||||
30000,
|
||||
30000,
|
||||
cors,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queryAuthG, err := mapping.AdaptFuncToEnsure(
|
||||
namespace,
|
||||
labels.MustForName(componentLabels, AuthMName),
|
||||
true,
|
||||
apiDomain,
|
||||
"/caos.zitadel.auth.api.v1.AuthService/",
|
||||
"",
|
||||
grpcURL,
|
||||
30000,
|
||||
30000,
|
||||
cors,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queryMgmtGRPC, err := mapping.AdaptFuncToEnsure(
|
||||
namespace,
|
||||
labels.MustForName(componentLabels, MgmtMName),
|
||||
true,
|
||||
apiDomain,
|
||||
"/caos.zitadel.management.api.v1.ManagementService/",
|
||||
"",
|
||||
grpcURL,
|
||||
30000,
|
||||
30000,
|
||||
cors,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queriers := []operator.QueryFunc{
|
||||
operator.ResourceQueryToZitadelQuery(queryAdminG),
|
||||
operator.ResourceQueryToZitadelQuery(queryAuthG),
|
||||
operator.ResourceQueryToZitadelQuery(queryMgmtGRPC),
|
||||
}
|
||||
|
||||
return operator.QueriersToEnsureFunc(internalMonitor, false, queriers, k8sClient, queried)
|
||||
},
|
||||
operator.DestroyersToDestroyFunc(internalMonitor, destroyers),
|
||||
nil
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/caos/orbos/pkg/labels/mocklabels"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/configuration"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
apixv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
func SetReturnResourceVersion(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
group,
|
||||
version,
|
||||
kind,
|
||||
namespace,
|
||||
name string,
|
||||
resourceVersion string,
|
||||
) {
|
||||
ret := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"resourceVersion": resourceVersion,
|
||||
},
|
||||
},
|
||||
}
|
||||
k8sClient.EXPECT().GetNamespacedCRDResource(group, version, kind, namespace, name).Return(ret, nil)
|
||||
}
|
||||
|
||||
func TestGrpc_Adapt(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
namespace := "test"
|
||||
url := "url"
|
||||
dns := &configuration.DNS{
|
||||
Domain: "",
|
||||
TlsSecret: "",
|
||||
Subdomains: &configuration.Subdomains{
|
||||
Accounts: "",
|
||||
API: "",
|
||||
Console: "",
|
||||
Issuer: "",
|
||||
},
|
||||
}
|
||||
|
||||
componentLabels := mocklabels.Component
|
||||
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
k8sClient.EXPECT().CheckCRD("mappings.getambassador.io").Times(1).Return(&apixv1beta1.CustomResourceDefinition{}, nil)
|
||||
|
||||
group := "getambassador.io"
|
||||
version := "v2"
|
||||
kind := "Mapping"
|
||||
|
||||
cors := map[string]interface{}{
|
||||
"origins": "*",
|
||||
"methods": "POST, GET, OPTIONS, DELETE, PUT",
|
||||
"headers": "*",
|
||||
"credentials": true,
|
||||
"exposed_headers": "*",
|
||||
"max_age": "86400",
|
||||
}
|
||||
adminMName := labels.MustForName(componentLabels, AdminMName)
|
||||
adminM := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(adminMName),
|
||||
"name": adminMName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": ".",
|
||||
"prefix": "/caos.zitadel.admin.api.v1.AdminService/",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
"grpc": true,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, AdminMName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, AdminMName, adminM).Times(1)
|
||||
|
||||
authMName := labels.MustForName(componentLabels, AuthMName)
|
||||
authM := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(authMName),
|
||||
"name": authMName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": ".",
|
||||
"prefix": "/caos.zitadel.auth.api.v1.AuthService/",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
"grpc": true,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, AuthMName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, AuthMName, authM).Times(1)
|
||||
|
||||
mgmtMName := labels.MustForName(componentLabels, MgmtMName)
|
||||
mgmtM := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(mgmtMName),
|
||||
"name": mgmtMName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": ".",
|
||||
"prefix": "/caos.zitadel.management.api.v1.ManagementService/",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
"grpc": true,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, MgmtMName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, MgmtMName, mgmtM).Times(1)
|
||||
|
||||
query, _, err := AdaptFunc(monitor, componentLabels, namespace, url, dns)
|
||||
assert.NoError(t, err)
|
||||
queried := map[string]interface{}{}
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, ensure(k8sClient))
|
||||
}
|
||||
|
||||
func TestGrpc_Adapt2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
namespace := "test"
|
||||
url := "url"
|
||||
dns := &configuration.DNS{
|
||||
Domain: "domain",
|
||||
TlsSecret: "tls",
|
||||
Subdomains: &configuration.Subdomains{
|
||||
Accounts: "accounts",
|
||||
API: "api",
|
||||
Console: "console",
|
||||
Issuer: "issuer",
|
||||
},
|
||||
}
|
||||
|
||||
componentLabels := mocklabels.Component
|
||||
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
k8sClient.EXPECT().CheckCRD("mappings.getambassador.io").Times(1).Return(&apixv1beta1.CustomResourceDefinition{}, nil)
|
||||
|
||||
group := "getambassador.io"
|
||||
version := "v2"
|
||||
kind := "Mapping"
|
||||
|
||||
cors := map[string]interface{}{
|
||||
"origins": "*",
|
||||
"methods": "POST, GET, OPTIONS, DELETE, PUT",
|
||||
"headers": "*",
|
||||
"credentials": true,
|
||||
"exposed_headers": "*",
|
||||
"max_age": "86400",
|
||||
}
|
||||
|
||||
adminMName := labels.MustForName(componentLabels, AdminMName)
|
||||
adminM := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(adminMName),
|
||||
"name": adminMName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": "api.domain",
|
||||
"prefix": "/caos.zitadel.admin.api.v1.AdminService/",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
"grpc": true,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, AdminMName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, AdminMName, adminM).Times(1)
|
||||
|
||||
authMName := labels.MustForName(componentLabels, AuthMName)
|
||||
authM := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(authMName),
|
||||
"name": authMName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": "api.domain",
|
||||
"prefix": "/caos.zitadel.auth.api.v1.AuthService/",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
"grpc": true,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, AuthMName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, AuthMName, authM).Times(1)
|
||||
|
||||
mgmtMName := labels.MustForName(componentLabels, MgmtMName)
|
||||
mgmtM := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(mgmtMName),
|
||||
"name": mgmtMName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": "api.domain",
|
||||
"prefix": "/caos.zitadel.management.api.v1.ManagementService/",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
"grpc": true,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, MgmtMName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, MgmtMName, mgmtM).Times(1)
|
||||
|
||||
query, _, err := AdaptFunc(monitor, componentLabels, namespace, url, dns)
|
||||
assert.NoError(t, err)
|
||||
queried := map[string]interface{}{}
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, ensure(k8sClient))
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package hosts
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/kubernetes/resources/ambassador/host"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/configuration"
|
||||
)
|
||||
|
||||
const (
|
||||
AccountsHostName = "accounts"
|
||||
ApiHostName = "api"
|
||||
ConsoleHostName = "console"
|
||||
IssuerHostName = "issuer"
|
||||
)
|
||||
|
||||
func AdaptFunc(
|
||||
monitor mntr.Monitor,
|
||||
componentLabels *labels.Component,
|
||||
namespace string,
|
||||
dns *configuration.DNS,
|
||||
) (
|
||||
operator.QueryFunc,
|
||||
operator.DestroyFunc,
|
||||
error,
|
||||
) {
|
||||
internalMonitor := monitor.WithField("part", "hosts")
|
||||
|
||||
destroyAccounts, err := host.AdaptFuncToDestroy(namespace, AccountsHostName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyAPI, err := host.AdaptFuncToDestroy(namespace, ApiHostName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyConsole, err := host.AdaptFuncToDestroy(namespace, ConsoleHostName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyIssuer, err := host.AdaptFuncToDestroy(namespace, IssuerHostName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyers := []operator.DestroyFunc{
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyAccounts),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyAPI),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyConsole),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyIssuer),
|
||||
}
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (operator.EnsureFunc, error) {
|
||||
crd, err := k8sClient.CheckCRD("hosts.getambassador.io")
|
||||
if crd == nil || err != nil {
|
||||
return func(k8sClient kubernetes.ClientInt) error { return nil }, nil
|
||||
}
|
||||
|
||||
accountsDomain := dns.Subdomains.Accounts + "." + dns.Domain
|
||||
apiDomain := dns.Subdomains.API + "." + dns.Domain
|
||||
consoleDomain := dns.Subdomains.Console + "." + dns.Domain
|
||||
issuerDomain := dns.Subdomains.Issuer + "." + dns.Domain
|
||||
originCASecretName := dns.TlsSecret
|
||||
|
||||
accountsSelector := map[string]string{
|
||||
"hostname": accountsDomain,
|
||||
}
|
||||
queryAccounts, err := host.AdaptFuncToEnsure(namespace, AccountsHostName, labels.MustForNameK8SMap(componentLabels, AccountsHostName), accountsDomain, "none", "", accountsSelector, originCASecretName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
apiSelector := map[string]string{
|
||||
"hostname": apiDomain,
|
||||
}
|
||||
queryAPI, err := host.AdaptFuncToEnsure(namespace, ApiHostName, labels.MustForNameK8SMap(componentLabels, ApiHostName), apiDomain, "none", "", apiSelector, originCASecretName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
consoleSelector := map[string]string{
|
||||
"hostname": consoleDomain,
|
||||
}
|
||||
queryConsole, err := host.AdaptFuncToEnsure(namespace, ConsoleHostName, labels.MustForNameK8SMap(componentLabels, ConsoleHostName), consoleDomain, "none", "", consoleSelector, originCASecretName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
issuerSelector := map[string]string{
|
||||
"hostname": issuerDomain,
|
||||
}
|
||||
queryIssuer, err := host.AdaptFuncToEnsure(namespace, IssuerHostName, labels.MustForNameK8SMap(componentLabels, IssuerHostName), issuerDomain, "none", "", issuerSelector, originCASecretName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queriers := []operator.QueryFunc{
|
||||
operator.ResourceQueryToZitadelQuery(queryAccounts),
|
||||
operator.ResourceQueryToZitadelQuery(queryAPI),
|
||||
operator.ResourceQueryToZitadelQuery(queryConsole),
|
||||
operator.ResourceQueryToZitadelQuery(queryIssuer),
|
||||
}
|
||||
|
||||
return operator.QueriersToEnsureFunc(internalMonitor, false, queriers, k8sClient, queried)
|
||||
},
|
||||
operator.DestroyersToDestroyFunc(internalMonitor, destroyers),
|
||||
nil
|
||||
}
|
||||
@@ -0,0 +1,379 @@
|
||||
package hosts
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/orbos/pkg/labels/mocklabels"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/configuration"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
apixv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
func SetReturnResourceVersion(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
group,
|
||||
version,
|
||||
kind,
|
||||
namespace,
|
||||
name string,
|
||||
resourceVersion string,
|
||||
) {
|
||||
ret := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"resourceVersion": resourceVersion,
|
||||
},
|
||||
},
|
||||
}
|
||||
k8sClient.EXPECT().GetNamespacedCRDResource(group, version, kind, namespace, name).Return(ret, nil)
|
||||
}
|
||||
|
||||
func TestHosts_AdaptFunc(t *testing.T) {
|
||||
|
||||
monitor := mntr.Monitor{}
|
||||
namespace := "test"
|
||||
dns := &configuration.DNS{
|
||||
Domain: "",
|
||||
TlsSecret: "",
|
||||
Subdomains: &configuration.Subdomains{
|
||||
Accounts: "",
|
||||
API: "",
|
||||
Console: "",
|
||||
Issuer: "",
|
||||
},
|
||||
}
|
||||
|
||||
componentLabels := mocklabels.Component
|
||||
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
k8sClient.EXPECT().CheckCRD("hosts.getambassador.io").Times(1).Return(&apixv1beta1.CustomResourceDefinition{}, nil)
|
||||
|
||||
group := "getambassador.io"
|
||||
version := "v2"
|
||||
kind := "Host"
|
||||
|
||||
issuerHostName := labels.MustForName(componentLabels, IssuerHostName)
|
||||
issuerHost := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"kind": kind,
|
||||
"apiVersion": group + "/" + version,
|
||||
"metadata": map[string]interface{}{
|
||||
"name": issuerHostName.Name(),
|
||||
"namespace": namespace,
|
||||
"labels": labels.MustK8sMap(issuerHostName),
|
||||
"annotations": map[string]interface{}{
|
||||
"aes_res_changed": "true",
|
||||
},
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"hostname": ".",
|
||||
"acmeProvider": map[string]interface{}{
|
||||
"authority": "none",
|
||||
},
|
||||
"ambassadorId": []string{
|
||||
"default",
|
||||
},
|
||||
"selector": map[string]interface{}{
|
||||
"matchLabels": map[string]interface{}{
|
||||
"hostname": ".",
|
||||
},
|
||||
},
|
||||
"tlsSecret": map[string]interface{}{
|
||||
"name": "",
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, IssuerHostName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, IssuerHostName, issuerHost).Times(1)
|
||||
|
||||
consoleHostName := labels.MustForName(componentLabels, ConsoleHostName)
|
||||
consoleHost := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"kind": kind,
|
||||
"apiVersion": group + "/" + version,
|
||||
"metadata": map[string]interface{}{
|
||||
"name": consoleHostName.Name(),
|
||||
"namespace": namespace,
|
||||
"labels": labels.MustK8sMap(consoleHostName),
|
||||
"annotations": map[string]interface{}{
|
||||
"aes_res_changed": "true",
|
||||
},
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"hostname": ".",
|
||||
"acmeProvider": map[string]interface{}{
|
||||
"authority": "none",
|
||||
},
|
||||
"ambassadorId": []string{
|
||||
"default",
|
||||
},
|
||||
"selector": map[string]interface{}{
|
||||
"matchLabels": map[string]interface{}{
|
||||
"hostname": ".",
|
||||
},
|
||||
},
|
||||
"tlsSecret": map[string]interface{}{
|
||||
"name": "",
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, ConsoleHostName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, ConsoleHostName, consoleHost).Times(1)
|
||||
|
||||
apiHostName := labels.MustForName(componentLabels, ApiHostName)
|
||||
apiHost := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"kind": kind,
|
||||
"apiVersion": group + "/" + version,
|
||||
"metadata": map[string]interface{}{
|
||||
"name": apiHostName.Name(),
|
||||
"namespace": namespace,
|
||||
"labels": labels.MustK8sMap(apiHostName),
|
||||
"annotations": map[string]interface{}{
|
||||
"aes_res_changed": "true",
|
||||
},
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"hostname": ".",
|
||||
"acmeProvider": map[string]interface{}{
|
||||
"authority": "none",
|
||||
},
|
||||
"ambassadorId": []string{
|
||||
"default",
|
||||
},
|
||||
"selector": map[string]interface{}{
|
||||
"matchLabels": map[string]interface{}{
|
||||
"hostname": ".",
|
||||
},
|
||||
},
|
||||
"tlsSecret": map[string]interface{}{
|
||||
"name": "",
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, ApiHostName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, ApiHostName, apiHost).Times(1)
|
||||
|
||||
accountsHostName := labels.MustForName(componentLabels, AccountsHostName)
|
||||
accountsHost := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"kind": kind,
|
||||
"apiVersion": group + "/" + version,
|
||||
"metadata": map[string]interface{}{
|
||||
"name": accountsHostName.Name(),
|
||||
"namespace": namespace,
|
||||
"labels": labels.MustK8sMap(accountsHostName),
|
||||
"annotations": map[string]interface{}{
|
||||
"aes_res_changed": "true",
|
||||
},
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"hostname": ".",
|
||||
"acmeProvider": map[string]interface{}{
|
||||
"authority": "none",
|
||||
},
|
||||
"ambassadorId": []string{
|
||||
"default",
|
||||
},
|
||||
"selector": map[string]interface{}{
|
||||
"matchLabels": map[string]interface{}{
|
||||
"hostname": ".",
|
||||
},
|
||||
},
|
||||
"tlsSecret": map[string]interface{}{
|
||||
"name": "",
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, AccountsHostName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, AccountsHostName, accountsHost).Times(1)
|
||||
|
||||
query, _, err := AdaptFunc(monitor, componentLabels, namespace, dns)
|
||||
assert.NoError(t, err)
|
||||
queried := map[string]interface{}{}
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, ensure(k8sClient))
|
||||
}
|
||||
|
||||
func TestHosts_AdaptFunc2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
namespace := "test"
|
||||
dns := &configuration.DNS{
|
||||
Domain: "domain",
|
||||
TlsSecret: "tls",
|
||||
Subdomains: &configuration.Subdomains{
|
||||
Accounts: "accounts",
|
||||
API: "api",
|
||||
Console: "console",
|
||||
Issuer: "issuer",
|
||||
},
|
||||
}
|
||||
|
||||
componentLabels := mocklabels.Component
|
||||
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
k8sClient.EXPECT().CheckCRD("hosts.getambassador.io").Times(1).Return(&apixv1beta1.CustomResourceDefinition{}, nil)
|
||||
|
||||
group := "getambassador.io"
|
||||
version := "v2"
|
||||
kind := "Host"
|
||||
|
||||
issuerHostName := labels.MustForName(componentLabels, IssuerHostName)
|
||||
issuerHost := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"kind": kind,
|
||||
"apiVersion": group + "/" + version,
|
||||
"metadata": map[string]interface{}{
|
||||
"name": issuerHostName.Name(),
|
||||
"namespace": namespace,
|
||||
"labels": labels.MustK8sMap(issuerHostName),
|
||||
"annotations": map[string]interface{}{
|
||||
"aes_res_changed": "true",
|
||||
},
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"hostname": "issuer.domain",
|
||||
"acmeProvider": map[string]interface{}{
|
||||
"authority": "none",
|
||||
},
|
||||
"ambassadorId": []string{
|
||||
"default",
|
||||
},
|
||||
"selector": map[string]interface{}{
|
||||
"matchLabels": map[string]interface{}{
|
||||
"hostname": "issuer.domain",
|
||||
},
|
||||
},
|
||||
"tlsSecret": map[string]interface{}{
|
||||
"name": "tls",
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, IssuerHostName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, IssuerHostName, issuerHost).Times(1)
|
||||
|
||||
consoleHostName := labels.MustForName(componentLabels, ConsoleHostName)
|
||||
consoleHost := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"kind": kind,
|
||||
"apiVersion": group + "/" + version,
|
||||
"metadata": map[string]interface{}{
|
||||
"name": consoleHostName.Name(),
|
||||
"namespace": namespace,
|
||||
"labels": labels.MustK8sMap(consoleHostName),
|
||||
"annotations": map[string]interface{}{
|
||||
"aes_res_changed": "true",
|
||||
},
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"hostname": "console.domain",
|
||||
"acmeProvider": map[string]interface{}{
|
||||
"authority": "none",
|
||||
},
|
||||
"ambassadorId": []string{
|
||||
"default",
|
||||
},
|
||||
"selector": map[string]interface{}{
|
||||
"matchLabels": map[string]interface{}{
|
||||
"hostname": "console.domain",
|
||||
},
|
||||
},
|
||||
"tlsSecret": map[string]interface{}{
|
||||
"name": "tls",
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, ConsoleHostName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, ConsoleHostName, consoleHost).Times(1)
|
||||
|
||||
apiHostName := labels.MustForName(componentLabels, ApiHostName)
|
||||
apiHost := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"kind": kind,
|
||||
"apiVersion": group + "/" + version,
|
||||
"metadata": map[string]interface{}{
|
||||
"name": apiHostName.Name(),
|
||||
"namespace": namespace,
|
||||
"labels": labels.MustK8sMap(apiHostName),
|
||||
"annotations": map[string]interface{}{
|
||||
"aes_res_changed": "true",
|
||||
},
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"hostname": "api.domain",
|
||||
"acmeProvider": map[string]interface{}{
|
||||
"authority": "none",
|
||||
},
|
||||
"ambassadorId": []string{
|
||||
"default",
|
||||
},
|
||||
"selector": map[string]interface{}{
|
||||
"matchLabels": map[string]interface{}{
|
||||
"hostname": "api.domain",
|
||||
},
|
||||
},
|
||||
"tlsSecret": map[string]interface{}{
|
||||
"name": "tls",
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, ApiHostName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, ApiHostName, apiHost).Times(1)
|
||||
|
||||
accountsHostName := labels.MustForName(componentLabels, AccountsHostName)
|
||||
accountsHost := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"kind": kind,
|
||||
"apiVersion": group + "/" + version,
|
||||
"metadata": map[string]interface{}{
|
||||
"name": accountsHostName.Name(),
|
||||
"namespace": namespace,
|
||||
"labels": labels.MustK8sMap(accountsHostName),
|
||||
"annotations": map[string]interface{}{
|
||||
"aes_res_changed": "true",
|
||||
},
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"hostname": "accounts.domain",
|
||||
"acmeProvider": map[string]interface{}{
|
||||
"authority": "none",
|
||||
},
|
||||
"ambassadorId": []string{
|
||||
"default",
|
||||
},
|
||||
"selector": map[string]interface{}{
|
||||
"matchLabels": map[string]interface{}{
|
||||
"hostname": "accounts.domain",
|
||||
},
|
||||
},
|
||||
"tlsSecret": map[string]interface{}{
|
||||
"name": "tls",
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, AccountsHostName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, AccountsHostName, accountsHost).Times(1)
|
||||
|
||||
query, _, err := AdaptFunc(monitor, componentLabels, namespace, dns)
|
||||
assert.NoError(t, err)
|
||||
queried := map[string]interface{}{}
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, ensure(k8sClient))
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/kubernetes/resources/ambassador/mapping"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/configuration"
|
||||
)
|
||||
|
||||
const (
|
||||
AdminRName = "admin-rest-v1"
|
||||
MgmtName = "mgmt-v1"
|
||||
OauthName = "oauth-v1"
|
||||
AuthRName = "auth-rest-v1"
|
||||
AuthorizeName = "authorize-v1"
|
||||
EndsessionName = "endsession-v1"
|
||||
IssuerName = "issuer-v1"
|
||||
)
|
||||
|
||||
func AdaptFunc(
|
||||
monitor mntr.Monitor,
|
||||
componentLabels *labels.Component,
|
||||
namespace string,
|
||||
httpUrl string,
|
||||
dns *configuration.DNS,
|
||||
) (
|
||||
operator.QueryFunc,
|
||||
operator.DestroyFunc,
|
||||
error,
|
||||
) {
|
||||
internalMonitor := monitor.WithField("part", "http")
|
||||
|
||||
destroyAdminR, err := mapping.AdaptFuncToDestroy(namespace, AdminRName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyMgmtRest, err := mapping.AdaptFuncToDestroy(namespace, MgmtName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyOAuthv2, err := mapping.AdaptFuncToDestroy(namespace, OauthName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyAuthR, err := mapping.AdaptFuncToDestroy(namespace, AuthRName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyAuthorize, err := mapping.AdaptFuncToDestroy(namespace, AuthorizeName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyEndsession, err := mapping.AdaptFuncToDestroy(namespace, EndsessionName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyIssuer, err := mapping.AdaptFuncToDestroy(namespace, IssuerName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyers := []operator.DestroyFunc{
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyAdminR),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyMgmtRest),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyOAuthv2),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyAuthR),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyAuthorize),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyEndsession),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyIssuer),
|
||||
}
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (operator.EnsureFunc, error) {
|
||||
crd, err := k8sClient.CheckCRD("mappings.getambassador.io")
|
||||
if crd == nil || err != nil {
|
||||
return func(k8sClient kubernetes.ClientInt) error { return nil }, nil
|
||||
}
|
||||
|
||||
accountsDomain := dns.Subdomains.Accounts + "." + dns.Domain
|
||||
apiDomain := dns.Subdomains.API + "." + dns.Domain
|
||||
issuerDomain := dns.Subdomains.Issuer + "." + dns.Domain
|
||||
|
||||
cors := &mapping.CORS{
|
||||
Origins: "*",
|
||||
Methods: "POST, GET, OPTIONS, DELETE, PUT",
|
||||
Headers: "*",
|
||||
Credentials: true,
|
||||
ExposedHeaders: "*",
|
||||
MaxAge: "86400",
|
||||
}
|
||||
|
||||
queryAdminR, err := mapping.AdaptFuncToEnsure(
|
||||
namespace,
|
||||
labels.MustForName(componentLabels, AdminRName),
|
||||
false,
|
||||
apiDomain,
|
||||
"/admin/v1",
|
||||
"",
|
||||
httpUrl,
|
||||
30000,
|
||||
30000,
|
||||
cors,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queryMgmtRest, err := mapping.AdaptFuncToEnsure(
|
||||
namespace,
|
||||
labels.MustForName(componentLabels, MgmtName),
|
||||
false,
|
||||
apiDomain,
|
||||
"/management/v1/",
|
||||
"",
|
||||
httpUrl,
|
||||
30000,
|
||||
30000,
|
||||
cors,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queryOAuthv2, err := mapping.AdaptFuncToEnsure(
|
||||
namespace,
|
||||
labels.MustForName(componentLabels, OauthName),
|
||||
false,
|
||||
apiDomain,
|
||||
"/oauth/v2/",
|
||||
"",
|
||||
httpUrl,
|
||||
30000,
|
||||
30000,
|
||||
cors,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queryAuthR, err := mapping.AdaptFuncToEnsure(
|
||||
namespace,
|
||||
labels.MustForName(componentLabels, AuthRName),
|
||||
false,
|
||||
apiDomain,
|
||||
"/auth/v1/",
|
||||
"",
|
||||
httpUrl,
|
||||
30000,
|
||||
30000,
|
||||
cors,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queryAuthorize, err := mapping.AdaptFuncToEnsure(
|
||||
namespace,
|
||||
labels.MustForName(componentLabels, AuthorizeName),
|
||||
false,
|
||||
accountsDomain,
|
||||
"/oauth/v2/authorize",
|
||||
"",
|
||||
httpUrl,
|
||||
30000,
|
||||
30000,
|
||||
cors,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queryEndsession, err := mapping.AdaptFuncToEnsure(
|
||||
namespace,
|
||||
labels.MustForName(componentLabels, EndsessionName),
|
||||
false,
|
||||
accountsDomain,
|
||||
"/oauth/v2/endsession",
|
||||
"",
|
||||
httpUrl,
|
||||
30000,
|
||||
30000,
|
||||
cors,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queryIssuer, err := mapping.AdaptFuncToEnsure(
|
||||
namespace,
|
||||
labels.MustForName(componentLabels, IssuerName),
|
||||
false,
|
||||
issuerDomain,
|
||||
"/.well-known/openid-configuration",
|
||||
"/oauth/v2/.well-known/openid-configuration",
|
||||
httpUrl,
|
||||
30000,
|
||||
30000,
|
||||
cors,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queriers := []operator.QueryFunc{
|
||||
operator.ResourceQueryToZitadelQuery(queryAdminR),
|
||||
operator.ResourceQueryToZitadelQuery(queryMgmtRest),
|
||||
operator.ResourceQueryToZitadelQuery(queryOAuthv2),
|
||||
operator.ResourceQueryToZitadelQuery(queryAuthR),
|
||||
operator.ResourceQueryToZitadelQuery(queryAuthorize),
|
||||
operator.ResourceQueryToZitadelQuery(queryEndsession),
|
||||
operator.ResourceQueryToZitadelQuery(queryIssuer),
|
||||
}
|
||||
|
||||
return operator.QueriersToEnsureFunc(internalMonitor, false, queriers, k8sClient, queried)
|
||||
},
|
||||
operator.DestroyersToDestroyFunc(internalMonitor, destroyers),
|
||||
nil
|
||||
}
|
||||
@@ -0,0 +1,451 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/orbos/pkg/labels/mocklabels"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/configuration"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
apixv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
func SetReturnResourceVersion(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
group,
|
||||
version,
|
||||
kind,
|
||||
namespace,
|
||||
name string,
|
||||
resourceVersion string,
|
||||
) {
|
||||
ret := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"resourceVersion": resourceVersion,
|
||||
},
|
||||
},
|
||||
}
|
||||
k8sClient.EXPECT().GetNamespacedCRDResource(group, version, kind, namespace, name).Return(ret, nil)
|
||||
}
|
||||
|
||||
func TestHttp_Adapt(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
namespace := "test"
|
||||
url := "url"
|
||||
dns := &configuration.DNS{
|
||||
Domain: "",
|
||||
TlsSecret: "",
|
||||
Subdomains: &configuration.Subdomains{
|
||||
Accounts: "",
|
||||
API: "",
|
||||
Console: "",
|
||||
Issuer: "",
|
||||
},
|
||||
}
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
k8sClient.EXPECT().CheckCRD("mappings.getambassador.io").Times(1).Return(&apixv1beta1.CustomResourceDefinition{}, nil)
|
||||
|
||||
group := "getambassador.io"
|
||||
version := "v2"
|
||||
kind := "Mapping"
|
||||
|
||||
cors := map[string]interface{}{
|
||||
"origins": "*",
|
||||
"methods": "POST, GET, OPTIONS, DELETE, PUT",
|
||||
"headers": "*",
|
||||
"credentials": true,
|
||||
"exposed_headers": "*",
|
||||
"max_age": "86400",
|
||||
}
|
||||
|
||||
componentLabels := mocklabels.Component
|
||||
endSessionName := labels.MustForName(componentLabels, EndsessionName)
|
||||
endsession := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(endSessionName),
|
||||
"name": endSessionName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": ".",
|
||||
"prefix": "/oauth/v2/endsession",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, EndsessionName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, EndsessionName, endsession).Times(1)
|
||||
|
||||
issuerName := labels.MustForName(componentLabels, IssuerName)
|
||||
issuer := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(issuerName),
|
||||
"name": issuerName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": ".",
|
||||
"prefix": "/.well-known/openid-configuration",
|
||||
"rewrite": "/oauth/v2/.well-known/openid-configuration",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, IssuerName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, IssuerName, issuer).Times(1)
|
||||
|
||||
authorizeName := labels.MustForName(componentLabels, AuthorizeName)
|
||||
authorize := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(authorizeName),
|
||||
"name": authorizeName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": ".",
|
||||
"prefix": "/oauth/v2/authorize",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, AuthorizeName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, AuthorizeName, authorize).Times(1)
|
||||
|
||||
oauthName := labels.MustForName(componentLabels, OauthName)
|
||||
oauth := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(oauthName),
|
||||
"name": oauthName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": ".",
|
||||
"prefix": "/oauth/v2/",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, OauthName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, OauthName, oauth).Times(1)
|
||||
|
||||
mgmtName := labels.MustForName(componentLabels, MgmtName)
|
||||
mgmt := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(mgmtName),
|
||||
"name": mgmtName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": ".",
|
||||
"prefix": "/management/v1/",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, MgmtName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, MgmtName, mgmt).Times(1)
|
||||
|
||||
adminRName := labels.MustForName(componentLabels, AdminRName)
|
||||
adminR := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(adminRName),
|
||||
"name": adminRName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": ".",
|
||||
"prefix": "/admin/v1",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, AdminRName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, AdminRName, adminR).Times(1)
|
||||
|
||||
authRName := labels.MustForName(componentLabels, AuthRName)
|
||||
authR := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(authRName),
|
||||
"name": authRName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": ".",
|
||||
"prefix": "/auth/v1/",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, AuthRName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, AuthRName, authR).Times(1)
|
||||
|
||||
query, _, err := AdaptFunc(monitor, componentLabels, namespace, url, dns)
|
||||
assert.NoError(t, err)
|
||||
queried := map[string]interface{}{}
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, ensure(k8sClient))
|
||||
}
|
||||
|
||||
func TestHttp_Adapt2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
namespace := "test"
|
||||
url := "url"
|
||||
dns := &configuration.DNS{
|
||||
Domain: "domain",
|
||||
TlsSecret: "tls",
|
||||
Subdomains: &configuration.Subdomains{
|
||||
Accounts: "accounts",
|
||||
API: "api",
|
||||
Console: "console",
|
||||
Issuer: "issuer",
|
||||
},
|
||||
}
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
k8sClient.EXPECT().CheckCRD("mappings.getambassador.io").Times(1).Return(&apixv1beta1.CustomResourceDefinition{}, nil)
|
||||
|
||||
group := "getambassador.io"
|
||||
version := "v2"
|
||||
kind := "Mapping"
|
||||
|
||||
cors := map[string]interface{}{
|
||||
"origins": "*",
|
||||
"methods": "POST, GET, OPTIONS, DELETE, PUT",
|
||||
"headers": "*",
|
||||
"credentials": true,
|
||||
"exposed_headers": "*",
|
||||
"max_age": "86400",
|
||||
}
|
||||
|
||||
componentLabels := mocklabels.Component
|
||||
|
||||
endsessionName := labels.MustForName(componentLabels, EndsessionName)
|
||||
endsession := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(endsessionName),
|
||||
"name": endsessionName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": "accounts.domain",
|
||||
"prefix": "/oauth/v2/endsession",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, EndsessionName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, EndsessionName, endsession).Times(1)
|
||||
|
||||
issuerName := labels.MustForName(componentLabels, IssuerName)
|
||||
issuer := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(issuerName),
|
||||
"name": issuerName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": "issuer.domain",
|
||||
"prefix": "/.well-known/openid-configuration",
|
||||
"rewrite": "/oauth/v2/.well-known/openid-configuration",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, IssuerName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, IssuerName, issuer).Times(1)
|
||||
|
||||
authorizeName := labels.MustForName(componentLabels, AuthorizeName)
|
||||
authorize := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(authorizeName),
|
||||
"name": authorizeName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": "accounts.domain",
|
||||
"prefix": "/oauth/v2/authorize",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, AuthorizeName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, AuthorizeName, authorize).Times(1)
|
||||
|
||||
oauthName := labels.MustForName(componentLabels, OauthName)
|
||||
oauth := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(oauthName),
|
||||
"name": oauthName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": "api.domain",
|
||||
"prefix": "/oauth/v2/",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, OauthName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, OauthName, oauth).Times(1)
|
||||
|
||||
mgmtName := labels.MustForName(componentLabels, MgmtName)
|
||||
mgmt := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(mgmtName),
|
||||
"name": mgmtName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": "api.domain",
|
||||
"prefix": "/management/v1/",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, MgmtName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, MgmtName, mgmt).Times(1)
|
||||
|
||||
adminRName := labels.MustForName(componentLabels, AdminRName)
|
||||
adminR := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(adminRName),
|
||||
"name": adminRName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": "api.domain",
|
||||
"prefix": "/admin/v1",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, AdminRName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, AdminRName, adminR).Times(1)
|
||||
|
||||
authRName := labels.MustForName(componentLabels, AuthRName)
|
||||
authR := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(authRName),
|
||||
"name": authRName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": "api.domain",
|
||||
"prefix": "/auth/v1/",
|
||||
"rewrite": "",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
"cors": cors,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, AuthRName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, AuthRName, authR).Times(1)
|
||||
|
||||
query, _, err := AdaptFunc(monitor, componentLabels, namespace, url, dns)
|
||||
assert.NoError(t, err)
|
||||
queried := map[string]interface{}{}
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, ensure(k8sClient))
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/kubernetes/resources/ambassador/mapping"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/configuration"
|
||||
)
|
||||
|
||||
const (
|
||||
ConsoleName = "console-v1"
|
||||
AccountsName = "accounts-v1"
|
||||
)
|
||||
|
||||
func AdaptFunc(
|
||||
monitor mntr.Monitor,
|
||||
componentLabels *labels.Component,
|
||||
namespace string,
|
||||
uiURL string,
|
||||
dns *configuration.DNS,
|
||||
) (
|
||||
operator.QueryFunc,
|
||||
operator.DestroyFunc,
|
||||
error,
|
||||
) {
|
||||
internalMonitor := monitor.WithField("part", "ui")
|
||||
|
||||
destroyAcc, err := mapping.AdaptFuncToDestroy(namespace, AccountsName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyConsole, err := mapping.AdaptFuncToDestroy(namespace, ConsoleName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyers := []operator.DestroyFunc{
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyAcc),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyConsole),
|
||||
}
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (operator.EnsureFunc, error) {
|
||||
crd, err := k8sClient.CheckCRD("mappings.getambassador.io")
|
||||
if crd == nil || err != nil {
|
||||
return func(k8sClient kubernetes.ClientInt) error { return nil }, nil
|
||||
}
|
||||
|
||||
accountsDomain := dns.Subdomains.Accounts + "." + dns.Domain
|
||||
consoleDomain := dns.Subdomains.Console + "." + dns.Domain
|
||||
|
||||
queryConsole, err := mapping.AdaptFuncToEnsure(
|
||||
namespace,
|
||||
labels.MustForName(componentLabels, ConsoleName),
|
||||
false,
|
||||
consoleDomain,
|
||||
"/",
|
||||
"/console/",
|
||||
uiURL,
|
||||
0,
|
||||
0,
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queryAcc, err := mapping.AdaptFuncToEnsure(
|
||||
namespace,
|
||||
labels.MustForName(componentLabels, AccountsName),
|
||||
false,
|
||||
accountsDomain,
|
||||
"/",
|
||||
"/login/",
|
||||
uiURL,
|
||||
30000,
|
||||
30000,
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queriers := []operator.QueryFunc{
|
||||
operator.ResourceQueryToZitadelQuery(queryConsole),
|
||||
operator.ResourceQueryToZitadelQuery(queryAcc),
|
||||
}
|
||||
|
||||
return operator.QueriersToEnsureFunc(internalMonitor, false, queriers, k8sClient, queried)
|
||||
},
|
||||
operator.DestroyersToDestroyFunc(internalMonitor, destroyers),
|
||||
nil
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/orbos/pkg/labels/mocklabels"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/configuration"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
apixv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
func SetReturnResourceVersion(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
group,
|
||||
version,
|
||||
kind,
|
||||
namespace,
|
||||
name string,
|
||||
resourceVersion string,
|
||||
) {
|
||||
ret := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"resourceVersion": resourceVersion,
|
||||
},
|
||||
},
|
||||
}
|
||||
k8sClient.EXPECT().GetNamespacedCRDResource(group, version, kind, namespace, name).Return(ret, nil)
|
||||
}
|
||||
|
||||
func SetCheckCRD(k8sClient *kubernetesmock.MockClientInt) {
|
||||
k8sClient.EXPECT().CheckCRD("mappings.getambassador.io").Times(1).Return(&apixv1beta1.CustomResourceDefinition{}, nil)
|
||||
}
|
||||
|
||||
func SetMappingsEmpty(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
namespace string,
|
||||
accountsLabels *labels.Name,
|
||||
consoleLabels *labels.Name,
|
||||
url string,
|
||||
) {
|
||||
group := "getambassador.io"
|
||||
version := "v2"
|
||||
kind := "Mapping"
|
||||
|
||||
accounts := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(accountsLabels),
|
||||
"name": accountsLabels.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": ".",
|
||||
"prefix": "/",
|
||||
"rewrite": "/login/",
|
||||
"service": url,
|
||||
"timeout_ms": 30000,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, accountsLabels.Name(), "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, accountsLabels.Name(), accounts).Times(1)
|
||||
|
||||
console := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(consoleLabels),
|
||||
"name": consoleLabels.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"host": ".",
|
||||
"prefix": "/",
|
||||
"rewrite": "/console/",
|
||||
"service": url,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, consoleLabels.Name(), "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, consoleLabels.Name(), console).Times(1)
|
||||
}
|
||||
|
||||
func TestUi_Adapt(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
namespace := "test"
|
||||
uiURL := "url"
|
||||
dns := &configuration.DNS{
|
||||
Domain: "",
|
||||
TlsSecret: "",
|
||||
Subdomains: &configuration.Subdomains{
|
||||
Accounts: "",
|
||||
API: "",
|
||||
Console: "",
|
||||
Issuer: "",
|
||||
},
|
||||
}
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
componentLabels := mocklabels.Component
|
||||
|
||||
SetCheckCRD(k8sClient)
|
||||
SetMappingsEmpty(
|
||||
k8sClient,
|
||||
namespace,
|
||||
labels.MustForName(componentLabels, AccountsName),
|
||||
labels.MustForName(componentLabels, ConsoleName),
|
||||
uiURL,
|
||||
)
|
||||
|
||||
query, _, err := AdaptFunc(monitor, componentLabels, namespace, uiURL, dns)
|
||||
assert.NoError(t, err)
|
||||
queried := map[string]interface{}{}
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, ensure(k8sClient))
|
||||
}
|
||||
|
||||
func TestUi_Adapt2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
namespace := "test"
|
||||
uiURL := "url"
|
||||
dns := &configuration.DNS{
|
||||
Domain: "domain",
|
||||
TlsSecret: "tls",
|
||||
Subdomains: &configuration.Subdomains{
|
||||
Accounts: "accounts",
|
||||
API: "api",
|
||||
Console: "console",
|
||||
Issuer: "issuer",
|
||||
},
|
||||
}
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
SetCheckCRD(k8sClient)
|
||||
|
||||
group := "getambassador.io"
|
||||
version := "v2"
|
||||
kind := "Mapping"
|
||||
|
||||
componentLabels := mocklabels.Component
|
||||
|
||||
accountsName := labels.MustForName(componentLabels, AccountsName)
|
||||
accounts := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(accountsName),
|
||||
"name": accountsName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"connect_timeout_ms": 30000,
|
||||
"host": "accounts.domain",
|
||||
"prefix": "/",
|
||||
"rewrite": "/login/",
|
||||
"service": uiURL,
|
||||
"timeout_ms": 30000,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, AccountsName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, AccountsName, accounts).Times(1)
|
||||
|
||||
consoleName := labels.MustForName(componentLabels, ConsoleName)
|
||||
console := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": group + "/" + version,
|
||||
"kind": kind,
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": labels.MustK8sMap(consoleName),
|
||||
"name": consoleName.Name(),
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"host": "console.domain",
|
||||
"prefix": "/",
|
||||
"rewrite": "/console/",
|
||||
"service": uiURL,
|
||||
},
|
||||
},
|
||||
}
|
||||
SetReturnResourceVersion(k8sClient, group, version, kind, namespace, ConsoleName, "")
|
||||
k8sClient.EXPECT().ApplyNamespacedCRDResource(group, version, kind, namespace, ConsoleName, console).Times(1)
|
||||
|
||||
query, _, err := AdaptFunc(monitor, componentLabels, namespace, uiURL, dns)
|
||||
assert.NoError(t, err)
|
||||
queried := map[string]interface{}{}
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, ensure(k8sClient))
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package configuration
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/kubernetes/resources/configmap"
|
||||
"github.com/caos/orbos/pkg/kubernetes/resources/secret"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/configuration/users"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
|
||||
)
|
||||
|
||||
type ConsoleEnv struct {
|
||||
AuthServiceURL string `json:"authServiceUrl"`
|
||||
MgmtServiceURL string `json:"mgmtServiceUrl"`
|
||||
Issuer string `json:"issuer"`
|
||||
ClientID string `json:"clientid"`
|
||||
}
|
||||
|
||||
const (
|
||||
googleServiceAccountJSONPath = "google-serviceaccount-key.json"
|
||||
zitadelKeysPath = "zitadel-keys.yaml"
|
||||
timeout time.Duration = 60
|
||||
)
|
||||
|
||||
func AdaptFunc(
|
||||
monitor mntr.Monitor,
|
||||
componentLabels *labels.Component,
|
||||
namespace string,
|
||||
desired *Configuration,
|
||||
cmName string,
|
||||
certPath string,
|
||||
secretName string,
|
||||
secretPath string,
|
||||
consoleCMName string,
|
||||
secretVarsName string,
|
||||
secretPasswordName string,
|
||||
necessaryUsers map[string]string,
|
||||
getClientID func() string,
|
||||
dbClient database.ClientInt,
|
||||
) (
|
||||
operator.QueryFunc,
|
||||
operator.DestroyFunc,
|
||||
func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) map[string]string,
|
||||
error,
|
||||
) {
|
||||
internalMonitor := monitor.WithField("component", "configuration")
|
||||
|
||||
literalsSecret := literalsSecret(desired, googleServiceAccountJSONPath, zitadelKeysPath)
|
||||
literalsSecretVars := literalsSecretVars(desired)
|
||||
|
||||
destroyCM, err := configmap.AdaptFuncToDestroy(namespace, cmName)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
destroyS, err := secret.AdaptFuncToDestroy(namespace, secretName)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
destroyCCM, err := configmap.AdaptFuncToDestroy(namespace, consoleCMName)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
destroySV, err := secret.AdaptFuncToDestroy(namespace, secretVarsName)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
destroySP, err := secret.AdaptFuncToDestroy(namespace, secretPasswordName)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
_, destroyUser, err := users.AdaptFunc(internalMonitor, necessaryUsers, dbClient)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
destroyers := []operator.DestroyFunc{
|
||||
destroyUser,
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyS),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyCM),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyCCM),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroySV),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroySP),
|
||||
}
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (operator.EnsureFunc, error) {
|
||||
queryUser, _, err := users.AdaptFunc(internalMonitor, necessaryUsers, dbClient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
queryS, err := secret.AdaptFuncToEnsure(namespace, labels.MustForName(componentLabels, secretName), literalsSecret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
querySV, err := secret.AdaptFuncToEnsure(namespace, labels.MustForName(componentLabels, secretVarsName), literalsSecretVars)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
querySP, err := secret.AdaptFuncToEnsure(namespace, labels.MustForName(componentLabels, secretPasswordName), necessaryUsers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queryCCM, err := configmap.AdaptFuncToEnsure(
|
||||
namespace,
|
||||
consoleCMName,
|
||||
labels.MustForNameK8SMap(componentLabels, consoleCMName),
|
||||
literalsConsoleCM(
|
||||
getClientID(),
|
||||
desired.DNS,
|
||||
k8sClient,
|
||||
namespace,
|
||||
consoleCMName,
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queryCM, err := configmap.AdaptFuncToEnsure(
|
||||
namespace,
|
||||
cmName,
|
||||
labels.MustForNameK8SMap(componentLabels, cmName),
|
||||
literalsConfigMap(
|
||||
desired,
|
||||
necessaryUsers,
|
||||
certPath,
|
||||
secretPath,
|
||||
googleServiceAccountJSONPath,
|
||||
zitadelKeysPath,
|
||||
queried,
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queriers := []operator.QueryFunc{
|
||||
queryUser,
|
||||
operator.ResourceQueryToZitadelQuery(queryS),
|
||||
operator.ResourceQueryToZitadelQuery(queryCCM),
|
||||
operator.ResourceQueryToZitadelQuery(querySV),
|
||||
operator.ResourceQueryToZitadelQuery(querySP),
|
||||
operator.ResourceQueryToZitadelQuery(queryCM),
|
||||
}
|
||||
|
||||
return operator.QueriersToEnsureFunc(internalMonitor, false, queriers, k8sClient, queried)
|
||||
},
|
||||
operator.DestroyersToDestroyFunc(internalMonitor, destroyers),
|
||||
func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) map[string]string {
|
||||
return map[string]string{
|
||||
secretName: getHash(literalsSecret),
|
||||
secretVarsName: getHash(literalsSecretVars),
|
||||
secretPasswordName: getHash(necessaryUsers),
|
||||
cmName: getHash(
|
||||
literalsConfigMap(
|
||||
desired,
|
||||
necessaryUsers,
|
||||
certPath,
|
||||
secretPath,
|
||||
googleServiceAccountJSONPath,
|
||||
zitadelKeysPath,
|
||||
queried,
|
||||
),
|
||||
),
|
||||
consoleCMName: getHash(
|
||||
literalsConsoleCM(
|
||||
getClientID(),
|
||||
desired.DNS,
|
||||
k8sClient,
|
||||
namespace,
|
||||
consoleCMName,
|
||||
),
|
||||
),
|
||||
}
|
||||
},
|
||||
nil
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
package configuration
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/orbos/pkg/labels/mocklabels"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
|
||||
databasemock "github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database/mock"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
func SetConfigMap(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
namespace string,
|
||||
cmName string,
|
||||
labels map[string]string,
|
||||
queried map[string]interface{},
|
||||
desired *Configuration,
|
||||
users map[string]string,
|
||||
certPath, secretPath, googleServiceAccountJSONPath, zitadelKeysPath string,
|
||||
) {
|
||||
|
||||
k8sClient.EXPECT().ApplyConfigmap(&corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: namespace,
|
||||
Name: cmName,
|
||||
Labels: labels,
|
||||
},
|
||||
Data: literalsConfigMap(desired, users, certPath, secretPath, googleServiceAccountJSONPath, zitadelKeysPath, queried),
|
||||
})
|
||||
}
|
||||
|
||||
func SetSecretVars(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
namespace string,
|
||||
secretVarsName string,
|
||||
labels map[string]string,
|
||||
desired *Configuration,
|
||||
) {
|
||||
|
||||
k8sClient.EXPECT().ApplySecret(&corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: namespace,
|
||||
Name: secretVarsName,
|
||||
Labels: labels,
|
||||
},
|
||||
Type: "Opaque",
|
||||
StringData: literalsSecretVars(desired),
|
||||
}).Times(1)
|
||||
}
|
||||
func SetConsoleCM(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
namespace string,
|
||||
consoleCMName string,
|
||||
labels map[string]string,
|
||||
getClientID func() string,
|
||||
desired *Configuration,
|
||||
) {
|
||||
|
||||
k8sClient.EXPECT().GetConfigMap(namespace, consoleCMName).Times(2).Return(nil, errors.New("Not Found"))
|
||||
consoleCM := &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: namespace,
|
||||
Name: consoleCMName,
|
||||
Labels: labels,
|
||||
},
|
||||
Data: literalsConsoleCM(getClientID(), desired.DNS, k8sClient, namespace, consoleCMName),
|
||||
}
|
||||
k8sClient.EXPECT().ApplyConfigmap(consoleCM).Times(1)
|
||||
}
|
||||
func SetSecrets(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
namespace string,
|
||||
secretName string,
|
||||
labels map[string]string,
|
||||
desired *Configuration,
|
||||
) {
|
||||
k8sClient.EXPECT().ApplySecret(&corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: namespace,
|
||||
Name: secretName,
|
||||
Labels: labels,
|
||||
},
|
||||
Type: "Opaque",
|
||||
StringData: literalsSecret(desired, googleServiceAccountJSONPath, zitadelKeysPath),
|
||||
}).Times(1)
|
||||
}
|
||||
|
||||
func SetSecretPasswords(
|
||||
k8sClient *kubernetesmock.MockClientInt,
|
||||
namespace string,
|
||||
secretPasswordName string,
|
||||
labels map[string]string,
|
||||
users map[string]string,
|
||||
) {
|
||||
|
||||
k8sClient.EXPECT().ApplySecret(&corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: namespace,
|
||||
Name: secretPasswordName,
|
||||
Labels: labels,
|
||||
},
|
||||
Type: "Opaque",
|
||||
StringData: users,
|
||||
}).Times(1)
|
||||
}
|
||||
|
||||
func TestConfiguration_Adapt(t *testing.T) {
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
dbClient := databasemock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
monitor := mntr.Monitor{Fields: map[string]interface{}{"component": "configuration"}}
|
||||
namespace := "test"
|
||||
cmName := "cm"
|
||||
secretName := "secret"
|
||||
consoleCMName := "console"
|
||||
secretVarsName := "vars"
|
||||
secretPasswordName := "passwords"
|
||||
getClientID := func() string { return "test" }
|
||||
certPath := "test"
|
||||
secretPath := "test"
|
||||
users := map[string]string{
|
||||
"migration": "migration",
|
||||
"management": "management",
|
||||
"auth": "auth",
|
||||
"authz": "authz",
|
||||
"adminapi": "adminapi",
|
||||
"notification": "notification",
|
||||
"eventstore": "eventstore",
|
||||
}
|
||||
|
||||
componentLabels := mocklabels.Component
|
||||
|
||||
queried := map[string]interface{}{}
|
||||
database.SetDatabaseInQueried(queried, &database.Current{
|
||||
Host: "host",
|
||||
Port: "port",
|
||||
Users: []string{},
|
||||
})
|
||||
for user := range users {
|
||||
dbClient.EXPECT().AddUser(monitor, user, k8sClient).Times(1)
|
||||
}
|
||||
|
||||
SetConfigMap(
|
||||
k8sClient,
|
||||
namespace,
|
||||
cmName,
|
||||
labels.MustForNameK8SMap(componentLabels, cmName),
|
||||
queried,
|
||||
desiredEmpty,
|
||||
users,
|
||||
certPath,
|
||||
secretPath,
|
||||
googleServiceAccountJSONPath,
|
||||
zitadelKeysPath)
|
||||
|
||||
SetSecretVars(
|
||||
k8sClient,
|
||||
namespace,
|
||||
secretVarsName,
|
||||
labels.MustForNameK8SMap(componentLabels, secretVarsName),
|
||||
desiredEmpty,
|
||||
)
|
||||
|
||||
SetConsoleCM(
|
||||
k8sClient,
|
||||
namespace,
|
||||
consoleCMName,
|
||||
labels.MustForNameK8SMap(componentLabels, consoleCMName),
|
||||
getClientID,
|
||||
desiredEmpty,
|
||||
)
|
||||
|
||||
SetSecrets(
|
||||
k8sClient,
|
||||
namespace,
|
||||
secretName,
|
||||
labels.MustForNameK8SMap(componentLabels, secretName),
|
||||
desiredEmpty,
|
||||
)
|
||||
|
||||
SetSecretPasswords(
|
||||
k8sClient,
|
||||
namespace,
|
||||
secretPasswordName,
|
||||
labels.MustForNameK8SMap(componentLabels, secretPasswordName),
|
||||
users,
|
||||
)
|
||||
|
||||
query, _, _, err := AdaptFunc(
|
||||
monitor,
|
||||
componentLabels,
|
||||
namespace,
|
||||
desiredEmpty,
|
||||
cmName,
|
||||
certPath,
|
||||
secretName,
|
||||
secretPath,
|
||||
consoleCMName,
|
||||
secretVarsName,
|
||||
secretPasswordName,
|
||||
users,
|
||||
getClientID,
|
||||
dbClient,
|
||||
)
|
||||
|
||||
assert.NoError(t, err)
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, ensure(k8sClient))
|
||||
|
||||
}
|
||||
|
||||
func TestConfiguration_AdaptFull(t *testing.T) {
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
dbClient := databasemock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
monitor := mntr.Monitor{Fields: map[string]interface{}{"component": "configuration"}}
|
||||
namespace := "test2"
|
||||
cmName := "cm2"
|
||||
secretName := "secret2"
|
||||
consoleCMName := "console2"
|
||||
secretVarsName := "vars2"
|
||||
secretPasswordName := "passwords2"
|
||||
getClientID := func() string { return "test2" }
|
||||
certPath := "test2"
|
||||
secretPath := "test2"
|
||||
users := map[string]string{
|
||||
"migration": "migration",
|
||||
"management": "management",
|
||||
"auth": "auth",
|
||||
"authz": "authz",
|
||||
"adminapi": "adminapi",
|
||||
"notification": "notification",
|
||||
"eventstore": "eventstore",
|
||||
}
|
||||
|
||||
componentLabels := mocklabels.Component
|
||||
|
||||
queried := map[string]interface{}{}
|
||||
database.SetDatabaseInQueried(queried, &database.Current{
|
||||
Host: "host2",
|
||||
Port: "port2",
|
||||
Users: []string{},
|
||||
})
|
||||
for user := range users {
|
||||
dbClient.EXPECT().AddUser(monitor, user, k8sClient).Times(1)
|
||||
}
|
||||
|
||||
SetConfigMap(
|
||||
k8sClient,
|
||||
namespace,
|
||||
cmName,
|
||||
labels.MustForNameK8SMap(componentLabels, cmName),
|
||||
queried,
|
||||
desiredFull,
|
||||
users,
|
||||
certPath,
|
||||
secretPath,
|
||||
googleServiceAccountJSONPath,
|
||||
zitadelKeysPath)
|
||||
|
||||
SetSecretVars(
|
||||
k8sClient,
|
||||
namespace,
|
||||
secretVarsName,
|
||||
labels.MustForNameK8SMap(componentLabels, secretVarsName),
|
||||
desiredFull,
|
||||
)
|
||||
|
||||
SetConsoleCM(
|
||||
k8sClient,
|
||||
namespace,
|
||||
consoleCMName,
|
||||
labels.MustForNameK8SMap(componentLabels, consoleCMName),
|
||||
getClientID,
|
||||
desiredFull,
|
||||
)
|
||||
|
||||
SetSecrets(
|
||||
k8sClient,
|
||||
namespace,
|
||||
secretName,
|
||||
labels.MustForNameK8SMap(componentLabels, secretName),
|
||||
desiredFull,
|
||||
)
|
||||
|
||||
SetSecretPasswords(
|
||||
k8sClient,
|
||||
namespace,
|
||||
secretPasswordName,
|
||||
labels.MustForNameK8SMap(componentLabels, secretPasswordName),
|
||||
users,
|
||||
)
|
||||
|
||||
query, _, _, err := AdaptFunc(
|
||||
monitor,
|
||||
componentLabels,
|
||||
namespace,
|
||||
desiredFull,
|
||||
cmName,
|
||||
certPath,
|
||||
secretName,
|
||||
secretPath,
|
||||
consoleCMName,
|
||||
secretVarsName,
|
||||
secretPasswordName,
|
||||
users,
|
||||
getClientID,
|
||||
dbClient,
|
||||
)
|
||||
|
||||
assert.NoError(t, err)
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, ensure(k8sClient))
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package configuration
|
||||
|
||||
import "github.com/caos/orbos/pkg/secret"
|
||||
|
||||
type Configuration struct {
|
||||
Tracing *Tracing `yaml:"tracing,omitempty"`
|
||||
Cache *Cache `yaml:"cache,omitempty"`
|
||||
Secrets *Secrets `yaml:"secrets,omitempty"`
|
||||
Notifications *Notifications `yaml:"notifications,omitempty"`
|
||||
Passwords *Passwords `yaml:"passwords,omitempty"`
|
||||
DebugMode bool `yaml:"debugMode"`
|
||||
LogLevel string `yaml:"logLevel"`
|
||||
DNS *DNS `yaml:"dns"`
|
||||
ClusterDNS string `yaml:"clusterdns"`
|
||||
}
|
||||
|
||||
type DNS struct {
|
||||
Domain string `yaml:"domain"`
|
||||
TlsSecret string `yaml:"tlsSecret"`
|
||||
Subdomains *Subdomains `yaml:"subdomains"`
|
||||
}
|
||||
|
||||
type Subdomains struct {
|
||||
Accounts string `yaml:"accounts"`
|
||||
API string `yaml:"api"`
|
||||
Console string `yaml:"console"`
|
||||
Issuer string `yaml:"issuer"`
|
||||
}
|
||||
type Passwords struct {
|
||||
Migration *secret.Secret `yaml:"migration"`
|
||||
Management *secret.Secret `yaml:"management"`
|
||||
Auth *secret.Secret `yaml:"auth"`
|
||||
Authz *secret.Secret `yaml:"authz"`
|
||||
Adminapi *secret.Secret `yaml:"adminapi"`
|
||||
Notification *secret.Secret `yaml:"notification"`
|
||||
Eventstore *secret.Secret `yaml:"eventstore"`
|
||||
}
|
||||
|
||||
type Secrets struct {
|
||||
Keys *secret.Secret `yaml:"keys,omitempty"`
|
||||
UserVerificationID string `yaml:"userVerificationID,omitempty"`
|
||||
OTPVerificationID string `yaml:"otpVerificationID,omitempty"`
|
||||
OIDCKeysID string `yaml:"oidcKeysID,omitempty"`
|
||||
CookieID string `yaml:"cookieID,omitempty"`
|
||||
CSRFID string `yaml:"csrfID,omitempty"`
|
||||
DomainVerificationID string `yaml:"domainVerificationID,omitempty"`
|
||||
IDPConfigVerificationID string `yaml:"idpConfigVerificationID,omitempty"`
|
||||
}
|
||||
|
||||
type Notifications struct {
|
||||
GoogleChatURL *secret.Secret `yaml:"googleChatURL,omitempty"`
|
||||
Email *Email `yaml:"email,omitempty"`
|
||||
Twilio *Twilio `yaml:"twilio,omitempty"`
|
||||
}
|
||||
|
||||
type Tracing struct {
|
||||
ServiceAccountJSON *secret.Secret `yaml:"serviceAccountJSON,omitempty"`
|
||||
ProjectID string `yaml:"projectID,omitempty"`
|
||||
Fraction string `yaml:"fraction,omitempty"`
|
||||
Type string `yaml:"type,omitempty"`
|
||||
}
|
||||
|
||||
type Twilio struct {
|
||||
SenderName string `yaml:"senderName,omitempty"`
|
||||
AuthToken *secret.Secret `yaml:"authToken,omitempty"`
|
||||
SID *secret.Secret `yaml:"sid,omitempty"`
|
||||
}
|
||||
|
||||
type Email struct {
|
||||
SMTPHost string `yaml:"smtpHost,omitempty"`
|
||||
SMTPUser string `yaml:"smtpUser,omitempty"`
|
||||
SenderAddress string `yaml:"senderAddress,omitempty"`
|
||||
SenderName string `yaml:"senderName,omitempty"`
|
||||
TLS bool `yaml:"tls,omitempty"`
|
||||
AppKey *secret.Secret `yaml:"appKey,omitempty"`
|
||||
}
|
||||
|
||||
type Cache struct {
|
||||
MaxAge string `yaml:"maxAge,omitempty"`
|
||||
SharedMaxAge string `yaml:"sharedMaxAge,omitempty"`
|
||||
ShortMaxAge string `yaml:"shortMaxAge,omitempty"`
|
||||
ShortSharedMaxAge string `yaml:"shortSharedMaxAge,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package configuration
|
||||
|
||||
import (
|
||||
"crypto/sha512"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
func getHash(dataMap map[string]string) string {
|
||||
data, err := json.Marshal(dataMap)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
h := sha512.New()
|
||||
return base64.URLEncoding.EncodeToString(h.Sum(data))
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package configuration
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
jsonName = "environment.json"
|
||||
)
|
||||
|
||||
func literalsConfigMap(
|
||||
desired *Configuration,
|
||||
users map[string]string,
|
||||
certPath, secretPath, googleServiceAccountJSONPath, zitadelKeysPath string,
|
||||
queried map[string]interface{},
|
||||
) map[string]string {
|
||||
|
||||
tls := ""
|
||||
if desired.Notifications.Email.TLS {
|
||||
tls = "TRUE"
|
||||
} else {
|
||||
tls = "FALSE"
|
||||
}
|
||||
|
||||
literalsConfigMap := map[string]string{
|
||||
"GOOGLE_APPLICATION_CREDENTIALS": secretPath + "/" + googleServiceAccountJSONPath,
|
||||
"ZITADEL_KEY_PATH": secretPath + "/" + zitadelKeysPath,
|
||||
"ZITADEL_LOG_LEVEL": "info",
|
||||
"DEBUG_MODE": strconv.FormatBool(desired.DebugMode),
|
||||
"SMTP_TLS": tls,
|
||||
"CAOS_OIDC_DEV": "true",
|
||||
"CR_SSL_MODE": "require",
|
||||
"CR_ROOT_CERT": certPath + "/ca.crt",
|
||||
}
|
||||
|
||||
if users != nil {
|
||||
for user := range users {
|
||||
literalsConfigMap["CR_"+strings.ToUpper(user)+"_CERT"] = certPath + "/client." + user + ".crt"
|
||||
literalsConfigMap["CR_"+strings.ToUpper(user)+"_KEY"] = certPath + "/client." + user + ".key"
|
||||
}
|
||||
}
|
||||
|
||||
if desired != nil {
|
||||
if desired.Tracing != nil {
|
||||
literalsConfigMap["ZITADEL_TRACING_PROJECT_ID"] = desired.Tracing.ProjectID
|
||||
literalsConfigMap["ZITADEL_TRACING_FRACTION"] = desired.Tracing.Fraction
|
||||
literalsConfigMap["ZITADEL_TRACING_TYPE"] = desired.Tracing.Type
|
||||
}
|
||||
if desired.Secrets != nil {
|
||||
literalsConfigMap["ZITADEL_USER_VERIFICATION_KEY"] = desired.Secrets.UserVerificationID
|
||||
literalsConfigMap["ZITADEL_OTP_VERIFICATION_KEY"] = desired.Secrets.OTPVerificationID
|
||||
literalsConfigMap["ZITADEL_OIDC_KEYS_ID"] = desired.Secrets.OIDCKeysID
|
||||
literalsConfigMap["ZITADEL_COOKIE_KEY"] = desired.Secrets.CookieID
|
||||
literalsConfigMap["ZITADEL_CSRF_KEY"] = desired.Secrets.CSRFID
|
||||
literalsConfigMap["ZITADEL_DOMAIN_VERIFICATION_KEY"] = desired.Secrets.DomainVerificationID
|
||||
literalsConfigMap["ZITADEL_IDP_CONFIG_VERIFICATION_KEY"] = desired.Secrets.IDPConfigVerificationID
|
||||
}
|
||||
if desired.Notifications != nil {
|
||||
literalsConfigMap["TWILIO_SENDER_NAME"] = desired.Notifications.Twilio.SenderName
|
||||
literalsConfigMap["SMTP_HOST"] = desired.Notifications.Email.SMTPHost
|
||||
literalsConfigMap["SMTP_USER"] = desired.Notifications.Email.SMTPUser
|
||||
literalsConfigMap["EMAIL_SENDER_ADDRESS"] = desired.Notifications.Email.SenderAddress
|
||||
literalsConfigMap["EMAIL_SENDER_NAME"] = desired.Notifications.Email.SenderName
|
||||
}
|
||||
if desired.Cache != nil {
|
||||
literalsConfigMap["ZITADEL_CACHE_MAXAGE"] = desired.Cache.MaxAge
|
||||
literalsConfigMap["ZITADEL_CACHE_SHARED_MAXAGE"] = desired.Cache.SharedMaxAge
|
||||
literalsConfigMap["ZITADEL_SHORT_CACHE_MAXAGE"] = desired.Cache.ShortMaxAge
|
||||
literalsConfigMap["ZITADEL_SHORT_CACHE_SHARED_MAXAGE"] = desired.Cache.ShortSharedMaxAge
|
||||
}
|
||||
|
||||
if desired.LogLevel != "" {
|
||||
literalsConfigMap["ZITADEL_LOG_LEVEL"] = desired.LogLevel
|
||||
}
|
||||
|
||||
if desired.DNS != nil {
|
||||
defaultDomain := desired.DNS.Domain
|
||||
accountsDomain := desired.DNS.Subdomains.Accounts + "." + defaultDomain
|
||||
accounts := "https://" + accountsDomain
|
||||
issuer := "https://" + desired.DNS.Subdomains.Issuer + "." + defaultDomain
|
||||
oauth := "https://" + desired.DNS.Subdomains.API + "." + defaultDomain + "/oauth/v2"
|
||||
authorize := "https://" + desired.DNS.Subdomains.Accounts + "." + defaultDomain + "/oauth/v2"
|
||||
console := "https://" + desired.DNS.Subdomains.Console + "." + defaultDomain
|
||||
|
||||
literalsConfigMap["ZITADEL_ISSUER"] = issuer
|
||||
literalsConfigMap["ZITADEL_ACCOUNTS"] = accounts
|
||||
literalsConfigMap["ZITADEL_OAUTH"] = oauth
|
||||
literalsConfigMap["ZITADEL_AUTHORIZE"] = authorize
|
||||
literalsConfigMap["ZITADEL_CONSOLE"] = console
|
||||
literalsConfigMap["ZITADEL_ACCOUNTS_DOMAIN"] = accountsDomain
|
||||
literalsConfigMap["ZITADEL_COOKIE_DOMAIN"] = accountsDomain
|
||||
literalsConfigMap["ZITADEL_DEFAULT_DOMAIN"] = defaultDomain
|
||||
}
|
||||
}
|
||||
|
||||
db, err := database.GetDatabaseInQueried(queried)
|
||||
if err == nil {
|
||||
literalsConfigMap["ZITADEL_EVENTSTORE_HOST"] = db.Host
|
||||
literalsConfigMap["ZITADEL_EVENTSTORE_PORT"] = db.Port
|
||||
}
|
||||
|
||||
return literalsConfigMap
|
||||
}
|
||||
|
||||
func literalsSecret(desired *Configuration, googleServiceAccountJSONPath, zitadelKeysPath string) map[string]string {
|
||||
literalsSecret := map[string]string{}
|
||||
if desired != nil {
|
||||
if desired.Tracing != nil && desired.Tracing.ServiceAccountJSON != nil {
|
||||
literalsSecret[googleServiceAccountJSONPath] = desired.Tracing.ServiceAccountJSON.Value
|
||||
}
|
||||
if desired.Secrets != nil && desired.Secrets.Keys != nil {
|
||||
literalsSecret[zitadelKeysPath] = desired.Secrets.Keys.Value
|
||||
}
|
||||
}
|
||||
return literalsSecret
|
||||
}
|
||||
|
||||
func literalsSecretVars(desired *Configuration) map[string]string {
|
||||
literalsSecretVars := map[string]string{}
|
||||
if desired != nil {
|
||||
if desired.Notifications != nil {
|
||||
if desired.Notifications.Email.AppKey != nil {
|
||||
literalsSecretVars["ZITADEL_EMAILAPPKEY"] = desired.Notifications.Email.AppKey.Value
|
||||
}
|
||||
if desired.Notifications.GoogleChatURL != nil {
|
||||
literalsSecretVars["ZITADEL_GOOGLE_CHAT_URL"] = desired.Notifications.GoogleChatURL.Value
|
||||
}
|
||||
if desired.Notifications.Twilio.AuthToken != nil {
|
||||
literalsSecretVars["ZITADEL_TWILIO_AUTH_TOKEN"] = desired.Notifications.Twilio.AuthToken.Value
|
||||
}
|
||||
if desired.Notifications.Twilio.SID != nil {
|
||||
literalsSecretVars["ZITADEL_TWILIO_SID"] = desired.Notifications.Twilio.SID.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
return literalsSecretVars
|
||||
}
|
||||
|
||||
func literalsConsoleCM(
|
||||
clientID string,
|
||||
dns *DNS,
|
||||
k8sClient kubernetes.ClientInt,
|
||||
namespace string,
|
||||
cmName string,
|
||||
) map[string]string {
|
||||
literalsConsoleCM := map[string]string{}
|
||||
consoleEnv := ConsoleEnv{
|
||||
ClientID: clientID,
|
||||
}
|
||||
|
||||
cm, err := k8sClient.GetConfigMap(namespace, cmName)
|
||||
//only try to use the old CM when there is a CM found
|
||||
if cm != nil && err == nil {
|
||||
jsonData, ok := cm.Data[jsonName]
|
||||
if ok {
|
||||
literalsData := map[string]string{}
|
||||
err := json.Unmarshal([]byte(jsonData), &literalsData)
|
||||
if err == nil {
|
||||
oldClientID, ok := literalsData["clientid"]
|
||||
//only use the old ClientID if no new clientID is provided
|
||||
if ok && consoleEnv.ClientID == "" {
|
||||
consoleEnv.ClientID = oldClientID
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
consoleEnv.Issuer = "https://" + dns.Subdomains.Issuer + "." + dns.Domain
|
||||
consoleEnv.AuthServiceURL = "https://" + dns.Subdomains.API + "." + dns.Domain
|
||||
consoleEnv.MgmtServiceURL = "https://" + dns.Subdomains.API + "." + dns.Domain
|
||||
|
||||
data, err := json.Marshal(consoleEnv)
|
||||
if err != nil {
|
||||
return map[string]string{}
|
||||
}
|
||||
|
||||
literalsConsoleCM[jsonName] = string(data)
|
||||
return literalsConsoleCM
|
||||
}
|
||||
@@ -0,0 +1,425 @@
|
||||
package configuration
|
||||
|
||||
import (
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/caos/orbos/pkg/secret"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
desiredEmpty = &Configuration{
|
||||
Tracing: &Tracing{
|
||||
ServiceAccountJSON: &secret.Secret{Value: ""},
|
||||
ProjectID: "",
|
||||
Fraction: "",
|
||||
Type: "",
|
||||
},
|
||||
Secrets: &Secrets{
|
||||
Keys: &secret.Secret{Value: ""},
|
||||
UserVerificationID: "",
|
||||
OTPVerificationID: "",
|
||||
OIDCKeysID: "",
|
||||
CookieID: "",
|
||||
CSRFID: "",
|
||||
DomainVerificationID: "",
|
||||
IDPConfigVerificationID: "",
|
||||
},
|
||||
Notifications: &Notifications{
|
||||
GoogleChatURL: &secret.Secret{Value: ""},
|
||||
Email: &Email{
|
||||
SMTPHost: "",
|
||||
SMTPUser: "",
|
||||
SenderAddress: "",
|
||||
SenderName: "",
|
||||
TLS: false,
|
||||
AppKey: &secret.Secret{Value: ""},
|
||||
},
|
||||
Twilio: &Twilio{
|
||||
SenderName: "",
|
||||
AuthToken: &secret.Secret{Value: ""},
|
||||
SID: &secret.Secret{Value: ""},
|
||||
},
|
||||
},
|
||||
Passwords: &Passwords{
|
||||
Migration: &secret.Secret{Value: ""},
|
||||
Management: &secret.Secret{Value: ""},
|
||||
Auth: &secret.Secret{Value: ""},
|
||||
Authz: &secret.Secret{Value: ""},
|
||||
Adminapi: &secret.Secret{Value: ""},
|
||||
Notification: &secret.Secret{Value: ""},
|
||||
Eventstore: &secret.Secret{Value: ""},
|
||||
},
|
||||
DebugMode: false,
|
||||
LogLevel: "info",
|
||||
DNS: &DNS{
|
||||
Domain: "",
|
||||
TlsSecret: "",
|
||||
Subdomains: &Subdomains{
|
||||
Accounts: "",
|
||||
API: "",
|
||||
Console: "",
|
||||
Issuer: "",
|
||||
},
|
||||
},
|
||||
ClusterDNS: "",
|
||||
}
|
||||
|
||||
desiredFull = &Configuration{
|
||||
Tracing: &Tracing{
|
||||
ServiceAccountJSON: &secret.Secret{Value: "sajson"},
|
||||
ProjectID: "projectid",
|
||||
Fraction: "fraction",
|
||||
Type: "type",
|
||||
},
|
||||
Secrets: &Secrets{
|
||||
Keys: &secret.Secret{Value: "keys"},
|
||||
UserVerificationID: "userid",
|
||||
OTPVerificationID: "otpid",
|
||||
OIDCKeysID: "oidcid",
|
||||
CookieID: "cookieid",
|
||||
CSRFID: "csrfid",
|
||||
DomainVerificationID: "domainid",
|
||||
IDPConfigVerificationID: "idpid",
|
||||
},
|
||||
Notifications: &Notifications{
|
||||
GoogleChatURL: &secret.Secret{Value: "chat"},
|
||||
Email: &Email{
|
||||
SMTPHost: "smtphost",
|
||||
SMTPUser: "smtpuser",
|
||||
SenderAddress: "sender",
|
||||
SenderName: "sendername",
|
||||
TLS: true,
|
||||
AppKey: &secret.Secret{Value: "appkey"},
|
||||
},
|
||||
Twilio: &Twilio{
|
||||
SenderName: "sendername",
|
||||
AuthToken: &secret.Secret{Value: "authtoken"},
|
||||
SID: &secret.Secret{Value: "sid"},
|
||||
},
|
||||
},
|
||||
Passwords: &Passwords{
|
||||
Migration: &secret.Secret{Value: "migration"},
|
||||
Management: &secret.Secret{Value: "management"},
|
||||
Auth: &secret.Secret{Value: "auth"},
|
||||
Authz: &secret.Secret{Value: "authz"},
|
||||
Adminapi: &secret.Secret{Value: "adminapi"},
|
||||
Notification: &secret.Secret{Value: "notification"},
|
||||
Eventstore: &secret.Secret{Value: "eventstore"},
|
||||
},
|
||||
DebugMode: true,
|
||||
LogLevel: "debug",
|
||||
DNS: &DNS{
|
||||
Domain: "domain",
|
||||
TlsSecret: "tls",
|
||||
Subdomains: &Subdomains{
|
||||
Accounts: "accounts",
|
||||
API: "api",
|
||||
Console: "console",
|
||||
Issuer: "issuer",
|
||||
},
|
||||
},
|
||||
ClusterDNS: "cluster",
|
||||
}
|
||||
)
|
||||
|
||||
func TestConfiguration_LiteralsConfigMap(t *testing.T) {
|
||||
certPath := "test"
|
||||
secretPath := "test"
|
||||
googleSA := "test"
|
||||
zitadelKeyPath := "test"
|
||||
users := map[string]string{
|
||||
"migration": "migration",
|
||||
"management": "management",
|
||||
"auth": "auth",
|
||||
"authz": "authz",
|
||||
"adminapi": "adminapi",
|
||||
"notification": "notification",
|
||||
"eventstore": "eventstore",
|
||||
}
|
||||
|
||||
queried := map[string]interface{}{}
|
||||
database.SetDatabaseInQueried(queried, &database.Current{
|
||||
Host: "test",
|
||||
Port: "test",
|
||||
Users: []string{"test"},
|
||||
})
|
||||
|
||||
equals := map[string]string{
|
||||
"ZITADEL_LOG_LEVEL": "info",
|
||||
"CR_NOTIFICATION_KEY": "test/client.notification.key",
|
||||
"CR_AUTHZ_KEY": "test/client.authz.key",
|
||||
"ZITADEL_OTP_VERIFICATION_KEY": "",
|
||||
"ZITADEL_COOKIE_KEY": "",
|
||||
"SMTP_USER": "",
|
||||
"EMAIL_SENDER_NAME": "",
|
||||
"ZITADEL_COOKIE_DOMAIN": ".",
|
||||
"ZITADEL_EVENTSTORE_HOST": "test",
|
||||
"CR_ADMINAPI_CERT": "test/client.adminapi.crt",
|
||||
"ZITADEL_IDP_CONFIG_VERIFICATION_KEY": "",
|
||||
"ZITADEL_ACCOUNTS": "https://.",
|
||||
"ZITADEL_OAUTH": "https://./oauth/v2",
|
||||
"ZITADEL_EVENTSTORE_PORT": "test",
|
||||
"SMTP_TLS": "FALSE",
|
||||
"CR_ROOT_CERT": "test/ca.crt",
|
||||
"CR_NOTIFICATION_CERT": "test/client.notification.crt",
|
||||
"CR_EVENTSTORE_CERT": "test/client.eventstore.crt",
|
||||
"ZITADEL_USER_VERIFICATION_KEY": "",
|
||||
"ZITADEL_DEFAULT_DOMAIN": "",
|
||||
"CR_SSL_MODE": "require",
|
||||
"ZITADEL_KEY_PATH": "test/test",
|
||||
"CR_MANAGEMENT_CERT": "test/client.management.crt",
|
||||
"CR_AUTH_KEY": "test/client.auth.key",
|
||||
"CR_AUTHZ_CERT": "test/client.authz.crt",
|
||||
"CR_ADMINAPI_KEY": "test/client.adminapi.key",
|
||||
"ZITADEL_TRACING_PROJECT_ID": "",
|
||||
"ZITADEL_DOMAIN_VERIFICATION_KEY": "",
|
||||
"CR_EVENTSTORE_KEY": "test/client.eventstore.key",
|
||||
"ZITADEL_CSRF_KEY": "",
|
||||
"TWILIO_SENDER_NAME": "",
|
||||
"EMAIL_SENDER_ADDRESS": "",
|
||||
"ZITADEL_ISSUER": "https://.",
|
||||
"ZITADEL_CONSOLE": "https://.",
|
||||
"ZITADEL_ACCOUNTS_DOMAIN": ".",
|
||||
"GOOGLE_APPLICATION_CREDENTIALS": "test/test",
|
||||
"CR_MIGRATION_KEY": "test/client.migration.key",
|
||||
"ZITADEL_TRACING_FRACTION": "",
|
||||
"SMTP_HOST": "",
|
||||
"CAOS_OIDC_DEV": "true",
|
||||
"DEBUG_MODE": "false",
|
||||
"CR_AUTH_CERT": "test/client.auth.crt",
|
||||
"ZITADEL_OIDC_KEYS_ID": "",
|
||||
"CR_MIGRATION_CERT": "test/client.migration.crt",
|
||||
"CR_MANAGEMENT_KEY": "test/client.management.key",
|
||||
"ZITADEL_TRACING_TYPE": "",
|
||||
"ZITADEL_AUTHORIZE": "https://./oauth/v2",
|
||||
}
|
||||
|
||||
literals := literalsConfigMap(desiredEmpty, users, certPath, secretPath, googleSA, zitadelKeyPath, queried)
|
||||
|
||||
assert.Equal(t, equals, literals)
|
||||
}
|
||||
|
||||
func TestConfiguration_LiteralsConfigMapFull(t *testing.T) {
|
||||
certPath := "test"
|
||||
secretPath := "test"
|
||||
googleSA := "test"
|
||||
zitadelKeyPath := "test"
|
||||
users := map[string]string{
|
||||
"migration": "migration2",
|
||||
"management": "management2",
|
||||
"auth": "auth2",
|
||||
"authz": "authz2",
|
||||
"adminapi": "adminapi2",
|
||||
"notification": "notification2",
|
||||
"eventstore": "eventstore2",
|
||||
}
|
||||
|
||||
queried := map[string]interface{}{}
|
||||
database.SetDatabaseInQueried(queried, &database.Current{
|
||||
Host: "test",
|
||||
Port: "test",
|
||||
Users: []string{"test"},
|
||||
})
|
||||
|
||||
equals := map[string]string{
|
||||
"CAOS_OIDC_DEV": "true",
|
||||
"CR_ADMINAPI_CERT": "test/client.adminapi.crt",
|
||||
"CR_ADMINAPI_KEY": "test/client.adminapi.key",
|
||||
"CR_AUTHZ_CERT": "test/client.authz.crt",
|
||||
"CR_AUTHZ_KEY": "test/client.authz.key",
|
||||
"CR_AUTH_CERT": "test/client.auth.crt",
|
||||
"CR_AUTH_KEY": "test/client.auth.key",
|
||||
"CR_EVENTSTORE_CERT": "test/client.eventstore.crt",
|
||||
"CR_EVENTSTORE_KEY": "test/client.eventstore.key",
|
||||
"CR_MANAGEMENT_CERT": "test/client.management.crt",
|
||||
"CR_MANAGEMENT_KEY": "test/client.management.key",
|
||||
"CR_MIGRATION_CERT": "test/client.migration.crt",
|
||||
"CR_MIGRATION_KEY": "test/client.migration.key",
|
||||
"CR_NOTIFICATION_CERT": "test/client.notification.crt",
|
||||
"CR_NOTIFICATION_KEY": "test/client.notification.key",
|
||||
"CR_ROOT_CERT": "test/ca.crt",
|
||||
"CR_SSL_MODE": "require",
|
||||
"DEBUG_MODE": "true",
|
||||
"EMAIL_SENDER_ADDRESS": "sender",
|
||||
"EMAIL_SENDER_NAME": "sendername",
|
||||
"GOOGLE_APPLICATION_CREDENTIALS": "test/test",
|
||||
"SMTP_HOST": "smtphost",
|
||||
"SMTP_TLS": "TRUE",
|
||||
"SMTP_USER": "smtpuser",
|
||||
"TWILIO_SENDER_NAME": "sendername",
|
||||
"ZITADEL_ACCOUNTS": "https://accounts.domain",
|
||||
"ZITADEL_ACCOUNTS_DOMAIN": "accounts.domain",
|
||||
"ZITADEL_AUTHORIZE": "https://accounts.domain/oauth/v2",
|
||||
"ZITADEL_CONSOLE": "https://console.domain",
|
||||
"ZITADEL_COOKIE_DOMAIN": "accounts.domain",
|
||||
"ZITADEL_COOKIE_KEY": "cookieid",
|
||||
"ZITADEL_CSRF_KEY": "csrfid",
|
||||
"ZITADEL_DEFAULT_DOMAIN": "domain",
|
||||
"ZITADEL_DOMAIN_VERIFICATION_KEY": "domainid",
|
||||
"ZITADEL_EVENTSTORE_HOST": "test",
|
||||
"ZITADEL_EVENTSTORE_PORT": "test",
|
||||
"ZITADEL_IDP_CONFIG_VERIFICATION_KEY": "idpid",
|
||||
"ZITADEL_ISSUER": "https://issuer.domain",
|
||||
"ZITADEL_KEY_PATH": "test/test",
|
||||
"ZITADEL_LOG_LEVEL": "debug",
|
||||
"ZITADEL_OAUTH": "https://api.domain/oauth/v2",
|
||||
"ZITADEL_OIDC_KEYS_ID": "oidcid",
|
||||
"ZITADEL_OTP_VERIFICATION_KEY": "otpid",
|
||||
"ZITADEL_TRACING_FRACTION": "fraction",
|
||||
"ZITADEL_TRACING_PROJECT_ID": "projectid",
|
||||
"ZITADEL_TRACING_TYPE": "type",
|
||||
"ZITADEL_USER_VERIFICATION_KEY": "userid",
|
||||
}
|
||||
literals := literalsConfigMap(desiredFull, users, certPath, secretPath, googleSA, zitadelKeyPath, queried)
|
||||
|
||||
assert.EqualValues(t, equals, literals)
|
||||
}
|
||||
|
||||
func TestConfiguration_LiteralsSecrets(t *testing.T) {
|
||||
googleSA := "sajson"
|
||||
zitadelKeyPath := "zitadel"
|
||||
|
||||
equals := map[string]string{
|
||||
googleSA: "",
|
||||
zitadelKeyPath: "",
|
||||
}
|
||||
|
||||
literals := literalsSecret(desiredEmpty, googleSA, zitadelKeyPath)
|
||||
assert.EqualValues(t, equals, literals)
|
||||
}
|
||||
|
||||
func TestConfiguration_LiteralsSecretsFull(t *testing.T) {
|
||||
googleSA := "sajson"
|
||||
zitadelKeyPath := "zitadel"
|
||||
|
||||
equals := map[string]string{
|
||||
googleSA: "sajson",
|
||||
zitadelKeyPath: "keys",
|
||||
}
|
||||
|
||||
literals := literalsSecret(desiredFull, googleSA, zitadelKeyPath)
|
||||
assert.EqualValues(t, equals, literals)
|
||||
}
|
||||
|
||||
func TestConfiguration_LiteralsSecretVars(t *testing.T) {
|
||||
equals := map[string]string{
|
||||
"ZITADEL_EMAILAPPKEY": "",
|
||||
"ZITADEL_GOOGLE_CHAT_URL": "",
|
||||
"ZITADEL_TWILIO_AUTH_TOKEN": "",
|
||||
"ZITADEL_TWILIO_SID": "",
|
||||
}
|
||||
literals := literalsSecretVars(desiredEmpty)
|
||||
|
||||
assert.EqualValues(t, equals, literals)
|
||||
}
|
||||
|
||||
func TestConfiguration_LiteralsSecretVarsFull(t *testing.T) {
|
||||
equals := map[string]string{
|
||||
"ZITADEL_EMAILAPPKEY": "appkey",
|
||||
"ZITADEL_GOOGLE_CHAT_URL": "chat",
|
||||
"ZITADEL_TWILIO_AUTH_TOKEN": "authtoken",
|
||||
"ZITADEL_TWILIO_SID": "sid",
|
||||
}
|
||||
literals := literalsSecretVars(desiredFull)
|
||||
|
||||
assert.EqualValues(t, equals, literals)
|
||||
}
|
||||
|
||||
func TestConfiguration_LiteralsConsoleCM(t *testing.T) {
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
clientID := ""
|
||||
namespace := "test"
|
||||
cmName := "cm"
|
||||
|
||||
cm := &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: namespace,
|
||||
Name: cmName,
|
||||
},
|
||||
Data: map[string]string{"environment.json": "{\"authServiceUrl\":\"https://.\",\"mgmtServiceUrl\":\"https://.\",\"issuer\":\"https://.\",\"clientid\":\"\"}"},
|
||||
}
|
||||
|
||||
equals := map[string]string{"environment.json": "{\"authServiceUrl\":\"https://.\",\"mgmtServiceUrl\":\"https://.\",\"issuer\":\"https://.\",\"clientid\":\"\"}"}
|
||||
k8sClient.EXPECT().GetConfigMap(namespace, cmName).Times(1).Return(cm, nil)
|
||||
|
||||
literals := literalsConsoleCM(clientID, desiredEmpty.DNS, k8sClient, namespace, cmName)
|
||||
assert.EqualValues(t, equals, literals)
|
||||
}
|
||||
|
||||
func TestConfiguration_LiteralsConsoleCMFull(t *testing.T) {
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
clientID := "test"
|
||||
namespace := "test"
|
||||
cmName := "cm"
|
||||
|
||||
cm := &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: namespace,
|
||||
Name: cmName,
|
||||
},
|
||||
Data: map[string]string{},
|
||||
}
|
||||
|
||||
equals := map[string]string{
|
||||
"environment.json": "{\"authServiceUrl\":\"https://api.domain\",\"mgmtServiceUrl\":\"https://api.domain\",\"issuer\":\"https://issuer.domain\",\"clientid\":\"test\"}",
|
||||
}
|
||||
k8sClient.EXPECT().GetConfigMap(namespace, cmName).Times(1).Return(cm, nil)
|
||||
|
||||
literals := literalsConsoleCM(clientID, desiredFull.DNS, k8sClient, namespace, cmName)
|
||||
assert.EqualValues(t, equals, literals)
|
||||
}
|
||||
|
||||
func TestConfiguration_LiteralsConsoleCMWithCM(t *testing.T) {
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
clientID := "test"
|
||||
namespace := "test"
|
||||
cmName := "cm"
|
||||
|
||||
cm := &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: namespace,
|
||||
Name: cmName,
|
||||
},
|
||||
Data: map[string]string{
|
||||
"environment.json": "{\"authServiceUrl\":\"https://api.domain\",\"mgmtServiceUrl\":\"https://api.domain\",\"issuer\":\"https://issuer.domain\",\"clientid\":\"\"}",
|
||||
},
|
||||
}
|
||||
|
||||
equals := map[string]string{
|
||||
"environment.json": "{\"authServiceUrl\":\"https://api.domain\",\"mgmtServiceUrl\":\"https://api.domain\",\"issuer\":\"https://issuer.domain\",\"clientid\":\"test\"}",
|
||||
}
|
||||
k8sClient.EXPECT().GetConfigMap(namespace, cmName).Times(1).Return(cm, nil)
|
||||
|
||||
literals := literalsConsoleCM(clientID, desiredFull.DNS, k8sClient, namespace, cmName)
|
||||
assert.EqualValues(t, equals, literals)
|
||||
}
|
||||
|
||||
func TestConfiguration_LiteralsConsoleCMWithCMFull(t *testing.T) {
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
clientID := ""
|
||||
namespace := "test"
|
||||
cmName := "cm"
|
||||
|
||||
cm := &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: namespace,
|
||||
Name: cmName,
|
||||
},
|
||||
Data: map[string]string{
|
||||
"environment.json": "{\"authServiceUrl\":\"https://api.domain\",\"mgmtServiceUrl\":\"https://api.domain\",\"issuer\":\"https://issuer.domain\",\"clientid\":\"test\"}",
|
||||
},
|
||||
}
|
||||
|
||||
equals := map[string]string{
|
||||
"environment.json": "{\"authServiceUrl\":\"https://api.domain\",\"mgmtServiceUrl\":\"https://api.domain\",\"issuer\":\"https://issuer.domain\",\"clientid\":\"test\"}",
|
||||
}
|
||||
k8sClient.EXPECT().GetConfigMap(namespace, cmName).Times(1).Return(cm, nil)
|
||||
|
||||
literals := literalsConsoleCM(clientID, desiredFull.DNS, k8sClient, namespace, cmName)
|
||||
assert.EqualValues(t, equals, literals)
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package configuration
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func GetReadyFunc(
|
||||
monitor mntr.Monitor,
|
||||
namespace string,
|
||||
secretName string,
|
||||
secretVarsName string,
|
||||
secretPasswordName string,
|
||||
cmName string,
|
||||
consoleCMName string,
|
||||
) func(k8sClient kubernetes.ClientInt) error {
|
||||
return func(k8sClient kubernetes.ClientInt) error {
|
||||
monitor.Debug("Waiting for configuration to be created")
|
||||
if err := k8sClient.WaitForSecret(namespace, secretName, timeout); err != nil {
|
||||
return errors.Wrap(err, "error while waiting for secret")
|
||||
}
|
||||
|
||||
if err := k8sClient.WaitForSecret(namespace, secretVarsName, timeout); err != nil {
|
||||
return errors.Wrap(err, "error while waiting for vars secret ")
|
||||
}
|
||||
|
||||
if err := k8sClient.WaitForSecret(namespace, secretPasswordName, timeout); err != nil {
|
||||
return errors.Wrap(err, "error while waiting for password secret")
|
||||
}
|
||||
|
||||
if err := k8sClient.WaitForConfigMap(namespace, cmName, timeout); err != nil {
|
||||
return errors.Wrap(err, "error while waiting for configmap")
|
||||
}
|
||||
|
||||
if err := k8sClient.WaitForConfigMap(namespace, consoleCMName, timeout); err != nil {
|
||||
return errors.Wrap(err, "error while waiting for console configmap")
|
||||
}
|
||||
monitor.Debug("configuration is created")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package configuration
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConfiguration_Ready1(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
secretName := "testSecret"
|
||||
secretVarsName := "testVars"
|
||||
secretPasswordName := "testPasswords"
|
||||
cmName := "testCM"
|
||||
consoleCMName := "testConsole"
|
||||
|
||||
client.EXPECT().WaitForConfigMap(namespace, cmName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForConfigMap(namespace, consoleCMName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretVarsName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretPasswordName, timeout).Times(1).Return(nil)
|
||||
|
||||
readyFunc := GetReadyFunc(monitor, namespace, secretName, secretVarsName, secretPasswordName, cmName, consoleCMName)
|
||||
assert.NotNil(t, readyFunc)
|
||||
assert.NoError(t, readyFunc(client))
|
||||
}
|
||||
|
||||
func TestConfiguration_Ready2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test2"
|
||||
secretName := "testSecret2"
|
||||
secretVarsName := "testVars2"
|
||||
secretPasswordName := "testPasswords2"
|
||||
cmName := "testCM2"
|
||||
consoleCMName := "testConsole2"
|
||||
|
||||
client.EXPECT().WaitForConfigMap(namespace, cmName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForConfigMap(namespace, consoleCMName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretVarsName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretPasswordName, timeout).Times(1).Return(nil)
|
||||
|
||||
readyFunc := GetReadyFunc(monitor, namespace, secretName, secretVarsName, secretPasswordName, cmName, consoleCMName)
|
||||
assert.NotNil(t, readyFunc)
|
||||
assert.NoError(t, readyFunc(client))
|
||||
}
|
||||
|
||||
func TestConfiguration_ReadyFail1(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
secretName := "testSecret"
|
||||
secretVarsName := "testVars"
|
||||
secretPasswordName := "testPasswords"
|
||||
cmName := "testCM"
|
||||
consoleCMName := "testConsole"
|
||||
|
||||
client.EXPECT().WaitForConfigMap(namespace, cmName, timeout).Times(1).Return(errors.New("fail"))
|
||||
client.EXPECT().WaitForConfigMap(namespace, consoleCMName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretVarsName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretPasswordName, timeout).Times(1).Return(nil)
|
||||
|
||||
readyFunc := GetReadyFunc(monitor, namespace, secretName, secretVarsName, secretPasswordName, cmName, consoleCMName)
|
||||
assert.NotNil(t, readyFunc)
|
||||
assert.Error(t, readyFunc(client))
|
||||
}
|
||||
|
||||
func TestConfiguration_ReadyFail2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
secretName := "testSecret"
|
||||
secretVarsName := "testVars"
|
||||
secretPasswordName := "testPasswords"
|
||||
cmName := "testCM"
|
||||
consoleCMName := "testConsole"
|
||||
|
||||
client.EXPECT().WaitForConfigMap(namespace, cmName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForConfigMap(namespace, consoleCMName, timeout).Times(1).Return(errors.New("fail"))
|
||||
client.EXPECT().WaitForSecret(namespace, secretName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretVarsName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretPasswordName, timeout).Times(1).Return(nil)
|
||||
|
||||
readyFunc := GetReadyFunc(monitor, namespace, secretName, secretVarsName, secretPasswordName, cmName, consoleCMName)
|
||||
assert.NotNil(t, readyFunc)
|
||||
assert.Error(t, readyFunc(client))
|
||||
}
|
||||
|
||||
func TestConfiguration_ReadyFail3(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
secretName := "testSecret"
|
||||
secretVarsName := "testVars"
|
||||
secretPasswordName := "testPasswords"
|
||||
cmName := "testCM"
|
||||
consoleCMName := "testConsole"
|
||||
|
||||
client.EXPECT().WaitForConfigMap(namespace, cmName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForConfigMap(namespace, consoleCMName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretName, timeout).Times(1).Return(errors.New("fail"))
|
||||
client.EXPECT().WaitForSecret(namespace, secretVarsName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretPasswordName, timeout).Times(1).Return(nil)
|
||||
|
||||
readyFunc := GetReadyFunc(monitor, namespace, secretName, secretVarsName, secretPasswordName, cmName, consoleCMName)
|
||||
assert.NotNil(t, readyFunc)
|
||||
assert.Error(t, readyFunc(client))
|
||||
}
|
||||
|
||||
func TestConfiguration_ReadyFail4(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
secretName := "testSecret"
|
||||
secretVarsName := "testVars"
|
||||
secretPasswordName := "testPasswords"
|
||||
cmName := "testCM"
|
||||
consoleCMName := "testConsole"
|
||||
|
||||
client.EXPECT().WaitForConfigMap(namespace, cmName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForConfigMap(namespace, consoleCMName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretVarsName, timeout).Times(1).Return(errors.New("fail"))
|
||||
client.EXPECT().WaitForSecret(namespace, secretPasswordName, timeout).Times(1).Return(nil)
|
||||
|
||||
readyFunc := GetReadyFunc(monitor, namespace, secretName, secretVarsName, secretPasswordName, cmName, consoleCMName)
|
||||
assert.NotNil(t, readyFunc)
|
||||
assert.Error(t, readyFunc(client))
|
||||
}
|
||||
|
||||
func TestConfiguration_ReadyFail5(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
secretName := "testSecret"
|
||||
secretVarsName := "testVars"
|
||||
secretPasswordName := "testPasswords"
|
||||
cmName := "testCM"
|
||||
consoleCMName := "testConsole"
|
||||
|
||||
client.EXPECT().WaitForConfigMap(namespace, cmName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForConfigMap(namespace, consoleCMName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretVarsName, timeout).Times(1).Return(nil)
|
||||
client.EXPECT().WaitForSecret(namespace, secretPasswordName, timeout).Times(1).Return(errors.New("fail"))
|
||||
|
||||
readyFunc := GetReadyFunc(monitor, namespace, secretName, secretVarsName, secretPasswordName, cmName, consoleCMName)
|
||||
assert.NotNil(t, readyFunc)
|
||||
assert.Error(t, readyFunc(client))
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
|
||||
)
|
||||
|
||||
func AdaptFunc(
|
||||
monitor mntr.Monitor,
|
||||
users map[string]string,
|
||||
dbClient database.ClientInt,
|
||||
) (
|
||||
operator.QueryFunc,
|
||||
operator.DestroyFunc,
|
||||
error,
|
||||
) {
|
||||
internalMonitor := monitor.WithField("component", "db-users")
|
||||
destroyers := make([]operator.DestroyFunc, 0)
|
||||
|
||||
destroyers = append(destroyers, func(k8sClient kubernetes.ClientInt) error {
|
||||
list, err := dbClient.ListUsers(internalMonitor, k8sClient)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, listedUser := range list {
|
||||
if err := dbClient.DeleteUser(internalMonitor, listedUser, k8sClient); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
usernames := []string{}
|
||||
for username := range users {
|
||||
usernames = append(usernames, username)
|
||||
}
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (operator.EnsureFunc, error) {
|
||||
queriers := make([]operator.QueryFunc, 0)
|
||||
db, err := database.GetDatabaseInQueried(queried)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, username := range usernames {
|
||||
ensure := createIfNecessary(monitor, username, db.Users, dbClient)
|
||||
if ensure != nil {
|
||||
queriers = append(queriers, operator.EnsureFuncToQueryFunc(ensure))
|
||||
}
|
||||
}
|
||||
for _, listedUser := range db.Users {
|
||||
ensure := deleteIfNotRequired(monitor, listedUser, usernames, dbClient)
|
||||
if ensure != nil {
|
||||
queriers = append(queriers, operator.EnsureFuncToQueryFunc(ensure))
|
||||
}
|
||||
}
|
||||
|
||||
if queriers == nil || len(queriers) == 0 {
|
||||
return func(k8sClient kubernetes.ClientInt) error { return nil }, nil
|
||||
}
|
||||
return operator.QueriersToEnsureFunc(internalMonitor, false, queriers, k8sClient, queried)
|
||||
}, operator.DestroyersToDestroyFunc(internalMonitor, destroyers),
|
||||
nil
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
|
||||
databasemock "github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database/mock"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUsers_Adapt_CreateFirst(t *testing.T) {
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
users := map[string]string{"test": "testpw"}
|
||||
dbClient := databasemock.NewMockClientInt(gomock.NewController(t))
|
||||
monitor := mntr.Monitor{}
|
||||
|
||||
queried := map[string]interface{}{}
|
||||
database.SetDatabaseInQueried(queried, &database.Current{
|
||||
Host: "test",
|
||||
Port: "test",
|
||||
Users: []string{},
|
||||
})
|
||||
dbClient.EXPECT().AddUser(monitor, "test", client)
|
||||
|
||||
query, _, err := AdaptFunc(monitor, users, dbClient)
|
||||
assert.NoError(t, err)
|
||||
ensure, err := query(client, queried)
|
||||
assert.NoError(t, err)
|
||||
err = ensure(client)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestUsers_Adapt_DoNothing(t *testing.T) {
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
users := map[string]string{"test": "testpw"}
|
||||
dbClient := databasemock.NewMockClientInt(gomock.NewController(t))
|
||||
monitor := mntr.Monitor{}
|
||||
|
||||
queried := map[string]interface{}{}
|
||||
database.SetDatabaseInQueried(queried, &database.Current{
|
||||
Host: "test",
|
||||
Port: "test",
|
||||
Users: []string{"test"},
|
||||
})
|
||||
|
||||
query, _, err := AdaptFunc(monitor, users, dbClient)
|
||||
assert.NoError(t, err)
|
||||
ensure, err := query(client, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, ensure)
|
||||
assert.NoError(t, ensure(client))
|
||||
}
|
||||
|
||||
func TestUsers_Adapt_Add(t *testing.T) {
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
users := map[string]string{"test": "testpw", "test2": "testpw"}
|
||||
dbClient := databasemock.NewMockClientInt(gomock.NewController(t))
|
||||
monitor := mntr.Monitor{}
|
||||
|
||||
queried := map[string]interface{}{}
|
||||
database.SetDatabaseInQueried(queried, &database.Current{
|
||||
Host: "test",
|
||||
Port: "test",
|
||||
Users: []string{"test"},
|
||||
})
|
||||
dbClient.EXPECT().AddUser(monitor, "test2", client)
|
||||
|
||||
query, _, err := AdaptFunc(monitor, users, dbClient)
|
||||
assert.NoError(t, err)
|
||||
ensure, err := query(client, queried)
|
||||
assert.NoError(t, err)
|
||||
err = ensure(client)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestUsers_Adapt_Delete(t *testing.T) {
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
users := map[string]string{"test": "testpw", "test2": "testpw"}
|
||||
dbClient := databasemock.NewMockClientInt(gomock.NewController(t))
|
||||
monitor := mntr.Monitor{}
|
||||
|
||||
queried := map[string]interface{}{}
|
||||
database.SetDatabaseInQueried(queried, &database.Current{
|
||||
Host: "test",
|
||||
Port: "test",
|
||||
Users: []string{"test", "test2", "test3"},
|
||||
})
|
||||
|
||||
dbClient.EXPECT().DeleteUser(monitor, "test3", client)
|
||||
|
||||
query, _, err := AdaptFunc(monitor, users, dbClient)
|
||||
assert.NoError(t, err)
|
||||
ensure, err := query(client, queried)
|
||||
err = ensure(client)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestUsers_Adapt_DeleteMultiple(t *testing.T) {
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
users := map[string]string{}
|
||||
dbClient := databasemock.NewMockClientInt(gomock.NewController(t))
|
||||
monitor := mntr.Monitor{}
|
||||
|
||||
queried := map[string]interface{}{}
|
||||
database.SetDatabaseInQueried(queried, &database.Current{
|
||||
Host: "test",
|
||||
Port: "test",
|
||||
Users: []string{"test", "test2", "test3"},
|
||||
})
|
||||
|
||||
dbClient.EXPECT().DeleteUser(monitor, "test", client)
|
||||
dbClient.EXPECT().DeleteUser(monitor, "test2", client)
|
||||
dbClient.EXPECT().DeleteUser(monitor, "test3", client)
|
||||
|
||||
query, _, err := AdaptFunc(monitor, users, dbClient)
|
||||
assert.NoError(t, err)
|
||||
ensure, err := query(client, queried)
|
||||
err = ensure(client)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
|
||||
)
|
||||
|
||||
func createIfNecessary(monitor mntr.Monitor, user string, list []string, dbClient database.ClientInt) operator.EnsureFunc {
|
||||
existing := false
|
||||
for _, listedUser := range list {
|
||||
if listedUser == user {
|
||||
existing = true
|
||||
}
|
||||
}
|
||||
if !existing {
|
||||
return func(k8sClient kubernetes.ClientInt) error {
|
||||
return dbClient.AddUser(monitor, user, k8sClient)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteIfNotRequired(monitor mntr.Monitor, listedUser string, list []string, dbClient database.ClientInt) operator.EnsureFunc {
|
||||
required := false
|
||||
for _, user := range list {
|
||||
if user == listedUser {
|
||||
required = true
|
||||
}
|
||||
}
|
||||
if !required {
|
||||
return func(k8sClient kubernetes.ClientInt) error {
|
||||
return dbClient.DeleteUser(monitor, listedUser, k8sClient)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
databasemock "github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database/mock"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUsers_CreateIfNecessary(t *testing.T) {
|
||||
users := []string{}
|
||||
monitor := mntr.Monitor{}
|
||||
user := "test"
|
||||
dbClient := databasemock.NewMockClientInt(gomock.NewController(t))
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
dbClient.EXPECT().AddUser(monitor, user, k8sClient)
|
||||
function := createIfNecessary(monitor, user, users, dbClient)
|
||||
assert.NotNil(t, function)
|
||||
err := function(k8sClient)
|
||||
assert.NoError(t, err)
|
||||
|
||||
users = []string{"test"}
|
||||
function = createIfNecessary(monitor, user, users, dbClient)
|
||||
assert.Nil(t, function)
|
||||
|
||||
user2 := "test2"
|
||||
dbClient.EXPECT().AddUser(monitor, user2, k8sClient)
|
||||
function = createIfNecessary(monitor, user2, users, dbClient)
|
||||
assert.NotNil(t, function)
|
||||
err = function(k8sClient)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestUsers_DeleteIfNotRequired(t *testing.T) {
|
||||
users := []string{}
|
||||
monitor := mntr.Monitor{}
|
||||
user := "test"
|
||||
dbClient := databasemock.NewMockClientInt(gomock.NewController(t))
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
dbClient.EXPECT().DeleteUser(monitor, user, k8sClient)
|
||||
function := deleteIfNotRequired(monitor, user, users, dbClient)
|
||||
assert.NotNil(t, function)
|
||||
err := function(k8sClient)
|
||||
assert.NoError(t, err)
|
||||
|
||||
users = []string{"test"}
|
||||
function = deleteIfNotRequired(monitor, user, users, dbClient)
|
||||
assert.Nil(t, function)
|
||||
|
||||
user2 := "test2"
|
||||
dbClient.EXPECT().DeleteUser(monitor, user2, k8sClient)
|
||||
function = deleteIfNotRequired(monitor, user2, users, dbClient)
|
||||
assert.NotNil(t, function)
|
||||
err = function(k8sClient)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/zitadel/operator"
|
||||
)
|
||||
|
||||
func AdaptFunc(
|
||||
monitor mntr.Monitor,
|
||||
dbClient ClientInt,
|
||||
) (
|
||||
operator.QueryFunc,
|
||||
error,
|
||||
) {
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (operator.EnsureFunc, error) {
|
||||
|
||||
dbHost, dbPort, err := dbClient.GetConnectionInfo(monitor, k8sClient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
users, err := dbClient.ListUsers(monitor, k8sClient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
curr := &Current{
|
||||
Host: dbHost,
|
||||
Port: dbPort,
|
||||
Users: users,
|
||||
}
|
||||
|
||||
SetDatabaseInQueried(queried, curr)
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt) error {
|
||||
return nil
|
||||
}, nil
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
databasemock "github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database/mock"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDatabase_Adapt(t *testing.T) {
|
||||
dbClient := databasemock.NewMockClientInt(gomock.NewController(t))
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
host := "host"
|
||||
port := "port"
|
||||
users := []string{"test"}
|
||||
|
||||
monitor := mntr.Monitor{}
|
||||
queried := map[string]interface{}{}
|
||||
|
||||
dbClient.EXPECT().GetConnectionInfo(monitor, k8sClient).Return(host, port, nil)
|
||||
dbClient.EXPECT().ListUsers(monitor, k8sClient).Return([]string{"test"}, nil)
|
||||
|
||||
_, err := GetDatabaseInQueried(queried)
|
||||
assert.Error(t, err)
|
||||
|
||||
query, err := AdaptFunc(monitor, dbClient)
|
||||
assert.NoError(t, err)
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, ensure(k8sClient))
|
||||
|
||||
current, err := GetDatabaseInQueried(queried)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, host, current.Host)
|
||||
assert.Equal(t, port, current.Port)
|
||||
assert.Equal(t, users, current.Users)
|
||||
}
|
||||
|
||||
func TestDatabase_Adapt2(t *testing.T) {
|
||||
dbClient := databasemock.NewMockClientInt(gomock.NewController(t))
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
host := "host2"
|
||||
port := "port2"
|
||||
users := []string{"test2"}
|
||||
|
||||
monitor := mntr.Monitor{}
|
||||
queried := map[string]interface{}{}
|
||||
|
||||
dbClient.EXPECT().GetConnectionInfo(monitor, k8sClient).Return(host, port, nil)
|
||||
dbClient.EXPECT().ListUsers(monitor, k8sClient).Return(users, nil)
|
||||
|
||||
_, err := GetDatabaseInQueried(queried)
|
||||
assert.Error(t, err)
|
||||
|
||||
query, err := AdaptFunc(monitor, dbClient)
|
||||
assert.NoError(t, err)
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, ensure(k8sClient))
|
||||
|
||||
current, err := GetDatabaseInQueried(queried)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, host, current.Host)
|
||||
assert.Equal(t, port, current.Port)
|
||||
assert.Equal(t, users, current.Users)
|
||||
}
|
||||
|
||||
func TestDatabase_AdaptFailConnection(t *testing.T) {
|
||||
dbClient := databasemock.NewMockClientInt(gomock.NewController(t))
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
monitor := mntr.Monitor{}
|
||||
queried := map[string]interface{}{}
|
||||
|
||||
dbClient.EXPECT().GetConnectionInfo(monitor, k8sClient).Return("", "", errors.New("fail"))
|
||||
dbClient.EXPECT().ListUsers(monitor, k8sClient).Return([]string{"test"}, nil)
|
||||
|
||||
_, err := GetDatabaseInQueried(queried)
|
||||
assert.Error(t, err)
|
||||
|
||||
query, err := AdaptFunc(monitor, dbClient)
|
||||
assert.NoError(t, err)
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, ensure)
|
||||
|
||||
current, err := GetDatabaseInQueried(queried)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, current)
|
||||
}
|
||||
|
||||
func TestDatabase_AdaptFailUsers(t *testing.T) {
|
||||
dbClient := databasemock.NewMockClientInt(gomock.NewController(t))
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
host := "host"
|
||||
port := "port"
|
||||
|
||||
monitor := mntr.Monitor{}
|
||||
queried := map[string]interface{}{}
|
||||
|
||||
dbClient.EXPECT().GetConnectionInfo(monitor, k8sClient).Return(host, port, nil)
|
||||
dbClient.EXPECT().ListUsers(monitor, k8sClient).Return(nil, errors.New("fail"))
|
||||
|
||||
_, err := GetDatabaseInQueried(queried)
|
||||
assert.Error(t, err)
|
||||
|
||||
query, err := AdaptFunc(monitor, dbClient)
|
||||
assert.NoError(t, err)
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, ensure)
|
||||
|
||||
current, err := GetDatabaseInQueried(queried)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, current)
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/git"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/zitadel/pkg/databases"
|
||||
)
|
||||
|
||||
var _ ClientInt = (*Client)(nil)
|
||||
|
||||
type ClientInt interface {
|
||||
GetConnectionInfo(monitor mntr.Monitor, k8sClient kubernetes.ClientInt) (string, string, error)
|
||||
DeleteUser(monitor mntr.Monitor, user string, k8sClient kubernetes.ClientInt) error
|
||||
AddUser(monitor mntr.Monitor, user string, k8sClient kubernetes.ClientInt) error
|
||||
ListUsers(monitor mntr.Monitor, k8sClient kubernetes.ClientInt) ([]string, error)
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
Monitor mntr.Monitor
|
||||
gitClient *git.Client
|
||||
}
|
||||
|
||||
func NewClient(monitor mntr.Monitor, repoURL, repoKey string) (*Client, error) {
|
||||
gitClient, err := newGit(monitor, repoURL, repoKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Client{
|
||||
Monitor: monitor,
|
||||
gitClient: gitClient,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newGit(monitor mntr.Monitor, repoURL string, repoKey string) (*git.Client, error) {
|
||||
gitClient := git.New(context.Background(), monitor, "orbos", "[email protected]")
|
||||
if err := gitClient.Configure(repoURL, []byte(repoKey)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := gitClient.Clone(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return gitClient, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetConnectionInfo(monitor mntr.Monitor, k8sClient kubernetes.ClientInt) (string, string, error) {
|
||||
return databases.GetConnectionInfo(
|
||||
monitor,
|
||||
k8sClient,
|
||||
c.gitClient,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Current struct {
|
||||
Host string
|
||||
Port string
|
||||
Users []string
|
||||
}
|
||||
|
||||
func SetDatabaseInQueried(queried map[string]interface{}, current *Current) {
|
||||
queried["database"] = current
|
||||
}
|
||||
|
||||
func GetDatabaseInQueried(queried map[string]interface{}) (*Current, error) {
|
||||
curr, ok := queried["database"].(*Current)
|
||||
if !ok {
|
||||
return nil, errors.New("database current not in supported format")
|
||||
}
|
||||
|
||||
return curr, nil
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package database
|
||||
|
||||
//go:generate mockgen -source client.go -package databasemock -destination mock/client.mock.go github.com/caos/zitadel/operator/kinds/iam/zitadel/database ClientInt
|
||||
@@ -0,0 +1,94 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: client.go
|
||||
|
||||
// Package databasemock is a generated GoMock package.
|
||||
package databasemock
|
||||
|
||||
import (
|
||||
mntr "github.com/caos/orbos/mntr"
|
||||
kubernetes "github.com/caos/orbos/pkg/kubernetes"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// MockClientInt is a mock of ClientInt interface
|
||||
type MockClientInt struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockClientIntMockRecorder
|
||||
}
|
||||
|
||||
// MockClientIntMockRecorder is the mock recorder for MockClientInt
|
||||
type MockClientIntMockRecorder struct {
|
||||
mock *MockClientInt
|
||||
}
|
||||
|
||||
// NewMockClientInt creates a new mock instance
|
||||
func NewMockClientInt(ctrl *gomock.Controller) *MockClientInt {
|
||||
mock := &MockClientInt{ctrl: ctrl}
|
||||
mock.recorder = &MockClientIntMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use
|
||||
func (m *MockClientInt) EXPECT() *MockClientIntMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// GetConnectionInfo mocks base method
|
||||
func (m *MockClientInt) GetConnectionInfo(monitor mntr.Monitor, k8sClient kubernetes.ClientInt) (string, string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetConnectionInfo", monitor, k8sClient)
|
||||
ret0, _ := ret[0].(string)
|
||||
ret1, _ := ret[1].(string)
|
||||
ret2, _ := ret[2].(error)
|
||||
return ret0, ret1, ret2
|
||||
}
|
||||
|
||||
// GetConnectionInfo indicates an expected call of GetConnectionInfo
|
||||
func (mr *MockClientIntMockRecorder) GetConnectionInfo(monitor, k8sClient interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetConnectionInfo", reflect.TypeOf((*MockClientInt)(nil).GetConnectionInfo), monitor, k8sClient)
|
||||
}
|
||||
|
||||
// DeleteUser mocks base method
|
||||
func (m *MockClientInt) DeleteUser(monitor mntr.Monitor, user string, k8sClient kubernetes.ClientInt) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DeleteUser", monitor, user, k8sClient)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// DeleteUser indicates an expected call of DeleteUser
|
||||
func (mr *MockClientIntMockRecorder) DeleteUser(monitor, user, k8sClient interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteUser", reflect.TypeOf((*MockClientInt)(nil).DeleteUser), monitor, user, k8sClient)
|
||||
}
|
||||
|
||||
// AddUser mocks base method
|
||||
func (m *MockClientInt) AddUser(monitor mntr.Monitor, user string, k8sClient kubernetes.ClientInt) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AddUser", monitor, user, k8sClient)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// AddUser indicates an expected call of AddUser
|
||||
func (mr *MockClientIntMockRecorder) AddUser(monitor, user, k8sClient interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddUser", reflect.TypeOf((*MockClientInt)(nil).AddUser), monitor, user, k8sClient)
|
||||
}
|
||||
|
||||
// ListUsers mocks base method
|
||||
func (m *MockClientInt) ListUsers(monitor mntr.Monitor, k8sClient kubernetes.ClientInt) ([]string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ListUsers", monitor, k8sClient)
|
||||
ret0, _ := ret[0].([]string)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// ListUsers indicates an expected call of ListUsers
|
||||
func (mr *MockClientIntMockRecorder) ListUsers(monitor, k8sClient interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListUsers", reflect.TypeOf((*MockClientInt)(nil).ListUsers), monitor, k8sClient)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/zitadel/pkg/databases"
|
||||
)
|
||||
|
||||
func (c *Client) DeleteUser(monitor mntr.Monitor, user string, k8sClient kubernetes.ClientInt) error {
|
||||
return databases.DeleteUser(
|
||||
monitor,
|
||||
user,
|
||||
k8sClient,
|
||||
c.gitClient,
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Client) AddUser(monitor mntr.Monitor, user string, k8sClient kubernetes.ClientInt) error {
|
||||
return databases.AddUser(
|
||||
monitor,
|
||||
user,
|
||||
k8sClient,
|
||||
c.gitClient,
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Client) ListUsers(monitor mntr.Monitor, k8sClient kubernetes.ClientInt) ([]string, error) {
|
||||
return databases.ListUsers(
|
||||
monitor,
|
||||
k8sClient,
|
||||
c.gitClient,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/kubernetes/k8s"
|
||||
"github.com/caos/orbos/pkg/kubernetes/resources/deployment"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/operator/helpers"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
rootSecret = "client-root"
|
||||
dbSecrets = "db-secrets"
|
||||
containerName = "zitadel"
|
||||
RunAsUser = int64(1000)
|
||||
//zitadelImage can be found in github.com/caos/zitadel repo
|
||||
zitadelImage = "ghcr.io/caos/zitadel"
|
||||
timeout time.Duration = 60
|
||||
)
|
||||
|
||||
func AdaptFunc(
|
||||
monitor mntr.Monitor,
|
||||
nameLabels *labels.Name,
|
||||
podSelector *labels.Selector,
|
||||
force bool,
|
||||
version *string,
|
||||
namespace string,
|
||||
replicaCount int,
|
||||
affinity *k8s.Affinity,
|
||||
cmName string,
|
||||
certPath string,
|
||||
secretName string,
|
||||
secretPath string,
|
||||
consoleCMName string,
|
||||
secretVarsName string,
|
||||
secretPasswordsName string,
|
||||
users []string,
|
||||
nodeSelector map[string]string,
|
||||
tolerations []corev1.Toleration,
|
||||
resources *k8s.Resources,
|
||||
migrationDone operator.EnsureFunc,
|
||||
configurationDone operator.EnsureFunc,
|
||||
setupDone operator.EnsureFunc,
|
||||
getConfigurationHashes func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) map[string]string,
|
||||
) (
|
||||
operator.QueryFunc,
|
||||
operator.DestroyFunc,
|
||||
error,
|
||||
) {
|
||||
internalMonitor := monitor.WithField("type", "deployment")
|
||||
|
||||
destroy, err := deployment.AdaptFuncToDestroy(namespace, nameLabels.Name())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
destroyers := []operator.DestroyFunc{
|
||||
operator.ResourceDestroyToZitadelDestroy(destroy),
|
||||
}
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (operator.EnsureFunc, error) {
|
||||
|
||||
deploymentDef := deploymentDef(
|
||||
nameLabels,
|
||||
namespace,
|
||||
replicaCount,
|
||||
podSelector,
|
||||
nodeSelector,
|
||||
tolerations,
|
||||
affinity,
|
||||
users,
|
||||
version,
|
||||
resources,
|
||||
cmName,
|
||||
certPath,
|
||||
secretName,
|
||||
secretPath,
|
||||
consoleCMName,
|
||||
secretVarsName,
|
||||
secretPasswordsName,
|
||||
)
|
||||
|
||||
hashes := getConfigurationHashes(k8sClient, queried)
|
||||
if hashes != nil && len(hashes) != 0 {
|
||||
for k, v := range hashes {
|
||||
deploymentDef.Annotations[k] = v
|
||||
deploymentDef.Spec.Template.Annotations[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
query, err := deployment.AdaptFuncToEnsure(deploymentDef, force)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queriers := []operator.QueryFunc{
|
||||
operator.EnsureFuncToQueryFunc(migrationDone),
|
||||
operator.EnsureFuncToQueryFunc(configurationDone),
|
||||
operator.EnsureFuncToQueryFunc(setupDone),
|
||||
operator.ResourceQueryToZitadelQuery(query),
|
||||
}
|
||||
|
||||
return operator.QueriersToEnsureFunc(internalMonitor, false, queriers, k8sClient, queried)
|
||||
},
|
||||
operator.DestroyersToDestroyFunc(internalMonitor, destroyers),
|
||||
nil
|
||||
}
|
||||
|
||||
func deploymentDef(nameLabels *labels.Name, namespace string, replicaCount int, podSelector *labels.Selector, nodeSelector map[string]string, tolerations []corev1.Toleration, affinity *k8s.Affinity, users []string, version *string, resources *k8s.Resources, cmName string, certPath string, secretName string, secretPath string, consoleCMName string, secretVarsName string, secretPasswordsName string) *appsv1.Deployment {
|
||||
deploymentDef := &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: nameLabels.Name(),
|
||||
Namespace: namespace,
|
||||
Labels: labels.MustK8sMap(nameLabels),
|
||||
Annotations: map[string]string{},
|
||||
},
|
||||
Spec: appsv1.DeploymentSpec{
|
||||
Replicas: helpers.PointerInt32(int32(replicaCount)),
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: labels.MustK8sMap(podSelector),
|
||||
},
|
||||
Strategy: appsv1.DeploymentStrategy{
|
||||
Type: appsv1.RollingUpdateDeploymentStrategyType,
|
||||
RollingUpdate: &appsv1.RollingUpdateDeployment{
|
||||
MaxUnavailable: helpers.IntToIntStr(1),
|
||||
MaxSurge: helpers.IntToIntStr(1),
|
||||
},
|
||||
},
|
||||
Template: corev1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: labels.MustK8sMap(labels.AsSelectable(nameLabels)),
|
||||
Annotations: map[string]string{},
|
||||
},
|
||||
Spec: corev1.PodSpec{
|
||||
NodeSelector: nodeSelector,
|
||||
Tolerations: tolerations,
|
||||
Affinity: affinity.K8s(),
|
||||
InitContainers: []corev1.Container{
|
||||
GetInitContainer(
|
||||
rootSecret,
|
||||
dbSecrets,
|
||||
users,
|
||||
RunAsUser,
|
||||
),
|
||||
},
|
||||
Containers: []corev1.Container{
|
||||
GetContainer(
|
||||
containerName,
|
||||
*version,
|
||||
RunAsUser,
|
||||
true,
|
||||
GetResourcesFromDefault(resources),
|
||||
cmName,
|
||||
certPath,
|
||||
secretName,
|
||||
secretPath,
|
||||
consoleCMName,
|
||||
secretVarsName,
|
||||
secretPasswordsName,
|
||||
users,
|
||||
dbSecrets,
|
||||
"start",
|
||||
),
|
||||
},
|
||||
Volumes: GetVolumes(
|
||||
secretName,
|
||||
secretPasswordsName,
|
||||
consoleCMName,
|
||||
users,
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return deploymentDef
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/caos/orbos/pkg/labels/mocklabels"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/kubernetes/k8s"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/caos/zitadel/operator/helpers"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
func TestDeployment_Adapt(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
imageVersion := "test"
|
||||
namespace := "test"
|
||||
|
||||
replicaCount := 1
|
||||
nodeSelector := map[string]string{"test": "test"}
|
||||
secretVarsName := "testVars"
|
||||
secretPasswordsName := "testPasswords"
|
||||
secretPath := "testSecretPath"
|
||||
certPath := "testCert"
|
||||
secretName := "testSecret"
|
||||
consoleCMName := "testConsoleCM"
|
||||
cmName := "testCM"
|
||||
users := []string{"test"}
|
||||
annotations := map[string]string{"testHash": "test"}
|
||||
|
||||
k8sClient := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
resources := &k8s.Resources{
|
||||
Limits: corev1.ResourceList{
|
||||
corev1.ResourceCPU: resource.MustParse("2"),
|
||||
corev1.ResourceMemory: resource.MustParse("2Gi"),
|
||||
},
|
||||
Requests: corev1.ResourceList{
|
||||
corev1.ResourceCPU: resource.MustParse("500m"),
|
||||
corev1.ResourceMemory: resource.MustParse("512Mi"),
|
||||
},
|
||||
}
|
||||
|
||||
deploymentDef := &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: mocklabels.NameVal,
|
||||
Namespace: namespace,
|
||||
Labels: mocklabels.NameMap,
|
||||
Annotations: annotations,
|
||||
},
|
||||
Spec: appsv1.DeploymentSpec{
|
||||
Replicas: helpers.PointerInt32(int32(replicaCount)),
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: mocklabels.ClosedNameSelectorMap,
|
||||
},
|
||||
Strategy: appsv1.DeploymentStrategy{
|
||||
Type: appsv1.RollingUpdateDeploymentStrategyType,
|
||||
RollingUpdate: &appsv1.RollingUpdateDeployment{
|
||||
MaxUnavailable: helpers.IntToIntStr(1),
|
||||
MaxSurge: helpers.IntToIntStr(1),
|
||||
},
|
||||
},
|
||||
Template: corev1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: mocklabels.SelectableMap,
|
||||
Annotations: annotations,
|
||||
},
|
||||
Spec: corev1.PodSpec{
|
||||
NodeSelector: nodeSelector,
|
||||
Tolerations: nil,
|
||||
Affinity: nil,
|
||||
InitContainers: []corev1.Container{
|
||||
GetInitContainer(
|
||||
rootSecret,
|
||||
dbSecrets,
|
||||
users,
|
||||
RunAsUser,
|
||||
),
|
||||
},
|
||||
Containers: []corev1.Container{
|
||||
GetContainer(
|
||||
containerName,
|
||||
imageVersion,
|
||||
RunAsUser,
|
||||
true,
|
||||
resources,
|
||||
cmName,
|
||||
certPath,
|
||||
secretName,
|
||||
secretPath,
|
||||
consoleCMName,
|
||||
secretVarsName,
|
||||
secretPasswordsName,
|
||||
users,
|
||||
dbSecrets,
|
||||
"start",
|
||||
),
|
||||
},
|
||||
Volumes: GetVolumes(
|
||||
secretName,
|
||||
secretPasswordsName,
|
||||
consoleCMName,
|
||||
users,
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
k8sClient.EXPECT().ApplyDeployment(deploymentDef, false).Times(1)
|
||||
|
||||
getConfigurationHashes := func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) map[string]string {
|
||||
return map[string]string{"testHash": "test"}
|
||||
}
|
||||
migrationDone := func(k8sClient kubernetes.ClientInt) error {
|
||||
return nil
|
||||
}
|
||||
configurationDone := func(k8sClient kubernetes.ClientInt) error {
|
||||
return nil
|
||||
}
|
||||
setupDone := func(k8sClient kubernetes.ClientInt) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
query, _, err := AdaptFunc(
|
||||
monitor,
|
||||
mocklabels.Name,
|
||||
mocklabels.ClosedNameSelector,
|
||||
false,
|
||||
&imageVersion,
|
||||
namespace,
|
||||
replicaCount,
|
||||
nil,
|
||||
cmName,
|
||||
certPath,
|
||||
secretName,
|
||||
secretPath,
|
||||
consoleCMName,
|
||||
secretVarsName,
|
||||
secretPasswordsName,
|
||||
users,
|
||||
nodeSelector,
|
||||
nil,
|
||||
resources,
|
||||
migrationDone,
|
||||
configurationDone,
|
||||
setupDone,
|
||||
getConfigurationHashes,
|
||||
)
|
||||
assert.NoError(t, err)
|
||||
queried := map[string]interface{}{}
|
||||
ensure, err := query(k8sClient, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, ensure(k8sClient))
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/caos/orbos/pkg/kubernetes/k8s"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
)
|
||||
|
||||
func GetContainer(
|
||||
containerName string,
|
||||
version string,
|
||||
runAsUser int64,
|
||||
runAsNonRoot bool,
|
||||
resources *k8s.Resources,
|
||||
cmName string,
|
||||
certPath string,
|
||||
secretName string,
|
||||
secretPath string,
|
||||
consoleCMName string,
|
||||
secretVarsName string,
|
||||
secretPasswordsName string,
|
||||
users []string,
|
||||
dbSecrets string,
|
||||
command string,
|
||||
) corev1.Container {
|
||||
|
||||
envVars := []corev1.EnvVar{
|
||||
{Name: "POD_IP",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
FieldRef: &corev1.ObjectFieldSelector{
|
||||
FieldPath: "status.podIP",
|
||||
},
|
||||
}},
|
||||
{Name: "CHAT_URL",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: secretVarsName},
|
||||
Key: "ZITADEL_GOOGLE_CHAT_URL",
|
||||
},
|
||||
}},
|
||||
{Name: "TWILIO_TOKEN",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: secretVarsName},
|
||||
Key: "ZITADEL_TWILIO_AUTH_TOKEN",
|
||||
},
|
||||
}},
|
||||
{Name: "TWILIO_SERVICE_SID",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: secretVarsName},
|
||||
Key: "ZITADEL_TWILIO_SID",
|
||||
},
|
||||
}},
|
||||
{Name: "SMTP_PASSWORD",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: secretVarsName},
|
||||
Key: "ZITADEL_EMAILAPPKEY",
|
||||
},
|
||||
}},
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
envVars = append(envVars, corev1.EnvVar{
|
||||
Name: "CR_" + strings.ToUpper(user) + "_PASSWORD",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: secretPasswordsName},
|
||||
Key: user,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
volMounts := []corev1.VolumeMount{
|
||||
{Name: secretName, MountPath: secretPath},
|
||||
{Name: consoleCMName, MountPath: "/console/environment.json", SubPath: "environment.json"},
|
||||
{Name: dbSecrets, MountPath: certPath},
|
||||
}
|
||||
|
||||
return corev1.Container{
|
||||
Resources: corev1.ResourceRequirements(*resources),
|
||||
//Command: []string{"/bin/sh", "-c"},
|
||||
//Args: []string{"tail -f /dev/null;"},
|
||||
Args: []string{command},
|
||||
SecurityContext: &corev1.SecurityContext{
|
||||
RunAsUser: &runAsUser,
|
||||
RunAsNonRoot: &runAsNonRoot,
|
||||
},
|
||||
Name: containerName,
|
||||
Image: zitadelImage + ":" + version,
|
||||
ImagePullPolicy: "IfNotPresent",
|
||||
Ports: []corev1.ContainerPort{
|
||||
{Name: "grpc", ContainerPort: 50001},
|
||||
{Name: "http", ContainerPort: 50002},
|
||||
{Name: "ui", ContainerPort: 50003},
|
||||
},
|
||||
Env: envVars,
|
||||
EnvFrom: []corev1.EnvFromSource{
|
||||
{ConfigMapRef: &corev1.ConfigMapEnvSource{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: cmName},
|
||||
}}},
|
||||
VolumeMounts: volMounts,
|
||||
/*LivenessProbe: &corev1.Probe{
|
||||
Handler: corev1.Handler{
|
||||
HTTPGet: &corev1.HTTPGetAction{
|
||||
Path: "/healthz",
|
||||
Port: intstr.Parse("http"),
|
||||
Scheme: "HTTP",
|
||||
},
|
||||
},
|
||||
PeriodSeconds: 5,
|
||||
FailureThreshold: 2,
|
||||
InitialDelaySeconds: 60,
|
||||
},*/
|
||||
ReadinessProbe: &corev1.Probe{
|
||||
Handler: corev1.Handler{
|
||||
HTTPGet: &corev1.HTTPGetAction{
|
||||
Path: "/ready",
|
||||
Port: intstr.Parse("http"),
|
||||
Scheme: "HTTP",
|
||||
},
|
||||
},
|
||||
PeriodSeconds: 5,
|
||||
FailureThreshold: 2,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/pkg/kubernetes/k8s"
|
||||
"github.com/caos/zitadel/operator/helpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDeployment_GetContainer(t *testing.T) {
|
||||
secretVarsName := "testVars"
|
||||
version := "test"
|
||||
secretPasswordsName := "testPasswords"
|
||||
secretPath := "testSecretPath"
|
||||
certPath := "testCert"
|
||||
secretName := "testSecret"
|
||||
consoleCMName := "testConsoleCM"
|
||||
cmName := "testCM"
|
||||
users := []string{"test"}
|
||||
|
||||
resources := &k8s.Resources{
|
||||
Limits: corev1.ResourceList{
|
||||
corev1.ResourceCPU: resource.MustParse("2"),
|
||||
corev1.ResourceMemory: resource.MustParse("2Gi"),
|
||||
},
|
||||
Requests: corev1.ResourceList{
|
||||
corev1.ResourceCPU: resource.MustParse("500m"),
|
||||
corev1.ResourceMemory: resource.MustParse("512Mi"),
|
||||
},
|
||||
}
|
||||
|
||||
envVars := []corev1.EnvVar{
|
||||
{Name: "POD_IP",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
FieldRef: &corev1.ObjectFieldSelector{
|
||||
FieldPath: "status.podIP",
|
||||
},
|
||||
}},
|
||||
{Name: "CHAT_URL",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: secretVarsName},
|
||||
Key: "ZITADEL_GOOGLE_CHAT_URL",
|
||||
},
|
||||
}},
|
||||
{Name: "TWILIO_TOKEN",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: secretVarsName},
|
||||
Key: "ZITADEL_TWILIO_AUTH_TOKEN",
|
||||
},
|
||||
}},
|
||||
{Name: "TWILIO_SERVICE_SID",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: secretVarsName},
|
||||
Key: "ZITADEL_TWILIO_SID",
|
||||
},
|
||||
}},
|
||||
{Name: "SMTP_PASSWORD",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: secretVarsName},
|
||||
Key: "ZITADEL_EMAILAPPKEY",
|
||||
},
|
||||
}},
|
||||
{
|
||||
Name: "CR_TEST_PASSWORD",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: secretPasswordsName},
|
||||
Key: "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
volMounts := []corev1.VolumeMount{
|
||||
{Name: secretName, MountPath: secretPath},
|
||||
{Name: consoleCMName, MountPath: "/console/environment.json", SubPath: "environment.json"},
|
||||
{Name: dbSecrets, MountPath: certPath},
|
||||
}
|
||||
|
||||
equals := corev1.Container{
|
||||
Resources: corev1.ResourceRequirements(*resources),
|
||||
//Command: []string{"/bin/sh", "-c"},
|
||||
//Args: []string{"tail -f /dev/null;"},
|
||||
Args: []string{"start"},
|
||||
SecurityContext: &corev1.SecurityContext{
|
||||
RunAsUser: helpers.PointerInt64(RunAsUser),
|
||||
RunAsNonRoot: helpers.PointerBool(true),
|
||||
},
|
||||
Name: containerName,
|
||||
Image: zitadelImage + ":" + version,
|
||||
ImagePullPolicy: "IfNotPresent",
|
||||
Ports: []corev1.ContainerPort{
|
||||
{Name: "grpc", ContainerPort: 50001},
|
||||
{Name: "http", ContainerPort: 50002},
|
||||
{Name: "ui", ContainerPort: 50003},
|
||||
},
|
||||
Env: envVars,
|
||||
EnvFrom: []corev1.EnvFromSource{
|
||||
{ConfigMapRef: &corev1.ConfigMapEnvSource{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: cmName},
|
||||
}}},
|
||||
VolumeMounts: volMounts,
|
||||
/*LivenessProbe: &corev1.Probe{
|
||||
Handler: corev1.Handler{
|
||||
HTTPGet: &corev1.HTTPGetAction{
|
||||
Path: "/healthz",
|
||||
Port: intstr.Parse("http"),
|
||||
Scheme: "HTTP",
|
||||
},
|
||||
},
|
||||
PeriodSeconds: 5,
|
||||
FailureThreshold: 2,
|
||||
InitialDelaySeconds: 60,
|
||||
},*/
|
||||
ReadinessProbe: &corev1.Probe{
|
||||
Handler: corev1.Handler{
|
||||
HTTPGet: &corev1.HTTPGetAction{
|
||||
Path: "/ready",
|
||||
Port: intstr.Parse("http"),
|
||||
Scheme: "HTTP",
|
||||
},
|
||||
},
|
||||
PeriodSeconds: 5,
|
||||
FailureThreshold: 2,
|
||||
},
|
||||
}
|
||||
|
||||
container := GetContainer(
|
||||
containerName,
|
||||
version,
|
||||
RunAsUser,
|
||||
true,
|
||||
resources,
|
||||
cmName,
|
||||
certPath,
|
||||
secretName,
|
||||
secretPath,
|
||||
consoleCMName,
|
||||
secretVarsName,
|
||||
secretPasswordsName,
|
||||
users,
|
||||
dbSecrets,
|
||||
"start",
|
||||
)
|
||||
|
||||
assert.Equal(t, equals, container)
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
certMountPath = "/dbsecrets"
|
||||
certTempMountPath = "/tmp/dbsecrets"
|
||||
)
|
||||
|
||||
func GetInitContainer(
|
||||
rootSecret string,
|
||||
dbSecrets string,
|
||||
users []string,
|
||||
runAsUser int64,
|
||||
) corev1.Container {
|
||||
|
||||
initVolumeMounts := []corev1.VolumeMount{
|
||||
{Name: rootSecret, MountPath: certMountPath + "/client_root"},
|
||||
{Name: dbSecrets, MountPath: certTempMountPath},
|
||||
}
|
||||
|
||||
copySecrets := append([]string{}, "cp "+certMountPath+"/client_root/ca.crt "+certTempMountPath+"/ca.crt")
|
||||
for _, user := range users {
|
||||
userReplaced := strings.ReplaceAll(user, "_", "-")
|
||||
internalName := "client-" + userReplaced
|
||||
initVolumeMounts = append(initVolumeMounts, corev1.VolumeMount{
|
||||
Name: internalName,
|
||||
//ReadOnly: true,
|
||||
MountPath: certMountPath + "/client_" + user,
|
||||
})
|
||||
copySecrets = append(copySecrets, "cp "+certMountPath+"/client_"+user+"/client."+user+".crt "+certTempMountPath+"/client."+user+".crt")
|
||||
copySecrets = append(copySecrets, "cp "+certMountPath+"/client_"+user+"/client."+user+".key "+certTempMountPath+"/client."+user+".key")
|
||||
}
|
||||
|
||||
initCommands := append(
|
||||
copySecrets,
|
||||
"chown -R "+strconv.FormatInt(runAsUser, 10)+":"+strconv.FormatInt(runAsUser, 10)+" "+certTempMountPath+"",
|
||||
"chmod 0600 "+certTempMountPath+"/*",
|
||||
)
|
||||
|
||||
return corev1.Container{
|
||||
Name: "fix-permissions",
|
||||
Image: "alpine:3.11",
|
||||
Command: []string{"/bin/sh", "-c"},
|
||||
Args: []string{strings.Join(initCommands, " && ")},
|
||||
VolumeMounts: initVolumeMounts,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDeployment_GetInitContainer(t *testing.T) {
|
||||
users := []string{"test"}
|
||||
|
||||
initCommands := []string{
|
||||
"cp /dbsecrets/client_root/ca.crt /tmp/dbsecrets/ca.crt",
|
||||
"cp /dbsecrets/client_test/client.test.crt /tmp/dbsecrets/client.test.crt",
|
||||
"cp /dbsecrets/client_test/client.test.key /tmp/dbsecrets/client.test.key",
|
||||
"chown -R 1000:1000 /tmp/dbsecrets",
|
||||
"chmod 0600 /tmp/dbsecrets/*",
|
||||
}
|
||||
|
||||
initVolumeMounts := []corev1.VolumeMount{
|
||||
{Name: rootSecret, MountPath: certMountPath + "/client_root"},
|
||||
{Name: dbSecrets, MountPath: certTempMountPath},
|
||||
{Name: "client-test", MountPath: certMountPath + "/client_test"},
|
||||
}
|
||||
|
||||
equals := corev1.Container{
|
||||
Name: "fix-permissions",
|
||||
Image: "alpine:3.11",
|
||||
Command: []string{"/bin/sh", "-c"},
|
||||
Args: []string{strings.Join(initCommands, " && ")},
|
||||
VolumeMounts: initVolumeMounts,
|
||||
}
|
||||
|
||||
init := GetInitContainer(rootSecret, dbSecrets, users, RunAsUser)
|
||||
|
||||
assert.Equal(t, equals, init)
|
||||
}
|
||||
|
||||
func TestDeployment_GetInitContainer1(t *testing.T) {
|
||||
users := []string{"test1"}
|
||||
|
||||
initCommands := []string{
|
||||
"cp /dbsecrets/client_root/ca.crt /tmp/dbsecrets/ca.crt",
|
||||
"cp /dbsecrets/client_test1/client.test1.crt /tmp/dbsecrets/client.test1.crt",
|
||||
"cp /dbsecrets/client_test1/client.test1.key /tmp/dbsecrets/client.test1.key",
|
||||
"chown -R 1000:1000 /tmp/dbsecrets",
|
||||
"chmod 0600 /tmp/dbsecrets/*",
|
||||
}
|
||||
|
||||
initVolumeMounts := []corev1.VolumeMount{
|
||||
{Name: rootSecret, MountPath: certMountPath + "/client_root"},
|
||||
{Name: dbSecrets, MountPath: certTempMountPath},
|
||||
{Name: "client-test1", MountPath: certMountPath + "/client_test1"},
|
||||
}
|
||||
|
||||
equals := corev1.Container{
|
||||
Name: "fix-permissions",
|
||||
Image: "alpine:3.11",
|
||||
Command: []string{"/bin/sh", "-c"},
|
||||
Args: []string{strings.Join(initCommands, " && ")},
|
||||
VolumeMounts: initVolumeMounts,
|
||||
}
|
||||
|
||||
init := GetInitContainer(rootSecret, dbSecrets, users, RunAsUser)
|
||||
|
||||
assert.Equal(t, equals, init)
|
||||
}
|
||||
|
||||
func TestDeployment_GetInitContainer2(t *testing.T) {
|
||||
users := []string{"test1", "test2"}
|
||||
|
||||
initCommands := []string{
|
||||
"cp /dbsecrets/client_root/ca.crt /tmp/dbsecrets/ca.crt",
|
||||
"cp /dbsecrets/client_test1/client.test1.crt /tmp/dbsecrets/client.test1.crt",
|
||||
"cp /dbsecrets/client_test1/client.test1.key /tmp/dbsecrets/client.test1.key",
|
||||
"cp /dbsecrets/client_test2/client.test2.crt /tmp/dbsecrets/client.test2.crt",
|
||||
"cp /dbsecrets/client_test2/client.test2.key /tmp/dbsecrets/client.test2.key",
|
||||
"chown -R 1000:1000 /tmp/dbsecrets",
|
||||
"chmod 0600 /tmp/dbsecrets/*",
|
||||
}
|
||||
|
||||
initVolumeMounts := []corev1.VolumeMount{
|
||||
{Name: rootSecret, MountPath: certMountPath + "/client_root"},
|
||||
{Name: dbSecrets, MountPath: certTempMountPath},
|
||||
{Name: "client-test1", MountPath: certMountPath + "/client_test1"},
|
||||
{Name: "client-test2", MountPath: certMountPath + "/client_test2"},
|
||||
}
|
||||
|
||||
equals := corev1.Container{
|
||||
Name: "fix-permissions",
|
||||
Image: "alpine:3.11",
|
||||
Command: []string{"/bin/sh", "-c"},
|
||||
Args: []string{strings.Join(initCommands, " && ")},
|
||||
VolumeMounts: initVolumeMounts,
|
||||
}
|
||||
|
||||
init := GetInitContainer(rootSecret, dbSecrets, users, RunAsUser)
|
||||
|
||||
assert.Equal(t, equals, init)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func GetReadyFunc(monitor mntr.Monitor, namespace string, name *labels.Name) operator.EnsureFunc {
|
||||
return func(k8sClient kubernetes.ClientInt) error {
|
||||
monitor.Info("waiting for deployment to be ready")
|
||||
if err := k8sClient.WaitUntilDeploymentReady(namespace, name.Name(), true, true, 60); err != nil {
|
||||
monitor.Error(errors.Wrap(err, "error while waiting for deployment to be ready"))
|
||||
return err
|
||||
}
|
||||
monitor.Info("deployment is ready")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/caos/orbos/pkg/labels/mocklabels"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDeployment_Ready1(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
|
||||
client.EXPECT().WaitUntilDeploymentReady(namespace, mocklabels.NameVal, true, true, timeout).Times(1).Return(nil)
|
||||
readyFunc := GetReadyFunc(monitor, namespace, mocklabels.Name)
|
||||
assert.NotNil(t, readyFunc)
|
||||
assert.NoError(t, readyFunc(client))
|
||||
}
|
||||
|
||||
func TestDeployment_Ready2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test2"
|
||||
|
||||
client.EXPECT().WaitUntilDeploymentReady(namespace, mocklabels.NameVal, true, true, timeout).Times(1).Return(nil)
|
||||
readyFunc := GetReadyFunc(monitor, namespace, mocklabels.Name)
|
||||
assert.NotNil(t, readyFunc)
|
||||
assert.NoError(t, readyFunc(client))
|
||||
}
|
||||
|
||||
func TestDeployment_ReadyFailure1(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
|
||||
client.EXPECT().WaitUntilDeploymentReady(namespace, mocklabels.NameVal, true, true, timeout).Times(1).Return(errors.New("fail"))
|
||||
readyFunc := GetReadyFunc(monitor, namespace, mocklabels.Name)
|
||||
assert.NotNil(t, readyFunc)
|
||||
assert.Error(t, readyFunc(client))
|
||||
}
|
||||
|
||||
func TestDeployment_ReadyFailure2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test2"
|
||||
|
||||
client.EXPECT().WaitUntilDeploymentReady(namespace, mocklabels.NameVal, true, true, timeout).Times(1).Return(errors.New("fail"))
|
||||
readyFunc := GetReadyFunc(monitor, namespace, mocklabels.Name)
|
||||
assert.NotNil(t, readyFunc)
|
||||
assert.Error(t, readyFunc(client))
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/pkg/kubernetes/k8s"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
)
|
||||
|
||||
func GetResourcesFromDefault(resources *k8s.Resources) *k8s.Resources {
|
||||
ret := resources
|
||||
if ret == nil {
|
||||
ret = &k8s.Resources{
|
||||
Limits: corev1.ResourceList{
|
||||
corev1.ResourceCPU: resource.MustParse("2"),
|
||||
corev1.ResourceMemory: resource.MustParse("2Gi"),
|
||||
},
|
||||
Requests: corev1.ResourceList{
|
||||
corev1.ResourceCPU: resource.MustParse("500m"),
|
||||
corev1.ResourceMemory: resource.MustParse("512Mi"),
|
||||
},
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/pkg/kubernetes/k8s"
|
||||
"github.com/stretchr/testify/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDeployment_ResourcesDefault1(t *testing.T) {
|
||||
test := &k8s.Resources{
|
||||
Limits: corev1.ResourceList{
|
||||
corev1.ResourceCPU: resource.MustParse("1"),
|
||||
corev1.ResourceMemory: resource.MustParse("1Gi"),
|
||||
},
|
||||
Requests: corev1.ResourceList{
|
||||
corev1.ResourceCPU: resource.MustParse("100m"),
|
||||
corev1.ResourceMemory: resource.MustParse("128Mi"),
|
||||
},
|
||||
}
|
||||
|
||||
resources := GetResourcesFromDefault(test)
|
||||
assert.Equal(t, resources, test)
|
||||
}
|
||||
|
||||
func TestDeployment_ResourcesDefault2(t *testing.T) {
|
||||
test := &k8s.Resources{
|
||||
Limits: corev1.ResourceList{
|
||||
corev1.ResourceCPU: resource.MustParse("2"),
|
||||
corev1.ResourceMemory: resource.MustParse("2Gi"),
|
||||
},
|
||||
Requests: corev1.ResourceList{
|
||||
corev1.ResourceCPU: resource.MustParse("500m"),
|
||||
corev1.ResourceMemory: resource.MustParse("512Mi"),
|
||||
},
|
||||
}
|
||||
|
||||
resources := GetResourcesFromDefault(nil)
|
||||
assert.Equal(t, resources, test)
|
||||
}
|
||||
|
||||
func TestDeployment_ResourcesDefault3(t *testing.T) {
|
||||
test := &k8s.Resources{
|
||||
Limits: corev1.ResourceList{
|
||||
corev1.ResourceCPU: resource.MustParse("2"),
|
||||
corev1.ResourceMemory: resource.MustParse("1Gi"),
|
||||
},
|
||||
Requests: corev1.ResourceList{
|
||||
corev1.ResourceCPU: resource.MustParse("200m"),
|
||||
corev1.ResourceMemory: resource.MustParse("256Mi"),
|
||||
},
|
||||
}
|
||||
|
||||
resources := GetResourcesFromDefault(test)
|
||||
assert.Equal(t, resources, test)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/zitadel/operator"
|
||||
)
|
||||
|
||||
func GetScaleFunc(monitor mntr.Monitor, namespace string, name *labels.Name) func(replicaCount int) operator.EnsureFunc {
|
||||
return func(replicaCount int) operator.EnsureFunc {
|
||||
return func(k8sClient kubernetes.ClientInt) error {
|
||||
monitor.Info("Scaling deployment")
|
||||
return k8sClient.ScaleDeployment(namespace, name.Name(), replicaCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/caos/orbos/pkg/labels/mocklabels"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDeployment_Scale1(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
replicaCount := 1
|
||||
|
||||
client.EXPECT().ScaleDeployment(namespace, mocklabels.NameVal, replicaCount).Times(1).Return(nil)
|
||||
scaleFunc := GetScaleFunc(monitor, namespace, mocklabels.Name)
|
||||
assert.NotNil(t, scaleFunc)
|
||||
ensure := scaleFunc(replicaCount)
|
||||
assert.NotNil(t, ensure)
|
||||
assert.NoError(t, ensure(client))
|
||||
}
|
||||
|
||||
func TestDeployment_Scale2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
replicaCount := 0
|
||||
|
||||
client.EXPECT().ScaleDeployment(namespace, mocklabels.NameVal, replicaCount).Times(1).Return(nil)
|
||||
scaleFunc := GetScaleFunc(monitor, namespace, mocklabels.Name)
|
||||
assert.NotNil(t, scaleFunc)
|
||||
ensure := scaleFunc(replicaCount)
|
||||
assert.NotNil(t, ensure)
|
||||
assert.NoError(t, ensure(client))
|
||||
}
|
||||
|
||||
func TestDeployment_Scale3(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
replicaCount := 3
|
||||
|
||||
client.EXPECT().ScaleDeployment(namespace, mocklabels.NameVal, replicaCount).Times(1).Return(nil)
|
||||
scaleFunc := GetScaleFunc(monitor, namespace, mocklabels.Name)
|
||||
assert.NotNil(t, scaleFunc)
|
||||
ensure := scaleFunc(replicaCount)
|
||||
assert.NotNil(t, ensure)
|
||||
assert.NoError(t, ensure(client))
|
||||
}
|
||||
|
||||
func TestDeployment_ScaleFailure1(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
replicaCount := 0
|
||||
|
||||
client.EXPECT().ScaleDeployment(namespace, mocklabels.NameVal, replicaCount).Times(1).Return(errors.New("fail"))
|
||||
scaleFunc := GetScaleFunc(monitor, namespace, mocklabels.Name)
|
||||
assert.NotNil(t, scaleFunc)
|
||||
ensure := scaleFunc(replicaCount)
|
||||
assert.NotNil(t, ensure)
|
||||
assert.Error(t, ensure(client))
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/operator/helpers"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetVolumes(
|
||||
secretName string,
|
||||
secretPasswordsName string,
|
||||
consoleCMName string,
|
||||
users []string,
|
||||
) []corev1.Volume {
|
||||
volumes := []corev1.Volume{{
|
||||
Name: secretName,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: secretName,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Name: rootSecret,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: "cockroachdb.client.root",
|
||||
DefaultMode: helpers.PointerInt32(384),
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Name: secretPasswordsName,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: secretPasswordsName,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Name: consoleCMName,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
ConfigMap: &corev1.ConfigMapVolumeSource{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: consoleCMName},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Name: dbSecrets,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
EmptyDir: &corev1.EmptyDirVolumeSource{},
|
||||
},
|
||||
}}
|
||||
|
||||
return append(volumes, userVolumes(users)...)
|
||||
}
|
||||
|
||||
func userVolumes(
|
||||
users []string,
|
||||
) []corev1.Volume {
|
||||
volumes := make([]corev1.Volume, 0)
|
||||
|
||||
for _, user := range users {
|
||||
userReplaced := strings.ReplaceAll(user, "_", "-")
|
||||
internalName := "client-" + userReplaced
|
||||
volumes = append(volumes, corev1.Volume{
|
||||
Name: internalName,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: "cockroachdb.client." + userReplaced,
|
||||
DefaultMode: helpers.PointerInt32(384),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
return volumes
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/operator/helpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDeployment_Volumes(t *testing.T) {
|
||||
secretName := "testSecret"
|
||||
secretPasswordsName := "testPasswords"
|
||||
consoleCMName := "testCM"
|
||||
users := []string{"test"}
|
||||
|
||||
equals := []corev1.Volume{{
|
||||
Name: secretName,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: secretName,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Name: rootSecret,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: "cockroachdb.client.root",
|
||||
DefaultMode: helpers.PointerInt32(384),
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Name: secretPasswordsName,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: secretPasswordsName,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Name: consoleCMName,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
ConfigMap: &corev1.ConfigMapVolumeSource{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: consoleCMName},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Name: dbSecrets,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
EmptyDir: &corev1.EmptyDirVolumeSource{},
|
||||
},
|
||||
}, {Name: "client-test",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: "cockroachdb.client.test",
|
||||
DefaultMode: helpers.PointerInt32(384),
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
assert.ElementsMatch(t, equals, GetVolumes(secretName, secretPasswordsName, consoleCMName, users))
|
||||
|
||||
}
|
||||
|
||||
func TestDeployment_UserVolumes(t *testing.T) {
|
||||
users := []string{"test"}
|
||||
equals := []corev1.Volume{
|
||||
{Name: "client-test",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: "cockroachdb.client.test",
|
||||
DefaultMode: helpers.PointerInt32(384),
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
assert.ElementsMatch(t, equals, userVolumes(users))
|
||||
|
||||
users = []string{"te_st"}
|
||||
equals = []corev1.Volume{
|
||||
{Name: "client-te-st",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: "cockroachdb.client.te-st",
|
||||
DefaultMode: helpers.PointerInt32(384),
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
assert.ElementsMatch(t, equals, userVolumes(users))
|
||||
|
||||
users = []string{"test", "te-st"}
|
||||
equals = []corev1.Volume{
|
||||
{Name: "client-test",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: "cockroachdb.client.test",
|
||||
DefaultMode: helpers.PointerInt32(384),
|
||||
},
|
||||
},
|
||||
}, {Name: "client-te-st",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: "cockroachdb.client.te-st",
|
||||
DefaultMode: helpers.PointerInt32(384),
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
assert.ElementsMatch(t, equals, userVolumes(users))
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package zitadel
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/pkg/kubernetes/k8s"
|
||||
"github.com/caos/orbos/pkg/tree"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/configuration"
|
||||
"github.com/pkg/errors"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
type DesiredV0 struct {
|
||||
Common *tree.Common `yaml:",inline"`
|
||||
Spec *Spec
|
||||
}
|
||||
|
||||
type Spec struct {
|
||||
Verbose bool
|
||||
Force bool
|
||||
ReplicaCount int `yaml:"replicaCount,omitempty"`
|
||||
Configuration *configuration.Configuration `yaml:"configuration"`
|
||||
NodeSelector map[string]string `yaml:"nodeSelector,omitempty"`
|
||||
Tolerations []corev1.Toleration `yaml:"tolerations,omitempty"`
|
||||
Affinity *k8s.Affinity `yaml:"affinity,omitempty"`
|
||||
Resources *k8s.Resources `yaml:"resources,omitempty"`
|
||||
}
|
||||
|
||||
func parseDesiredV0(desiredTree *tree.Tree) (*DesiredV0, error) {
|
||||
desiredKind := &DesiredV0{
|
||||
Common: desiredTree.Common,
|
||||
Spec: &Spec{},
|
||||
}
|
||||
|
||||
if err := desiredTree.Original.Decode(desiredKind); err != nil {
|
||||
return nil, errors.Wrap(err, "parsing desired state failed")
|
||||
}
|
||||
|
||||
return desiredKind, nil
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package zitadel
|
||||
|
||||
/*
|
||||
func getLabels() map[string]string {
|
||||
return map[string]string{
|
||||
"app.kubernetes.io/managed-by": "zitadel.caos.ch",
|
||||
"app.kubernetes.io/part-of": "zitadel",
|
||||
"app.kubernetes.io/component": "iam",
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,241 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"crypto/sha512"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rakyll/statik/fs"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/kubernetes/resources/configmap"
|
||||
"github.com/caos/orbos/pkg/kubernetes/resources/job"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/operator/helpers"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
_ "github.com/caos/zitadel/statik"
|
||||
)
|
||||
|
||||
const (
|
||||
migrationConfigmap = "migrate-db"
|
||||
migrationsPath = "/migrate"
|
||||
rootUserInternal = "root"
|
||||
rootUserPath = "/certificates"
|
||||
envMigrationUser = "FLYWAY_USER"
|
||||
envMigrationPW = "FLYWAY_PASSWORD"
|
||||
jobNamePrefix = "cockroachdb-cluster-migration-"
|
||||
createFile = "create.sql"
|
||||
grantFile = "grant.sql"
|
||||
deleteFile = "delete.sql"
|
||||
)
|
||||
|
||||
func AdaptFunc(
|
||||
monitor mntr.Monitor,
|
||||
componentLabels *labels.Component,
|
||||
namespace string,
|
||||
reason string,
|
||||
secretPasswordName string,
|
||||
migrationUser string,
|
||||
users []string,
|
||||
nodeselector map[string]string,
|
||||
tolerations []corev1.Toleration,
|
||||
) (
|
||||
operator.QueryFunc,
|
||||
operator.DestroyFunc,
|
||||
error,
|
||||
) {
|
||||
internalMonitor := monitor.WithField("type", "migration")
|
||||
jobName := getJobName(reason)
|
||||
|
||||
destroyCM, err := configmap.AdaptFuncToDestroy(namespace, migrationConfigmap)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyJ, err := job.AdaptFuncToDestroy(jobName, namespace)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyers := []operator.DestroyFunc{
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyJ),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyCM),
|
||||
}
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (operator.EnsureFunc, error) {
|
||||
dbCurrent, err := database.GetDatabaseInQueried(queried)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dbHost := dbCurrent.Host
|
||||
dbPort := dbCurrent.Port
|
||||
|
||||
allScripts := getMigrationFiles(monitor, "/cockroach/")
|
||||
|
||||
nameLabels := labels.MustForNameK8SMap(componentLabels, jobName)
|
||||
jobDef := &batchv1.Job{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: jobName,
|
||||
Namespace: namespace,
|
||||
Labels: nameLabels,
|
||||
Annotations: map[string]string{
|
||||
"migrationhash": getHash(allScripts),
|
||||
},
|
||||
},
|
||||
Spec: batchv1.JobSpec{
|
||||
Completions: helpers.PointerInt32(1),
|
||||
Template: corev1.PodTemplateSpec{
|
||||
Spec: corev1.PodSpec{
|
||||
NodeSelector: nodeselector,
|
||||
Tolerations: tolerations,
|
||||
SecurityContext: &corev1.PodSecurityContext{},
|
||||
InitContainers: getPreContainer(dbHost, dbPort, migrationUser, secretPasswordName),
|
||||
Containers: []corev1.Container{
|
||||
getMigrationContainer(dbHost, dbPort, migrationUser, secretPasswordName, users),
|
||||
},
|
||||
RestartPolicy: "Never",
|
||||
DNSPolicy: "ClusterFirst",
|
||||
SchedulerName: "default-scheduler",
|
||||
TerminationGracePeriodSeconds: helpers.PointerInt64(30),
|
||||
Volumes: []corev1.Volume{{
|
||||
Name: migrationConfigmap,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
ConfigMap: &corev1.ConfigMapVolumeSource{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: migrationConfigmap},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Name: rootUserInternal,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: "cockroachdb.client.root",
|
||||
DefaultMode: helpers.PointerInt32(0400),
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Name: secretPasswordName,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: secretPasswordName,
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
allScriptsMap := make(map[string]string)
|
||||
for _, script := range allScripts {
|
||||
allScriptsMap[script.Filename] = script.Data
|
||||
}
|
||||
queryCM, err := configmap.AdaptFuncToEnsure(namespace, migrationConfigmap, labels.MustForNameK8SMap(componentLabels, migrationConfigmap), allScriptsMap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
queryJ, err := job.AdaptFuncToEnsure(jobDef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queriers := []operator.QueryFunc{
|
||||
operator.ResourceQueryToZitadelQuery(queryCM),
|
||||
operator.ResourceQueryToZitadelQuery(queryJ),
|
||||
}
|
||||
return operator.QueriersToEnsureFunc(internalMonitor, true, queriers, k8sClient, queried)
|
||||
},
|
||||
operator.DestroyersToDestroyFunc(internalMonitor, destroyers),
|
||||
nil
|
||||
}
|
||||
|
||||
func baseEnvVars(envMigrationUser, envMigrationPW, migrationUser, userPasswordsSecret string) []corev1.EnvVar {
|
||||
envVars := []corev1.EnvVar{
|
||||
{
|
||||
Name: envMigrationUser,
|
||||
Value: migrationUser,
|
||||
}, {
|
||||
Name: envMigrationPW,
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: userPasswordsSecret},
|
||||
Key: migrationUser,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return envVars
|
||||
}
|
||||
|
||||
func getHash(dataMap []migration) string {
|
||||
data, err := json.Marshal(dataMap)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
h := sha512.New()
|
||||
return base64.URLEncoding.EncodeToString(h.Sum(data))
|
||||
}
|
||||
|
||||
type migration struct {
|
||||
Filename string
|
||||
Data string
|
||||
}
|
||||
|
||||
const migrationFileRegex = `(V|U)(\.|\d)+(__)(\w|\_|\ )+(\.sql)`
|
||||
|
||||
func getMigrationFiles(monitor mntr.Monitor, root string) []migration {
|
||||
migrations := make([]migration, 0)
|
||||
files := []string{}
|
||||
/*
|
||||
absPath, err := filepath.Abs(root)
|
||||
if err != nil {
|
||||
return migrations
|
||||
}*/
|
||||
|
||||
statikFS, err := fs.New()
|
||||
if err != nil {
|
||||
monitor.Error(errors.Wrap(err, "failed to load migration files"))
|
||||
return migrations
|
||||
}
|
||||
err = fs.Walk(statikFS, root, func(path string, info os.FileInfo, err error) error {
|
||||
matched, err := regexp.MatchString(migrationFileRegex, info.Name())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.IsDir() && matched {
|
||||
files = append(files, info.Name())
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
sort.Strings(files)
|
||||
|
||||
for _, file := range files {
|
||||
|
||||
fullName := filepath.Join(root, file)
|
||||
|
||||
data, err := fs.ReadFile(statikFS, fullName)
|
||||
if err != nil || data == nil || len(data) == 0 {
|
||||
continue
|
||||
}
|
||||
migrations = append(migrations, migration{file, string(data)})
|
||||
}
|
||||
|
||||
return migrations
|
||||
}
|
||||
|
||||
func getJobName(reason string) string {
|
||||
return jobNamePrefix + reason
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
|
||||
"github.com/caos/orbos/pkg/labels/mocklabels"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/caos/zitadel/operator/helpers"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
macherrs "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
func TestMigration_BaseEnvVars(t *testing.T) {
|
||||
envMigrationUser := "envmigration"
|
||||
migrationUser := "migration"
|
||||
envMigrationPW := "migration"
|
||||
userPasswordsSecret := "passwords"
|
||||
|
||||
equals := []corev1.EnvVar{
|
||||
{
|
||||
Name: envMigrationUser,
|
||||
Value: migrationUser,
|
||||
}, {
|
||||
Name: envMigrationPW,
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: userPasswordsSecret},
|
||||
Key: migrationUser,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
envVars := baseEnvVars(envMigrationUser, envMigrationPW, migrationUser, userPasswordsSecret)
|
||||
assert.ElementsMatch(t, envVars, equals)
|
||||
}
|
||||
|
||||
func TestMigration_GetMigrationFiles(t *testing.T) {
|
||||
equals := []migration{
|
||||
{
|
||||
Filename: "V1.1__test.sql",
|
||||
Data: "test",
|
||||
},
|
||||
|
||||
{
|
||||
Filename: "V1.2__test2.sql",
|
||||
Data: "test2",
|
||||
},
|
||||
}
|
||||
|
||||
files := getMigrationFiles(mntr.Monitor{}, "/testfiles/")
|
||||
assert.ElementsMatch(t, equals, files)
|
||||
}
|
||||
|
||||
func TestMigration_AdaptFunc(t *testing.T) {
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
reason := "test"
|
||||
secretPasswordName := "test"
|
||||
migrationUser := "migration"
|
||||
users := []string{"test"}
|
||||
nodeselector := map[string]string{"test": "test"}
|
||||
tolerations := []corev1.Toleration{}
|
||||
dbHost := "test"
|
||||
dbPort := "test"
|
||||
|
||||
allScripts := getMigrationFiles(mntr.Monitor{}, "/cockroach/")
|
||||
|
||||
componentLabels := mocklabels.Component
|
||||
jobName := labels.MustForName(componentLabels, jobNamePrefix+reason)
|
||||
|
||||
jobDef := &batchv1.Job{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: jobName.Name(),
|
||||
Namespace: namespace,
|
||||
Labels: labels.MustK8sMap(jobName),
|
||||
Annotations: map[string]string{
|
||||
"migrationhash": getHash(allScripts),
|
||||
},
|
||||
},
|
||||
Spec: batchv1.JobSpec{
|
||||
Completions: helpers.PointerInt32(1),
|
||||
Template: corev1.PodTemplateSpec{
|
||||
Spec: corev1.PodSpec{
|
||||
NodeSelector: nodeselector,
|
||||
Tolerations: tolerations,
|
||||
SecurityContext: &corev1.PodSecurityContext{},
|
||||
InitContainers: getPreContainer(dbHost, dbPort, migrationUser, secretPasswordName),
|
||||
Containers: []corev1.Container{
|
||||
getMigrationContainer(dbHost, dbPort, migrationUser, secretPasswordName, users),
|
||||
},
|
||||
RestartPolicy: "Never",
|
||||
DNSPolicy: "ClusterFirst",
|
||||
SchedulerName: "default-scheduler",
|
||||
TerminationGracePeriodSeconds: helpers.PointerInt64(30),
|
||||
Volumes: []corev1.Volume{{
|
||||
Name: migrationConfigmap,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
ConfigMap: &corev1.ConfigMapVolumeSource{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: migrationConfigmap},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Name: rootUserInternal,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: "cockroachdb.client.root",
|
||||
DefaultMode: helpers.PointerInt32(0400),
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Name: secretPasswordName,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: secretPasswordName,
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
allScriptsMap := make(map[string]string)
|
||||
for _, script := range allScripts {
|
||||
allScriptsMap[script.Filename] = script.Data
|
||||
}
|
||||
|
||||
cmName := labels.MustForName(componentLabels, migrationConfigmap)
|
||||
cm := &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: cmName.Name(),
|
||||
Namespace: namespace,
|
||||
Labels: labels.MustK8sMap(cmName),
|
||||
},
|
||||
Data: allScriptsMap,
|
||||
}
|
||||
client.EXPECT().ApplyJob(jobDef).Times(1)
|
||||
client.EXPECT().GetJob(namespace, getJobName(reason)).Times(1).Return(nil, macherrs.NewNotFound(schema.GroupResource{"batch", "jobs"}, jobNamePrefix+reason))
|
||||
client.EXPECT().ApplyConfigmap(cm).Times(1)
|
||||
|
||||
query, _, err := AdaptFunc(
|
||||
mntr.Monitor{},
|
||||
componentLabels,
|
||||
namespace,
|
||||
reason,
|
||||
secretPasswordName,
|
||||
migrationUser,
|
||||
users,
|
||||
nodeselector,
|
||||
tolerations,
|
||||
)
|
||||
|
||||
queried := map[string]interface{}{}
|
||||
database.SetDatabaseInQueried(queried, &database.Current{
|
||||
Host: dbHost,
|
||||
Port: dbPort,
|
||||
})
|
||||
|
||||
assert.NoError(t, err)
|
||||
ensure, err := query(client, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, ensure(client))
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func GetCleanupFunc(
|
||||
monitor mntr.Monitor,
|
||||
namespace string,
|
||||
reason string,
|
||||
) operator.EnsureFunc {
|
||||
return func(k8sClient kubernetes.ClientInt) error {
|
||||
monitor.Info("cleanup migration job")
|
||||
if err := k8sClient.DeleteJob(namespace, getJobName(reason)); err != nil {
|
||||
monitor.Error(errors.Wrap(err, "error during job deletion"))
|
||||
return err
|
||||
}
|
||||
monitor.Info("migration cleanup is completed")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMigration_Cleanup1(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
reason := "test"
|
||||
|
||||
client.EXPECT().DeleteJob(namespace, getJobName(reason)).Times(1).Return(nil)
|
||||
cleanupFunc := GetCleanupFunc(monitor, namespace, reason)
|
||||
assert.NotNil(t, cleanupFunc)
|
||||
assert.NoError(t, cleanupFunc(client))
|
||||
}
|
||||
|
||||
func TestMigration_Cleanup2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test2"
|
||||
reason := "test2"
|
||||
|
||||
client.EXPECT().DeleteJob(namespace, getJobName(reason)).Times(1).Return(nil)
|
||||
cleanupFunc := GetCleanupFunc(monitor, namespace, reason)
|
||||
assert.NotNil(t, cleanupFunc)
|
||||
assert.NoError(t, cleanupFunc(client))
|
||||
}
|
||||
|
||||
func TestMigration_CleanupFailure1(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
reason := "test"
|
||||
|
||||
client.EXPECT().DeleteJob(namespace, getJobName(reason)).Times(1).Return(errors.New("failed"))
|
||||
cleanupFunc := GetCleanupFunc(monitor, namespace, reason)
|
||||
assert.NotNil(t, cleanupFunc)
|
||||
assert.Error(t, cleanupFunc(client))
|
||||
}
|
||||
|
||||
func TestMigration_CleanupFailure2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test2"
|
||||
reason := "test2"
|
||||
|
||||
client.EXPECT().DeleteJob(namespace, getJobName(reason)).Times(1).Return(errors.New("failed"))
|
||||
cleanupFunc := GetCleanupFunc(monitor, namespace, reason)
|
||||
assert.NotNil(t, cleanupFunc)
|
||||
assert.Error(t, cleanupFunc(client))
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
timeout = 20 * time.Minute
|
||||
)
|
||||
|
||||
func GetDoneFunc(
|
||||
monitor mntr.Monitor,
|
||||
namespace string,
|
||||
reason string,
|
||||
) operator.EnsureFunc {
|
||||
return func(k8sClient kubernetes.ClientInt) error {
|
||||
monitor.Info("waiting for migration to be completed")
|
||||
if err := k8sClient.WaitUntilJobCompleted(namespace, getJobName(reason), timeout); err != nil {
|
||||
monitor.Error(errors.Wrap(err, "error while waiting for migration to be completed"))
|
||||
return err
|
||||
}
|
||||
monitor.Info("migration is completed")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMigration_Done1(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
reason := "test"
|
||||
|
||||
client.EXPECT().WaitUntilJobCompleted(namespace, getJobName(reason), timeout).Times(1).Return(nil)
|
||||
cleanupFunc := GetDoneFunc(monitor, namespace, reason)
|
||||
assert.NotNil(t, cleanupFunc)
|
||||
assert.NoError(t, cleanupFunc(client))
|
||||
}
|
||||
|
||||
func TestMigration_Done2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test2"
|
||||
reason := "test2"
|
||||
|
||||
client.EXPECT().WaitUntilJobCompleted(namespace, getJobName(reason), timeout).Times(1).Return(nil)
|
||||
cleanupFunc := GetDoneFunc(monitor, namespace, reason)
|
||||
assert.NotNil(t, cleanupFunc)
|
||||
assert.NoError(t, cleanupFunc(client))
|
||||
}
|
||||
|
||||
func TestMigration_DoneFailure1(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
reason := "test"
|
||||
|
||||
client.EXPECT().WaitUntilJobCompleted(namespace, getJobName(reason), timeout).Times(1).Return(errors.New("failed"))
|
||||
doneFunc := GetDoneFunc(monitor, namespace, reason)
|
||||
assert.NotNil(t, doneFunc)
|
||||
assert.Error(t, doneFunc(client))
|
||||
}
|
||||
|
||||
func TestMigration_DoneFailure2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test2"
|
||||
reason := "test2"
|
||||
|
||||
client.EXPECT().WaitUntilJobCompleted(namespace, getJobName(reason), timeout).Times(1).Return(errors.New("failed"))
|
||||
doneFunc := GetDoneFunc(monitor, namespace, reason)
|
||||
assert.NotNil(t, doneFunc)
|
||||
assert.Error(t, doneFunc(client))
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
func getMigrationContainer(
|
||||
dbHost string,
|
||||
dbPort string,
|
||||
migrationUser string,
|
||||
secretPasswordName string,
|
||||
users []string,
|
||||
) corev1.Container {
|
||||
return corev1.Container{
|
||||
Name: "db-migration",
|
||||
Image: "flyway/flyway:7.5.1",
|
||||
Args: []string{
|
||||
"-url=jdbc:postgresql://" + dbHost + ":" + dbPort + "/defaultdb?&sslmode=verify-full&ssl=true&sslrootcert=" + rootUserPath + "/ca.crt&sslfactory=org.postgresql.ssl.NonValidatingFactory",
|
||||
"-locations=filesystem:" + migrationsPath,
|
||||
"migrate",
|
||||
},
|
||||
Env: migrationEnvVars(envMigrationUser, envMigrationPW, migrationUser, secretPasswordName, users),
|
||||
VolumeMounts: []corev1.VolumeMount{{
|
||||
Name: migrationConfigmap,
|
||||
MountPath: migrationsPath,
|
||||
}, {
|
||||
Name: rootUserInternal,
|
||||
MountPath: rootUserPath,
|
||||
}},
|
||||
TerminationMessagePath: corev1.TerminationMessagePathDefault,
|
||||
TerminationMessagePolicy: "File",
|
||||
ImagePullPolicy: "IfNotPresent",
|
||||
}
|
||||
}
|
||||
|
||||
func migrationEnvVars(envMigrationUser, envMigrationPW, migrationUser, userPasswordsSecret string, users []string) []corev1.EnvVar {
|
||||
envVars := baseEnvVars(envMigrationUser, envMigrationPW, migrationUser, userPasswordsSecret)
|
||||
|
||||
migrationEnvVars := make([]corev1.EnvVar, 0)
|
||||
for _, v := range envVars {
|
||||
migrationEnvVars = append(migrationEnvVars, v)
|
||||
}
|
||||
for _, user := range users {
|
||||
migrationEnvVars = append(migrationEnvVars, corev1.EnvVar{
|
||||
Name: "FLYWAY_PLACEHOLDERS_" + strings.ToUpper(user) + "PASSWORD",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: userPasswordsSecret},
|
||||
Key: user,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
return migrationEnvVars
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMigration_MigrationsEnvVars(t *testing.T) {
|
||||
|
||||
envMigrationUser := "envmigration"
|
||||
migrationUser := "migration"
|
||||
envMigrationPW := "migration"
|
||||
userPasswordsSecret := "passwords"
|
||||
user1 := "test"
|
||||
users := []string{}
|
||||
|
||||
baseEnv := baseEnvVars(envMigrationUser, envMigrationPW, migrationUser, userPasswordsSecret)
|
||||
|
||||
equals := make([]corev1.EnvVar, 0)
|
||||
for _, v := range baseEnv {
|
||||
equals = append(equals, v)
|
||||
}
|
||||
|
||||
envVars := migrationEnvVars(envMigrationUser, envMigrationPW, migrationUser, userPasswordsSecret, users)
|
||||
assert.ElementsMatch(t, envVars, equals)
|
||||
|
||||
users = []string{user1}
|
||||
equals = make([]corev1.EnvVar, 0)
|
||||
for _, v := range baseEnv {
|
||||
equals = append(equals, v)
|
||||
}
|
||||
equals = append(equals, corev1.EnvVar{
|
||||
Name: "FLYWAY_PLACEHOLDERS_" + strings.ToUpper(user1) + "PASSWORD",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: userPasswordsSecret},
|
||||
Key: user1,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
envVars = migrationEnvVars(envMigrationUser, envMigrationPW, migrationUser, userPasswordsSecret, users)
|
||||
assert.ElementsMatch(t, envVars, equals)
|
||||
|
||||
user2 := "test2"
|
||||
users = []string{user1, user2}
|
||||
|
||||
equals = make([]corev1.EnvVar, 0)
|
||||
for _, v := range baseEnv {
|
||||
equals = append(equals, v)
|
||||
}
|
||||
equals = append(equals, corev1.EnvVar{
|
||||
Name: "FLYWAY_PLACEHOLDERS_" + strings.ToUpper(user1) + "PASSWORD",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: userPasswordsSecret},
|
||||
Key: user1,
|
||||
},
|
||||
},
|
||||
})
|
||||
equals = append(equals, corev1.EnvVar{
|
||||
Name: "FLYWAY_PLACEHOLDERS_" + strings.ToUpper(user2) + "PASSWORD",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: userPasswordsSecret},
|
||||
Key: user2,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
envVars = migrationEnvVars(envMigrationUser, envMigrationPW, migrationUser, userPasswordsSecret, users)
|
||||
assert.ElementsMatch(t, envVars, equals)
|
||||
|
||||
user3 := "test3"
|
||||
users = []string{user1, user2, user3}
|
||||
|
||||
equals = make([]corev1.EnvVar, 0)
|
||||
for _, v := range baseEnv {
|
||||
equals = append(equals, v)
|
||||
}
|
||||
equals = append(equals, corev1.EnvVar{
|
||||
Name: "FLYWAY_PLACEHOLDERS_" + strings.ToUpper(user1) + "PASSWORD",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: userPasswordsSecret},
|
||||
Key: user1,
|
||||
},
|
||||
},
|
||||
})
|
||||
equals = append(equals, corev1.EnvVar{
|
||||
Name: "FLYWAY_PLACEHOLDERS_" + strings.ToUpper(user2) + "PASSWORD",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: userPasswordsSecret},
|
||||
Key: user2,
|
||||
},
|
||||
},
|
||||
})
|
||||
equals = append(equals, corev1.EnvVar{
|
||||
Name: "FLYWAY_PLACEHOLDERS_" + strings.ToUpper(user3) + "PASSWORD",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{Name: userPasswordsSecret},
|
||||
Key: user3,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
envVars = migrationEnvVars(envMigrationUser, envMigrationPW, migrationUser, userPasswordsSecret, users)
|
||||
assert.ElementsMatch(t, envVars, equals)
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func getPostContainers(
|
||||
dbHost string,
|
||||
dbPort string,
|
||||
migrationUser string,
|
||||
secretPasswordName string,
|
||||
) []corev1.Container {
|
||||
return []corev1.Container{
|
||||
{
|
||||
Name: "delete-flyway-user",
|
||||
Image: "cockroachdb/cockroach:v20.2.3",
|
||||
Command: []string{"/bin/bash", "-c", "--"},
|
||||
Args: []string{
|
||||
strings.Join([]string{
|
||||
deleteUserCommand(envMigrationUser, deleteFile),
|
||||
"cockroach.sh sql --certs-dir=/certificates --host=" + dbHost + ":" + dbPort + " -e \"$(cat " + deleteFile + ")\";",
|
||||
}, ";"),
|
||||
},
|
||||
Env: baseEnvVars(envMigrationUser, envMigrationPW, migrationUser, secretPasswordName),
|
||||
VolumeMounts: []corev1.VolumeMount{{
|
||||
Name: rootUserInternal,
|
||||
MountPath: rootUserPath,
|
||||
}},
|
||||
TerminationMessagePath: corev1.TerminationMessagePathDefault,
|
||||
TerminationMessagePolicy: "File",
|
||||
ImagePullPolicy: "IfNotPresent",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func deleteUserCommand(user, file string) string {
|
||||
return strings.Join([]string{
|
||||
"echo -n 'DROP USER IF EXISTS ' > " + file,
|
||||
"echo -n ${" + user + "} >> " + file,
|
||||
"echo -n ';' >> " + file,
|
||||
}, ";")
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMigration_DropUserCommand(t *testing.T) {
|
||||
user := "test"
|
||||
file := "test"
|
||||
equals := strings.Join([]string{
|
||||
"echo -n 'DROP USER IF EXISTS ' > " + file,
|
||||
"echo -n ${" + user + "} >> " + file,
|
||||
"echo -n ';' >> " + file,
|
||||
}, ";")
|
||||
|
||||
cmd := deleteUserCommand(user, file)
|
||||
assert.Equal(t, cmd, equals)
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func getPreContainer(
|
||||
dbHost string,
|
||||
dbPort string,
|
||||
migrationUser string,
|
||||
secretPasswordName string,
|
||||
) []corev1.Container {
|
||||
return []corev1.Container{
|
||||
{
|
||||
Name: "check-db-ready",
|
||||
Image: "postgres:9.6.17",
|
||||
Command: []string{
|
||||
"sh",
|
||||
"-c",
|
||||
"until pg_isready -h " + dbHost + " -p " + dbPort + "; do echo waiting for database; sleep 2; done;",
|
||||
},
|
||||
TerminationMessagePath: corev1.TerminationMessagePathDefault,
|
||||
TerminationMessagePolicy: "File",
|
||||
ImagePullPolicy: "IfNotPresent",
|
||||
},
|
||||
{
|
||||
Name: "create-flyway-user",
|
||||
Image: "cockroachdb/cockroach:v20.2.3",
|
||||
Env: baseEnvVars(envMigrationUser, envMigrationPW, migrationUser, secretPasswordName),
|
||||
VolumeMounts: []corev1.VolumeMount{{
|
||||
Name: rootUserInternal,
|
||||
MountPath: rootUserPath,
|
||||
}},
|
||||
Command: []string{"/bin/bash", "-c", "--"},
|
||||
Args: []string{
|
||||
strings.Join([]string{
|
||||
createUserCommand(envMigrationUser, envMigrationPW, createFile),
|
||||
grantUserCommand(envMigrationUser, grantFile),
|
||||
"cockroach.sh sql --certs-dir=/certificates --host=" + dbHost + ":" + dbPort + " -e \"$(cat " + createFile + ")\" -e \"$(cat " + grantFile + ")\";",
|
||||
},
|
||||
";"),
|
||||
},
|
||||
TerminationMessagePath: corev1.TerminationMessagePathDefault,
|
||||
TerminationMessagePolicy: "File",
|
||||
ImagePullPolicy: "IfNotPresent",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func createUserCommand(user, pw, file string) string {
|
||||
if user == "" || file == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
createUser := strings.Join([]string{
|
||||
"echo -n 'CREATE USER IF NOT EXISTS ' > " + file,
|
||||
"echo -n ${" + user + "} >> " + file,
|
||||
"echo -n ';' >> " + file,
|
||||
}, ";")
|
||||
|
||||
if pw != "" {
|
||||
createUser = strings.Join([]string{
|
||||
createUser,
|
||||
"echo -n 'ALTER USER ' >> " + file,
|
||||
"echo -n ${" + user + "} >> " + file,
|
||||
"echo -n ' WITH PASSWORD ' >> " + file,
|
||||
"echo -n ${" + pw + "} >> " + file,
|
||||
"echo -n ';' >> " + file,
|
||||
}, ";")
|
||||
}
|
||||
|
||||
return createUser
|
||||
}
|
||||
|
||||
func grantUserCommand(user, file string) string {
|
||||
return strings.Join([]string{
|
||||
"echo -n 'GRANT admin TO ' > " + file,
|
||||
"echo -n ${" + user + "} >> " + file,
|
||||
"echo -n ' WITH ADMIN OPTION;' >> " + file,
|
||||
}, ";")
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMigration_CreateUserCommand(t *testing.T) {
|
||||
user := "test"
|
||||
pw := "test"
|
||||
file := "test"
|
||||
equals := "echo -n 'CREATE USER IF NOT EXISTS ' > " + file + ";echo -n ${" + user + "} >> " + file + ";echo -n ';' >> " + file + ";echo -n 'ALTER USER ' >> " + file + ";echo -n ${" + user + "} >> " + file + ";echo -n ' WITH PASSWORD ' >> " + file + ";echo -n ${" + pw + "} >> " + file + ";echo -n ';' >> " + file
|
||||
|
||||
cmd := createUserCommand(user, pw, file)
|
||||
assert.Equal(t, cmd, equals)
|
||||
|
||||
user = "test1"
|
||||
pw = "test1"
|
||||
file = "test1"
|
||||
equals = "echo -n 'CREATE USER IF NOT EXISTS ' > " + file + ";echo -n ${" + user + "} >> " + file + ";echo -n ';' >> " + file + ";echo -n 'ALTER USER ' >> " + file + ";echo -n ${" + user + "} >> " + file + ";echo -n ' WITH PASSWORD ' >> " + file + ";echo -n ${" + pw + "} >> " + file + ";echo -n ';' >> " + file
|
||||
|
||||
cmd = createUserCommand(user, pw, file)
|
||||
assert.Equal(t, cmd, equals)
|
||||
|
||||
user = "test2"
|
||||
pw = "test2"
|
||||
file = "test2"
|
||||
equals = "echo -n 'CREATE USER IF NOT EXISTS ' > " + file + ";echo -n ${" + user + "} >> " + file + ";echo -n ';' >> " + file + ";echo -n 'ALTER USER ' >> " + file + ";echo -n ${" + user + "} >> " + file + ";echo -n ' WITH PASSWORD ' >> " + file + ";echo -n ${" + pw + "} >> " + file + ";echo -n ';' >> " + file
|
||||
|
||||
cmd = createUserCommand(user, pw, file)
|
||||
assert.Equal(t, cmd, equals)
|
||||
|
||||
user = "test"
|
||||
pw = ""
|
||||
file = "test"
|
||||
equals = "echo -n 'CREATE USER IF NOT EXISTS ' > " + file + ";echo -n ${" + user + "} >> " + file + ";echo -n ';' >> " + file
|
||||
|
||||
cmd = createUserCommand(user, pw, file)
|
||||
assert.Equal(t, cmd, equals)
|
||||
|
||||
user = "test2"
|
||||
pw = ""
|
||||
file = "test2"
|
||||
equals = "echo -n 'CREATE USER IF NOT EXISTS ' > " + file + ";echo -n ${" + user + "} >> " + file + ";echo -n ';' >> " + file
|
||||
|
||||
cmd = createUserCommand(user, pw, file)
|
||||
assert.Equal(t, cmd, equals)
|
||||
|
||||
user = "test2"
|
||||
pw = ""
|
||||
file = ""
|
||||
|
||||
cmd = createUserCommand(user, pw, file)
|
||||
assert.Equal(t, cmd, "")
|
||||
|
||||
user = ""
|
||||
pw = ""
|
||||
file = "test"
|
||||
|
||||
cmd = createUserCommand(user, pw, file)
|
||||
assert.Equal(t, cmd, "")
|
||||
|
||||
}
|
||||
|
||||
func TestMigration_GrantUserCommand(t *testing.T) {
|
||||
user := "test"
|
||||
file := "test"
|
||||
equals := strings.Join([]string{
|
||||
"echo -n 'GRANT admin TO ' > " + file,
|
||||
"echo -n ${" + user + "} >> " + file,
|
||||
"echo -n ' WITH ADMIN OPTION;' >> " + file,
|
||||
}, ";")
|
||||
|
||||
cmd := grantUserCommand(user, file)
|
||||
assert.Equal(t, cmd, equals)
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package zitadel
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/pkg/secret"
|
||||
)
|
||||
|
||||
func getSecretsMap(desiredKind *DesiredV0) map[string]*secret.Secret {
|
||||
secrets := map[string]*secret.Secret{}
|
||||
|
||||
if desiredKind.Spec != nil && desiredKind.Spec.Configuration != nil {
|
||||
conf := desiredKind.Spec.Configuration
|
||||
if conf.Tracing != nil {
|
||||
if conf.Tracing.ServiceAccountJSON == nil {
|
||||
conf.Tracing.ServiceAccountJSON = &secret.Secret{}
|
||||
}
|
||||
secrets["tracingserviceaccountjson"] = conf.Tracing.ServiceAccountJSON
|
||||
}
|
||||
|
||||
if conf.Secrets != nil {
|
||||
if conf.Secrets.Keys == nil {
|
||||
conf.Secrets.Keys = &secret.Secret{}
|
||||
}
|
||||
secrets["keys"] = conf.Secrets.Keys
|
||||
}
|
||||
|
||||
if conf.Notifications != nil {
|
||||
if conf.Notifications.GoogleChatURL == nil {
|
||||
conf.Notifications.GoogleChatURL = &secret.Secret{}
|
||||
}
|
||||
secrets["googlechaturl"] = conf.Notifications.GoogleChatURL
|
||||
|
||||
if conf.Notifications.Twilio.SID == nil {
|
||||
conf.Notifications.Twilio.SID = &secret.Secret{}
|
||||
}
|
||||
secrets["twiliosid"] = conf.Notifications.Twilio.SID
|
||||
|
||||
if conf.Notifications.Twilio.AuthToken == nil {
|
||||
conf.Notifications.Twilio.AuthToken = &secret.Secret{}
|
||||
}
|
||||
secrets["twilioauthtoken"] = conf.Notifications.Twilio.AuthToken
|
||||
|
||||
if conf.Notifications.Email.AppKey == nil {
|
||||
conf.Notifications.Email.AppKey = &secret.Secret{}
|
||||
}
|
||||
secrets["emailappkey"] = conf.Notifications.Email.AppKey
|
||||
}
|
||||
}
|
||||
return secrets
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/kubernetes/resources/service"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/zitadel/operator"
|
||||
)
|
||||
|
||||
func AdaptFunc(
|
||||
monitor mntr.Monitor,
|
||||
componentLabels *labels.Component,
|
||||
zitadelPodSelector *labels.Selector,
|
||||
namespace string,
|
||||
grpcServiceName string,
|
||||
grpcPort uint16,
|
||||
httpServiceName string,
|
||||
httpPort uint16,
|
||||
uiServiceName string,
|
||||
uiPort uint16,
|
||||
) (
|
||||
operator.QueryFunc,
|
||||
operator.DestroyFunc,
|
||||
error,
|
||||
) {
|
||||
internalMonitor := monitor.WithField("component", "services")
|
||||
|
||||
destroyGRPC, err := service.AdaptFuncToDestroy(namespace, grpcServiceName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyHTTP, err := service.AdaptFuncToDestroy(namespace, httpServiceName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyUI, err := service.AdaptFuncToDestroy(namespace, uiServiceName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyers := []operator.DestroyFunc{
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyGRPC),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyHTTP),
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyUI),
|
||||
}
|
||||
|
||||
grpcPorts := []service.Port{
|
||||
{Name: "grpc", Port: grpcPort, TargetPort: "grpc"},
|
||||
}
|
||||
queryGRPC, err := service.AdaptFuncToEnsure(namespace, labels.MustForName(componentLabels, grpcServiceName), grpcPorts, "", zitadelPodSelector, false, "", "")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
httpPorts := []service.Port{
|
||||
{Name: "http", Port: httpPort, TargetPort: "http"},
|
||||
}
|
||||
queryHTTP, err := service.AdaptFuncToEnsure(namespace, labels.AsSelectable(labels.MustForName(componentLabels, httpServiceName)), httpPorts, "", zitadelPodSelector, false, "", "")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
uiPorts := []service.Port{
|
||||
{Name: "ui", Port: uiPort, TargetPort: "ui"},
|
||||
}
|
||||
queryUI, err := service.AdaptFuncToEnsure(namespace, labels.MustForName(componentLabels, uiServiceName), uiPorts, "", zitadelPodSelector, false, "", "")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
queriers := []operator.QueryFunc{
|
||||
operator.ResourceQueryToZitadelQuery(queryGRPC),
|
||||
operator.ResourceQueryToZitadelQuery(queryHTTP),
|
||||
operator.ResourceQueryToZitadelQuery(queryUI),
|
||||
}
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (operator.EnsureFunc, error) {
|
||||
return operator.QueriersToEnsureFunc(internalMonitor, false, queriers, k8sClient, queried)
|
||||
},
|
||||
operator.DestroyersToDestroyFunc(internalMonitor, destroyers),
|
||||
|
||||
nil
|
||||
}
|
||||
@@ -0,0 +1,406 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/orbos/pkg/labels/mocklabels"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/golang/mock/gomock"
|
||||
"gotest.tools/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
)
|
||||
|
||||
func GetExpectedService(
|
||||
namespace string,
|
||||
zitadelPodSelector *labels.Selector,
|
||||
grpcPortName string,
|
||||
grpcServiceName *labels.Name,
|
||||
grpcPort uint16,
|
||||
httpPortName string,
|
||||
httpServiceName *labels.Name,
|
||||
httpPort uint16,
|
||||
uiPortName string,
|
||||
uiServiceName *labels.Name,
|
||||
uiPort uint16,
|
||||
) []*corev1.Service {
|
||||
|
||||
grpcPorts := []corev1.ServicePort{{
|
||||
Name: grpcPortName,
|
||||
Protocol: "",
|
||||
Port: int32(grpcPort),
|
||||
TargetPort: intstr.Parse(grpcPortName),
|
||||
NodePort: int32(0),
|
||||
},
|
||||
}
|
||||
|
||||
httpPorts := []corev1.ServicePort{{
|
||||
Name: httpPortName,
|
||||
Protocol: "",
|
||||
Port: int32(httpPort),
|
||||
TargetPort: intstr.Parse(httpPortName),
|
||||
NodePort: int32(0),
|
||||
},
|
||||
}
|
||||
|
||||
uiPorts := []corev1.ServicePort{{
|
||||
Name: uiPortName,
|
||||
Protocol: "",
|
||||
Port: int32(uiPort),
|
||||
TargetPort: intstr.Parse(uiPortName),
|
||||
NodePort: int32(0),
|
||||
},
|
||||
}
|
||||
|
||||
zitadelPodSelectorMap := labels.MustK8sMap(zitadelPodSelector)
|
||||
|
||||
return []*corev1.Service{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: grpcServiceName.Name(),
|
||||
Namespace: namespace,
|
||||
Labels: labels.MustK8sMap(grpcServiceName),
|
||||
},
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: grpcPorts,
|
||||
Selector: zitadelPodSelectorMap,
|
||||
Type: "",
|
||||
PublishNotReadyAddresses: false,
|
||||
ClusterIP: "",
|
||||
ExternalName: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: httpServiceName.Name(),
|
||||
Namespace: namespace,
|
||||
Labels: labels.MustK8sMap(labels.AsSelectable(httpServiceName)),
|
||||
},
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: httpPorts,
|
||||
Selector: zitadelPodSelectorMap,
|
||||
Type: "",
|
||||
PublishNotReadyAddresses: false,
|
||||
ClusterIP: "",
|
||||
ExternalName: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: uiServiceName.Name(),
|
||||
Namespace: namespace,
|
||||
Labels: labels.MustK8sMap(uiServiceName),
|
||||
},
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: uiPorts,
|
||||
Selector: zitadelPodSelectorMap,
|
||||
Type: "",
|
||||
PublishNotReadyAddresses: false,
|
||||
ClusterIP: "",
|
||||
ExternalName: "",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func serviceLabels(name ...string) (*labels.Component, *labels.Selector, []*labels.Name) {
|
||||
componentLabels := mocklabels.Component
|
||||
podSelectorLabels := labels.DeriveNameSelector(labels.MustForName(componentLabels, "zitadel"), false)
|
||||
nameLabels := make([]*labels.Name, len(name))
|
||||
for idx := range name {
|
||||
nameLabels[idx] = labels.MustForName(componentLabels, name[idx])
|
||||
}
|
||||
return componentLabels, podSelectorLabels, nameLabels
|
||||
}
|
||||
|
||||
func TestServices_AdaptEnsure1(t *testing.T) {
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
namespace := "test"
|
||||
grpcPortName := "grpc"
|
||||
grpcServiceName := "grpc"
|
||||
httpPortName := "http"
|
||||
httpServiceName := "http"
|
||||
uiPortName := "ui"
|
||||
uiServiceName := "ui"
|
||||
var grpcPort, httpPort, uiPort uint16 = 1, 2, 3
|
||||
|
||||
componentLabels, podSelectorLabels, nameLabels := serviceLabels(grpcServiceName, httpServiceName, uiServiceName)
|
||||
|
||||
for _, rsc := range GetExpectedService(
|
||||
namespace,
|
||||
podSelectorLabels,
|
||||
grpcPortName,
|
||||
nameLabels[0],
|
||||
grpcPort,
|
||||
httpPortName,
|
||||
nameLabels[1],
|
||||
httpPort,
|
||||
uiPortName,
|
||||
nameLabels[2],
|
||||
uiPort,
|
||||
) {
|
||||
client.EXPECT().ApplyService(rsc).Times(1)
|
||||
}
|
||||
|
||||
query, _, err := AdaptFunc(
|
||||
mntr.Monitor{},
|
||||
componentLabels,
|
||||
podSelectorLabels,
|
||||
namespace,
|
||||
grpcServiceName,
|
||||
grpcPort,
|
||||
httpServiceName,
|
||||
httpPort,
|
||||
uiServiceName,
|
||||
uiPort,
|
||||
)
|
||||
|
||||
assert.NilError(t, err)
|
||||
ensure, err := query(client, nil)
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(t, ensure(client))
|
||||
}
|
||||
|
||||
func TestServices_AdaptEnsure2(t *testing.T) {
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
namespace := "test0"
|
||||
grpcPortName := "grpc"
|
||||
grpcServiceName := "grpc1"
|
||||
httpPortName := "http"
|
||||
httpServiceName := "http2"
|
||||
uiPortName := "ui"
|
||||
uiServiceName := "ui3"
|
||||
var grpcPort, httpPort, uiPort uint16 = 11, 22, 33
|
||||
|
||||
componentLabels, podSelectorLabels, nameLabels := serviceLabels(grpcServiceName, httpServiceName, uiServiceName)
|
||||
|
||||
for _, rsc := range GetExpectedService(
|
||||
namespace,
|
||||
podSelectorLabels,
|
||||
grpcPortName,
|
||||
nameLabels[0],
|
||||
grpcPort,
|
||||
httpPortName,
|
||||
nameLabels[1],
|
||||
httpPort,
|
||||
uiPortName,
|
||||
nameLabels[2],
|
||||
uiPort,
|
||||
) {
|
||||
|
||||
client.EXPECT().ApplyService(rsc).Times(1)
|
||||
}
|
||||
|
||||
query, _, err := AdaptFunc(
|
||||
mntr.Monitor{},
|
||||
componentLabels,
|
||||
podSelectorLabels,
|
||||
namespace,
|
||||
grpcServiceName,
|
||||
grpcPort,
|
||||
httpServiceName,
|
||||
httpPort,
|
||||
uiServiceName,
|
||||
uiPort)
|
||||
|
||||
assert.NilError(t, err)
|
||||
ensure, err := query(client, nil)
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(t, ensure(client))
|
||||
}
|
||||
|
||||
func TestServices_AdaptEnsure3(t *testing.T) {
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
namespace := "test00"
|
||||
grpcPortName := "grpc"
|
||||
grpcServiceName := "grpc11"
|
||||
httpPortName := "http"
|
||||
httpServiceName := "http22"
|
||||
uiPortName := "ui"
|
||||
uiServiceName := "ui33"
|
||||
var grpcPort, httpPort, uiPort uint16 = 111, 222, 333
|
||||
|
||||
componentLabels, podSelectorLabels, nameLabels := serviceLabels(grpcServiceName, httpServiceName, uiServiceName)
|
||||
|
||||
for _, rsc := range GetExpectedService(
|
||||
namespace,
|
||||
podSelectorLabels,
|
||||
grpcPortName,
|
||||
nameLabels[0],
|
||||
grpcPort,
|
||||
httpPortName,
|
||||
nameLabels[1],
|
||||
httpPort,
|
||||
uiPortName,
|
||||
nameLabels[2],
|
||||
uiPort,
|
||||
) {
|
||||
|
||||
client.EXPECT().ApplyService(rsc).Times(1)
|
||||
}
|
||||
|
||||
query, _, err := AdaptFunc(
|
||||
mntr.Monitor{},
|
||||
componentLabels,
|
||||
podSelectorLabels,
|
||||
namespace,
|
||||
grpcServiceName,
|
||||
grpcPort,
|
||||
httpServiceName,
|
||||
httpPort,
|
||||
uiServiceName,
|
||||
uiPort)
|
||||
|
||||
assert.NilError(t, err)
|
||||
ensure, err := query(client, nil)
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(t, ensure(client))
|
||||
}
|
||||
|
||||
func TestServices_AdaptDestroy1(t *testing.T) {
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
namespace := "test"
|
||||
grpcPortName := "grpc"
|
||||
grpcServiceName := "grpc"
|
||||
httpPortName := "http"
|
||||
httpServiceName := "http"
|
||||
uiPortName := "ui"
|
||||
uiServiceName := "ui"
|
||||
var grpcPort, httpPort, uiPort uint16 = 1, 2, 3
|
||||
|
||||
componentLabels, podSelectorLabels, nameLabels := serviceLabels(grpcServiceName, httpServiceName, uiServiceName)
|
||||
|
||||
for _, rsc := range GetExpectedService(
|
||||
namespace,
|
||||
podSelectorLabels,
|
||||
grpcPortName,
|
||||
nameLabels[0],
|
||||
grpcPort,
|
||||
httpPortName,
|
||||
nameLabels[1],
|
||||
httpPort,
|
||||
uiPortName,
|
||||
nameLabels[2],
|
||||
uiPort,
|
||||
) {
|
||||
|
||||
client.EXPECT().DeleteService(rsc.Namespace, rsc.Name).Times(1)
|
||||
}
|
||||
|
||||
_, destroy, err := AdaptFunc(
|
||||
mntr.Monitor{},
|
||||
componentLabels,
|
||||
podSelectorLabels,
|
||||
namespace,
|
||||
grpcServiceName,
|
||||
grpcPort,
|
||||
httpServiceName,
|
||||
httpPort,
|
||||
uiServiceName,
|
||||
uiPort)
|
||||
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(t, destroy(client))
|
||||
}
|
||||
|
||||
func TestServices_AdaptDestroy2(t *testing.T) {
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
namespace := "test0"
|
||||
grpcPortName := "grpc"
|
||||
grpcServiceName := "grpc1"
|
||||
httpPortName := "http"
|
||||
httpServiceName := "http2"
|
||||
uiPortName := "ui"
|
||||
uiServiceName := "ui3"
|
||||
var grpcPort, httpPort, uiPort uint16 = 11, 22, 33
|
||||
|
||||
componentLabels, podSelectorLabels, nameLabels := serviceLabels(grpcServiceName, httpServiceName, uiServiceName)
|
||||
|
||||
for _, rsc := range GetExpectedService(
|
||||
namespace,
|
||||
podSelectorLabels,
|
||||
grpcPortName,
|
||||
nameLabels[0],
|
||||
grpcPort,
|
||||
httpPortName,
|
||||
nameLabels[1],
|
||||
httpPort,
|
||||
uiPortName,
|
||||
nameLabels[2],
|
||||
uiPort,
|
||||
) {
|
||||
|
||||
client.EXPECT().DeleteService(rsc.Namespace, rsc.Name).Times(1)
|
||||
}
|
||||
|
||||
_, destroy, err := AdaptFunc(
|
||||
mntr.Monitor{},
|
||||
componentLabels,
|
||||
podSelectorLabels,
|
||||
namespace,
|
||||
grpcServiceName,
|
||||
grpcPort,
|
||||
httpServiceName,
|
||||
httpPort,
|
||||
uiServiceName,
|
||||
uiPort)
|
||||
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(t, destroy(client))
|
||||
}
|
||||
|
||||
func TestServices_AdaptDestroy3(t *testing.T) {
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
|
||||
namespace := "test00"
|
||||
grpcPortName := "grpc"
|
||||
grpcServiceName := "grpc11"
|
||||
httpPortName := "http"
|
||||
httpServiceName := "http22"
|
||||
uiPortName := "ui"
|
||||
uiServiceName := "ui33"
|
||||
var grpcPort, httpPort, uiPort uint16 = 111, 222, 333
|
||||
|
||||
componentLabels, podSelectorLabels, nameLabels := serviceLabels(grpcServiceName, httpServiceName, uiServiceName)
|
||||
|
||||
for _, rsc := range GetExpectedService(
|
||||
namespace,
|
||||
podSelectorLabels,
|
||||
grpcPortName,
|
||||
nameLabels[0],
|
||||
grpcPort,
|
||||
httpPortName,
|
||||
nameLabels[1],
|
||||
httpPort,
|
||||
uiPortName,
|
||||
nameLabels[2],
|
||||
uiPort,
|
||||
) {
|
||||
|
||||
client.EXPECT().DeleteService(rsc.Namespace, rsc.Name).Times(1)
|
||||
}
|
||||
|
||||
_, destroy, err := AdaptFunc(
|
||||
mntr.Monitor{},
|
||||
componentLabels,
|
||||
podSelectorLabels,
|
||||
namespace,
|
||||
grpcServiceName,
|
||||
grpcPort,
|
||||
httpServiceName,
|
||||
httpPort,
|
||||
uiServiceName,
|
||||
uiPort)
|
||||
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(t, destroy(client))
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetClientIDFunc(
|
||||
namespace string,
|
||||
httpServiceName string,
|
||||
httpPort uint16,
|
||||
) func() string {
|
||||
return func() string {
|
||||
resp, err := http.Get("http://" + httpServiceName + "." + namespace + ":" + strconv.Itoa(int(httpPort)) + "/clientID")
|
||||
if err != nil || resp.StatusCode >= 400 {
|
||||
return ""
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSuffix(strings.TrimPrefix(string(body), "\""), "\"")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/kubernetes/k8s"
|
||||
"github.com/caos/orbos/pkg/kubernetes/resources/job"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/operator/helpers"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/deployment"
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
jobNamePrefix = "zitadel-setup-"
|
||||
containerName = "zitadel"
|
||||
rootSecret = "client-root"
|
||||
dbSecrets = "db-secrets"
|
||||
timeout time.Duration = 300
|
||||
)
|
||||
|
||||
func AdaptFunc(
|
||||
monitor mntr.Monitor,
|
||||
componentLabels *labels.Component,
|
||||
namespace string,
|
||||
reason string,
|
||||
nodeselector map[string]string,
|
||||
tolerations []corev1.Toleration,
|
||||
resources *k8s.Resources,
|
||||
version *string,
|
||||
cmName string,
|
||||
certPath string,
|
||||
secretName string,
|
||||
secretPath string,
|
||||
consoleCMName string,
|
||||
secretVarsName string,
|
||||
secretPasswordsName string,
|
||||
users []string,
|
||||
migrationDone operator.EnsureFunc,
|
||||
configurationDone operator.EnsureFunc,
|
||||
getConfigurationHashes func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) map[string]string,
|
||||
) (
|
||||
operator.QueryFunc,
|
||||
operator.DestroyFunc,
|
||||
error,
|
||||
) {
|
||||
internalMonitor := monitor.WithField("component", "setup")
|
||||
|
||||
jobName := getJobName(reason)
|
||||
nameLabels := labels.MustForName(componentLabels, jobName)
|
||||
|
||||
destroyJ, err := job.AdaptFuncToDestroy(jobName, namespace)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
destroyers := []operator.DestroyFunc{
|
||||
operator.ResourceDestroyToZitadelDestroy(destroyJ),
|
||||
}
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) (operator.EnsureFunc, error) {
|
||||
|
||||
jobDef := jobDef(
|
||||
nameLabels,
|
||||
users,
|
||||
version,
|
||||
resources,
|
||||
cmName,
|
||||
certPath,
|
||||
secretName,
|
||||
secretPath,
|
||||
consoleCMName,
|
||||
secretVarsName,
|
||||
secretPasswordsName,
|
||||
namespace,
|
||||
componentLabels,
|
||||
nodeselector,
|
||||
tolerations,
|
||||
)
|
||||
|
||||
hashes := getConfigurationHashes(k8sClient, queried)
|
||||
if hashes != nil && len(hashes) != 0 {
|
||||
for k, v := range hashes {
|
||||
jobDef.Annotations[k] = v
|
||||
jobDef.Spec.Template.Annotations[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
query, err := job.AdaptFuncToEnsure(jobDef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queriers := []operator.QueryFunc{
|
||||
operator.EnsureFuncToQueryFunc(migrationDone),
|
||||
operator.EnsureFuncToQueryFunc(configurationDone),
|
||||
operator.ResourceQueryToZitadelQuery(query),
|
||||
}
|
||||
|
||||
return operator.QueriersToEnsureFunc(internalMonitor, false, queriers, k8sClient, queried)
|
||||
},
|
||||
operator.DestroyersToDestroyFunc(internalMonitor, destroyers),
|
||||
nil
|
||||
}
|
||||
|
||||
func jobDef(name *labels.Name, users []string, version *string, resources *k8s.Resources, cmName string, certPath string, secretName string, secretPath string, consoleCMName string, secretVarsName string, secretPasswordsName string, namespace string, componentLabels *labels.Component, nodeselector map[string]string, tolerations []corev1.Toleration) *batchv1.Job {
|
||||
initContainers := []corev1.Container{
|
||||
deployment.GetInitContainer(
|
||||
rootSecret,
|
||||
dbSecrets,
|
||||
users,
|
||||
deployment.RunAsUser,
|
||||
)}
|
||||
|
||||
containers := []corev1.Container{
|
||||
deployment.GetContainer(
|
||||
containerName,
|
||||
*version,
|
||||
deployment.RunAsUser,
|
||||
true,
|
||||
deployment.GetResourcesFromDefault(resources),
|
||||
cmName,
|
||||
certPath,
|
||||
secretName,
|
||||
secretPath,
|
||||
consoleCMName,
|
||||
secretVarsName,
|
||||
secretPasswordsName,
|
||||
users,
|
||||
dbSecrets,
|
||||
"setup",
|
||||
)}
|
||||
|
||||
volumes := deployment.GetVolumes(secretName, secretPasswordsName, consoleCMName, users)
|
||||
|
||||
return &batchv1.Job{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name.Name(),
|
||||
Namespace: namespace,
|
||||
Labels: labels.MustK8sMap(name),
|
||||
Annotations: map[string]string{},
|
||||
},
|
||||
Spec: batchv1.JobSpec{
|
||||
Completions: helpers.PointerInt32(1),
|
||||
Template: corev1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{},
|
||||
},
|
||||
Spec: corev1.PodSpec{
|
||||
NodeSelector: nodeselector,
|
||||
Tolerations: tolerations,
|
||||
InitContainers: initContainers,
|
||||
Containers: containers,
|
||||
SecurityContext: &corev1.PodSecurityContext{},
|
||||
|
||||
RestartPolicy: "Never",
|
||||
DNSPolicy: "ClusterFirst",
|
||||
SchedulerName: "default-scheduler",
|
||||
TerminationGracePeriodSeconds: helpers.PointerInt64(30),
|
||||
Volumes: volumes,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func getJobName(reason string) string {
|
||||
return jobNamePrefix + reason
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/kubernetes/k8s"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/caos/orbos/pkg/labels"
|
||||
"github.com/caos/orbos/pkg/labels/mocklabels"
|
||||
"github.com/caos/zitadel/operator/helpers"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/database"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/deployment"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
macherrs "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
func TestSetup_AdaptFunc(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
reason := "test"
|
||||
users := []string{"test"}
|
||||
nodeselector := map[string]string{"test": "test"}
|
||||
tolerations := []corev1.Toleration{}
|
||||
dbHost := "test"
|
||||
dbPort := "test"
|
||||
|
||||
version := "test"
|
||||
secretVarsName := "testVars"
|
||||
secretPasswordsName := "testPasswords"
|
||||
secretPath := "testSecretPath"
|
||||
certPath := "testCert"
|
||||
secretName := "testSecret"
|
||||
consoleCMName := "testConsoleCM"
|
||||
cmName := "testCM"
|
||||
annotations := map[string]string{"testHash": "test"}
|
||||
|
||||
componentLabels := mocklabels.Component
|
||||
|
||||
resources := &k8s.Resources{
|
||||
Limits: corev1.ResourceList{
|
||||
corev1.ResourceCPU: resource.MustParse("2"),
|
||||
corev1.ResourceMemory: resource.MustParse("2Gi"),
|
||||
},
|
||||
Requests: corev1.ResourceList{
|
||||
corev1.ResourceCPU: resource.MustParse("500m"),
|
||||
corev1.ResourceMemory: resource.MustParse("512Mi"),
|
||||
},
|
||||
}
|
||||
|
||||
initContainers := []corev1.Container{deployment.GetInitContainer(rootSecret, dbSecrets, users, deployment.RunAsUser)}
|
||||
containers := []corev1.Container{deployment.GetContainer(
|
||||
containerName,
|
||||
version,
|
||||
deployment.RunAsUser,
|
||||
true,
|
||||
resources,
|
||||
cmName,
|
||||
certPath,
|
||||
secretName,
|
||||
secretPath,
|
||||
consoleCMName,
|
||||
secretVarsName,
|
||||
secretPasswordsName,
|
||||
users,
|
||||
dbSecrets,
|
||||
"setup",
|
||||
)}
|
||||
volumes := deployment.GetVolumes(secretName, secretPasswordsName, consoleCMName, users)
|
||||
|
||||
jobName := labels.MustForName(componentLabels, jobNamePrefix+reason)
|
||||
jobDef := &batchv1.Job{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: jobName.Name(),
|
||||
Namespace: namespace,
|
||||
Labels: labels.MustK8sMap(jobName),
|
||||
Annotations: annotations,
|
||||
},
|
||||
Spec: batchv1.JobSpec{
|
||||
Completions: helpers.PointerInt32(1),
|
||||
Template: corev1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: annotations,
|
||||
},
|
||||
Spec: corev1.PodSpec{
|
||||
NodeSelector: nodeselector,
|
||||
Tolerations: tolerations,
|
||||
InitContainers: initContainers,
|
||||
Containers: containers,
|
||||
SecurityContext: &corev1.PodSecurityContext{},
|
||||
|
||||
RestartPolicy: "Never",
|
||||
DNSPolicy: "ClusterFirst",
|
||||
SchedulerName: "default-scheduler",
|
||||
TerminationGracePeriodSeconds: helpers.PointerInt64(30),
|
||||
Volumes: volumes,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
client.EXPECT().ApplyJob(jobDef).Times(1)
|
||||
client.EXPECT().GetJob(namespace, getJobName(reason)).Times(1).Return(nil, macherrs.NewNotFound(schema.GroupResource{"batch", "jobs"}, jobNamePrefix+reason))
|
||||
|
||||
getConfigurationHashes := func(k8sClient kubernetes.ClientInt, queried map[string]interface{}) map[string]string {
|
||||
return map[string]string{"testHash": "test"}
|
||||
}
|
||||
migrationDone := func(k8sClient kubernetes.ClientInt) error {
|
||||
return nil
|
||||
}
|
||||
configurationDone := func(k8sClient kubernetes.ClientInt) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
query, _, err := AdaptFunc(
|
||||
monitor,
|
||||
componentLabels,
|
||||
namespace,
|
||||
reason,
|
||||
nodeselector,
|
||||
tolerations,
|
||||
resources,
|
||||
&version,
|
||||
cmName,
|
||||
certPath,
|
||||
secretName,
|
||||
secretPath,
|
||||
consoleCMName,
|
||||
secretVarsName,
|
||||
secretPasswordsName,
|
||||
users,
|
||||
migrationDone,
|
||||
configurationDone,
|
||||
getConfigurationHashes,
|
||||
)
|
||||
|
||||
queried := map[string]interface{}{}
|
||||
database.SetDatabaseInQueried(queried, &database.Current{
|
||||
Host: dbHost,
|
||||
Port: dbPort,
|
||||
})
|
||||
|
||||
assert.NoError(t, err)
|
||||
ensure, err := query(client, queried)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, ensure(client))
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func GetDoneFunc(
|
||||
monitor mntr.Monitor,
|
||||
namespace string,
|
||||
reason string,
|
||||
) operator.EnsureFunc {
|
||||
return func(k8sClient kubernetes.ClientInt) error {
|
||||
monitor.Info("waiting for setup to be completed")
|
||||
if err := k8sClient.WaitUntilJobCompleted(namespace, getJobName(reason), timeout); err != nil {
|
||||
monitor.Error(errors.Wrap(err, "error while waiting for setup to be completed"))
|
||||
return err
|
||||
}
|
||||
monitor.Info("migration is completed")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetesmock "github.com/caos/orbos/pkg/kubernetes/mock"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSetup_Done1(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
reason := "test"
|
||||
|
||||
client.EXPECT().WaitUntilJobCompleted(namespace, getJobName(reason), timeout).Times(1).Return(nil)
|
||||
cleanupFunc := GetDoneFunc(monitor, namespace, reason)
|
||||
assert.NotNil(t, cleanupFunc)
|
||||
assert.NoError(t, cleanupFunc(client))
|
||||
}
|
||||
|
||||
func TestSetup_Done2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test2"
|
||||
reason := "test2"
|
||||
|
||||
client.EXPECT().WaitUntilJobCompleted(namespace, getJobName(reason), timeout).Times(1).Return(nil)
|
||||
cleanupFunc := GetDoneFunc(monitor, namespace, reason)
|
||||
assert.NotNil(t, cleanupFunc)
|
||||
assert.NoError(t, cleanupFunc(client))
|
||||
}
|
||||
|
||||
func TestSetup_DoneFailure1(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test"
|
||||
reason := "test"
|
||||
|
||||
client.EXPECT().WaitUntilJobCompleted(namespace, getJobName(reason), timeout).Times(1).Return(errors.New("failed"))
|
||||
doneFunc := GetDoneFunc(monitor, namespace, reason)
|
||||
assert.NotNil(t, doneFunc)
|
||||
assert.Error(t, doneFunc(client))
|
||||
}
|
||||
|
||||
func TestSetup_DoneFailure2(t *testing.T) {
|
||||
monitor := mntr.Monitor{}
|
||||
client := kubernetesmock.NewMockClientInt(gomock.NewController(t))
|
||||
namespace := "test2"
|
||||
reason := "test2"
|
||||
|
||||
client.EXPECT().WaitUntilJobCompleted(namespace, getJobName(reason), timeout).Times(1).Return(errors.New("failed"))
|
||||
doneFunc := GetDoneFunc(monitor, namespace, reason)
|
||||
assert.NotNil(t, doneFunc)
|
||||
assert.Error(t, doneFunc(client))
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package zitadel
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam/zitadel/configuration"
|
||||
)
|
||||
|
||||
const migrationUser = "flyway"
|
||||
|
||||
func getAllUsers(desired *DesiredV0) map[string]string {
|
||||
passwords := &configuration.Passwords{}
|
||||
if desired != nil && desired.Spec != nil && desired.Spec.Configuration != nil && desired.Spec.Configuration.Passwords != nil {
|
||||
passwords = desired.Spec.Configuration.Passwords
|
||||
}
|
||||
users := make(map[string]string, 0)
|
||||
|
||||
migrationPassword := migrationUser
|
||||
if passwords.Migration != nil {
|
||||
migrationPassword = passwords.Migration.Value
|
||||
}
|
||||
users[migrationUser] = migrationPassword
|
||||
|
||||
mgmtUser := "management"
|
||||
mgmtPassword := mgmtUser
|
||||
if passwords != nil && passwords.Management != nil {
|
||||
mgmtPassword = passwords.Management.Value
|
||||
}
|
||||
users[mgmtUser] = mgmtPassword
|
||||
|
||||
adminUser := "adminapi"
|
||||
adminPassword := adminUser
|
||||
if passwords != nil && passwords.Adminapi != nil {
|
||||
adminPassword = passwords.Adminapi.Value
|
||||
}
|
||||
users[adminUser] = adminPassword
|
||||
|
||||
authUser := "auth"
|
||||
authPassword := authUser
|
||||
if passwords != nil && passwords.Auth != nil {
|
||||
authPassword = passwords.Auth.Value
|
||||
}
|
||||
users[authUser] = authPassword
|
||||
|
||||
authzUser := "authz"
|
||||
authzPassword := authzUser
|
||||
if passwords != nil && passwords.Authz != nil {
|
||||
authzPassword = passwords.Authz.Value
|
||||
}
|
||||
users[authzUser] = authzPassword
|
||||
|
||||
notUser := "notification"
|
||||
notPassword := notUser
|
||||
if passwords != nil && passwords.Notification != nil {
|
||||
notPassword = passwords.Notification.Value
|
||||
}
|
||||
users[notUser] = notPassword
|
||||
|
||||
esUser := "eventstore"
|
||||
esPassword := esUser
|
||||
if passwords != nil && passwords.Eventstore != nil {
|
||||
esPassword = passwords.Eventstore.Value
|
||||
}
|
||||
users[esUser] = esPassword
|
||||
|
||||
return users
|
||||
}
|
||||
|
||||
func getZitadelUserList() []string {
|
||||
allUsersMap := getAllUsers(nil)
|
||||
|
||||
allZitadelUsers := make([]string, 0)
|
||||
for k := range allUsersMap {
|
||||
if k != migrationUser {
|
||||
allZitadelUsers = append(allZitadelUsers, k)
|
||||
}
|
||||
}
|
||||
sort.Slice(allZitadelUsers, func(i, j int) bool {
|
||||
return allZitadelUsers[i] < allZitadelUsers[j]
|
||||
})
|
||||
|
||||
return allZitadelUsers
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package orb
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/orb"
|
||||
"github.com/caos/orbos/pkg/secret"
|
||||
"github.com/caos/orbos/pkg/tree"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/operator/zitadel/kinds/iam"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func AdaptFunc(
|
||||
orbconfig *orb.Orb,
|
||||
action string,
|
||||
binaryVersion *string,
|
||||
features []string,
|
||||
) operator.AdaptFunc {
|
||||
return func(
|
||||
monitor mntr.Monitor,
|
||||
desiredTree *tree.Tree,
|
||||
currentTree *tree.Tree,
|
||||
) (
|
||||
queryFunc operator.QueryFunc,
|
||||
destroyFunc operator.DestroyFunc,
|
||||
allSecrets map[string]*secret.Secret,
|
||||
err error,
|
||||
) {
|
||||
defer func() {
|
||||
err = errors.Wrapf(err, "building %s failed", desiredTree.Common.Kind)
|
||||
}()
|
||||
|
||||
allSecrets = make(map[string]*secret.Secret)
|
||||
|
||||
orbMonitor := monitor.WithField("kind", "orb")
|
||||
|
||||
desiredKind, err := parseDesiredV0(desiredTree)
|
||||
if err != nil {
|
||||
return nil, nil, allSecrets, errors.Wrap(err, "parsing desired state failed")
|
||||
}
|
||||
desiredTree.Parsed = desiredKind
|
||||
currentTree = &tree.Tree{}
|
||||
|
||||
if desiredKind.Spec.Verbose && !orbMonitor.IsVerbose() {
|
||||
orbMonitor = orbMonitor.Verbose()
|
||||
}
|
||||
|
||||
operatorLabels := mustZITADELOperator(binaryVersion)
|
||||
|
||||
iamCurrent := &tree.Tree{}
|
||||
queryIAM, destroyIAM, zitadelSecrets, err := iam.GetQueryAndDestroyFuncs(
|
||||
orbMonitor,
|
||||
operatorLabels,
|
||||
desiredKind.IAM,
|
||||
iamCurrent,
|
||||
desiredKind.Spec.NodeSelector,
|
||||
desiredKind.Spec.Tolerations,
|
||||
orbconfig,
|
||||
action,
|
||||
&desiredKind.Spec.Version,
|
||||
features,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, allSecrets, err
|
||||
}
|
||||
secret.AppendSecrets("", allSecrets, zitadelSecrets)
|
||||
|
||||
destroyers := make([]operator.DestroyFunc, 0)
|
||||
queriers := make([]operator.QueryFunc, 0)
|
||||
for _, feature := range features {
|
||||
switch feature {
|
||||
case "iam", "migration", "scaleup", "scaledown":
|
||||
queriers = append(queriers, queryIAM)
|
||||
destroyers = append(destroyers, destroyIAM)
|
||||
case "operator":
|
||||
queriers = append(queriers, operator.EnsureFuncToQueryFunc(Reconcile(monitor, desiredTree, false)))
|
||||
}
|
||||
}
|
||||
|
||||
currentTree.Parsed = &DesiredV0{
|
||||
Common: &tree.Common{
|
||||
Kind: "zitadel.caos.ch/Orb",
|
||||
Version: "v0",
|
||||
},
|
||||
IAM: iamCurrent,
|
||||
}
|
||||
|
||||
return func(k8sClient kubernetes.ClientInt, _ map[string]interface{}) (operator.EnsureFunc, error) {
|
||||
queried := map[string]interface{}{}
|
||||
monitor.WithField("queriers", len(queriers)).Info("Querying")
|
||||
return operator.QueriersToEnsureFunc(monitor, true, queriers, k8sClient, queried)
|
||||
},
|
||||
func(k8sClient kubernetes.ClientInt) error {
|
||||
monitor.WithField("destroyers", len(queriers)).Info("Destroy")
|
||||
return operator.DestroyersToDestroyFunc(monitor, destroyers)(k8sClient)
|
||||
},
|
||||
allSecrets,
|
||||
nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package orb
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/pkg/tree"
|
||||
"github.com/pkg/errors"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
type DesiredV0 struct {
|
||||
Common *tree.Common `yaml:",inline"`
|
||||
Spec struct {
|
||||
Verbose bool
|
||||
NodeSelector map[string]string `yaml:"nodeSelector,omitempty"`
|
||||
Tolerations []corev1.Toleration `yaml:"tolerations,omitempty"`
|
||||
Version string `yaml:"version,omitempty"`
|
||||
SelfReconciling bool `yaml:"selfReconciling"`
|
||||
//Use this registry to pull the database operator image from
|
||||
//@default: ghcr.io
|
||||
CustomImageRegistry string `json:"customImageRegistry,omitempty" yaml:"customImageRegistry,omitempty"`
|
||||
}
|
||||
IAM *tree.Tree
|
||||
}
|
||||
|
||||
func parseDesiredV0(desiredTree *tree.Tree) (*DesiredV0, error) {
|
||||
desiredKind := &DesiredV0{Common: desiredTree.Common}
|
||||
|
||||
if err := desiredTree.Original.Decode(desiredKind); err != nil {
|
||||
return nil, errors.Wrap(err, "parsing desired state failed")
|
||||
}
|
||||
desiredKind.Common.Version = "v0"
|
||||
|
||||
return desiredKind, nil
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package orb
|
||||
|
||||
import "github.com/caos/orbos/pkg/labels"
|
||||
|
||||
func mustZITADELOperator(binaryVersion *string) *labels.Operator {
|
||||
|
||||
version := "unknown"
|
||||
if binaryVersion != nil {
|
||||
version = *binaryVersion
|
||||
}
|
||||
|
||||
return labels.MustForOperator("ZITADEL", "zitadel.caos.ch", version)
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package orb
|
||||
|
||||
import (
|
||||
"github.com/caos/orbos/mntr"
|
||||
kubernetes2 "github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/tree"
|
||||
"github.com/caos/orbos/pkg/treelabels"
|
||||
"github.com/caos/zitadel/operator"
|
||||
"github.com/caos/zitadel/pkg/kubernetes"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func Reconcile(monitor mntr.Monitor, desiredTree *tree.Tree, takeoff bool) operator.EnsureFunc {
|
||||
return func(k8sClient kubernetes2.ClientInt) (err error) {
|
||||
defer func() {
|
||||
err = errors.Wrapf(err, "building %s failed", desiredTree.Common.Kind)
|
||||
}()
|
||||
|
||||
desiredKind, err := parseDesiredV0(desiredTree)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "parsing desired state failed")
|
||||
}
|
||||
desiredTree.Parsed = desiredKind
|
||||
|
||||
recMonitor := monitor.WithField("version", desiredKind.Spec.Version)
|
||||
|
||||
if desiredKind.Spec.Version == "" {
|
||||
err := errors.New("No version set in zitadel.yml")
|
||||
recMonitor.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
imageRegistry := desiredKind.Spec.CustomImageRegistry
|
||||
if imageRegistry == "" {
|
||||
imageRegistry = "ghcr.io"
|
||||
}
|
||||
|
||||
if takeoff || desiredKind.Spec.SelfReconciling {
|
||||
if err := kubernetes.EnsureZitadelOperatorArtifacts(monitor, treelabels.MustForAPI(desiredTree, mustZITADELOperator(&desiredKind.Spec.Version)), k8sClient, desiredKind.Spec.Version, desiredKind.Spec.NodeSelector, desiredKind.Spec.Tolerations, imageRegistry); err != nil {
|
||||
recMonitor.Error(errors.Wrap(err, "Failed to deploy zitadel-operator into k8s-cluster"))
|
||||
return err
|
||||
}
|
||||
|
||||
recMonitor.Info("Applied zitadel-operator")
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package zitadel
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/caos/zitadel/operator"
|
||||
|
||||
"github.com/caos/orbos/mntr"
|
||||
"github.com/caos/orbos/pkg/git"
|
||||
"github.com/caos/orbos/pkg/kubernetes"
|
||||
"github.com/caos/orbos/pkg/tree"
|
||||
)
|
||||
|
||||
func Takeoff(monitor mntr.Monitor, gitClient *git.Client, adapt operator.AdaptFunc, k8sClient *kubernetes.Client) func() error {
|
||||
return func() error {
|
||||
internalMonitor := monitor.WithField("operator", "zitadel")
|
||||
internalMonitor.Info("Takeoff")
|
||||
treeDesired, err := operator.Parse(gitClient, "zitadel.yml")
|
||||
if err != nil {
|
||||
monitor.Error(err)
|
||||
return err
|
||||
}
|
||||
treeCurrent := &tree.Tree{}
|
||||
|
||||
if !k8sClient.Available() {
|
||||
internalMonitor.Error(errors.New("kubeclient is not available"))
|
||||
return err
|
||||
}
|
||||
|
||||
query, _, _, err := adapt(internalMonitor, treeDesired, treeCurrent)
|
||||
if err != nil {
|
||||
internalMonitor.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
ensure, err := query(k8sClient, map[string]interface{}{})
|
||||
if err != nil {
|
||||
internalMonitor.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := ensure(k8sClient); err != nil {
|
||||
internalMonitor.Error(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user