Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add hpa and resources limits #37

Merged
merged 5 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def load_about():
packages=find_packages(exclude=["tests*"]),
include_package_data=True,
python_requires=">=3.8",
install_requires=["tutor"],
install_requires=["tutor<16.0.0"],
entry_points={"tutor.plugin.v1": ["codejail = tutorcodejail.plugin"]},
classifiers=[
"Development Status :: 3 - Alpha",
Expand Down
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
10 changes: 10 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,
"MIN_REPLICAS": 1,
"MAX_REPLICAS": 4,
"AVG_CPU": 65,
"AVG_MEMORY": "500Mi",
},
"overrides": {},
}
Expand Down Expand Up @@ -82,6 +91,7 @@
[
("codejail/build", "plugins"),
("codejail/apps", "plugins"),
("codejail/k8s", "plugins"),
],
)
# Load patches from files
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
Henrrypg marked this conversation as resolved.
Show resolved Hide resolved
kind: HorizontalPodAutoscaler
metadata:
name: codejail
labels:
app.kubernetes.io/name: codejail
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 %}