Skip to content

Commit

Permalink
kustomize: add HorizontalPodAutoscaler to Clair+Mirror (PROJQUAY-1449)
Browse files Browse the repository at this point in the history
Adds basic HorizontalPodAutoscalers for the 'clair' and 'mirror'
managed components.

Signed-off-by: Alec Merdler <alecmerdler@gmail.com>
  • Loading branch information
alecmerdler committed Apr 29, 2021
1 parent fcaf16b commit 1c6d3f1
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
25 changes: 25 additions & 0 deletions kustomize/components/clair/clair.horizontalpodautoscaler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: clair-app
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: clair-app
minReplicas: 2
maxReplicas: 10
# TODO: Use custom Prometheus metrics (https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-metrics-apis)
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 90
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 90
1 change: 1 addition & 0 deletions kustomize/components/clair/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ resources:
- ./clair.serviceaccount.yaml
- ./postgres.serviceaccount.yaml
- ./clair.deployment.yaml
- ./clair.horizontalpodautoscaler.yaml
- ./clair.service.yaml
- ./postgres.persistentvolumeclaim.yaml
- ./postgres.deployment.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spec:
apiVersion: apps/v1
kind: Deployment
name: quay-app
minReplicas: 1
minReplicas: 2
maxReplicas: 20
# TODO: Use custom Prometheus metrics (https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-metrics-apis)
metrics:
Expand Down
1 change: 1 addition & 0 deletions kustomize/components/mirror/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
resources:
- ./mirror.deployment.yaml
- ./mirror.horizontalpodautoscaler.yaml
vars:
- name: QUAY_APP_SERVICE_HOST
objref:
Expand Down
25 changes: 25 additions & 0 deletions kustomize/components/mirror/mirror.horizontalpodautoscaler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: quay-mirror
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: quay-mirror
minReplicas: 2
maxReplicas: 20
# TODO: Use custom Prometheus metrics (https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-metrics-apis)
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 90
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 90
10 changes: 9 additions & 1 deletion pkg/kustomize/kustomize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
objectbucket "github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1"
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
autoscaling "k8s.io/api/autoscaling/v2beta2"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -219,6 +220,7 @@ var quayComponents = map[string][]client.Object{
&corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "clair-config-secret"}},
&appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "clair-app"}},
&corev1.Service{ObjectMeta: metav1.ObjectMeta{Name: "clair-app"}},
&autoscaling.HorizontalPodAutoscaler{ObjectMeta: metav1.ObjectMeta{Name: "clair-app"}},
&appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "clair-postgres"}},
&corev1.PersistentVolumeClaim{ObjectMeta: metav1.ObjectMeta{Name: "clair-postgres"}},
&corev1.Service{ObjectMeta: metav1.ObjectMeta{Name: "clair-postgres"}},
Expand Down Expand Up @@ -247,6 +249,10 @@ var quayComponents = map[string][]client.Object{
},
"mirror": {
&appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "quay-mirror"}},
&autoscaling.HorizontalPodAutoscaler{ObjectMeta: metav1.ObjectMeta{Name: "quay-mirror"}},
},
"horizontalpodautoscaler": {
&autoscaling.HorizontalPodAutoscaler{ObjectMeta: metav1.ObjectMeta{Name: "quay-app"}},
},
}

Expand Down Expand Up @@ -277,6 +283,7 @@ var inflateTests = []struct {
{Kind: "redis", Managed: true},
{Kind: "objectstorage", Managed: true},
{Kind: "mirror", Managed: true},
{Kind: "horizontalpodautoscaler", Managed: true},
},
},
},
Expand All @@ -288,7 +295,7 @@ var inflateTests = []struct {
"config.yaml": encode(map[string]interface{}{"SERVER_HOSTNAME": "quay.io"}),
},
},
withComponents([]string{"base", "clair", "postgres", "redis", "objectstorage", "mirror"}),
withComponents([]string{"base", "clair", "postgres", "redis", "objectstorage", "mirror", "horizontalpodautoscaler"}),
nil,
},
{
Expand All @@ -301,6 +308,7 @@ var inflateTests = []struct {
{Kind: "redis", Managed: false},
{Kind: "objectstorage", Managed: false},
{Kind: "mirror", Managed: false},
{Kind: "horizontalpodautoscaler", Managed: false},
},
},
},
Expand Down

0 comments on commit 1c6d3f1

Please sign in to comment.