1
1
import * as k8s from '@pulumi/kubernetes' ;
2
2
import * as kx from '@pulumi/kubernetesx' ;
3
3
import { Output } from '@pulumi/pulumi' ;
4
+ import { memoryParser } from './k8s' ;
4
5
import { getLocalComposeConfig } from './local-config' ;
5
6
import { normalizeEnv , PodBuilder } from './pod-builder' ;
6
7
@@ -16,9 +17,13 @@ export class Redis {
16
17
} ,
17
18
) { }
18
19
19
- deploy ( { limits } : { limits : k8s . types . input . core . v1 . ResourceRequirements [ 'limits' ] } ) {
20
+ deploy ( input : { limits : { memory : string ; cpu : string } } ) {
20
21
const redisService = getLocalComposeConfig ( ) . service ( 'redis' ) ;
21
22
const name = 'redis-store' ;
23
+ const limits : k8s . types . input . core . v1 . ResourceRequirements [ 'limits' ] = {
24
+ memory : input . limits . memory ,
25
+ cpu : input . limits . cpu ,
26
+ } ;
22
27
23
28
const env : k8s . types . input . core . v1 . EnvVar [ ] = normalizeEnv ( this . options . env ?? { } ) . concat ( [
24
29
{
@@ -76,6 +81,9 @@ export class Redis {
76
81
} ,
77
82
] ;
78
83
84
+ const memoryInBytes = memoryParser ( input . limits . memory ) * 0.8 ; // Redis recommends 80%
85
+ const memoryInMegabytes = Math . floor ( memoryInBytes / 1024 / 1024 ) ;
86
+
79
87
const pb = new PodBuilder ( {
80
88
restartPolicy : 'Always' ,
81
89
containers : [
@@ -97,6 +105,10 @@ export class Redis {
97
105
command : [ '/bin/sh' , '/scripts/liveness.sh' ] ,
98
106
} ,
99
107
} ,
108
+ // Note: this is needed, otherwise local config is not loaded at all
109
+ command : [ '/opt/bitnami/scripts/redis/entrypoint.sh' ] ,
110
+ // This is where we can pass actual flags to the bitnami/redis runtime
111
+ args : [ '/opt/bitnami/scripts/redis/run.sh' , `--maxmemory ${ memoryInMegabytes } mb` ] ,
100
112
readinessProbe : {
101
113
initialDelaySeconds : 5 ,
102
114
periodSeconds : 8 ,
0 commit comments