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

Add HPA, PDB and Pod Affinity for both Operator and Connect components #170

Merged
merged 9 commits into from
Aug 27, 2024
33 changes: 29 additions & 4 deletions charts/connect/README.md

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions charts/connect/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ Sets extra service annotations
{{- end }}
{{- end -}}

{{/*
Sets extra annotations
*/}}
{{- define "onepassword-connect.extraAnnotations" -}}
{{- with .annotations }}
annotations:
{{- $tp := typeOf . }}
{{- if eq $tp "string" }}
{{- tpl . . | nindent 4 }}
{{- else }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
{{- end -}}

{{/*
Sets environment variables when profiler is enabled
*/}}
Expand Down
12 changes: 8 additions & 4 deletions charts/connect/templates/connect-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.connect.nodeSelector }}
{{- with .Values.connect.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.connect.priorityClassName }}
priorityClassName: {{ .Values.connect.priorityClassName }}
{{- end }}
{{- with .Values.connect.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: {{ .Values.connect.dataVolume.name }}
{{ .Values.connect.dataVolume.type }}: {{- toYaml .Values.connect.dataVolume.values | nindent 12 }}
Expand All @@ -52,7 +56,7 @@ spec:
secretName: {{ .Values.connect.tls.secret }}
{{- end }}
tolerations:
{{ toYaml .Values.connect.tolerations | indent 8 }}
{{- toYaml .Values.connect.tolerations | nindent 8 }}
containers:
- name: {{ .Values.connect.api.name }}
image: {{ .Values.connect.api.imageRepository }}:{{ tpl .Values.connect.version . }}
Expand Down
39 changes: 39 additions & 0 deletions charts/connect/templates/connect-hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{- if (and .Values.connect.create .Values.connect.hpa.enabled ) }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ .Values.connect.applicationName }}
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/component: connect
{{- include "onepassword-connect.labels" . | nindent 4 }}
{{- include "onepassword-connect.extraAnnotations" .Values.connect.hpa }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ .Values.connect.applicationName }}
minReplicas: {{ .Values.connect.hpa.minReplicas }}
maxReplicas: {{ .Values.connect.hpa.maxReplicas }}
metrics:
{{- with .Values.connect.hpa.avgMemoryUtilization }}
- type: Resource
resource:
name: memory
target:
averageUtilization: {{ . }}
type: Utilization
{{- end }}
{{- with .Values.connect.hpa.avgCpuUtilization }}
- type: Resource
resource:
name: cpu
target:
averageUtilization: {{ . }}
type: Utilization
{{- end }}
{{- with .Values.connect.hpa.behavior }}
behavior:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
21 changes: 21 additions & 0 deletions charts/connect/templates/connect-pdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- if (and .Values.connect.create .Values.connect.pdb.enabled ) }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ .Values.connect.applicationName }}
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/component: connect
{{- include "onepassword-connect.labels" . | nindent 4 }}
{{- include "onepassword-connect.extraAnnotations" .Values.connect.pdb }}
spec:
{{- with .Values.connect.pdb.maxUnavailable }}
maxUnavailable: {{ . }}
{{- else }}
minAvailable: {{ .Values.connect.pdb.minAvailable }}
{{- end }}
selector:
matchLabels:
app.kubernetes.io/component: connect
{{- include "onepassword-connect.selectorLabels" . | nindent 6 }}
{{- end }}
14 changes: 9 additions & 5 deletions charts/connect/templates/operator-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
replicas: 1
replicas: {{ .Values.operator.replicas }}
selector:
matchLabels:
name: {{ .Values.connect.applicationName }}
Expand All @@ -32,15 +32,19 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.operator.nodeSelector }}
{{- with .Values.operator.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.operator.priorityClassName }}
priorityClassName: {{ .Values.operator.priorityClassName }}
{{- end }}
{{- with .Values.operator.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
tolerations:
{{ toYaml .Values.operator.tolerations | indent 8 }}
{{- toYaml .Values.operator.tolerations | nindent 8 }}
serviceAccountName: {{ .Values.operator.serviceAccount.name }}
containers:
- name: {{ .Values.connect.applicationName }}
Expand Down
39 changes: 39 additions & 0 deletions charts/connect/templates/operator-hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{- if (and .Values.operator.create .Values.operator.hpa.enabled ) }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ .Values.operator.applicationName }}
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/component: operator
{{- include "onepassword-connect.labels" . | nindent 4 }}
{{- include "onepassword-connect.extraAnnotations" .Values.operator.hpa }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ .Values.operator.applicationName }}
minReplicas: {{ .Values.operator.hpa.minReplicas }}
maxReplicas: {{ .Values.operator.hpa.maxReplicas }}
metrics:
{{- with .Values.operator.hpa.avgMemoryUtilization }}
- type: Resource
resource:
name: memory
target:
averageUtilization: {{ . }}
type: Utilization
{{- end }}
{{- with .Values.operator.hpa.avgCpuUtilization }}
- type: Resource
resource:
name: cpu
target:
averageUtilization: {{ . }}
type: Utilization
{{- end }}
{{- with .Values.operator.hpa.behavior }}
behavior:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
21 changes: 21 additions & 0 deletions charts/connect/templates/operator-pdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- if (and .Values.operator.create .Values.operator.pdb.enabled ) }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ .Values.operator.applicationName }}
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/component: operator
{{- include "onepassword-connect.labels" . | nindent 4 }}
{{- include "onepassword-connect.extraAnnotations" .Values.operator.pdb }}
spec:
{{- with .Values.operator.pdb.maxUnavailable }}
maxUnavailable: {{ . }}
{{- else }}
minAvailable: {{ .Values.operator.pdb.minAvailable }}
{{- end }}
selector:
matchLabels:
app.kubernetes.io/component: operator
{{- include "onepassword-connect.selectorLabels" . | nindent 6 }}
{{- end }}
65 changes: 65 additions & 0 deletions charts/connect/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,37 @@ connect:
# See: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector
nodeSelector: {}

