Skip to content

Commit

Permalink
feat(k8s.construct.api): utilize getResources to merge resources fo…
Browse files Browse the repository at this point in the history
…r each component

Signed-off-by: Braden Mars <[email protected]>
  • Loading branch information
BradenM committed Sep 30, 2024
1 parent 9a54571 commit cc6868c
Showing 1 changed file with 40 additions and 36 deletions.
76 changes: 40 additions & 36 deletions packages/k8s/construct/api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ export class ApiWSGI
}) as ApiWSGIProps
super(scope, id, propsWithDefaults)

const resources = this.getResources({
cpu: {
request: 1000,
limit: 1800,
},
memory: {
request: 1200,
limit: 1200,
},
})

const backend = this.addContainer({
name: 'gunicorn',
portNumber: 5000,
Expand All @@ -220,17 +231,7 @@ export class ApiWSGI
'--timeout=90',
],
...(props.probes ?? this.createHttpProbes(this.httpProbePath)),
// todo: allow config via configs schema
resources: {
cpu: {
request: kplus.Cpu.millis(1000),
limit: kplus.Cpu.millis(1800),
},
memory: {
request: Size.mebibytes(1200),
limit: Size.mebibytes(1200),
},
},
resources,
})

const staticVolume = kplus.Volume.fromEmptyDir(
Expand Down Expand Up @@ -526,6 +527,15 @@ export class CeleryBeat extends ApiComponent {

constructor(scope: Construct, id: string, props: ApiProps) {
super(scope, id, props)
const resources = this.getResources({
cpu: {
request: 20,
},
memory: {
request: 400,
limit: 400,
},
})
this.addContainer({
name: 'celerybeat',
command: ['/serve.sh', 'celerybeat'],
Expand All @@ -536,15 +546,7 @@ export class CeleryBeat extends ApiComponent {
user: 1000,
group: 1000,
},
resources: {
cpu: {
request: kplus.Cpu.millis(20),
},
memory: {
request: Size.mebibytes(400),
limit: Size.mebibytes(400),
},
},
resources,
})
}

Expand All @@ -564,6 +566,13 @@ export class CeleryWorker extends ApiComponent<CeleryProps> {

const queues = [...new Set(props.queues)]

const resources = this.getResources({
memory: {
limit: 900,
request: 900,
},
})

this.addContainer({
name,
command: [
Expand All @@ -583,13 +592,7 @@ export class CeleryWorker extends ApiComponent<CeleryProps> {
user: 1000,
group: 1000,
},
resources: {
cpu: this.props.containerDefaults!.resources!.cpu!,
memory: {
limit: Size.mebibytes(900),
request: Size.mebibytes(900),
},
},
resources,
})
}
}
Expand All @@ -599,6 +602,15 @@ export class AdminWebSocket extends ApiComponent {

constructor(scope: Construct, id: string, props: ApiProps) {
super(scope, id, props)
const resources = this.getResources({
cpu: {
request: 3,
},
memory: {
request: 250,
limit: 250,
},
})
this.addContainer({
name: 'adminwebsocket',
command: ['/serve.sh', 'adminwebsocket'],
Expand All @@ -609,15 +621,7 @@ export class AdminWebSocket extends ApiComponent {
user: 1000,
group: 1000,
},
resources: {
cpu: {
request: kplus.Cpu.millis(3),
},
memory: {
request: Size.mebibytes(250),
limit: Size.mebibytes(250),
},
},
resources,
})
}
}

0 comments on commit cc6868c

Please sign in to comment.