Skip to content

Commit

Permalink
feat: add hpa and resource limits to allow auto scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrrypg committed Jul 7, 2023
1 parent e1e70e6 commit 0176f2a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tutorcodejail/patches/k8s-deployments
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ spec:
- mountPath: /openedx/codejailservice/codejailservice/tutor.py
name: settings-codejail
subPath: tutor.py
resources:
limits:
cpu: "{{ CODEJAIL_LIMIT_CPU }}"
memory: "{{ CODEJAIL_LIMIT_MEMORY }}"
requests:
cpu: "{{ CODEJAIL_REQUEST_CPU }}"
memory: "{{ CODEJAIL_REQUEST_MEMORY }}"
volumes:
- name: settings-codejail
configMap:
Expand Down
1 change: 1 addition & 0 deletions tutorcodejail/patches/kustomization-resources
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- plugins/codejail/k8s/hpa.yml
9 changes: 9 additions & 0 deletions tutorcodejail/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
"HOST": "codejailservice",
"SANDBOX_PYTHON_VERSION": "3.8.6",
"SKIP_INIT": False,
"LIMIT_CPU": "1",
"LIMIT_MEMORY": "1Gi",
"REQUEST_CPU": "512m",
"REQUEST_MEMORY": "512Mi",
"ENABLE_HPA": False,
"HPA_MIN_REPLICAS": 1,
"HPA_MAX_REPLICAS": 4,
"AVG_CPU": 65,
"AVG_MEMORY": 65
},
"overrides": {},
}
Expand Down
Empty file.
32 changes: 32 additions & 0 deletions tutorcodejail/templates/codejail/k8s/hpa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{%- if CODEJAIL_ENABLE_HPA %}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: codejail-hpa
labels:
app.kubernetes.io/name: codejail-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: codejailservice
minReplicas: {{ CODEJAIL_MIN_REPLICAS }}
maxReplicas: {{ CODEJAIL_MAX_REPLICAS }}
metrics:
{%- if CODEJAIL_AVG_CPU > 0 %}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ CODEJAIL_AVG_CPU }}
{%- endif %}
{%- if CODEJAIL_AVG_MEMORY|length %}
- type: Resource
resource:
name: memory
target:
type: AverageValue
averageValue: {{ CODEJAIL_AVG_MEMORY }}
{%- endif %}
{%- endif %}

0 comments on commit 0176f2a

Please sign in to comment.