Skip to content

Commit

Permalink
add apiversion capabilities check to helm template (#2137)
Browse files Browse the repository at this point in the history
Co-authored-by: Yusuke Kato <[email protected]>
  • Loading branch information
datelier and kpango committed Jul 26, 2023
1 parent 38de959 commit dda49f0
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 5 deletions.
18 changes: 18 additions & 0 deletions charts/vald/templates/agent/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
#
{{- $agent := .Values.agent -}}
{{- if and $agent.enabled $agent.hpa.enabled }}
{{- if (.Capabilities.APIVersions.Has "autoscaling/v2") }}
apiVersion: autoscaling/v2
{{- else if (.Capabilities.APIVersions.Has "autoscaling/v2beta2") }}
apiVersion: autoscaling/v2beta2
{{- else if (.Capabilities.APIVersions.Has "autoscaling/v2beta1") }}
apiVersion: autoscaling/v2beta1
{{- else }}
apiVersion: autoscaling/v1
{{- end }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ $agent.name }}
Expand All @@ -33,6 +41,16 @@ spec:
apiVersion: apps/v1
kind: {{ $agent.kind }}
name: {{ $agent.name }}
{{- if or (.Capabilities.APIVersions.Has "autoscaling/v2") (.Capabilities.APIVersions.Has "autoscaling/v2beta2") (.Capabilities.APIVersions.Has "autoscaling/v2beta1") }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ $agent.hpa.targetCPUUtilizationPercentage }}
{{ else }}
targetCPUUtilizationPercentage: {{ $agent.hpa.targetCPUUtilizationPercentage }}
{{- end }}
status:
{{- end }}
6 changes: 5 additions & 1 deletion charts/vald/templates/agent/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
{{- $lb := .Values.gateway.lb -}}
{{- $index := .Values.manager.index -}}
{{- if .Values.defaults.networkPolicy.enabled }}
kind: NetworkPolicy
{{- if (.Capabilities.APIVersions.Has "networking.k8s.io/v1alpha1") }}
apiVersion: networking.k8s.io/v1alpha1
{{- else }}
apiVersion: networking.k8s.io/v1
{{- end }}
kind: NetworkPolicy
metadata:
name: agent-allow
spec:
Expand Down
4 changes: 4 additions & 0 deletions charts/vald/templates/agent/pdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#
{{- $agent := .Values.agent -}}
{{- if $agent.enabled }}
{{- if (.Capabilities.APIVersions.Has "policy/v1beta1") }}
apiVersion: policy/v1beta1
{{- else }}
apiVersion: policy/v1
{{- end }}
kind: PodDisruptionBudget
metadata:
name: {{ $agent.name }}
Expand Down
18 changes: 18 additions & 0 deletions charts/vald/templates/discoverer/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
#
{{- $discoverer := .Values.discoverer -}}
{{- if $discoverer.hpa.enabled }}
{{- if (.Capabilities.APIVersions.Has "autoscaling/v2") }}
apiVersion: autoscaling/v2
{{- else if (.Capabilities.APIVersions.Has "autoscaling/v2beta2") }}
apiVersion: autoscaling/v2beta2
{{- else if (.Capabilities.APIVersions.Has "autoscaling/v2beta1") }}
apiVersion: autoscaling/v2beta1
{{- else }}
apiVersion: autoscaling/v1
{{- end }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ $discoverer.name }}
Expand All @@ -33,6 +41,16 @@ spec:
apiVersion: apps/v1
kind: {{ $discoverer.kind }}
name: {{ $discoverer.name }}
{{- if or (.Capabilities.APIVersions.Has "autoscaling/v2") (.Capabilities.APIVersions.Has "autoscaling/v2beta2") (.Capabilities.APIVersions.Has "autoscaling/v2beta1") }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ $discoverer.hpa.targetCPUUtilizationPercentage }}
{{- else }}
targetCPUUtilizationPercentage: {{ $discoverer.hpa.targetCPUUtilizationPercentage }}
{{- end }}
status:
{{- end }}
6 changes: 5 additions & 1 deletion charts/vald/templates/discoverer/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
{{- $lb := .Values.gateway.lb -}}
{{- $index := .Values.manager.index -}}
{{- if .Values.defaults.networkPolicy.enabled }}
kind: NetworkPolicy
{{- if (.Capabilities.APIVersions.Has "networking.k8s.io/v1alpha1") }}
apiVersion: networking.k8s.io/v1alpha1
{{- else }}
apiVersion: networking.k8s.io/v1
{{- end }}
kind: NetworkPolicy
metadata:
name: discoverer-allow
spec:
Expand Down
4 changes: 4 additions & 0 deletions charts/vald/templates/discoverer/pdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#
{{- $discoverer := .Values.discoverer -}}
{{- if $discoverer.enabled }}
{{- if (.Capabilities.APIVersions.Has "policy/v1beta1") }}
apiVersion: policy/v1beta1
{{- else }}
apiVersion: policy/v1
{{- end }}
kind: PodDisruptionBudget
metadata:
name: {{ $discoverer.name }}
Expand Down
18 changes: 18 additions & 0 deletions charts/vald/templates/gateway/filter/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
#
{{- $gateway := .Values.gateway.filter -}}
{{- if and $gateway.enabled $gateway.hpa.enabled }}
{{- if (.Capabilities.APIVersions.Has "autoscaling/v2") }}
apiVersion: autoscaling/v2
{{- else if (.Capabilities.APIVersions.Has "autoscaling/v2beta2") }}
apiVersion: autoscaling/v2beta2
{{- else if (.Capabilities.APIVersions.Has "autoscaling/v2beta1") }}
apiVersion: autoscaling/v2beta1
{{- else }}
apiVersion: autoscaling/v1
{{- end }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ $gateway.name }}
Expand All @@ -33,6 +41,16 @@ spec:
apiVersion: apps/v1
kind: {{ $gateway.kind }}
name: {{ $gateway.name }}
{{- if or (.Capabilities.APIVersions.Has "autoscaling/v2") (.Capabilities.APIVersions.Has "autoscaling/v2beta2") (.Capabilities.APIVersions.Has "autoscaling/v2beta1") }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ $gateway.hpa.targetCPUUtilizationPercentage }}
{{- else }}
targetCPUUtilizationPercentage: {{ $gateway.hpa.targetCPUUtilizationPercentage }}
{{- end }}
status:
{{- end }}
4 changes: 4 additions & 0 deletions charts/vald/templates/gateway/filter/ing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#
{{- $gateway := .Values.gateway.filter -}}
{{- if and $gateway.enabled $gateway.ingress.enabled }}
{{- if (.Capabilities.APIVersions.Has "networking.k8s.io/v1alpha1") }}
apiVersion: networking.k8s.io/v1alpha1
{{- else }}
apiVersion: networking.k8s.io/v1
{{- end }}
kind: Ingress
metadata:
annotations:
Expand Down
6 changes: 5 additions & 1 deletion charts/vald/templates/gateway/filter/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
{{- $lb := .Values.gateway.lb -}}
{{- $filter := .Values.gateway.filter -}}
{{- if .Values.defaults.networkPolicy.enabled }}
kind: NetworkPolicy
{{- if (.Capabilities.APIVersions.Has "networking.k8s.io/v1alpha1") }}
apiVersion: networking.k8s.io/v1alpha1
{{- else }}
apiVersion: networking.k8s.io/v1
{{- end }}
kind: NetworkPolicy
metadata:
name: filter-allow
spec:
Expand Down
4 changes: 4 additions & 0 deletions charts/vald/templates/gateway/filter/pdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#
{{- $gateway := .Values.gateway.filter -}}
{{- if $gateway.enabled }}
{{- if (.Capabilities.APIVersions.Has "policy/v1beta1") }}
apiVersion: policy/v1beta1
{{- else }}
apiVersion: policy/v1
{{- end }}
kind: PodDisruptionBudget
metadata:
name: {{ $gateway.name }}
Expand Down
18 changes: 18 additions & 0 deletions charts/vald/templates/gateway/lb/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
#
{{- $gateway := .Values.gateway.lb -}}
{{- if and $gateway.enabled $gateway.hpa.enabled }}
{{- if (.Capabilities.APIVersions.Has "autoscaling/v2") }}
apiVersion: autoscaling/v2
{{- else if (.Capabilities.APIVersions.Has "autoscaling/v2beta2") }}
apiVersion: autoscaling/v2beta2
{{- else if (.Capabilities.APIVersions.Has "autoscaling/v2beta1") }}
apiVersion: autoscaling/v2beta1
{{- else }}
apiVersion: autoscaling/v1
{{- end }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ $gateway.name }}
Expand All @@ -33,6 +41,16 @@ spec:
apiVersion: apps/v1
kind: {{ $gateway.kind }}
name: {{ $gateway.name }}
{{- if or (.Capabilities.APIVersions.Has "autoscaling/v2") (.Capabilities.APIVersions.Has "autoscaling/v2beta2") (.Capabilities.APIVersions.Has "autoscaling/v2beta1") }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ $gateway.hpa.targetCPUUtilizationPercentage }}
{{- else }}
targetCPUUtilizationPercentage: {{ $gateway.hpa.targetCPUUtilizationPercentage }}
{{- end }}
status:
{{- end }}
4 changes: 4 additions & 0 deletions charts/vald/templates/gateway/lb/ing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#
{{- $gateway := .Values.gateway.lb -}}
{{- if and $gateway.enabled $gateway.ingress.enabled }}
{{- if (.Capabilities.APIVersions.Has "networking.k8s.io/v1alpha1") }}
apiVersion: networking.k8s.io/v1alpha1
{{- else }}
apiVersion: networking.k8s.io/v1
{{- end }}
kind: Ingress
metadata:
annotations:
Expand Down
6 changes: 5 additions & 1 deletion charts/vald/templates/gateway/lb/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
{{- $filter := .Values.gateway.filter -}}
{{- $discoverer := .Values.discoverer -}}
{{- if .Values.defaults.networkPolicy.enabled }}
kind: NetworkPolicy
{{- if (.Capabilities.APIVersions.Has "networking.k8s.io/v1alpha1") }}
apiVersion: networking.k8s.io/v1alpha1
{{- else }}
apiVersion: networking.k8s.io/v1
{{- end }}
kind: NetworkPolicy
metadata:
name: lb-allow
spec:
Expand Down
4 changes: 4 additions & 0 deletions charts/vald/templates/gateway/lb/pdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#
{{- $gateway := .Values.gateway.lb -}}
{{- if $gateway.enabled }}
{{- if (.Capabilities.APIVersions.Has "policy/v1beta1") }}
apiVersion: policy/v1beta1
{{- else }}
apiVersion: policy/v1
{{- end }}
kind: PodDisruptionBudget
metadata:
name: {{ $gateway.name }}
Expand Down
6 changes: 5 additions & 1 deletion charts/vald/templates/manager/index/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
{{- $discoverer := .Values.discoverer -}}
{{- $index := .Values.manager.index -}}
{{- if .Values.defaults.networkPolicy.enabled }}
kind: NetworkPolicy
{{- if (.Capabilities.APIVersions.Has "networking.k8s.io/v1alpha1") }}
apiVersion: networking.k8s.io/v1alpha1
{{- else }}
apiVersion: networking.k8s.io/v1
{{- end }}
kind: NetworkPolicy
metadata:
name: index-allow
spec:
Expand Down
4 changes: 4 additions & 0 deletions charts/vald/templates/manager/index/pdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#
{{- $index := .Values.manager.index -}}
{{- if $index.enabled }}
{{- if (.Capabilities.APIVersions.Has "policy/v1beta1") }}
apiVersion: policy/v1beta1
{{- else }}
apiVersion: policy/v1
{{- end }}
kind: PodDisruptionBudget
metadata:
name: {{ $index.name }}
Expand Down

0 comments on commit dda49f0

Please sign in to comment.