Skip to content

Commit

Permalink
Merge pull request #19 from kubercow/apiversion
Browse files Browse the repository at this point in the history
added networking.k8s.io/v1 to fix problem with v1.22
  • Loading branch information
andrzejwp authored May 22, 2023
2 parents 1c8bc61 + d3635c6 commit 5307e1e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
31 changes: 31 additions & 0 deletions chart/bitwarden-k8s/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,34 @@ Create chart name and version as used by the chart label.
{{- define "bitwarden-k8s.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for ingress.
*/}}
{{- define "bitwarden-k8s.ingress.apiVersion" -}}
{{- if and (.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19-0" .Capabilities.KubeVersion.Version) -}}
{{- print "networking.k8s.io/v1" -}}
{{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" -}}
{{- print "networking.k8s.io/v1beta1" -}}
{{- else -}}
{{- print "extensions/v1beta1" -}}
{{- end -}}
{{- end -}}
{{/*
Return if ingress is stable.
*/}}
{{- define "bitwarden-k8s.ingress.isStable" -}}
{{- eq (include "bitwarden-k8s.ingress.apiVersion" .) "networking.k8s.io/v1" -}}
{{- end -}}
{{/*
Return if ingress supports ingressClassName.
*/}}
{{- define "bitwarden-k8s.ingress.supportsIngressClassName" -}}
{{- or (eq (include "bitwarden-k8s.ingress.isStable" .) "true") (and (eq (include "bitwarden-k8s.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}}
{{- end -}}
{{/*
Return if ingress supports pathType.
*/}}
{{- define "bitwarden-k8s.ingress.supportsPathType" -}}
{{- or (eq (include "bitwarden-k8s.ingress.isStable" .) "true") (and (eq (include "bitwarden-k8s.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}}
{{- end -}}
20 changes: 18 additions & 2 deletions chart/bitwarden-k8s/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "bitwarden-k8s.fullname" . -}}
{{- $ingressPath := .Values.ingress.path -}}
apiVersion: extensions/v1beta1
{{- $ingressApiIsStable := eq (include "bitwarden-k8s.ingress.isStable" .) "true" -}}
{{- $ingressSupportsIngressClassName := eq (include "bitwarden-k8s.ingress.supportsIngressClassName" .) "true" -}}
{{- $ingressSupportsPathType := eq (include "bitwarden-k8s.ingress.supportsPathType" .) "true" -}}
{{- $ingressPathType := .Values.ingress.pathType -}}
{{- $servicePort := .Values.service.port -}}

apiVersion: {{ include "bitwarden-k8s.ingress.apiVersion" . }}
kind: Ingress
metadata:
name: {{ $fullName }}
Expand Down Expand Up @@ -31,8 +37,18 @@ spec:
http:
paths:
- path: {{ $ingressPath }}
{{- if $ingressSupportsPathType }}
pathType: {{ $ingressPathType }}
{{- end }}
backend:
{{- if $ingressApiIsStable }}
service:
name: {{ $fullName }}
port:
number: {{ $servicePort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: http
servicePort: {{ $servicePort }}
{{- end }}
{{- end }}
{{- end }}
4 changes: 4 additions & 0 deletions chart/bitwarden-k8s/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ ingress:
hosts:
- bitwarden.example

# pathType is only for k8s >= 1.1=
pathType: Prefix


resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
Expand Down

0 comments on commit 5307e1e

Please sign in to comment.