Skip to content

Commit a074bd6

Browse files
authored
feat: add resource requests/limits to postgres-package (#14)
* feat: add resource requests/limits to postgres-package * Update kurtosis.yml * fix lint * fix replace * fix replace * add new line
1 parent a82017a commit a074bd6

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

kurtosis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ name: "github.com/kurtosis-tech/postgres-package"
22
description: |
33
# Postgres
44
This is the Kurtosis package for launching a Postgres instance. It also contains configuration parameters to help get going with the instance; see the `main.star#run` function for details.
5+

main.star

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ DATA_DIRECTORY_PATH = "/data/"
1010

1111
CONFIG_FILENAME = "postgresql.conf" # Expected to be in the artifact
1212

13+
POSTGRES_MIN_CPU = 10
14+
POSTGRES_MAX_CPU = 1000
15+
POSTGRES_MIN_MEMORY = 32
16+
POSTGRES_MAX_MEMORY = 1024
17+
1318

1419
def run(
1520
plan,
@@ -23,6 +28,10 @@ def run(
2328
extra_configs=[],
2429
persistent=True,
2530
launch_adminer=False,
31+
min_cpu=POSTGRES_MIN_CPU,
32+
max_cpu=POSTGRES_MAX_CPU,
33+
min_memory=POSTGRES_MIN_MEMORY,
34+
max_memory=POSTGRES_MAX_MEMORY,
2635
):
2736
"""Launches a Postgresql database instance, optionally seeding it with a SQL file script
2837
@@ -38,7 +47,11 @@ def run(
3847
If not empty, the Postgres server will be populated with the data upon start
3948
extra_configs (list[string]): Each argument gets passed as a '-c' argument to the Postgres server
4049
persistent (bool): Whether the data should be persisted. Defaults to True; Note that this isn't supported on multi node k8s cluster as of 2023-10-16
41-
launch_adminer (bool): Whether to launch adminer which launches a website to inspect postgres database entries. Defaults to False.
50+
launch_adminer (bool): Whether to launch adminer which launches a website to inspect postgres database entries. Defaults to False.
51+
min_cpu (int): Define how much CPU millicores the service should be assigned at least.
52+
max_cpu (int): Define how much CPU millicores the service should be assign max.
53+
min_memory (int): Define how much MB of memory the service should be assigned at least.
54+
max_memory (int): Define how much MB of memory the service should be assigned max.
4255
Returns:
4356
An object containing useful information about the Postgres database running inside the enclave:
4457
```
@@ -109,16 +122,21 @@ def run(
109122
cmd=cmd,
110123
files=files,
111124
env_vars=env_vars,
125+
min_cpu=min_cpu,
126+
max_cpu=max_cpu,
127+
min_memory=min_memory,
128+
max_memory=max_memory,
112129
),
113130
)
114131

115132
if launch_adminer:
116-
adminer = adminer_module.run(plan,
117-
default_db=database,
118-
default_driver=PG_DRIVER,
119-
default_password=password,
120-
default_server=postgres_service.hostname,
121-
default_username=user
133+
adminer = adminer_module.run(
134+
plan,
135+
default_db=database,
136+
default_driver=PG_DRIVER,
137+
default_password=password,
138+
default_server=postgres_service.hostname,
139+
default_username=user,
122140
)
123141

124142
url = "{protocol}://{user}:{password}@{hostname}/{database}".format(
@@ -136,6 +154,10 @@ def run(
136154
user=user,
137155
password=password,
138156
database=database,
157+
min_cpu=min_cpu,
158+
max_cpu=max_cpu,
159+
min_memory=min_memory,
160+
max_memory=max_memory,
139161
)
140162

141163

0 commit comments

Comments
 (0)