@mcpg-dev/pulumi

中文文档
0.1.0-beta.45发布于 2026/11/02Apache-2.0TypeScriptCommonJS构建来源已验证

Opinionated Pulumi components for MCPG (operator, gateway, tenant, trust).

原始使用文档
文档目录10 节
  1. Prerequisites
  2. Quick start
  3. Components
  4. Operator and CRD lifecycle
  5. Gateway readiness
  6. Tenancy: two different things
  7. Cluster credentials
  8. Configuration
  9. Licence
  10. See also

@mcpg/pulumi

Opinionated Pulumi components for running MCPG on Kubernetes: the operator, the CRDs, cluster trust, gateways, plugin sets, routes, and tenants. Each component wraps a piece of the platform that is easy to get subtly wrong — CRD lifecycle, gateway configuration shape, tenant isolation — behind typed TypeScript inputs. Built on @mcpg/pulumi-crds (the generated, typed CRD SDK) and @pulumi/kubernetes.

Reach for it when your MCPG deployment lives in a Pulumi program and you would rather express "one operator, one gateway, three tenants" than assemble Helm releases and raw custom resources by hand.

Prerequisites

  • Pulumi with the TypeScript runtime, and a Kubernetes provider configured for the target cluster.
  • cert-manager in the cluster, unless you turn it off. The operator's admission webhook fails closed and needs real TLS, so Operator sets certManager.enabled=true by default.

Quick start

import { McpgStack } from "@mcpg/pulumi";

new McpgStack("prod", {
  operator: { chartVersion: "<chart-version>" },
  gateway: {
    image: { repository: "ghcr.io/mcpg-dev/source-code/gateway", tag: "<tag>" },
    governance: { audit: { sinks: [{ kind: "dev.mcpg.builtin.audit.local-file" }] } },
  },
});

McpgStack composes the common case: an Operator, a TrustBootstrap seeding the cluster-default revocation list (set trust: false to skip it), and — when gateway is given — one Gateway in the operator's namespace. Both of the latter depend on the operator being installed first.

The package is built from this workspace:

pnpm --filter ./iac/pulumi/components run build       # tsc → bin/
pnpm --filter ./iac/pulumi/components exec tsc -b --noEmit   # tsc --noEmit

Components

ComponentCreates
OperatorThe operator Helm release plus the CRDs as first-class resources.
GatewayAn MCPGGateway, with spec.config assembled by the config builder.
PluginSetAn MCPGPluginSet — plugin entries and optional capability grants.
TrustBootstrapThe cluster-default MCPGRevocationList, and carries the signing-key reference.
ClusterAn MCPGCluster — the coordination backend a gateway's clusterRef points at.
RouteAn MCPGRoute — a tool subset bound into a shared gateway with identity, policy, and audit chains.
TenantCRAn MCPGTenant — declarative tenant governance.
TenantA namespace with isolation, and optionally a plugin set and a gateway.
McpgStackOperator plus trust plus one gateway.

Operator and CRD lifecycle

Helm installs the files under a chart's crds/ directory once and never upgrades or deletes them. Operator sidesteps that by applying the CRDs as a ConfigGroup it owns — server-side applied, upgraded like any other resource — and telling the chart to stand back with skipCrds plus crd.install=false. crdsDir points at the CRD YAMLs (default ../../codegen/schemas/v1alpha1/crds, resolved from the Pulumi program's directory).

The release defaults to namespace mcpg-system, chart mcpg-operator from ociChartRepo(), and cert-manager enabled. Set watchNamespace to restrict the operator to a single namespace. Anything in values is spread over those defaults, so a key you supply replaces the corresponding default block.

ociChartRepo() composes oci://<base>/charts from the registry coordinates in src/oci.ts, whose defaults mirror tools/release/oci-registry.json. Override one chart with chartRepo, or a whole stack with MCPG_OCI_HOST / MCPG_OCI_NAMESPACE / MCPG_OCI_PATH — the same environment contract the shell and Node publish helpers honour. ociImageRepo(name) and ociPluginRegistry() compose image and plugin references off the same base.

Gateway readiness

Gateway annotates the resource with pulumi.com/waitFor: condition=Ready, so pulumi up waits on the operator reporting the gateway ready rather than on the custom resource merely existing. Pass waitForReady: false to skip the wait.

Tenancy: two different things

