Skip to content

Commit 9141974

Browse files
0.4.8 backport: Pulumi: Support creating arbitrary CRs via infra stack (#1715)
Backports #1715 so we can use on DevNet right away. [static] Signed-off-by: Martin Florian <martin.florian@digitalasset.com>
1 parent 07de6d1 commit 9141974

File tree

5 files changed

+149
-0
lines changed

5 files changed

+149
-0
lines changed

cluster/deployment/mock/config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,30 @@ svs:
117117
kms:
118118
keyRingId: sv-3_participant_mock
119119
locationId: us-central1
120+
infra:
121+
extraCustomResources:
122+
deny-onboard-prepare-endpoint:
123+
apiVersion: security.istio.io/v1
124+
kind: AuthorizationPolicy
125+
metadata:
126+
name: deny-onboard-prepare-endpoint
127+
# if we pass a list here, pulumi will multiply the CR for us
128+
namespace: [ sv-1, sv-2 ]
129+
spec:
130+
selector:
131+
matchLabels:
132+
app: sv-app
133+
action: DENY
134+
rules:
135+
- to:
136+
- operation:
137+
paths: ["/api/sv/v0/devnet/onboard/validator/prepare"]
138+
mock-cr:
139+
apiVersion: mock.example.com/v1
140+
kind: MockResource
141+
metadata:
142+
name: mock-resource
143+
namespace: validator1
144+
spec:
145+
key: value
146+
anotherKey: anotherValue

cluster/expected/infra/expected.json

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,25 @@
20472047
"provider": "",
20482048
"type": "command:local:Command"
20492049
},
2050+
{
2051+
"custom": true,
2052+
"id": "",
2053+
"inputs": {
2054+
"apiVersion": "mock.example.com/v1",
2055+
"kind": "MockResource",
2056+
"metadata": {
2057+
"name": "mock-resource",
2058+
"namespace": "validator1"
2059+
},
2060+
"spec": {
2061+
"anotherKey": "anotherValue",
2062+
"key": "value"
2063+
}
2064+
},
2065+
"name": "mock-cr",
2066+
"provider": "",
2067+
"type": "kubernetes:mock.example.com/v1:MockResource"
2068+
},
20502069
{
20512070
"custom": true,
20522071
"id": "",
@@ -2928,6 +2947,78 @@
29282947
"provider": "",
29292948
"type": "kubernetes:core/v1:Secret"
29302949
},
2950+
{
2951+
"custom": true,
2952+
"id": "",
2953+
"inputs": {
2954+
"apiVersion": "security.istio.io/v1",
2955+
"kind": "AuthorizationPolicy",
2956+
"metadata": {
2957+
"name": "deny-onboard-prepare-endpoint",
2958+
"namespace": "sv-1"
2959+
},
2960+
"spec": {
2961+
"action": "DENY",
2962+
"rules": [
2963+
{
2964+
"to": [
2965+
{
2966+
"operation": {
2967+
"paths": [
2968+
"/api/sv/v0/devnet/onboard/validator/prepare"
2969+
]
2970+
}
2971+
}
2972+
]
2973+
}
2974+
],
2975+
"selector": {
2976+
"matchLabels": {
2977+
"app": "sv-app"
2978+
}
2979+
}
2980+
}
2981+
},
2982+
"name": "sv-1-deny-onboard-prepare-endpoint",
2983+
"provider": "",
2984+
"type": "kubernetes:security.istio.io/v1:AuthorizationPolicy"
2985+
},
2986+
{
2987+
"custom": true,
2988+
"id": "",
2989+
"inputs": {
2990+
"apiVersion": "security.istio.io/v1",
2991+
"kind": "AuthorizationPolicy",
2992+
"metadata": {
2993+
"name": "deny-onboard-prepare-endpoint",
2994+
"namespace": "sv-2"
2995+
},
2996+
"spec": {
2997+
"action": "DENY",
2998+
"rules": [
2999+
{
3000+
"to": [
3001+
{
3002+
"operation": {
3003+
"paths": [
3004+
"/api/sv/v0/devnet/onboard/validator/prepare"
3005+
]
3006+
}
3007+
}
3008+
]
3009+
}
3010+
],
3011+
"selector": {
3012+
"matchLabels": {
3013+
"app": "sv-app"
3014+
}
3015+
}
3016+
}
3017+
},
3018+
"name": "sv-2-deny-onboard-prepare-endpoint",
3019+
"provider": "",
3020+
"type": "kubernetes:security.istio.io/v1:AuthorizationPolicy"
3021+
},
29313022
{
29323023
"custom": true,
29333024
"id": "",

cluster/pulumi/infra/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const InfraConfigSchema = z.object({
5353
istio: z.object({
5454
enableIngressAccessLogging: z.boolean(),
5555
}),
56+
extraCustomResources: z.object({}).catchall(z.any()).default({}),
5657
}),
5758
monitoring: MonitoringConfigSchema,
5859
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import * as k8s from '@pulumi/kubernetes';
4+
5+
import { infraConfig } from './config';
6+
7+
// Automatically duplicates CRs if multiple namespaces given
8+
export function installExtraCustomResources(): void {
9+
const extraCrs = infraConfig.extraCustomResources;
10+
Object.entries(extraCrs).forEach(([name, spec]) => {
11+
if (Array.isArray(spec.metadata?.namespace)) {
12+
spec.metadata.namespace.forEach((ns: string) => {
13+
const patchedName = `${ns}-${name}`;
14+
const patchedSpec = {
15+
...spec,
16+
metadata: {
17+
...spec.metadata,
18+
namespace: ns,
19+
},
20+
};
21+
new k8s.apiextensions.CustomResource(patchedName, patchedSpec);
22+
});
23+
} else {
24+
new k8s.apiextensions.CustomResource(name, spec);
25+
}
26+
});
27+
}

cluster/pulumi/infra/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { config } from 'splice-pulumi-common';
66
import { clusterIsResetPeriodically, enableAlerts } from './alertings';
77
import { configureAuth0 } from './auth0';
88
import { clusterBaseDomain, clusterBasename, monitoringConfig } from './config';
9+
import { installExtraCustomResources } from './extraCustomResources';
910
import {
1011
getNotificationChannel,
1112
installCloudSQLMaintenanceUpdateAlerts,
@@ -40,6 +41,8 @@ istioMonitoring(network.ingressNs, []);
4041

4142
configureStorage();
4243

44+
installExtraCustomResources();
45+
4346
let configuredAuth0;
4447
if (config.envFlag('CLUSTER_CONFIGURE_AUTH0', true)) {
4548
configuredAuth0 = configureAuth0(clusterBasename, network.dnsNames);

0 commit comments

Comments
 (0)