Skip to content

Commit

Permalink
Co-authored-by: Andrés Felipe Bermúdez Mendoza <andres.bermudez@edune…
Browse files Browse the repository at this point in the history
…xt.co>

feat: add enterprise-catalog-worker deployment.
feat: enable async enterprise-catalog-worker.
feat: add hpa to enterprise-catalog.
refactor: address suggestions.
Update tutorenterprise/templates/enterprise/apps/enterprise-catalog/settings/partials/common.py
  • Loading branch information
Jacatove authored and Squirrel18 committed Jan 5, 2024
1 parent 0182bf4 commit 54165bc
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 2 deletions.
42 changes: 42 additions & 0 deletions tutorenterprise/patches/k8s-deployments
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,48 @@ spec:
subPath: production.py
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: "{{ ENTERPRISE_CATALOG_LIMIT_CPU }}"
memory: "{{ ENTERPRISE_CATALOG_LIMIT_MEMORY }}"
requests:
cpu: "{{ ENTERPRISE_CATALOG_REQUEST_CPU }}"
memory: "{{ ENTERPRISE_CATALOG_REQUEST_MEMORY }}"
volumes:
- name: settings
configMap:
name: enterprise-catalog-settings
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: enterprise-catalog-worker
labels:
app.kubernetes.io/name: enterprise-catalog-worker
spec:
selector:
matchLabels:
app.kubernetes.io/name: enterprise-catalog-worker
template:
metadata:
labels:
app.kubernetes.io/name: enterprise-catalog-worker
spec:
securityContext:
runAsUser: 1000
runAsGroup: 1000
containers:
- name: enterprise-catalog-worker
image: {{ ENTERPRISE_CATALOG_DOCKER_IMAGE }}
args: ["celery", "--app=enterprise_catalog.celery", "worker", "--loglevel=info"]
ports:
- containerPort: 8000
volumeMounts:
- mountPath: /openedx/enterprise-catalog/enterprise_catalog/settings/tutor/production.py
name: settings
subPath: production.py
securityContext:
allowPrivilegeEscalation: false
volumes:
- name: settings
configMap:
Expand Down
1 change: 1 addition & 0 deletions tutorenterprise/patches/kustomization-resources
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- plugins/enterprise/k8s/hpa.yml
16 changes: 16 additions & 0 deletions tutorenterprise/patches/local-docker-compose-services
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@ enterprise-catalog:
- redis
{% if RUN_MYSQL %}- mysql{% endif %}
{% if RUN_LMS %}- lms{% endif %}

enterprise-catalog-worker:
image: {{ ENTERPRISE_CATALOG_DOCKER_IMAGE }}
environment:
DJANGO_SETTINGS_MODULE: enterprise_catalog.settings.tutor.production
command: celery --app=enterprise_catalog.celery:app worker -l INFO
restart: unless-stopped
volumes:
- ../plugins/enterprise/apps/enterprise-catalog/settings:/openedx/enterprise-catalog/enterprise_catalog/settings/tutor:ro
depends_on:
- discovery
- ecommerce
- redis
- enterprise-catalog
{% if RUN_MYSQL %}- mysql{% endif %}
{% if RUN_LMS %}- lms{% endif %}
11 changes: 11 additions & 0 deletions tutorenterprise/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
"CATALOG_DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}paops/enterprise-catalog:{{ ENTERPRISE_VERSION }}",
"DISCOVERY_USER": "discovery",
"ECOMMERCE_OAUTH_USER": "{{ ECOMMERCE_OAUTH2_KEY }}",
### HPA ###
"CATALOG_LIMIT_CPU": "1",
"CATALOG_LIMIT_MEMORY": "1Gi",
"CATALOG_REQUEST_CPU": "512m",
"CATALOG_REQUEST_MEMORY": "512Mi",
"CATALOG_ENABLE_HPA": False,
"CATALOG_MIN_REPLICAS": 1,
"CATALOG_MAX_REPLICAS": 4,
"CATALOG_AVG_CPU": 65,
"CATALOG_AVG_MEMORY": "500Mi",
},
"unique": {
"OAUTH2_SECRET_KEY": "{{ 64|random_string }}",
Expand Down Expand Up @@ -161,6 +171,7 @@
[
("enterprise/build", "plugins"),
("enterprise/apps", "plugins"),
("enterprise/k8s", "plugins"),
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
{% include "enterprise/apps/enterprise-catalog/settings/partials/common.py" %}

DISCOVERY_CATALOG_QUERY_CACHE_TIMEOUT = 0
CELERY_TASK_ALWAYS_EAGER = True

{{ patch("enterprise-catalog-development-settings") }}
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
ECOMMERCE_BASE_URL = "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ ECOMMERCE_HOST }}"
LICENSE_MANAGER_BASE_URL = ""

# Worker settings. We currently don't support async workers for the Enterprise Catalogue service.
# Enterprise Catalogue Worker settings.
CELERY_WORKER_HIJACK_ROOT_LOGGER = True
CELERY_TASK_ALWAYS_EAGER = True
CELERY_TASK_ALWAYS_EAGER = False
CELERY_BROKER_TRANSPORT = "redis"
CELERY_BROKER_HOSTNAME = "{{ REDIS_HOST }}:{{ REDIS_PORT }}"
CELERY_BROKER_VHOST = "{{ OPENEDX_CELERY_REDIS_DB }}"
Expand Down
32 changes: 32 additions & 0 deletions tutorenterprise/templates/enterprise/k8s/hpa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{%- if ENTERPRISE_CATALOG_ENABLE_HPA %}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: enterprise-catalog
labels:
app.kubernetes.io/name: enterprise-catalog
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: enterprise-catalog
minReplicas: {{ ENTERPRISE_CATALOG_MIN_REPLICAS }}
maxReplicas: {{ ENTERPRISE_CATALOG_MAX_REPLICAS }}
metrics:
{%- if ENTERPRISE_CATALOG_AVG_CPU > 0 %}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ ENTERPRISE_CATALOG_AVG_CPU }}
{%- endif %}
{%- if ENTERPRISE_CATALOG_AVG_MEMORY|length %}
- type: Resource
resource:
name: memory
target:
type: AverageValue
averageValue: {{ ENTERPRISE_CATALOG_AVG_MEMORY }}
{%- endif %}
{%- endif %}

0 comments on commit 54165bc

Please sign in to comment.