mirror of
https://github.com/graphql-hive/console
synced 2026-04-21 14:37:17 +00:00
fix(deployment): pass --maxmemory to Redis instance (#6737)
This commit is contained in:
parent
c6badf5fe7
commit
8e3873fa46
2 changed files with 36 additions and 1 deletions
23
deployment/utils/k8s.ts
Normal file
23
deployment/utils/k8s.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
const memoryMultipliers: Record<string, number> = {
|
||||
k: 1000,
|
||||
M: 1000 ** 2,
|
||||
G: 1000 ** 3,
|
||||
T: 1000 ** 4,
|
||||
P: 1000 ** 5,
|
||||
E: 1000 ** 6,
|
||||
Ki: 1024,
|
||||
Mi: 1024 ** 2,
|
||||
Gi: 1024 ** 3,
|
||||
Ti: 1024 ** 4,
|
||||
Pi: 1024 ** 5,
|
||||
Ei: 1024 ** 6,
|
||||
} as const;
|
||||
|
||||
export function memoryParser(input: string): number {
|
||||
const unitMatch = input.match(/^([0-9]+)([A-Za-z]{1,2})$/);
|
||||
if (unitMatch) {
|
||||
return parseInt(unitMatch[1], 10) * memoryMultipliers[unitMatch[2]];
|
||||
}
|
||||
|
||||
return parseInt(input, 10);
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import * as k8s from '@pulumi/kubernetes';
|
||||
import * as kx from '@pulumi/kubernetesx';
|
||||
import { Output } from '@pulumi/pulumi';
|
||||
import { memoryParser } from './k8s';
|
||||
import { getLocalComposeConfig } from './local-config';
|
||||
import { normalizeEnv, PodBuilder } from './pod-builder';
|
||||
|
||||
|
|
@ -16,9 +17,13 @@ export class Redis {
|
|||
},
|
||||
) {}
|
||||
|
||||
deploy({ limits }: { limits: k8s.types.input.core.v1.ResourceRequirements['limits'] }) {
|
||||
deploy(input: { limits: { memory: string; cpu: string } }) {
|
||||
const redisService = getLocalComposeConfig().service('redis');
|
||||
const name = 'redis-store';
|
||||
const limits: k8s.types.input.core.v1.ResourceRequirements['limits'] = {
|
||||
memory: input.limits.memory,
|
||||
cpu: input.limits.cpu,
|
||||
};
|
||||
|
||||
const env: k8s.types.input.core.v1.EnvVar[] = normalizeEnv(this.options.env ?? {}).concat([
|
||||
{
|
||||
|
|
@ -76,6 +81,9 @@ export class Redis {
|
|||
},
|
||||
];
|
||||
|
||||
const memoryInBytes = memoryParser(input.limits.memory) * 0.8; // Redis recommends 80%
|
||||
const memoryInMegabytes = Math.floor(memoryInBytes / 1024 / 1024);
|
||||
|
||||
const pb = new PodBuilder({
|
||||
restartPolicy: 'Always',
|
||||
containers: [
|
||||
|
|
@ -97,6 +105,10 @@ export class Redis {
|
|||
command: ['/bin/sh', '/scripts/liveness.sh'],
|
||||
},
|
||||
},
|
||||
// Note: this is needed, otherwise local config is not loaded at all
|
||||
command: ['/opt/bitnami/scripts/redis/entrypoint.sh'],
|
||||
// This is where we can pass actual flags to the bitnami/redis runtime
|
||||
args: ['/opt/bitnami/scripts/redis/run.sh', `--maxmemory ${memoryInMegabytes}mb`],
|
||||
readinessProbe: {
|
||||
initialDelaySeconds: 5,
|
||||
periodSeconds: 8,
|
||||
|
|
|
|||
Loading…
Reference in a new issue