Tenant is an imperative fan-out — it creates the namespace, a default-deny cross-tenant ingress NetworkPolicy (unless networkPolicy: false), and optionally a plugin set and a gateway inside it. Instantiate it in a loop to build a fleet. It does not create an MCPGTenant, so it does not engage the operator's tenant governance.

TenantCR creates the MCPGTenant custom resource: the plugin allowlist, per-namespace quotas, replica ceilings, and exclusive namespace ownership the operator enforces at admission. Use it when tenant boundaries must be enforced rather than merely arranged, alongside or instead of Tenant.

Cluster credentials

Cluster accepts credentialRefs naming pre-existing Secrets, and credentials, where an entry carrying data makes the component create the Secret in operatorNamespace (default mcpg-system) and wire the reference for you. Both forms surface to the gateway as cred://cluster/<name>. TrustBootstrap takes a signing-key Secret reference the same way: only the reference travels, never the key bytes, so no signing material lands in Pulumi state.

Configuration

Gateway builds the gateway's spec.config from typed sections. The operator passes that document through untouched, and the gateway parses it strictly — unknown keys are a boot-time error, which makes the shape worth getting right.

import { Gateway } from "@mcpg/pulumi";

new Gateway("orders", {
  namespace: "mcpg-system",
  image: { repository: "ghcr.io/mcpg-dev/source-code/gateway", tag: "<tag>" },
  server: { bind_address: "0.0.0.0:8080" },
  governance: { audit: { sinks: [{ kind: "dev.mcpg.builtin.audit.local-file" }] } },
  plugins: [
    { id: "dev.mcpg.backend.sql", source: { oci: "ghcr.io/mcpg-dev/source-code/plugins/backend-sql:protocol-1" } },
  ],
  extraConfig: { mcp: { capabilities: { tools: [] } } },
});
FieldTypeDefaultDescription
serverobjectomittedEmitted at config.gateway.server, under the gateway: umbrella — a top-level server key is rejected by the gateway's parser.
governanceobjectomittedEmitted at config.governance. Audit sinks are a list (audit.sinks[]), not a scalar.
observabilityobjectomittedEmitted at config.observability.
mcpobjectomittedEmitted at config.mcp.
pluginsarrayomittedEmitted at config.plugins, and only when non-empty. Each entry carries id and a source declaring exactly one of path or oci; the per-entry toggle is disabled, not enabled.
extraConfigobject{}An arbitrary configuration fragment merged last, so its top-level keys win. The escape hatch for anything the typed sections do not cover.

The same last-wins rule applies one level up: extraSpec on Gateway is merged over the assembled spec, after the typed passthrough blocks (acceptedRouteNamespaces, podAnnotations, podLabels, resources, service, ingress, autoscaling, monitoring, networkPolicy, podDisruptionBudget, workloadIdentity, scheduling, probes, imagePullSecrets).

The config builder's semantics are covered by unit tests that need no dependencies beyond Node itself:

pnpm --filter ./iac/pulumi/components run build
node --test iac/pulumi/components/bin/config.test.js

Licence

Apache-2.0.

See also

版本与发布记录

@mcpg-dev/pulumi 共发布 28 个版本,首次发布于 2026/08/13;过去 12 个月发布了 28 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.0-beta.45latest2026/11/021 天前
0.1.0-beta.442026/11/012 天前
0.1.0-beta.432026/10/304 天前
0.1.0-beta.412026/10/1915 天前
0.1.0-beta.402026/10/1816 天前
0.1.0-beta.392026/10/1717 天前

其他发布通道:canary → 0.1.0-canary.732,beta → 0.1.0-beta.13。

关于 @mcpg-dev/pulumi 的常见问题

@mcpg-dev/pulumi 是什么?

针对MCPG(运营商、网关、租户、信任)的固执己见的Pulumi组件。

如何安装 @mcpg-dev/pulumi?

在项目目录运行 npm install @mcpg-dev/pulumi,或使用 pnpm add / yarn add / bun add。

@mcpg-dev/pulumi 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@mcpg-dev/pulumi 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@mcpg-dev/pulumi 可以商用吗?

@mcpg-dev/pulumi 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@mcpg-dev/pulumi 还在维护吗?

最新版本 0.1.0-beta.45 发布于 2026/11/02(1 天前);至今共发布 28 个版本,其中过去 12 个月发布了 28 个;首次发布于 2026/08/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。