Skip to content

Commit

Permalink
feat: add hpa to enterprise-catalog.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacatove committed Nov 1, 2023
1 parent 0182bf4 commit a4eb030
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tutorenterprise/patches/k8s-deployments
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ 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:
Expand Down
10 changes: 10 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_HPA_MIN_REPLICAS": 1,
"CATALOG_HPA_MAX_REPLICAS": 4,
"CATALOG_AVG_CPU": 65,
"CATALOG_AVG_MEMORY": 65,
},
"unique": {
"OAUTH2_SECRET_KEY": "{{ 64|random_string }}",
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: codejail-hpa
labels:
app.kubernetes.io/name: codejail-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: codejailservice
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 a4eb030

Please sign in to comment.