Skip to content
Open
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
1 change: 1 addition & 0 deletions apps/supervisor/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const Env = z.object({
KUBERNETES_MEMORY_REQUEST_MIN_GB: z.coerce.number().min(0).default(0),
KUBERNETES_MEMORY_REQUEST_RATIO: z.coerce.number().min(0).max(1).default(1), // Ratio of memory limit, so 1 = 100% of memory limit
KUBERNETES_MEMORY_OVERHEAD_GB: z.coerce.number().min(0).optional(), // Optional memory overhead to add to the limit in GB
KUBERNETES_TOPOLOGY_SPREAD_CONSTRAINTS: z.string().optional(), // JSON string

// Placement tags settings
PLACEMENT_TAGS_ENABLED: BoolEnv.default(false),
Expand Down
19 changes: 19 additions & 0 deletions apps/supervisor/src/workloadManager/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ export class KubernetesWorkloadManager implements WorkloadManager {
};
}

private parseTopologySpreadConstraints(): k8s.V1TopologySpreadConstraint[] | null {
if (!env.KUBERNETES_TOPOLOGY_SPREAD_CONSTRAINTS) {
return null;
}

try {
return JSON.parse(env.KUBERNETES_TOPOLOGY_SPREAD_CONSTRAINTS);
} catch (error) {
this.logger.error("[KubernetesWorkloadManager] Failed to parse topology spread constraints", {
error: error instanceof Error ? error.message : String(error),
raw: env.KUBERNETES_TOPOLOGY_SPREAD_CONSTRAINTS,
});
return null;
}
}

private stripImageDigest(imageRef: string): string {
if (!env.KUBERNETES_STRIP_IMAGE_DIGEST) {
return imageRef;
Expand Down Expand Up @@ -270,6 +286,8 @@ export class KubernetesWorkloadManager implements WorkloadManager {
}

get #defaultPodSpec(): Omit<k8s.V1PodSpec, "containers"> {
const topologySpreadConstraints = this.parseTopologySpreadConstraints();

return {
restartPolicy: "Never",
automountServiceAccountToken: false,
Expand All @@ -281,6 +299,7 @@ export class KubernetesWorkloadManager implements WorkloadManager {
},
}
: {}),
...(topologySpreadConstraints ? { topologySpreadConstraints } : {}),
};
}

Expand Down
2 changes: 1 addition & 1 deletion hosting/k8s/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: trigger
description: The official Trigger.dev Helm chart
type: application
version: 4.0.1
version: 4.0.2
appVersion: v4.0.4
home: https://trigger.dev
sources:
Expand Down
8 changes: 8 additions & 0 deletions hosting/k8s/helm/templates/supervisor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ spec:
value: {{ default "10Gi" .Values.supervisor.config.kubernetes.ephemeralStorageSizeLimit | quote }}
- name: KUBERNETES_EPHEMERAL_STORAGE_SIZE_REQUEST
value: {{ default "2Gi" .Values.supervisor.config.kubernetes.ephemeralStorageSizeRequest | quote }}
{{- with .Values.supervisor.config.kubernetes.topologySpreadConstraints }}
- name: KUBERNETES_TOPOLOGY_SPREAD_CONSTRAINTS
value: {{ tpl (toYaml .) $ | toJson | quote }}
{{- end }}
Comment on lines +187 to +190

Choose a reason for hiding this comment

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

I realize I requested adding support for topology spread constraints for the jobs too but I am not sure if, in practice, it would be effective, since only a single replica of a job is running at any given time, correct? If so, I suggest removing this for now.

# Pod cleaner configuration
- name: POD_CLEANER_ENABLED
value: {{ .Values.supervisor.config.podCleaner.enabled | quote }}
Expand Down Expand Up @@ -272,6 +276,10 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.supervisor.topologySpreadConstraints }}
topologySpreadConstraints:
{{- tpl (toYaml .) $ | nindent 8 }}
{{- end }}
Comment on lines +279 to +282

Choose a reason for hiding this comment

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

It seems that supervisor deployment is locked to a replica count of 1. Curious what the reason for that is?

Choose a reason for hiding this comment

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

The reason I am asking is, although it's good to have the topology spread constraints config surfaced to users, it's likely going to be ineffectual because of the replica count being locked to 1.

---
apiVersion: v1
kind: Service
Expand Down
4 changes: 4 additions & 0 deletions hosting/k8s/helm/templates/webapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.webapp.topologySpreadConstraints }}
topologySpreadConstraints:
{{- tpl (toYaml .) $ | nindent 8 }}
{{- end }}
---
apiVersion: v1
kind: Service
Expand Down
6 changes: 6 additions & 0 deletions hosting/k8s/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ webapp:
nodeSelector: {}
tolerations: []
affinity: {}
# Topology Spread Constraints for pod assignment spread across your cluster among failure-domains. Evaluated as a template
topologySpreadConstraints: []

logLevel: "info"
gracefulShutdownTimeout: 1000
Expand Down Expand Up @@ -263,6 +265,8 @@ supervisor:
workerNodetypeLabel: "" # When set, runs will only be scheduled on nodes with "nodetype=<label>"
ephemeralStorageSizeLimit: "" # Default: 10Gi
ephemeralStorageSizeRequest: "" # Default: 2Gi´
# Topology Spread Constraints for worker pods created by the supervisor. Evaluated as a template
topologySpreadConstraints: []
podCleaner:
enabled: true
batchSize: 100
Expand Down Expand Up @@ -353,6 +357,8 @@ supervisor:
nodeSelector: {}
tolerations: []
affinity: {}
# Topology Spread Constraints for pod assignment spread across your cluster among failure-domains. Evaluated as a template
topologySpreadConstraints: []

# PostgreSQL configuration
# Subchart: https://github.com/bitnami/charts/tree/main/bitnami/postgresql
Expand Down
Loading