Skip to content

Commit 1117ffe

Browse files
author
Alan Christie
committed
style: Adjusted logging (leaner)
1 parent c743d09 commit 1117ffe

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

operator/handlers.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
148148
Kubernetes constantly calling back for a given create.
149149
"""
150150

151-
logging.info("Starting create (name=%s namespace=%s)...", name, namespace)
152-
logging.info("spec=%s (name=%s)", spec, name)
151+
logging.info("Creating %s (namespace=%s)...", name, namespace)
152+
logging.info("Incoming %s spec=%s", name, spec)
153153

154154
# All Data-Manager provided material
155155
# will be namespaced under the 'imDataManager' property
@@ -221,23 +221,30 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
221221
except kubernetes.client.exceptions.ApiException as ex:
222222
# We 'expect' 404, anything else is an error
223223
if ex.status != 404:
224-
logging.warning(
225-
"Got ApiException [%s/%s] getting CONFIG ConfigMap",
224+
logging.error(
225+
"Got ApiException [%s/%s] getting existing CONFIG ConfigMap %s",
226226
ex.status,
227227
ex.reason,
228+
cm_name,
228229
)
229230
raise ex
230231
if config_cm:
231232
# We retrieved an existing CONFIG - extract the token from it
232233
json_data = json.loads(config_cm.data[json_data_key])
233234
token = json_data["ServerApp"]["token"]
234-
logging.info("Retrieved prior token from CONFIG ConfigMap (%s)", token)
235+
logging.debug(
236+
"Retrieved prior token from CONFIG ConfigMap %s (%s)",
237+
cm_name,
238+
token,
239+
)
235240
else:
236241
# No prior config - we're free to allocate a new token
237242
characters = string.ascii_letters + string.digits
238243
token = "".join(random.sample(characters, 16))
239-
logging.info(
240-
"No prior CONFIG ConfigMap exists, assigning new token (%s)", token
244+
logging.debug(
245+
"No prior CONFIG ConfigMap exists for %s, assigning new token (%s)",
246+
cm_name,
247+
token,
241248
)
242249
assert token
243250

@@ -262,7 +269,7 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
262269
core_api.create_namespaced_config_map(
263270
namespace, config_cm_body, _request_timeout=_REQUEST_TIMEOUT
264271
)
265-
logging.info("Created CONFIG ConfigMap %s", cm_name)
272+
logging.debug("Created CONFIG ConfigMap %s", cm_name)
266273

267274
cm_name = f"bp-{name}"
268275
bp_cm_body = {
@@ -276,12 +283,12 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
276283
core_api.create_namespaced_config_map(
277284
namespace, bp_cm_body, _request_timeout=_REQUEST_TIMEOUT
278285
)
279-
logging.info("Created BP ConfigMap (%s)", cm_name)
286+
logging.debug("Created BP ConfigMap %s", cm_name)
280287
except kubernetes.client.exceptions.ApiException as ex:
281288
if ex.status != 409 or ex.reason != "Conflict":
282289
raise ex
283290
# Warn, but ignore and return a valid 'create' response now.
284-
logging.info(
291+
logging.debug(
285292
"Got 409/Conflict creating BP ConfigMap %s. Ignoring - object already present",
286293
cm_name,
287294
)
@@ -298,12 +305,12 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
298305
core_api.create_namespaced_config_map(
299306
namespace, startup_cm_body, _request_timeout=_REQUEST_TIMEOUT
300307
)
301-
logging.info("Created STARTUP ConfigMap (%s)", cm_name)
308+
logging.debug("Created STARTUP ConfigMap %s", cm_name)
302309
except kubernetes.client.exceptions.ApiException as ex:
303310
if ex.status != 409 or ex.reason != "Conflict":
304311
raise ex
305312
# Warn, but ignore and return a valid 'create' response now.
306-
logging.info(
313+
logging.debug(
307314
"Got 409/Conflict creating STARTUP ConfigMap %s. Ignoring - object already present",
308315
cm_name,
309316
)
@@ -425,12 +432,12 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
425432
apps_api.create_namespaced_deployment(
426433
namespace, deployment_body, _request_timeout=_REQUEST_TIMEOUT
427434
)
428-
logging.info("Created Deployment %s", name)
435+
logging.debug("Created Deployment %s", name)
429436
except kubernetes.client.exceptions.ApiException as ex:
430437
if ex.status != 409 or ex.reason != "Conflict":
431438
raise ex
432439
# Warn, but ignore and return a valid 'create' response now.
433-
logging.info(
440+
logging.debug(
434441
"Got 409/Conflict creating Deployment %s. Ignoring - object already present",
435442
name,
436443
)
@@ -463,12 +470,12 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
463470
core_api.create_namespaced_service(
464471
namespace, service_body, _request_timeout=_REQUEST_TIMEOUT
465472
)
466-
logging.info("Created Service %s", name)
473+
logging.debug("Created Service %s", name)
467474
except kubernetes.client.exceptions.ApiException as ex:
468475
if ex.status != 409 or ex.reason != "Conflict":
469476
raise ex
470477
# Warn, but ignore and return a valid 'create' response now.
471-
logging.info(
478+
logging.debug(
472479
"Got 409/Conflict creating Service %s. Ignoring - object already present",
473480
name,
474481
)
@@ -523,19 +530,19 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
523530
ext_api.create_namespaced_ingress(
524531
namespace, ingress_body, _request_timeout=_REQUEST_TIMEOUT
525532
)
526-
logging.info("Created Ingress %s", name)
533+
logging.debug("Created Ingress %s", name)
527534
except kubernetes.client.exceptions.ApiException as ex:
528535
if ex.status != 409 or ex.reason != "Conflict":
529536
raise ex
530537
# Warn, but ignore and return a valid 'create' response now.
531-
logging.info(
538+
logging.debug(
532539
"Got 409/Conflict creating Ingress %s. Ignoring - object already present",
533540
name,
534541
)
535542

536543
# Done
537544
# ----
538-
logging.info("Success! (name=%s namespace=%s)", name, namespace)
545+
logging.info("Done %s (namespace=%s token=%s)", name, namespace, token)
539546

540547
return {
541548
"notebook": {

0 commit comments

Comments
 (0)