Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deployment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"@pulumi/aws": "7.12.0",
"@pulumi/cloudflare": "4.16.0",
"@pulumi/command": "1.0.1",
"@pulumi/kubernetes": "4.23.0",
"@pulumi/kubernetes": "4.24.1",
"@pulumi/kubernetesx": "0.1.6",
"@pulumi/pulumi": "3.185.0",
"@pulumi/pulumi": "3.214.0",
"@pulumi/random": "4.18.2",
"js-yaml": "4.1.1",
"pg-connection-string": "2.9.1",
Expand Down
3 changes: 2 additions & 1 deletion deployment/services/supertokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as pulumi from '@pulumi/pulumi';
import * as random from '@pulumi/random';
import { serviceLocalEndpoint } from '../utils/local-endpoint';
import { ServiceSecret } from '../utils/secrets';
import { createService } from '../utils/service-deployment';
import { Environment } from './environment';
import { Postgres } from './postgres';

Expand Down Expand Up @@ -95,7 +96,7 @@ export function deploySuperTokens(
},
);

const service = deployment.createService({});
const service = createService('supertokens', deployment);

return {
deployment,
Expand Down
3 changes: 2 additions & 1 deletion deployment/utils/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Output } from '@pulumi/pulumi';
import { memoryParser } from './k8s';
import { getLocalComposeConfig } from './local-config';
import { normalizeEnv, PodBuilder } from './pod-builder';
import { createService } from './service-deployment';

const REDIS_PORT = 6379;
const METRICS_PORT = 9121;
Expand Down Expand Up @@ -168,7 +169,7 @@ export class Redis {
},
});

const service = deployment.createService({});
const service = createService(name, deployment);

return { deployment, service, redisPort: REDIS_PORT, metricsPort: METRICS_PORT };
}
Expand Down
3 changes: 0 additions & 3 deletions deployment/utils/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ export class ServiceSecret<T extends Record<string, string | Output<string>>> {
) {
this.raw = data;
this.record = new k8s.core.v1.Secret(this.name, {
metadata: {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't set explicit name, then Pulumi will use the this.name (pass the the ctor) and will appends some suffix to it. Since Secrets are immutable, when we change the secret, it will re-create a new one with a new suffix, leading to a chain of reaction that causes a RollingUpgrade to the pod.

If we explicitly set the name, then when the secret changes, we get a new one, and the Deployment needs to be re-created (instead of updated to point to the new Secret), and this leads to downtime as the pod is replaced without rolling upgrade.

name: this.name,
},
stringData: this.data,
type: 'Opaque',
});
Expand Down
31 changes: 30 additions & 1 deletion deployment/utils/service-deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export class ServiceDeployment {
});
}

const service = deployment.createService({});
const service = createService(this.name, deployment);

if (this.options.autoScaling) {
new k8s.autoscaling.v2.HorizontalPodAutoscaler(
Expand Down Expand Up @@ -360,3 +360,32 @@ export class ServiceDeployment {
return { deployment, service };
}
}

export function createService(name: string, deployment: kx.Deployment) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main difference from @pulumi/kubernetesx are:

  • we evaluate labels and ports separately (instead of grouping them together and construct the spec field) - this leads to loose dependency and only change the Service if the port or labels has chaneged (instead of any change).
  • No parent set on the Pulumi resource, so no strict coupling between the Service and the Deployment.

const labels = deployment.spec.selector.matchLabels;
const ports = deployment.spec.template.spec.containers.apply(containers => {
const ports: { name: string; port: number }[] = [];

containers.forEach(container => {
if (container.ports) {
container.ports.forEach(port => {
ports.push({ name: port.name || name, port: port.containerPort });
});
}
});

return ports;
});

return new k8s.core.v1.Service(
name,
{
spec: {
ports: ports,
selector: labels,
type: 'ClusterIP',
},
},
{},
);
}
Loading
Loading