#  Copyright © Microsoft Corporation
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

{{- if has .Values.env .Values.featureFlag.hpa.enabledEnvs }}
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: {{ .Chart.Name }}
  namespace: osdu
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ .Chart.Name }}
  minReplicas: {{ .Values.global.minReplicaCount }}
  maxReplicas: {{ .Values.global.maxReplicaCount }}
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 50
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 150
      policies:
      - type: Pods
        value: 2
        periodSeconds: 30
    scaleUp:
      stabilizationWindowSeconds: 10
      selectPolicy: Max
      policies:
      - type: Pods
        value: 6
        periodSeconds: 10
      - type: Percent
        value: 50
        periodSeconds: 10
{{- end }}