Skip to content

Commit 35cd6f5

Browse files
committed
fixup! fixup! Restore gc admin password after snapshot restore
1 parent 02f9fdb commit 35cd6f5

File tree

6 files changed

+30
-8
lines changed

6 files changed

+30
-8
lines changed

crate/operator/bootstrap.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
from kubernetes_asyncio.stream import WsApiClient
3030

3131
from crate.operator.config import config
32-
from crate.operator.constants import CONNECT_TIMEOUT, GC_USERNAME, SYSTEM_USERNAME
32+
from crate.operator.constants import (
33+
CONNECT_TIMEOUT,
34+
GC_USER_SECRET_NAME,
35+
GC_USERNAME,
36+
SYSTEM_USERNAME,
37+
)
3338
from crate.operator.cratedb import create_user, get_connection
3439
from crate.operator.utils import crate
3540
from crate.operator.utils.k8s_api_client import GlobalApiClient
@@ -205,7 +210,9 @@ async def bootstrap_gc_admin_user(core: CoreV1Api, namespace: str, name: str):
205210
async with get_connection(host, password, timeout=CONNECT_TIMEOUT) as conn:
206211
async with conn.cursor() as cursor:
207212
password = await resolve_secret_key_ref(
208-
core, namespace, {"key": "password", "name": f"user-gc-{name}"}
213+
core,
214+
namespace,
215+
{"key": "password", "name": GC_USER_SECRET_NAME.format(name=name)},
209216
)
210217
await create_user(cursor, namespace, name, GC_USERNAME, password)
211218

crate/operator/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
SYSTEM_USERNAME = "system"
3636
GC_USERNAME = "gc_admin"
37+
GC_USER_SECRET_NAME = "user-gc-{name}"
3738

3839
CONNECT_TIMEOUT = 10.0
3940

crate/operator/create.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
DCUTIL_BINARY,
9696
DCUTIL_CHECKSUM,
9797
DECOMMISSION_TIMEOUT,
98+
GC_USER_SECRET_NAME,
9899
LABEL_COMPONENT,
99100
LABEL_MANAGED_BY,
100101
LABEL_NAME,
@@ -1217,7 +1218,7 @@ def get_gc_user_secret(
12171218
return V1Secret(
12181219
data={"password": b64encode(gen_password(50))},
12191220
metadata=V1ObjectMeta(
1220-
name=f"user-gc-{name}",
1221+
name=GC_USER_SECRET_NAME.format(name=name),
12211222
labels=labels,
12221223
owner_references=owner_references,
12231224
),

crate/operator/grand_central.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
from crate.operator.bootstrap import bootstrap_gc_admin_user
6868
from crate.operator.config import config
6969
from crate.operator.constants import (
70+
GC_USER_SECRET_NAME,
7071
GC_USERNAME,
7172
GRAND_CENTRAL_BACKEND_API_PORT,
7273
GRAND_CENTRAL_INIT_CONTAINER,
@@ -133,7 +134,7 @@ def get_grand_central_deployment(
133134
name="GRAND_CENTRAL_CRATEDB_PASSWORD",
134135
value_from=V1EnvVarSource(
135136
secret_key_ref=V1SecretKeySelector(
136-
key="password", name=f"user-gc-{name}"
137+
key="password", name=GC_USER_SECRET_NAME.format(name=name)
137138
),
138139
),
139140
),

crate/operator/utils/kubeapi.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@
3232
)
3333

3434
from crate.operator.config import config
35-
from crate.operator.constants import API_GROUP, LABEL_USER_PASSWORD, RESOURCE_CRATEDB
35+
from crate.operator.constants import (
36+
API_GROUP,
37+
GC_USER_SECRET_NAME,
38+
LABEL_USER_PASSWORD,
39+
RESOURCE_CRATEDB,
40+
)
3641
from crate.operator.utils.formatting import b64decode
3742
from crate.operator.utils.k8s_api_client import GlobalApiClient
3843
from crate.operator.utils.typing import K8sModel, SecretKeyRef
@@ -247,5 +252,7 @@ async def get_gc_user_password(core: CoreV1Api, namespace: str, name: str) -> st
247252
:param name: The name of the CrateDB cluster.
248253
"""
249254
return await resolve_secret_key_ref(
250-
core, namespace, {"key": "password", "name": f"user-gc-{name}"}
255+
core,
256+
namespace,
257+
{"key": "password", "name": GC_USER_SECRET_NAME.format(name=name)},
251258
)

tests/test_create_grand_central.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from crate.operator.constants import (
3232
API_GROUP,
33+
GC_USER_SECRET_NAME,
3334
GC_USERNAME,
3435
GRAND_CENTRAL_PROMETHEUS_PORT,
3536
GRAND_CENTRAL_RESOURCE_PREFIX,
@@ -200,10 +201,14 @@ async def test_create_grand_central(faker, namespace, kopf_runner, api_client):
200201
does_secret_exist,
201202
core,
202203
namespace.metadata.name,
203-
f"user-gc-{name}",
204+
GC_USER_SECRET_NAME.format(name=name),
204205
)
205206
secrets = (await core.list_namespaced_secret(namespace.metadata.name)).items
206-
secret_pw = next(filter(lambda x: x.metadata.name == f"user-gc-{name}", secrets))
207+
secret_pw = next(
208+
filter(
209+
lambda x: x.metadata.name == GC_USER_SECRET_NAME.format(name=name), secrets
210+
)
211+
)
207212

208213
gc_admin_pw = b64decode(secret_pw.data["password"])
209214

0 commit comments

Comments
 (0)