Skip to content

Commit

Permalink
fix: make spot weight optional and default to 60 (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
omBratteng authored Oct 30, 2024
1 parent dc64f68 commit 1b539b8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const urnPrefix = 'dailydotdev:pulumi-common';
export const defaultSpotWeight = 60;
8 changes: 5 additions & 3 deletions src/k8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import EnvVar = core.v1.EnvVar;
import { Resource } from '@pulumi/pulumi/resource';
import { camelToUnderscore } from './utils';
import { NodeLabels } from './kubernetes';
import { defaultSpotWeight } from './constants';

export type PodResources = { cpu?: string; memory?: string };

Expand Down Expand Up @@ -230,7 +231,7 @@ export type KubernetesApplicationArgs = {
}>;
spot?: {
enabled: boolean;
weight: number;
weight?: number;
required?: boolean;
};
};
Expand Down Expand Up @@ -288,7 +289,8 @@ export const createAutoscaledApplication = ({
const affinity: k8s.types.input.core.v1.Affinity = {};

if (spot?.enabled && !isAdhocEnv) {
const nonSpotWeight = 100 - spot.weight;
const spotWeight = spot?.weight ?? defaultSpotWeight;
const nonSpotWeight = 100 - spotWeight;
tolerations.push({
key: 'spot',
operator: 'Equal',
Expand All @@ -314,7 +316,7 @@ export const createAutoscaledApplication = ({
: {
preferredDuringSchedulingIgnoredDuringExecution: [
{
weight: spot.weight,
weight: spotWeight,
preference: {
matchExpressions: [
{
Expand Down
10 changes: 6 additions & 4 deletions src/suite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import { location } from '../config';
import { stripCpuFromLimits } from '../utils';
import { NodeLabels } from '../kubernetes';
import { defaultSpotWeight } from '../constants';

/**
* Takes a custom definition of an autoscaling metric and turn it into a k8s definition
Expand Down Expand Up @@ -156,7 +157,7 @@ function deployCron(
limits,
requests,
dependsOn,
spot = { enabled: false, weight: 50, required: false },
spot = { enabled: false, weight: defaultSpotWeight, required: false },
}: CronArgs,
): k8s.batch.v1.CronJob {
const appResourcePrefix = `${resourcePrefix}${
Expand All @@ -168,7 +169,8 @@ function deployCron(
const affinity: k8s.types.input.core.v1.Affinity = {};

if (spot?.enabled) {
const nonSpotWeight = 100 - spot.weight;
const spotWeight = spot?.weight ?? defaultSpotWeight;
const nonSpotWeight = 100 - spotWeight;
tolerations.push({
key: 'spot',
operator: 'Equal',
Expand All @@ -194,7 +196,7 @@ function deployCron(
: {
preferredDuringSchedulingIgnoredDuringExecution: [
{
weight: spot.weight,
weight: spotWeight,
preference: {
matchExpressions: [
{
Expand Down Expand Up @@ -322,7 +324,7 @@ function deployApplication(
ports = [],
servicePorts = [],
backendConfig,
spot = { enabled: false, weight: 60, required: false },
spot = { enabled: false, weight: defaultSpotWeight, required: false },
}: ApplicationArgs,
): ApplicationReturn {
const appResourcePrefix = `${resourcePrefix}${
Expand Down
4 changes: 2 additions & 2 deletions src/suite/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type ApplicationArgs = {
}>;
spot?: {
enabled: boolean;
weight: number;
weight?: number;
required?: boolean;
};
};
Expand Down Expand Up @@ -80,7 +80,7 @@ export type CronArgs = {
volumeMounts?: Input<Input<k8s.types.input.core.v1.VolumeMount>[]>;
spot?: {
enabled: boolean;
weight: number;
weight?: number;
required?: boolean;
};
};
Expand Down

0 comments on commit 1b539b8

Please sign in to comment.