Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
feat(k8s): bring back the hpa (#83)
Browse files Browse the repository at this point in the history
Revert "feat(k8s): remove hpa (#54)"
  • Loading branch information
douglasduteil authored Mar 23, 2021
1 parent d41bb4e commit 40a9139
Show file tree
Hide file tree
Showing 6 changed files with 574 additions and 304 deletions.
38 changes: 38 additions & 0 deletions .k8s/__tests__/__snapshots__/kosko generate --env dev.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,43 @@ spec:
- hosts:
- master-dev2-serving-ml.dev2.fabrique.social.gouv.fr
secretName: wildcard-crt
---
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
annotations:
kapp.k14s.io/disable-default-ownership-label-rules: ''
kapp.k14s.io/disable-default-label-scoping-rules: ''
app.gitlab.com/app: socialgouv-serving-ml
app.gitlab.com/env: master-dev2
app.gitlab.com/env.name: master-dev2
labels:
app: serving-ml
application: master-dev2-serving-ml
owner: serving-ml
team: serving-ml
cert: wildcard
name: serving-ml
namespace: serving-ml-144-master-dev2
spec:
minReplicas: 1
maxReplicas: 10
metrics:
- resource:
name: cpu
target:
averageUtilization: 4000
type: Utilization
type: Resource
- resource:
name: memory
target:
averageUtilization: 100
type: Utilization
type: Resource
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: serving-ml
"
`;
38 changes: 38 additions & 0 deletions .k8s/__tests__/__snapshots__/kosko generate --env preprod.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,43 @@ spec:
- hosts:
- preprod-serving-ml.dev2.fabrique.social.gouv.fr
secretName: wildcard-crt
---
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
annotations:
kapp.k14s.io/disable-default-ownership-label-rules: ''
kapp.k14s.io/disable-default-label-scoping-rules: ''
app.gitlab.com/app: socialgouv-serving-ml
app.gitlab.com/env: preprod-dev2
app.gitlab.com/env.name: preprod-dev2
labels:
app: serving-ml
application: v1-2-3-serving-ml
owner: serving-ml
team: serving-ml
cert: wildcard
name: serving-ml
namespace: serving-ml-144-preprod-dev2
spec:
minReplicas: 2
maxReplicas: 10
metrics:
- resource:
name: cpu
target:
averageUtilization: 4000
type: Utilization
type: Resource
- resource:
name: memory
target:
averageUtilization: 100
type: Utilization
type: Resource
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: serving-ml
"
`;
37 changes: 37 additions & 0 deletions .k8s/__tests__/__snapshots__/kosko generate --env prod.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,42 @@ spec:
- hosts:
- serving-ml.fabrique.social.gouv.fr
secretName: serving-ml-crt
---
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
annotations:
kapp.k14s.io/disable-default-ownership-label-rules: ''
kapp.k14s.io/disable-default-label-scoping-rules: ''
app.gitlab.com/app: socialgouv-serving-ml
app.gitlab.com/env: prod2
app.gitlab.com/env.name: prod2
labels:
app: serving-ml
application: serving-ml
owner: serving-ml
team: serving-ml
name: serving-ml
namespace: serving-ml
spec:
minReplicas: 2
maxReplicas: 10
metrics:
- resource:
name: cpu
target:
averageUtilization: 4000
type: Utilization
type: Resource
- resource:
name: memory
target:
averageUtilization: 100
type: Utilization
type: Resource
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: serving-ml
"
`;
47 changes: 46 additions & 1 deletion .k8s/components/serving-ml.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ok } from "assert";
import env from "@kosko/env";
import { create } from "@socialgouv/kosko-charts/components/app";
import type{ Deployment } from "kubernetes-models/apps/v1";
import { HorizontalPodAutoscaler } from "kubernetes-models/autoscaling/v2beta2";
import { IIoK8sApiCoreV1HTTPGetAction } from "kubernetes-models/v1";
import { getHarborImagePath } from "@socialgouv/kosko-charts/utils/getHarborImagePath";

Expand Down Expand Up @@ -43,5 +46,47 @@ const manifests = create("serving-ml", {
},
},
});
const deployment = manifests.find(
(manifest): manifest is Deployment => manifest.kind === "Deployment"
);
ok(deployment);

export default [...manifests];

const hpa = new HorizontalPodAutoscaler({
metadata: deployment.metadata,
spec: {
minReplicas: process.env.CI_COMMIT_TAG ? 2 : 1,
maxReplicas: 10,

metrics: [
{
resource: {
name: "cpu",
target: {
averageUtilization: 4000,
type: "Utilization",
},
},
type: "Resource",
},
{
resource: {
name: "memory",
target: {
averageUtilization: 100,
type: "Utilization",
},
},
type: "Resource",
},
],

scaleTargetRef: {
apiVersion: deployment.apiVersion,
kind: deployment.kind,
name: deployment.metadata!.name!,
},
},
});

export default [...manifests, hpa];
18 changes: 11 additions & 7 deletions .k8s/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@
]
},
"dependencies": {
"@kosko/env": "^1.0.3",
"@kosko/env": "1.0.3",
"@kubernetes-models/sealed-secrets": "^1.0.3",
"@socialgouv/kosko-charts": "^4.7.11",
"@types/node": "^14.14.31",
"@socialgouv/kosko-charts": "^5.0.0",
"@types/node": "^14.14.35",
"kosko": "^1.0.3",
"kubernetes-models": "^1.0.3",
"ts-node": "^9.1.1",
"typescript": "^4.1.5"
"typescript": "^4.2.3"
},
"devDependencies": {
"@babel/core": "^7.12.17",
"@babel/plugin-transform-modules-commonjs": "^7.12.13",
"@types/jest": "^26.0.20",
"@babel/core": "^7.13.10",
"@babel/plugin-transform-modules-commonjs": "^7.13.8",
"@types/jest": "^26.0.21",
"dotenv": "^8.2.0",
"jest": "^26.6.3"
},
"resolutions": {
"@kosko/cli": "1.1.0",
"@kosko/env": "1.0.3"
},
"license": "Apache-2.0",
"scripts": {
"generate": "kosko generate",
Expand Down
Loading

0 comments on commit 40a9139

Please sign in to comment.