# Affinity rules for the Connect pod
affinity: {}

## Horizontal Pod Autoscaling for the Connect pod
hpa:
# Enable Horizontal Pod Autoscaling for the Connect pod
enabled: false
# Additional annotations to be added to the HPA Connect
annotations: {}
# Minimum number of replicas for the Connect pod
minReplicas: 1
# Maximum number of replicas for the Connect pod
maxReplicas: 3
# Average Memory utilization percentage for the Connect pod
avgMemoryUtilization: 50
# Average CPU utilization percentage for the Connect pod
avgCpuUtilization: 50
# Defines the Autoscaling Behavior in up/down directions
behavior: {}

## Pod Disruption Budget for the Connect pod
pdb:
# Enable Pod Disruption Budget for the Connect pod
enabled: false
# Additional annotations to be added to the PDB Connect
annotations: {}
# Number of pods that are unavailble after eviction as number or percentage (eg.: 50%)
maxUnavailable: 1
# Number of pods that are available after eviction as number or percentage (eg.: 50%)
minAvailable: 0

# 1Password Connect API and Sync Service
probes:
# Denotes whether the 1Password Connect API readiness probe will operate
Expand Down Expand Up @@ -203,6 +234,9 @@ operator:
# Denotes whether the 1Password Operator will be deployed
create: false

# The number of replicas to run the 1Password Connect Operator deployment
replicas: 1

# Denotes whether the 1Password Operator will automatically restart deployments based on associated updated secrets.
autoRestart: false

Expand All @@ -225,6 +259,37 @@ operator:
# See: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector
nodeSelector: {}

# Affinity rules for the Operator pod
affinity: {}

## Horizontal Pod Autoscaling for the Operator pod
hpa:
# Enable Horizontal Pod Autoscaling for the Operator pod
enabled: false
# Additional annotations to be added to the HPA Operator
annotations: {}
# Minimum number of replicas for the Operator pod
minReplicas: 1
# Maximum number of replicas for the Operator pod
maxReplicas: 3
# Average Memory utilization percentage for the Operator pod
avgMemoryUtilization: 50
# Average CPU utilization percentage for the Operator pod
avgCpuUtilization: 50
# Defines the Autoscaling Behavior in up/down directions
behavior: {}

## Pod Disruption Budget for the Operator pod
pdb:
# Enable Pod Disruption Budget for the Operator pod
enabled: false
# Additional annotations to be added to the PDB Operator
annotations: {}
# Number of pods that are unavailble after eviction as number or percentage (eg.: 50%)
maxUnavailable: 1
# Number of pods that are available after eviction as number or percentage (eg.: 50%)
minAvailable: 0

# Additional annotations to be added to the Operator pods.
annotations: {}

Expand Down
Loading