console/deployment/utils/pod-builder.ts

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-05-18 07:26:57 +00:00
import * as k8s from '@pulumi/kubernetes';
2022-12-28 19:22:54 +00:00
import * as kx from '@pulumi/kubernetesx';
2022-05-18 07:26:57 +00:00
import * as pulumi from '@pulumi/pulumi';
export function normalizeEnv(env: kx.types.Container['env']): any[] {
if (env == null) {
return [];
}
if (Array.isArray(env)) {
return env;
}
return Object.keys(env).map(name => ({
name,
value: (env as kx.types.EnvMap)[name],
}));
2022-05-18 07:26:57 +00:00
}
export class PodBuilder extends kx.PodBuilder {
public asExtendedDeploymentSpec(
args?: kx.types.PodBuilderDeploymentSpec,
metadata?: k8s.types.input.meta.v1.ObjectMeta,
2022-05-18 07:26:57 +00:00
): pulumi.Output<k8s.types.input.apps.v1.DeploymentSpec> {
const podName = this.podSpec.containers.apply((containers: any) => {
return pulumi.output(containers[0].name);
});
const appLabels = { app: podName };
const _args = args || {};
const deploymentSpec: k8s.types.input.apps.v1.DeploymentSpec = {
..._args,
selector: { matchLabels: appLabels },
replicas: _args.replicas ?? 1,
template: {
metadata: { labels: appLabels, ...metadata },
2022-05-18 07:26:57 +00:00
spec: this.podSpec,
},
};
return pulumi.output(deploymentSpec);
}
}