Skip to content

Commit a87a495

Browse files
author
Alan Christie
committed
style: Fixed pylint warnings
1 parent cd6403d commit a87a495

File tree

2 files changed

+43
-35
lines changed

2 files changed

+43
-35
lines changed

.pylintrc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
# Disable some distracting checks.
44
# See http://pylint.pycqa.org/en/latest/user_guide/message-control.html
5-
#
6-
# R : (Refactoring) warnings
7-
disable = consider-using-f-string,
8-
line-too-long,
9-
missing-class-docstring,
10-
missing-function-docstring,
11-
missing-module-docstring,
12-
R,
13-
too-many-lines,
5+
# For now ... disable
6+
# all C (convention) warnings
7+
# all R (Refactoring) warnings
8+
# along with any specific (distracting) errors/warnings.
9+
# See http://pylint.pycqa.org/en/latest/user_guide/message-control.html
10+
disable = C0103, R, E0401, E1101, E1136,
11+
anomalous-backslash-in-string

operator/handlers.py

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""A kopf handler for the Jupyter CRD.
2+
"""
13
import logging
24
import random
35
import os
@@ -8,18 +10,18 @@
810
import kopf
911

1012
# Some (key) default deployment variables...
11-
default_image = "jupyter/minimal-notebook:notebook-6.3.0"
12-
default_sa = "default"
13-
default_cpu_limit = "1"
14-
default_cpu_request = "10m"
15-
default_mem_limit = "1Gi"
16-
default_mem_request = "256Mi"
17-
default_user_id = 1000
18-
default_group_id = 100
19-
default_ingress_proxy_body_size = "500m"
13+
_DEFAULT_IMAGE = "jupyter/minimal-notebook:notebook-6.3.0"
14+
_DEFAULT_SA = "default"
15+
_DEFAULT_CPU_LIMIT = "1"
16+
_DEFAULT_CPU_REQUEST = "10m"
17+
_DEFAULT_MEM_LIMIT = "1Gi"
18+
_DEFAULT_MEM_REQUEST = "256Mi"
19+
_DEFAULT_USER_ID = 1000
20+
_DEFAULT_GROUP_ID = 100
21+
_DEFAULT_INGRESS_PROXY_BODY_SIZE = "500m"
2022

2123
# The ingress class
22-
ingress_class = "nginx"
24+
_INGRESS_CLASS = "nginx"
2325
# The ingress domain must be provided.
2426
ingress_domain = os.environ["INGRESS_DOMAIN"]
2527
# The ingress TLS secret is optional.
@@ -49,7 +51,7 @@
4951
# As part of the startup we erase the existing '~/.bashrc' and,
5052
# as a minimum, set a more suitable PS1 (see ch2385).
5153
# 'conda init' then puts its stuff into the same file.
52-
notebook_startup = """#!/bin/bash
54+
_NOTEBOOK_STARTUP = """#!/bin/bash
5355
echo "PS1='\$(pwd) \$UID$ '" > ~/.bashrc
5456
echo "umask 0002" >> ~/.bashrc
5557
conda init
@@ -70,7 +72,7 @@
7072

7173
# The bash-profile
7274
# which simply launches the .bashrc
73-
bash_profile = """if [ -f ~/.bashrc ]; then
75+
_BASH_PROFILE = """if [ -f ~/.bashrc ]; then
7476
source ~/.bashrc
7577
fi
7678
"""
@@ -79,7 +81,7 @@
7981
# A ConfigMap whose content is written into '/etc'
8082
# and copied to the $HOME/.jupyter by the notebook_startup
8183
# script (above).
82-
notebook_config = """{
84+
_NOTEBOOK_CONFIG = """{
8385
"NotebookApp": {
8486
"token": "%(token)s",
8587
"base_url": "%(base_url)s"
@@ -97,6 +99,14 @@ def configure(settings: kopf.OperatorSettings, **_: Any) -> None:
9799

98100
@kopf.on.create("squonk.it", "v1", "jupyternotebooks", id="jupyter")
99101
def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[str, Any]:
102+
"""Handler for CRD create events.
103+
Here we construct the required Kubernetes objects,
104+
adopting them in kopf before using the corresponding Kubernetes API
105+
to create them.
106+
107+
We handle errors typically raising 'kopf.PermanentError' to prevent
108+
Kubernetes constantly calling back for a given create.
109+
"""
100110

101111
characters = string.ascii_letters + string.digits
102112
token = "".join(random.sample(characters, 16))
@@ -113,22 +123,22 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
113123
"apiVersion": "v1",
114124
"kind": "ConfigMap",
115125
"metadata": {"name": "bp-%s" % name, "labels": {"app": name}},
116-
"data": {".bash_profile": bash_profile},
126+
"data": {".bash_profile": _BASH_PROFILE},
117127
}
118128

119129
startup_cm_body = {
120130
"apiVersion": "v1",
121131
"kind": "ConfigMap",
122132
"metadata": {"name": "startup-%s" % name, "labels": {"app": name}},
123-
"data": {"start.sh": notebook_startup},
133+
"data": {"start.sh": _NOTEBOOK_STARTUP},
124134
}
125135

126136
config_vars = {"token": token, "base_url": name}
127137
config_cm_body = {
128138
"apiVersion": "v1",
129139
"kind": "ConfigMap",
130140
"metadata": {"name": "config-%s" % name, "labels": {"app": name}},
131-
"data": {"jupyter_notebook_config.json": notebook_config % config_vars},
141+
"data": {"jupyter_notebook_config.json": _NOTEBOOK_CONFIG % config_vars},
132142
}
133143

134144
kopf.adopt(bp_cm_body)
@@ -152,14 +162,14 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
152162

153163
notebook_interface = material.get("notebook", {}).get("interface", "lab")
154164

155-
image = material.get("image", default_image)
156-
service_account = material.get("serviceAccountName", default_sa)
165+
image = material.get("image", _DEFAULT_IMAGE)
166+
service_account = material.get("serviceAccountName", _DEFAULT_SA)
157167

158168
resources = material.get("resources", {})
159-
cpu_limit = resources.get("limits", {}).get("cpu", default_cpu_limit)
160-
cpu_request = resources.get("requests", {}).get("cpu", default_cpu_request)
161-
memory_limit = resources.get("limits", {}).get("memory", default_mem_limit)
162-
memory_request = resources.get("requests", {}).get("memory", default_mem_request)
169+
cpu_limit = resources.get("limits", {}).get("cpu", _DEFAULT_CPU_LIMIT)
170+
cpu_request = resources.get("requests", {}).get("cpu", _DEFAULT_CPU_REQUEST)
171+
memory_limit = resources.get("limits", {}).get("memory", _DEFAULT_MEM_LIMIT)
172+
memory_request = resources.get("requests", {}).get("memory", _DEFAULT_MEM_REQUEST)
163173

164174
# Data Manager API compliance.
165175
#
@@ -170,10 +180,10 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
170180
# as the Kubernetes 'File System Group' (fsGroup).
171181
# This should allow us to run and manipulate the files.
172182
sc_run_as_user = material.get("securityContext", {}).get(
173-
"runAsUser", default_user_id
183+
"runAsUser", _DEFAULT_USER_ID
174184
)
175185
sc_run_as_group = material.get("securityContext", {}).get(
176-
"runAsGroup", default_group_id
186+
"runAsGroup", _DEFAULT_GROUP_ID
177187
)
178188

179189
# Project storage
@@ -309,7 +319,7 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
309319
logging.info("Creating Ingress %s...", name)
310320

311321
ingress_proxy_body_size = material.get(
312-
"ingressProxyBodySize", default_ingress_proxy_body_size
322+
"ingressProxyBodySize", _DEFAULT_INGRESS_PROXY_BODY_SIZE
313323
)
314324

315325
ingress_path = f"/{name}"
@@ -322,7 +332,7 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
322332
"name": name,
323333
"labels": {"app": name},
324334
"annotations": {
325-
"kubernetes.io/ingress.class": ingress_class,
335+
"kubernetes.io/ingress.class": _INGRESS_CLASS,
326336
"nginx.ingress.kubernetes.io/proxy-body-size": f"{ingress_proxy_body_size}",
327337
},
328338
},

0 commit comments

Comments
 (0)