@reyemtech/nimbus 2.12.5 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/cjs/backup/index.d.ts.map +1 -1
- package/dist/cjs/backup/index.js +6 -1
- package/dist/cjs/backup/index.js.map +1 -1
- package/dist/cjs/cli/migrate-cnpg-ownership.d.ts +43 -0
- package/dist/cjs/cli/migrate-cnpg-ownership.d.ts.map +1 -0
- package/dist/cjs/cli/migrate-cnpg-ownership.js +67 -0
- package/dist/cjs/cli/migrate-cnpg-ownership.js.map +1 -0
- package/dist/cjs/cli/migrate-cnpg-roles.d.ts +92 -0
- package/dist/cjs/cli/migrate-cnpg-roles.d.ts.map +1 -0
- package/dist/cjs/cli/migrate-cnpg-roles.js +337 -0
- package/dist/cjs/cli/migrate-cnpg-roles.js.map +1 -0
- package/dist/cjs/cli/migrate-cnpg.d.ts +38 -0
- package/dist/cjs/cli/migrate-cnpg.d.ts.map +1 -0
- package/dist/cjs/cli/migrate-cnpg.js +258 -0
- package/dist/cjs/cli/migrate-cnpg.js.map +1 -0
- package/dist/cjs/cli/migrate-exec.d.ts +45 -0
- package/dist/cjs/cli/migrate-exec.d.ts.map +1 -0
- package/dist/cjs/cli/migrate-exec.js +104 -0
- package/dist/cjs/cli/migrate-exec.js.map +1 -0
- package/dist/cjs/cli/migrate-psql.d.ts +125 -0
- package/dist/cjs/cli/migrate-psql.d.ts.map +1 -0
- package/dist/cjs/cli/migrate-psql.js +213 -0
- package/dist/cjs/cli/migrate-psql.js.map +1 -0
- package/dist/cjs/cli/migrate-report.d.ts +27 -0
- package/dist/cjs/cli/migrate-report.d.ts.map +1 -0
- package/dist/cjs/cli/migrate-report.js +29 -0
- package/dist/cjs/cli/migrate-report.js.map +1 -0
- package/dist/cjs/cli/migrate-superuser.d.ts +22 -0
- package/dist/cjs/cli/migrate-superuser.d.ts.map +1 -0
- package/dist/cjs/cli/migrate-superuser.js +73 -0
- package/dist/cjs/cli/migrate-superuser.js.map +1 -0
- package/dist/cjs/cli/migrate.d.ts +37 -0
- package/dist/cjs/cli/migrate.d.ts.map +1 -0
- package/dist/cjs/cli/migrate.js +67 -0
- package/dist/cjs/cli/migrate.js.map +1 -0
- package/dist/cjs/cli.d.ts +1 -0
- package/dist/cjs/cli.d.ts.map +1 -1
- package/dist/cjs/cli.js +6 -0
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/operator/cnpg-common.d.ts +56 -0
- package/dist/cjs/operator/cnpg-common.d.ts.map +1 -0
- package/dist/cjs/operator/cnpg-common.js +82 -0
- package/dist/cjs/operator/cnpg-common.js.map +1 -0
- package/dist/cjs/operator/cnpg-database.d.ts +66 -0
- package/dist/cjs/operator/cnpg-database.d.ts.map +1 -0
- package/dist/cjs/operator/cnpg-database.js +296 -0
- package/dist/cjs/operator/cnpg-database.js.map +1 -0
- package/dist/cjs/operator/cnpg-roles.d.ts +173 -0
- package/dist/cjs/operator/cnpg-roles.d.ts.map +1 -0
- package/dist/cjs/operator/cnpg-roles.js +225 -0
- package/dist/cjs/operator/cnpg-roles.js.map +1 -0
- package/dist/cjs/operator/cnpg.d.ts.map +1 -1
- package/dist/cjs/operator/cnpg.js +50 -162
- package/dist/cjs/operator/cnpg.js.map +1 -1
- package/dist/cjs/operator/connection-uri.d.ts +44 -0
- package/dist/cjs/operator/connection-uri.d.ts.map +1 -0
- package/dist/cjs/operator/connection-uri.js +49 -0
- package/dist/cjs/operator/connection-uri.js.map +1 -0
- package/dist/cjs/operator/credentials.d.ts +76 -0
- package/dist/cjs/operator/credentials.d.ts.map +1 -0
- package/dist/cjs/operator/credentials.js +106 -0
- package/dist/cjs/operator/credentials.js.map +1 -0
- package/dist/cjs/operator/database-options.d.ts +121 -0
- package/dist/cjs/operator/database-options.d.ts.map +1 -0
- package/dist/cjs/operator/database-options.js +131 -0
- package/dist/cjs/operator/database-options.js.map +1 -0
- package/dist/cjs/operator/grants/postgres-job.d.ts +109 -0
- package/dist/cjs/operator/grants/postgres-job.d.ts.map +1 -0
- package/dist/cjs/operator/grants/postgres-job.js +232 -0
- package/dist/cjs/operator/grants/postgres-job.js.map +1 -0
- package/dist/cjs/operator/grants/postgres-sql.d.ts +130 -0
- package/dist/cjs/operator/grants/postgres-sql.d.ts.map +1 -0
- package/dist/cjs/operator/grants/postgres-sql.js +305 -0
- package/dist/cjs/operator/grants/postgres-sql.js.map +1 -0
- package/dist/cjs/operator/grants/privileges.d.ts +24 -0
- package/dist/cjs/operator/grants/privileges.d.ts.map +1 -0
- package/dist/cjs/operator/grants/privileges.js +35 -0
- package/dist/cjs/operator/grants/privileges.js.map +1 -0
- package/dist/cjs/operator/grants/role-config.d.ts +80 -0
- package/dist/cjs/operator/grants/role-config.d.ts.map +1 -0
- package/dist/cjs/operator/grants/role-config.js +134 -0
- package/dist/cjs/operator/grants/role-config.js.map +1 -0
- package/dist/cjs/operator/index.d.ts +1 -1
- package/dist/cjs/operator/index.d.ts.map +1 -1
- package/dist/cjs/operator/index.js.map +1 -1
- package/dist/cjs/operator/interfaces.d.ts +223 -1
- package/dist/cjs/operator/interfaces.d.ts.map +1 -1
- package/dist/cjs/operator/interfaces.js.map +1 -1
- package/dist/cjs/operator/mariadb-common.d.ts +99 -0
- package/dist/cjs/operator/mariadb-common.d.ts.map +1 -0
- package/dist/cjs/operator/mariadb-common.js +141 -0
- package/dist/cjs/operator/mariadb-common.js.map +1 -0
- package/dist/cjs/operator/mariadb-database.d.ts +65 -0
- package/dist/cjs/operator/mariadb-database.d.ts.map +1 -0
- package/dist/cjs/operator/mariadb-database.js +285 -0
- package/dist/cjs/operator/mariadb-database.js.map +1 -0
- package/dist/cjs/operator/mariadb-roles.d.ts +264 -0
- package/dist/cjs/operator/mariadb-roles.d.ts.map +1 -0
- package/dist/cjs/operator/mariadb-roles.js +366 -0
- package/dist/cjs/operator/mariadb-roles.js.map +1 -0
- package/dist/cjs/operator/mariadb.d.ts.map +1 -1
- package/dist/cjs/operator/mariadb.js +35 -147
- package/dist/cjs/operator/mariadb.js.map +1 -1
- package/dist/cjs/operator/neo4j-common.d.ts +62 -0
- package/dist/cjs/operator/neo4j-common.d.ts.map +1 -0
- package/dist/cjs/operator/neo4j-common.js +89 -0
- package/dist/cjs/operator/neo4j-common.js.map +1 -0
- package/dist/cjs/operator/neo4j-database.d.ts +88 -0
- package/dist/cjs/operator/neo4j-database.d.ts.map +1 -0
- package/dist/cjs/operator/neo4j-database.js +274 -0
- package/dist/cjs/operator/neo4j-database.js.map +1 -0
- package/dist/cjs/operator/neo4j-roles.d.ts +203 -0
- package/dist/cjs/operator/neo4j-roles.d.ts.map +1 -0
- package/dist/cjs/operator/neo4j-roles.js +298 -0
- package/dist/cjs/operator/neo4j-roles.js.map +1 -0
- package/dist/cjs/operator/neo4j.d.ts.map +1 -1
- package/dist/cjs/operator/neo4j.js +32 -132
- package/dist/cjs/operator/neo4j.js.map +1 -1
- package/dist/cjs/operator/resource-identity.d.ts +170 -0
- package/dist/cjs/operator/resource-identity.d.ts.map +1 -0
- package/dist/cjs/operator/resource-identity.js +231 -0
- package/dist/cjs/operator/resource-identity.js.map +1 -0
- package/dist/cjs/operator/role-registry.d.ts +85 -0
- package/dist/cjs/operator/role-registry.d.ts.map +1 -0
- package/dist/cjs/operator/role-registry.js +72 -0
- package/dist/cjs/operator/role-registry.js.map +1 -0
- package/dist/cjs/platform/components/image-pruner.d.ts +3 -1
- package/dist/cjs/platform/components/image-pruner.d.ts.map +1 -1
- package/dist/cjs/platform/components/image-pruner.js +38 -19
- package/dist/cjs/platform/components/image-pruner.js.map +1 -1
- package/dist/cjs/types/errors.d.ts +3 -0
- package/dist/cjs/types/errors.d.ts.map +1 -1
- package/dist/cjs/types/errors.js +3 -0
- package/dist/cjs/types/errors.js.map +1 -1
- package/dist/esm/backup/index.d.ts.map +1 -1
- package/dist/esm/backup/index.js +6 -1
- package/dist/esm/backup/index.js.map +1 -1
- package/dist/esm/cli/migrate-cnpg-ownership.d.ts +43 -0
- package/dist/esm/cli/migrate-cnpg-ownership.d.ts.map +1 -0
- package/dist/esm/cli/migrate-cnpg-ownership.js +67 -0
- package/dist/esm/cli/migrate-cnpg-ownership.js.map +1 -0
- package/dist/esm/cli/migrate-cnpg-roles.d.ts +92 -0
- package/dist/esm/cli/migrate-cnpg-roles.d.ts.map +1 -0
- package/dist/esm/cli/migrate-cnpg-roles.js +337 -0
- package/dist/esm/cli/migrate-cnpg-roles.js.map +1 -0
- package/dist/esm/cli/migrate-cnpg.d.ts +38 -0
- package/dist/esm/cli/migrate-cnpg.d.ts.map +1 -0
- package/dist/esm/cli/migrate-cnpg.js +258 -0
- package/dist/esm/cli/migrate-cnpg.js.map +1 -0
- package/dist/esm/cli/migrate-exec.d.ts +45 -0
- package/dist/esm/cli/migrate-exec.d.ts.map +1 -0
- package/dist/esm/cli/migrate-exec.js +104 -0
- package/dist/esm/cli/migrate-exec.js.map +1 -0
- package/dist/esm/cli/migrate-psql.d.ts +125 -0
- package/dist/esm/cli/migrate-psql.d.ts.map +1 -0
- package/dist/esm/cli/migrate-psql.js +213 -0
- package/dist/esm/cli/migrate-psql.js.map +1 -0
- package/dist/esm/cli/migrate-report.d.ts +27 -0
- package/dist/esm/cli/migrate-report.d.ts.map +1 -0
- package/dist/esm/cli/migrate-report.js +29 -0
- package/dist/esm/cli/migrate-report.js.map +1 -0
- package/dist/esm/cli/migrate-superuser.d.ts +22 -0
- package/dist/esm/cli/migrate-superuser.d.ts.map +1 -0
- package/dist/esm/cli/migrate-superuser.js +73 -0
- package/dist/esm/cli/migrate-superuser.js.map +1 -0
- package/dist/esm/cli/migrate.d.ts +37 -0
- package/dist/esm/cli/migrate.d.ts.map +1 -0
- package/dist/esm/cli/migrate.js +67 -0
- package/dist/esm/cli/migrate.js.map +1 -0
- package/dist/esm/cli.d.ts +1 -0
- package/dist/esm/cli.d.ts.map +1 -1
- package/dist/esm/cli.js +6 -0
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/operator/cnpg-common.d.ts +56 -0
- package/dist/esm/operator/cnpg-common.d.ts.map +1 -0
- package/dist/esm/operator/cnpg-common.js +82 -0
- package/dist/esm/operator/cnpg-common.js.map +1 -0
- package/dist/esm/operator/cnpg-database.d.ts +66 -0
- package/dist/esm/operator/cnpg-database.d.ts.map +1 -0
- package/dist/esm/operator/cnpg-database.js +296 -0
- package/dist/esm/operator/cnpg-database.js.map +1 -0
- package/dist/esm/operator/cnpg-roles.d.ts +173 -0
- package/dist/esm/operator/cnpg-roles.d.ts.map +1 -0
- package/dist/esm/operator/cnpg-roles.js +225 -0
- package/dist/esm/operator/cnpg-roles.js.map +1 -0
- package/dist/esm/operator/cnpg.d.ts.map +1 -1
- package/dist/esm/operator/cnpg.js +50 -162
- package/dist/esm/operator/cnpg.js.map +1 -1
- package/dist/esm/operator/connection-uri.d.ts +44 -0
- package/dist/esm/operator/connection-uri.d.ts.map +1 -0
- package/dist/esm/operator/connection-uri.js +49 -0
- package/dist/esm/operator/connection-uri.js.map +1 -0
- package/dist/esm/operator/credentials.d.ts +76 -0
- package/dist/esm/operator/credentials.d.ts.map +1 -0
- package/dist/esm/operator/credentials.js +106 -0
- package/dist/esm/operator/credentials.js.map +1 -0
- package/dist/esm/operator/database-options.d.ts +121 -0
- package/dist/esm/operator/database-options.d.ts.map +1 -0
- package/dist/esm/operator/database-options.js +131 -0
- package/dist/esm/operator/database-options.js.map +1 -0
- package/dist/esm/operator/grants/postgres-job.d.ts +109 -0
- package/dist/esm/operator/grants/postgres-job.d.ts.map +1 -0
- package/dist/esm/operator/grants/postgres-job.js +232 -0
- package/dist/esm/operator/grants/postgres-job.js.map +1 -0
- package/dist/esm/operator/grants/postgres-sql.d.ts +130 -0
- package/dist/esm/operator/grants/postgres-sql.d.ts.map +1 -0
- package/dist/esm/operator/grants/postgres-sql.js +305 -0
- package/dist/esm/operator/grants/postgres-sql.js.map +1 -0
- package/dist/esm/operator/grants/privileges.d.ts +24 -0
- package/dist/esm/operator/grants/privileges.d.ts.map +1 -0
- package/dist/esm/operator/grants/privileges.js +35 -0
- package/dist/esm/operator/grants/privileges.js.map +1 -0
- package/dist/esm/operator/grants/role-config.d.ts +80 -0
- package/dist/esm/operator/grants/role-config.d.ts.map +1 -0
- package/dist/esm/operator/grants/role-config.js +134 -0
- package/dist/esm/operator/grants/role-config.js.map +1 -0
- package/dist/esm/operator/index.d.ts +1 -1
- package/dist/esm/operator/index.d.ts.map +1 -1
- package/dist/esm/operator/index.js.map +1 -1
- package/dist/esm/operator/interfaces.d.ts +223 -1
- package/dist/esm/operator/interfaces.d.ts.map +1 -1
- package/dist/esm/operator/interfaces.js.map +1 -1
- package/dist/esm/operator/mariadb-common.d.ts +99 -0
- package/dist/esm/operator/mariadb-common.d.ts.map +1 -0
- package/dist/esm/operator/mariadb-common.js +141 -0
- package/dist/esm/operator/mariadb-common.js.map +1 -0
- package/dist/esm/operator/mariadb-database.d.ts +65 -0
- package/dist/esm/operator/mariadb-database.d.ts.map +1 -0
- package/dist/esm/operator/mariadb-database.js +285 -0
- package/dist/esm/operator/mariadb-database.js.map +1 -0
- package/dist/esm/operator/mariadb-roles.d.ts +264 -0
- package/dist/esm/operator/mariadb-roles.d.ts.map +1 -0
- package/dist/esm/operator/mariadb-roles.js +366 -0
- package/dist/esm/operator/mariadb-roles.js.map +1 -0
- package/dist/esm/operator/mariadb.d.ts.map +1 -1
- package/dist/esm/operator/mariadb.js +35 -147
- package/dist/esm/operator/mariadb.js.map +1 -1
- package/dist/esm/operator/neo4j-common.d.ts +62 -0
- package/dist/esm/operator/neo4j-common.d.ts.map +1 -0
- package/dist/esm/operator/neo4j-common.js +89 -0
- package/dist/esm/operator/neo4j-common.js.map +1 -0
- package/dist/esm/operator/neo4j-database.d.ts +88 -0
- package/dist/esm/operator/neo4j-database.d.ts.map +1 -0
- package/dist/esm/operator/neo4j-database.js +274 -0
- package/dist/esm/operator/neo4j-database.js.map +1 -0
- package/dist/esm/operator/neo4j-roles.d.ts +203 -0
- package/dist/esm/operator/neo4j-roles.d.ts.map +1 -0
- package/dist/esm/operator/neo4j-roles.js +298 -0
- package/dist/esm/operator/neo4j-roles.js.map +1 -0
- package/dist/esm/operator/neo4j.d.ts.map +1 -1
- package/dist/esm/operator/neo4j.js +32 -132
- package/dist/esm/operator/neo4j.js.map +1 -1
- package/dist/esm/operator/resource-identity.d.ts +170 -0
- package/dist/esm/operator/resource-identity.d.ts.map +1 -0
- package/dist/esm/operator/resource-identity.js +231 -0
- package/dist/esm/operator/resource-identity.js.map +1 -0
- package/dist/esm/operator/role-registry.d.ts +85 -0
- package/dist/esm/operator/role-registry.d.ts.map +1 -0
- package/dist/esm/operator/role-registry.js +72 -0
- package/dist/esm/operator/role-registry.js.map +1 -0
- package/dist/esm/platform/components/image-pruner.d.ts +3 -1
- package/dist/esm/platform/components/image-pruner.d.ts.map +1 -1
- package/dist/esm/platform/components/image-pruner.js +38 -19
- package/dist/esm/platform/components/image-pruner.js.map +1 -1
- package/dist/esm/types/errors.d.ts +3 -0
- package/dist/esm/types/errors.d.ts.map +1 -1
- package/dist/esm/types/errors.js +3 -0
- package/dist/esm/types/errors.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Databases inside a CloudNativePG cluster.
|
|
4
|
+
*
|
|
5
|
+
* Provisioning is declarative: a `DatabaseRole` CR owns each login role and its
|
|
6
|
+
* password, and a `Database` CR owns the database and its ownership. The
|
|
7
|
+
* operator reconciles both continuously, so drift (a dropped role, a changed
|
|
8
|
+
* owner) is corrected rather than silently persisting. Privilege grants have no
|
|
9
|
+
* CRD equivalent, so they are applied by a `psql` Job authenticated as the
|
|
10
|
+
* database owner — see {@link createPostgresGrantJob}.
|
|
11
|
+
*
|
|
12
|
+
* @module operator/cnpg-database
|
|
13
|
+
*/
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
+
}) : function(o, v) {
|
|
28
|
+
o["default"] = v;
|
|
29
|
+
});
|
|
30
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
+
var ownKeys = function(o) {
|
|
32
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
+
var ar = [];
|
|
34
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
+
return ar;
|
|
36
|
+
};
|
|
37
|
+
return ownKeys(o);
|
|
38
|
+
};
|
|
39
|
+
return function (mod) {
|
|
40
|
+
if (mod && mod.__esModule) return mod;
|
|
41
|
+
var result = {};
|
|
42
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.createSingleCnpgDatabaseInstance = createSingleCnpgDatabaseInstance;
|
|
49
|
+
const k8s = __importStar(require("@pulumi/kubernetes"));
|
|
50
|
+
const pulumi = __importStar(require("@pulumi/pulumi"));
|
|
51
|
+
const cnpg_common_js_1 = require("./cnpg-common.js");
|
|
52
|
+
const cnpg_roles_js_1 = require("./cnpg-roles.js");
|
|
53
|
+
const postgres_job_js_1 = require("./grants/postgres-job.js");
|
|
54
|
+
const postgres_sql_js_1 = require("./grants/postgres-sql.js");
|
|
55
|
+
const role_config_js_1 = require("./grants/role-config.js");
|
|
56
|
+
const database_options_js_1 = require("./database-options.js");
|
|
57
|
+
const errors_js_1 = require("../types/errors.js");
|
|
58
|
+
/** Label marking every object this module creates as nimbus-managed. */
|
|
59
|
+
const MANAGED_BY_LABEL = "app.kubernetes.io/managed-by";
|
|
60
|
+
/** Value of {@link MANAGED_BY_LABEL}. */
|
|
61
|
+
const MANAGED_BY_VALUE = "nimbus";
|
|
62
|
+
/**
|
|
63
|
+
* Create a single database instance within a CNPG cluster.
|
|
64
|
+
*
|
|
65
|
+
* Both CRs adopt pre-existing objects — CNPG detects the database/role and
|
|
66
|
+
* `ALTER`s it to match the manifest instead of failing — so this is safe to
|
|
67
|
+
* apply on top of databases previously created by the psql bootstrap Job.
|
|
68
|
+
*
|
|
69
|
+
* Connection secrets with the owner's credentials are replicated to the target
|
|
70
|
+
* namespaces, and `config.sql` (if any) is applied by a Job running as the
|
|
71
|
+
* owner. Additional roles are added afterwards via the returned `addRole()`.
|
|
72
|
+
*
|
|
73
|
+
* @param options - Cluster, database name, configuration, and provider
|
|
74
|
+
* @returns The database instance, with `addRole()` bound to it
|
|
75
|
+
* @throws {AnyCloudError} code `INVALID_GRANT` when a role's grant lists no privileges
|
|
76
|
+
* @throws {AnyCloudError} code `UNSUPPORTED_PRIVILEGE` when a grant names a
|
|
77
|
+
* privilege the SQL compiler cannot emit
|
|
78
|
+
* @throws {AnyCloudError} code `UNSUPPORTED_ROLE_OPTION` when `dbName` or the
|
|
79
|
+
* resolved owner name is blank, or when `addRole()` is called with a blank
|
|
80
|
+
* name, with the database owner's own name, with a role name any other
|
|
81
|
+
* database on the same cluster has already claimed, or with an
|
|
82
|
+
* `engineOptions` block belonging to another engine
|
|
83
|
+
*/
|
|
84
|
+
function createSingleCnpgDatabaseInstance(options) {
|
|
85
|
+
const { clusterName, dbName, config, endpoint, port, pgVersion, cluster, provider } = options;
|
|
86
|
+
const { roleRegistry } = options;
|
|
87
|
+
(0, role_config_js_1.assertValidDatabaseName)(dbName);
|
|
88
|
+
const username = config.owner ?? dbName;
|
|
89
|
+
(0, role_config_js_1.assertValidRoleName)(username, dbName);
|
|
90
|
+
// The owner is a cluster-global role like any other, so it claims its name
|
|
91
|
+
// too — otherwise a later addRole() on a *different* database could take it.
|
|
92
|
+
(0, cnpg_common_js_1.claimCnpgRoleName)(roleRegistry, username, dbName);
|
|
93
|
+
const labels = {
|
|
94
|
+
[MANAGED_BY_LABEL]: MANAGED_BY_VALUE,
|
|
95
|
+
"nimbus/cluster": clusterName,
|
|
96
|
+
"nimbus/database": dbName,
|
|
97
|
+
};
|
|
98
|
+
const ownerNaming = (0, cnpg_roles_js_1.ownerRoleNaming)(clusterName, dbName);
|
|
99
|
+
const ownerConfig = (0, role_config_js_1.resolveRoleConfig)({
|
|
100
|
+
namespaces: config.namespaces,
|
|
101
|
+
login: true,
|
|
102
|
+
reclaimPolicy: config.reclaimPolicy,
|
|
103
|
+
});
|
|
104
|
+
const owner = (0, cnpg_roles_js_1.provisionCnpgRole)({
|
|
105
|
+
clusterName,
|
|
106
|
+
roleName: username,
|
|
107
|
+
naming: ownerNaming,
|
|
108
|
+
resolved: ownerConfig,
|
|
109
|
+
labels,
|
|
110
|
+
cluster,
|
|
111
|
+
provider,
|
|
112
|
+
});
|
|
113
|
+
// Database CR: owns the database and its ownership. `spec.name` is the raw
|
|
114
|
+
// PostgreSQL identifier so the CR adopts a database created under that exact
|
|
115
|
+
// name; only metadata.name is sanitized for DNS-1123.
|
|
116
|
+
const database = new k8s.apiextensions.CustomResource(`${clusterName}-${dbName}-database-cr`, {
|
|
117
|
+
apiVersion: cnpg_common_js_1.CNPG_API_VERSION,
|
|
118
|
+
kind: cnpg_common_js_1.DATABASE_KIND,
|
|
119
|
+
metadata: {
|
|
120
|
+
name: (0, cnpg_common_js_1.toResourceName)(`${clusterName}-${dbName}-db`),
|
|
121
|
+
namespace: cnpg_common_js_1.DATA_NAMESPACE,
|
|
122
|
+
labels,
|
|
123
|
+
},
|
|
124
|
+
spec: {
|
|
125
|
+
cluster: { name: clusterName },
|
|
126
|
+
name: dbName,
|
|
127
|
+
owner: username,
|
|
128
|
+
ensure: cnpg_common_js_1.ENSURE_PRESENT,
|
|
129
|
+
databaseReclaimPolicy: ownerConfig.reclaimPolicy,
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
// The owning role must exist before CREATE DATABASE ... OWNER.
|
|
133
|
+
{ provider, dependsOn: [cluster, owner.role] });
|
|
134
|
+
const secrets = (0, cnpg_roles_js_1.replicateCnpgConnectionSecrets)({
|
|
135
|
+
naming: ownerNaming,
|
|
136
|
+
namespaces: ownerConfig.namespaces,
|
|
137
|
+
dbName,
|
|
138
|
+
username,
|
|
139
|
+
password: owner.credentials.stablePassword,
|
|
140
|
+
endpoint,
|
|
141
|
+
port,
|
|
142
|
+
labels,
|
|
143
|
+
provider,
|
|
144
|
+
dependsOn: [database],
|
|
145
|
+
});
|
|
146
|
+
// Owner-scoped Job for `config.sql`. `grants` is omitted rather than passed
|
|
147
|
+
// as `[]`: the owner's privileges are not managed here at all, where `[]`
|
|
148
|
+
// would mean "the owner should hold nothing". Because the role and the owner
|
|
149
|
+
// are the same the compiler emits no revoke preamble either way, so this only
|
|
150
|
+
// ever runs the supplied statements — and creates nothing at all when `sql`
|
|
151
|
+
// is omitted.
|
|
152
|
+
//
|
|
153
|
+
// It is also the head of this database's grant-Job chain: see
|
|
154
|
+
// `previousGrantJob` below.
|
|
155
|
+
const ownerJob = (0, postgres_job_js_1.createPostgresGrantJob)({
|
|
156
|
+
clusterName,
|
|
157
|
+
databaseName: dbName,
|
|
158
|
+
roleName: username,
|
|
159
|
+
ownerName: username,
|
|
160
|
+
ownerSecretName: ownerNaming.credentialSecret,
|
|
161
|
+
extraSql: config.sql ?? [],
|
|
162
|
+
namespace: cnpg_common_js_1.DATA_NAMESPACE,
|
|
163
|
+
endpoint,
|
|
164
|
+
pgVersion,
|
|
165
|
+
labels,
|
|
166
|
+
provider,
|
|
167
|
+
dependsOn: [database, owner.role, owner.credentials.userSecret],
|
|
168
|
+
});
|
|
169
|
+
// Last grant Job created for THIS database, or `undefined` until one exists.
|
|
170
|
+
// Each new Job is chained after it so the database's grant transactions run
|
|
171
|
+
// one at a time — see the note on the `dependsOn` passed below, and
|
|
172
|
+
// {@link createPostgresGrantJob}'s own documentation of the requirement.
|
|
173
|
+
let previousGrantJob = ownerJob;
|
|
174
|
+
return {
|
|
175
|
+
name: dbName,
|
|
176
|
+
clusterName,
|
|
177
|
+
host: endpoint,
|
|
178
|
+
port,
|
|
179
|
+
database: pulumi.output(dbName),
|
|
180
|
+
secrets,
|
|
181
|
+
nativeResource: database,
|
|
182
|
+
addRole(roleName, roleConfig) {
|
|
183
|
+
(0, role_config_js_1.assertValidRoleName)(roleName, dbName);
|
|
184
|
+
// The owner already has a DatabaseRole CR from createDatabase(). Adding
|
|
185
|
+
// it again would create a SECOND CR for the same PostgreSQL role, bound
|
|
186
|
+
// to a different basic-auth Secret, and the two controllers would then
|
|
187
|
+
// fight over the role's password indefinitely — leaving the owner's
|
|
188
|
+
// replicated connection Secrets holding a credential that no longer
|
|
189
|
+
// authenticates. The two CRs have different Pulumi logical names, so
|
|
190
|
+
// `pulumi preview` sees no conflict and this fails only in production.
|
|
191
|
+
if (roleName === username) {
|
|
192
|
+
throw new errors_js_1.AnyCloudError(`Role "${roleName}" is the owner of database "${dbName}" and is created by ` +
|
|
193
|
+
`createDatabase(); it cannot be added again. Use a different role name, or ` +
|
|
194
|
+
`change the database's "owner".`, errors_js_1.ERROR_CODES.UNSUPPORTED_ROLE_OPTION);
|
|
195
|
+
}
|
|
196
|
+
// A `mariadb` block here names an engine that will never run this role,
|
|
197
|
+
// so its host and connection cap would be dropped while the role
|
|
198
|
+
// provisioned as if they had been applied.
|
|
199
|
+
(0, database_options_js_1.assertNoForeignEngineOptions)({
|
|
200
|
+
roleName,
|
|
201
|
+
databaseName: dbName,
|
|
202
|
+
engineOptions: roleConfig?.engineOptions,
|
|
203
|
+
honoured: "postgresql",
|
|
204
|
+
engine: database_options_js_1.ENGINE_NAMES.CNPG,
|
|
205
|
+
});
|
|
206
|
+
const resolved = (0, role_config_js_1.resolveRoleConfig)(roleConfig);
|
|
207
|
+
// The grant compiler validates privileges, but it does not run until the
|
|
208
|
+
// grant Job is built further down — long after the claim below. Checking
|
|
209
|
+
// here keeps every rejecting guard ahead of the claim: an unsupported
|
|
210
|
+
// privilege otherwise left the role name claimed for a role that was
|
|
211
|
+
// never provisioned, so correcting it and retrying in the same program
|
|
212
|
+
// run was refused as a duplicate.
|
|
213
|
+
(0, postgres_sql_js_1.assertSupportedPrivileges)(resolved.grants);
|
|
214
|
+
// Same hazard one scope wider: the check above only sees this database's
|
|
215
|
+
// own owner, while a role of this name may already belong to a sibling
|
|
216
|
+
// database on the same cluster — the same role, since PostgreSQL has only
|
|
217
|
+
// one. The registry is what notices.
|
|
218
|
+
//
|
|
219
|
+
// Claimed after the guards above, not before them, so a call they reject
|
|
220
|
+
// leaves no claim behind: nothing was provisioned, so fixing the config
|
|
221
|
+
// must not then fail with a duplicate-name error about a role that never
|
|
222
|
+
// existed.
|
|
223
|
+
(0, cnpg_common_js_1.claimCnpgRoleName)(roleRegistry, roleName, dbName);
|
|
224
|
+
const naming = (0, cnpg_roles_js_1.additionalRoleNaming)(clusterName, dbName, roleName);
|
|
225
|
+
const provisioned = (0, cnpg_roles_js_1.provisionCnpgRole)({
|
|
226
|
+
clusterName,
|
|
227
|
+
roleName,
|
|
228
|
+
naming,
|
|
229
|
+
resolved,
|
|
230
|
+
postgresOptions: roleConfig?.engineOptions?.postgresql,
|
|
231
|
+
labels,
|
|
232
|
+
cluster,
|
|
233
|
+
provider,
|
|
234
|
+
});
|
|
235
|
+
// Grants are applied as the database owner — never as superuser — so the
|
|
236
|
+
// Job depends on the owner's credential Secret as well as both CRs.
|
|
237
|
+
//
|
|
238
|
+
// It also depends on the previous grant Job for this database, which is
|
|
239
|
+
// what serializes them. Each Job's script revokes and re-grants across
|
|
240
|
+
// every schema of the same database, so two running at once contend for
|
|
241
|
+
// the same catalog rows and can abort with `tuple concurrently updated`.
|
|
242
|
+
// A Job that exhausts its backoffLimit is never retried — the name is
|
|
243
|
+
// content-addressed, so an unchanged spec re-derives the same name and
|
|
244
|
+
// Pulumi diffs it as a no-op — which turns a transient collision into a
|
|
245
|
+
// permanent failure needing a manual `kubectl delete job`. Jobs for
|
|
246
|
+
// OTHER databases are deliberately not chained: they are separate
|
|
247
|
+
// transactions on separate databases and cannot contend.
|
|
248
|
+
const grantJob = (0, postgres_job_js_1.createPostgresGrantJob)({
|
|
249
|
+
clusterName,
|
|
250
|
+
databaseName: dbName,
|
|
251
|
+
roleName,
|
|
252
|
+
ownerName: username,
|
|
253
|
+
ownerSecretName: ownerNaming.credentialSecret,
|
|
254
|
+
grants: resolved.grants,
|
|
255
|
+
namespace: cnpg_common_js_1.DATA_NAMESPACE,
|
|
256
|
+
endpoint,
|
|
257
|
+
pgVersion,
|
|
258
|
+
labels,
|
|
259
|
+
provider,
|
|
260
|
+
dependsOn: [
|
|
261
|
+
database,
|
|
262
|
+
provisioned.role,
|
|
263
|
+
owner.credentials.userSecret,
|
|
264
|
+
...(previousGrantJob ? [previousGrantJob] : []),
|
|
265
|
+
],
|
|
266
|
+
});
|
|
267
|
+
if (grantJob) {
|
|
268
|
+
previousGrantJob = grantJob;
|
|
269
|
+
}
|
|
270
|
+
// The connection Secret waits on the grant Job so a consumer cannot read
|
|
271
|
+
// working credentials, connect, and hit permission errors before the
|
|
272
|
+
// privileges have landed. There is no Job only when `grants` was omitted
|
|
273
|
+
// entirely; `grants: []` still produces one, which revokes.
|
|
274
|
+
const roleSecrets = (0, cnpg_roles_js_1.replicateCnpgConnectionSecrets)({
|
|
275
|
+
naming,
|
|
276
|
+
namespaces: resolved.namespaces,
|
|
277
|
+
dbName,
|
|
278
|
+
username: roleName,
|
|
279
|
+
password: provisioned.credentials.stablePassword,
|
|
280
|
+
endpoint,
|
|
281
|
+
port,
|
|
282
|
+
labels,
|
|
283
|
+
provider,
|
|
284
|
+
dependsOn: grantJob ? [database, provisioned.role, grantJob] : [database, provisioned.role],
|
|
285
|
+
});
|
|
286
|
+
return {
|
|
287
|
+
name: roleName,
|
|
288
|
+
databaseName: dbName,
|
|
289
|
+
clusterName,
|
|
290
|
+
secrets: roleSecrets,
|
|
291
|
+
nativeResource: provisioned.role,
|
|
292
|
+
};
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
//# sourceMappingURL=cnpg-database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cnpg-database.js","sourceRoot":"","sources":["../../../src/operator/cnpg-database.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFH,4EA6OC;AApUD,wDAA0C;AAC1C,uDAAyC;AACzC,qDAO0B;AAC1B,mDAKyB;AACzB,8DAAkE;AAClE,8DAAqE;AACrE,4DAIiC;AACjC,+DAAmF;AACnF,kDAAgE;AAShE,wEAAwE;AACxE,MAAM,gBAAgB,GAAG,8BAA8B,CAAC;AACxD,yCAAyC;AACzC,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AA6BlC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,gCAAgC,CAAC,OAA6B;IAC5E,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,Q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AAC,WAAW,CAAC,cAAc;gBAChD,QAAQ;gBACR,IAAI;gBACJ,MAAM;gBACN,QAAQ;gBACR,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,WAAW,CAAC,IAAI,CAAC;aAC5F,CAAC,CAAC;YAEH,OAAO;gBACL,IAAI,EAAE,QAAQ;gBACd,YAAY,EAAE,MAAM;gBACpB,WAAW;gBACX,OAAO,EAAE,WAAW;gBACpB,cAAc,EAAE,WAAW,CAAC,IAAI;aACjC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostgreSQL roles inside a CloudNativePG cluster.
|
|
3
|
+
*
|
|
4
|
+
* Every role — the database owner created alongside the database, and every
|
|
5
|
+
* role added later via `addRole()` — is provisioned by the single function
|
|
6
|
+
* {@link provisionCnpgRole}. Only their names differ, and those names are the
|
|
7
|
+
* one genuinely dangerous part: Pulumi identifies a resource by its logical
|
|
8
|
+
* name, so renaming one deletes and recreates it, and for a credential Secret
|
|
9
|
+
* that regenerates the password and breaks every application already using it.
|
|
10
|
+
* {@link ownerRoleNaming} therefore pins the owner's names to the exact strings
|
|
11
|
+
* live stacks already carry.
|
|
12
|
+
*
|
|
13
|
+
* @module operator/cnpg-roles
|
|
14
|
+
*/
|
|
15
|
+
import * as k8s from "@pulumi/kubernetes";
|
|
16
|
+
import * as pulumi from "@pulumi/pulumi";
|
|
17
|
+
import { type IRoleCredentials } from "./credentials.js";
|
|
18
|
+
import type { IResolvedRoleConfig } from "./grants/role-config.js";
|
|
19
|
+
/**
|
|
20
|
+
* Every name — Pulumi logical and Kubernetes — used by one provisioned role.
|
|
21
|
+
*
|
|
22
|
+
* Collecting them in one place keeps the replace-on-rename risk reviewable
|
|
23
|
+
* instead of scattered through the provisioning code.
|
|
24
|
+
*/
|
|
25
|
+
export interface ICnpgRoleNaming {
|
|
26
|
+
/** Pulumi logical name of the Opaque credential Secret. */
|
|
27
|
+
readonly credentialResource: string;
|
|
28
|
+
/** Kubernetes name of the Opaque credential Secret. */
|
|
29
|
+
readonly credentialSecret: string;
|
|
30
|
+
/** Pulumi logical name of the basic-auth projection Secret. */
|
|
31
|
+
readonly basicAuthResource: string;
|
|
32
|
+
/** Kubernetes name of the basic-auth projection Secret. */
|
|
33
|
+
readonly basicAuthSecret: string;
|
|
34
|
+
/** Pulumi logical name of the `DatabaseRole` custom resource. */
|
|
35
|
+
readonly roleResource: string;
|
|
36
|
+
/** Kubernetes name of the `DatabaseRole` custom resource. */
|
|
37
|
+
readonly roleMetadataName: string;
|
|
38
|
+
/** Pulumi logical name prefix of the replicated connection Secrets. */
|
|
39
|
+
readonly connectionResourcePrefix: string;
|
|
40
|
+
/** Kubernetes name of each replicated connection Secret. */
|
|
41
|
+
readonly connectionSecret: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Names for the database owner's role.
|
|
45
|
+
*
|
|
46
|
+
* These strings predate the shared provisioner and are reproduced verbatim:
|
|
47
|
+
* `-user-secret`, `-role-secret`, `-role-cr`, and `-secret-{namespace}` are the
|
|
48
|
+
* logical names live stacks already carry. Do not "tidy" them.
|
|
49
|
+
*
|
|
50
|
+
* @param clusterName - CNPG cluster name
|
|
51
|
+
* @param dbName - Database name
|
|
52
|
+
* @returns The owner role's pinned naming
|
|
53
|
+
*/
|
|
54
|
+
export declare function ownerRoleNaming(clusterName: string, dbName: string): ICnpgRoleNaming;
|
|
55
|
+
/**
|
|
56
|
+
* Names for a role added via `addRole()`.
|
|
57
|
+
*
|
|
58
|
+
* Every name is prefixed `{cluster}-{database}-role-{role}` so it can never
|
|
59
|
+
* collide with the owner's pinned names above — the owner's shortest stem is
|
|
60
|
+
* `{cluster}-{database}-role`, which this only matches for an empty role name.
|
|
61
|
+
*
|
|
62
|
+
* The role segment comes from {@link toIdentitySegment}, not from plain
|
|
63
|
+
* sanitizing: `Read_Only` and `read_only` are two distinct, simultaneously valid
|
|
64
|
+
* PostgreSQL roles that sanitize alike, and two resources deriving one logical
|
|
65
|
+
* name abort the entire preview with a duplicate-URN error. Every segment
|
|
66
|
+
* carries the hash, including names that needed no sanitizing, so no raw name
|
|
67
|
+
* can land on another's encoded form.
|
|
68
|
+
*
|
|
69
|
+
* Every name is then bounded by {@link toBoundedName}: cluster, database and
|
|
70
|
+
* role names are all caller-controlled and unbounded, and a `metadata.name` over
|
|
71
|
+
* {@link DNS_1123_SUBDOMAIN_MAX_LENGTH} is rejected by the Kubernetes API at
|
|
72
|
+
* apply time — after preview has passed, so the Secrets and the `DatabaseRole`
|
|
73
|
+
* the role needs are never created. The grant Job, which is bound by the
|
|
74
|
+
* stricter 63-character label limit, names itself: see `createPostgresGrantJob`.
|
|
75
|
+
*
|
|
76
|
+
* @param clusterName - CNPG cluster name
|
|
77
|
+
* @param dbName - Database name
|
|
78
|
+
* @param roleName - Role name as it exists in PostgreSQL
|
|
79
|
+
* @returns Naming for the additional role's resources, each within the DNS-1123
|
|
80
|
+
* subdomain limit
|
|
81
|
+
*/
|
|
82
|
+
export declare function additionalRoleNaming(clusterName: string, dbName: string, roleName: string): ICnpgRoleNaming;
|
|
83
|
+
/**
|
|
84
|
+
* PostgreSQL-specific role attributes.
|
|
85
|
+
*
|
|
86
|
+
* Mirrors `IDatabaseRoleConfig.engineOptions.postgresql`; declared separately so
|
|
87
|
+
* this module depends on a named shape rather than an inline anonymous one.
|
|
88
|
+
*/
|
|
89
|
+
export interface ICnpgPostgresRoleOptions {
|
|
90
|
+
/** Existing roles this role becomes a member of (e.g. `["pg_read_all_data"]`). */
|
|
91
|
+
readonly inRoles?: string[];
|
|
92
|
+
/** Maximum concurrent connections. Default: unlimited. */
|
|
93
|
+
readonly connectionLimit?: number;
|
|
94
|
+
/** Timestamp after which the password expires. */
|
|
95
|
+
readonly validUntil?: string;
|
|
96
|
+
}
|
|
97
|
+
/** Inputs for {@link provisionCnpgRole}. */
|
|
98
|
+
export interface ICnpgRoleOptions {
|
|
99
|
+
/** CNPG cluster the role belongs to. */
|
|
100
|
+
readonly clusterName: string;
|
|
101
|
+
/** Role name as it will exist in PostgreSQL, passed through verbatim. */
|
|
102
|
+
readonly roleName: string;
|
|
103
|
+
/** Pinned Pulumi and Kubernetes names for this role's resources. */
|
|
104
|
+
readonly naming: ICnpgRoleNaming;
|
|
105
|
+
/** Role configuration with defaults applied. */
|
|
106
|
+
readonly resolved: IResolvedRoleConfig;
|
|
107
|
+
/** Optional PostgreSQL-only role attributes. */
|
|
108
|
+
readonly postgresOptions?: ICnpgPostgresRoleOptions;
|
|
109
|
+
/** Labels applied to every created object. */
|
|
110
|
+
readonly labels: Record<string, string>;
|
|
111
|
+
/** The CNPG Cluster CR the role is created in. */
|
|
112
|
+
readonly cluster: k8s.apiextensions.CustomResource;
|
|
113
|
+
/** Kubernetes provider. */
|
|
114
|
+
readonly provider: k8s.Provider;
|
|
115
|
+
}
|
|
116
|
+
/** A provisioned role and the credentials backing it. */
|
|
117
|
+
export interface ICnpgProvisionedRole {
|
|
118
|
+
/** The `DatabaseRole` custom resource. */
|
|
119
|
+
readonly role: k8s.apiextensions.CustomResource;
|
|
120
|
+
/** The role's Opaque credential Secret and its stable password. */
|
|
121
|
+
readonly credentials: IRoleCredentials;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Provision one PostgreSQL role: a credential Secret, its basic-auth
|
|
125
|
+
* projection, and the `DatabaseRole` CR that reconciles the role itself.
|
|
126
|
+
*
|
|
127
|
+
* Two Secrets exist because `Secret.type` is immutable in Kubernetes: the
|
|
128
|
+
* Opaque credential Secret cannot be converted to `kubernetes.io/basic-auth`
|
|
129
|
+
* (the only shape the CNPG `DatabaseRole` controller reads) without a replace,
|
|
130
|
+
* which would regenerate the password.
|
|
131
|
+
*
|
|
132
|
+
* Adopting an existing role forces omitted attributes back to their defaults,
|
|
133
|
+
* so `login` is always set explicitly.
|
|
134
|
+
*
|
|
135
|
+
* @param options - Cluster, role name, pinned naming, and resolved config
|
|
136
|
+
* @returns The `DatabaseRole` CR plus the credentials it authenticates with
|
|
137
|
+
*/
|
|
138
|
+
export declare function provisionCnpgRole(options: ICnpgRoleOptions): ICnpgProvisionedRole;
|
|
139
|
+
/** Inputs for {@link replicateCnpgConnectionSecrets}. */
|
|
140
|
+
export interface ICnpgConnectionSecretOptions {
|
|
141
|
+
/** Pinned naming for the role whose credentials are replicated. */
|
|
142
|
+
readonly naming: ICnpgRoleNaming;
|
|
143
|
+
/** Namespaces to replicate into. */
|
|
144
|
+
readonly namespaces: ReadonlyArray<string>;
|
|
145
|
+
/** Database the connection points at. */
|
|
146
|
+
readonly dbName: string;
|
|
147
|
+
/** Role the connection authenticates as. */
|
|
148
|
+
readonly username: string;
|
|
149
|
+
/** The role's password, read back from its credential Secret. */
|
|
150
|
+
readonly password: pulumi.Output<string>;
|
|
151
|
+
/** Cluster read-write endpoint. */
|
|
152
|
+
readonly endpoint: pulumi.Output<string>;
|
|
153
|
+
/** Cluster port. */
|
|
154
|
+
readonly port: pulumi.Output<number>;
|
|
155
|
+
/** Labels applied to each Secret. */
|
|
156
|
+
readonly labels: Record<string, string>;
|
|
157
|
+
/** Kubernetes provider. */
|
|
158
|
+
readonly provider: k8s.Provider;
|
|
159
|
+
/** Resources each Secret must be created after — always includes the `Database` CR. */
|
|
160
|
+
readonly dependsOn: ReadonlyArray<pulumi.Resource>;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Replicate a role's connection details into each consuming namespace.
|
|
164
|
+
*
|
|
165
|
+
* The `username`, `password` and `database` keys carry raw values; only the
|
|
166
|
+
* composed `uri` percent-encodes them, because there a `@` or `:` in a role name
|
|
167
|
+
* would otherwise be read as a URI delimiter. See {@link encodeUriComponentValue}.
|
|
168
|
+
*
|
|
169
|
+
* @param options - Naming, namespaces, connection details, and dependencies
|
|
170
|
+
* @returns Map of namespace → created Secret name
|
|
171
|
+
*/
|
|
172
|
+
export declare function replicateCnpgConnectionSecrets(options: ICnpgConnectionSecretOptions): Record<string, pulumi.Output<string>>;
|
|
173
|
+
//# sourceMappingURL=cnpg-roles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cnpg-roles.d.ts","sourceRoot":"","sources":["../../../src/operator/cnpg-roles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AAQzC,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAC;AAO1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAOnE;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,uDAAuD;IACvD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,+DAA+D;IAC/D,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,2DAA2D;IAC3D,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,iEAAiE;IACjE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,6DAA6D;IAC7D,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,uEAAuE;IACvE,QAAQ,CAAC,wBAAwB,EAAE,MAAM,CAAC;IAC1C,4DAA4D;IAC5D,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,CAYpF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAA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