Skip to content

Commit

Permalink
adds redis instance for user session data to OCP
Browse files Browse the repository at this point in the history
'redis-users' service available in docker-compose definition, but
explicit creation of another service for this purpose is required in the
openshift resource definitions.

This commit includes these definitions and sets the environment
variables required so that services can access the new cache instance.

Signed-off-by: James Kunstle <[email protected]>
  • Loading branch information
JamesKunstle committed Oct 2, 2023
1 parent e00540b commit 138c934
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 9 deletions.
8 changes: 4 additions & 4 deletions 8Knot/_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def load_user(id):
User | None: User object if user ID in session, None otherwise.
"""
users_cache = redis.StrictRedis(
host="redis-users",
host=os.getenv("REDIS_SERVICE_USERS_HOST", "redis-users"),
port=6379,
password=os.getenv("REDIS_PASSWORD", ""),
)
Expand Down Expand Up @@ -97,7 +97,7 @@ def logout():
"""
users_cache = redis.StrictRedis(
host="redis-users",
host=os.getenv("REDIS_SERVICE_USERS_HOST", "redis-users"),
port=6379,
password=os.getenv("REDIS_PASSWORD", ""),
)
Expand Down Expand Up @@ -128,7 +128,7 @@ def oauth2_authorize():
None
"""
users_cache = redis.StrictRedis(
host="redis-users",
host=os.getenv("REDIS_SERVICE_USERS_HOST", "redis-users"),
port=6379,
password=os.getenv("REDIS_PASSWORD", ""),
)
Expand Down Expand Up @@ -175,7 +175,7 @@ def oauth2_callback():
None
"""
users_cache = redis.StrictRedis(
host="redis-users",
host=os.getenv("REDIS_SERVICE_USERS_HOST", "redis-users"),
port=6379,
password=os.getenv("REDIS_PASSWORD", ""),
)
Expand Down
8 changes: 4 additions & 4 deletions 8Knot/pages/index/index_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def kick_off_group_collection(url, n_clicks):
if current_user.is_authenticated:
user_id = current_user.get_id()
users_cache = redis.StrictRedis(
host="redis-users",
host=os.getenv("REDIS_SERVICE_USERS_HOST", "redis-users"),
port=6379,
password=os.getenv("REDIS_PASSWORD", ""),
)
Expand Down Expand Up @@ -122,7 +122,7 @@ def login_username_button(url):
logging.warning(f"LOGINBUTTON: USER LOGGED IN {current_user}")
# TODO: implement more permanent interface
users_cache = redis.StrictRedis(
host="redis-users",
host=os.getenv("REDIS_SERVICE_USERS_HOST", "redis-users"),
port=6379,
password=os.getenv("REDIS_PASSWORD", ""),
)
Expand Down Expand Up @@ -182,7 +182,7 @@ def dynamic_multiselect_options(user_in: str, selections):
logging.warning(f"LOGINBUTTON: USER LOGGED IN {current_user}")
# TODO: implement more permanent interface
users_cache = redis.StrictRedis(
host="redis-users",
host=os.getenv("REDIS_SERVICE_USERS_HOST", "redis-users"),
port=6379,
password=os.getenv("REDIS_PASSWORD", ""),
decode_responses=True,
Expand Down Expand Up @@ -251,7 +251,7 @@ def multiselect_values_to_repo_ids(n_clicks, user_vals):
logging.warning(f"LOGINBUTTON: USER LOGGED IN {current_user}")
# TODO: implement more permanent interface
users_cache = redis.StrictRedis(
host="redis-users",
host=os.getenv("REDIS_SERVICE_USERS_HOST", "redis-users"),
port=6379,
password=os.getenv("REDIS_PASSWORD", ""),
decode_responses=True,
Expand Down
6 changes: 5 additions & 1 deletion 8Knot/queries/user_groups_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def user_groups_query(self, user_id):
"""
logging.warning(f"{QUERY_NAME}_DATA_QUERY - START")

users_cache = redis.StrictRedis(host="redis-users", port=6379, password=os.getenv("REDIS_PASSWORD", ""))
users_cache = redis.StrictRedis(
host=os.getenv("REDIS_SERVICE_USERS_HOST", "redis-users"),
port=6379,
password=os.getenv("REDIS_PASSWORD", ""),
)

# checks connection to Redis, raises redis.exceptions.ConnectionError if connection fails.
# returns True if connection succeeds.
Expand Down
94 changes: 94 additions & 0 deletions openshift/base/8k-redis-users.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
image.openshift.io/triggers: '[{"from":{"kind":"ImageStreamTag","name":"redis:6-el8","namespace":"openshift"},"fieldPath":"spec.template.spec.containers[?(@.name==\"redis-users\")].image","pause":"false"}]'
labels:
name: eightknot-redis-users
app.kubernetes.io/name: eightknot-redis-users
name: eightknot-redis-users
spec:
replicas: 1
selector:
matchLabels:
name: eightknot-redis-users
strategy:
type: Recreate
template:
metadata:
labels:
name: eightknot-redis-users
spec:
containers:
- envFrom:
- secretRef:
name: eightknot-redis
image: image-registry.openshift-image-registry.svc:5000/openshift/redis:6-el8
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 6379
timeoutSeconds: 1
name: eightknot-redis-users
ports:
- containerPort: 6379
protocol: TCP
readinessProbe:
exec:
command:
- /bin/sh
- -i
- -c
- test "$(redis-cli -h 127.0.0.1 -a $REDIS_PASSWORD ping)" == "PONG"
failureThreshold: 3
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 4Gi
requests:
memory: 128Mi
volumeMounts:
- mountPath: /var/lib/redis/data
name: redis-data
restartPolicy: Always
volumes:
- name: empty
emptyDir: {}
- name: redis-data
persistentVolumeClaim:
claimName: eightknot-redis-data
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/part-of: eightknot-app
name: eightknot-redis-users
spec:
ports:
- name: redis
port: 6379
protocol: TCP
targetPort: 6379
selector:
name: eightknot-redis-users
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: eightknot-redis-users-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 4Gi
volumeMode: Filesystem
1 change: 1 addition & 0 deletions openshift/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ resources:
- 8k-redis.yaml
- 8k-worker-callback.yaml
- 8k-worker-query.yaml
- 8k-redis-users.yaml
# - namespace.yaml
- secret-augur.yaml
- secret-redis.yaml
1 change: 1 addition & 0 deletions openshift/base/secret-redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ stringData:
REDIS_PASSWORD: secretpassword
# kludge - rename to REDIS_HOST, REDIS_PORT
REDIS_SERVICE_HOST: eightknot-redis
REDIS_SERVICE_USERS_HOST: eightknot-redis-users

0 comments on commit 138c934

Please sign in to comment.