diff --git a/templates/_httpRoute.tpl b/templates/_httpRoute.tpl new file mode 100644 index 0000000..2cc17ac --- /dev/null +++ b/templates/_httpRoute.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} + +{{/* annotations */}} + +{{- define "reposilite.httpRoute.annotations" -}} +{{ include "reposilite.annotations" . }} +{{- if .Values.gatewayAPI.core.httpRoute.annotations }} +{{ toYaml .Values.gatewayAPI.core.httpRoute.annotations }} +{{- end }} +{{- end }} + +{{/* enabled */}} + +{{- define "reposilite.httpRoute.enabled" -}} +{{- if and .Values.gatewayAPI.enabled + .Values.gatewayAPI.core.httpRoute.enabled + .Values.service.enabled +-}} +true +{{- else -}} +false +{{- end -}} +{{- end }} + +{{/* labels */}} + +{{- define "reposilite.httpRoute.labels" -}} +{{ include "reposilite.labels" . }} +{{- if .Values.gatewayAPI.core.httpRoute.labels }} +{{ toYaml .Values.gatewayAPI.core.httpRoute.labels }} +{{- end }} +{{- end }} diff --git a/templates/httpRoute.yaml b/templates/httpRoute.yaml new file mode 100644 index 0000000..1fff995 --- /dev/null +++ b/templates/httpRoute.yaml @@ -0,0 +1,36 @@ +{{- if eq (include "reposilite.httpRoute.enabled" $) "true" }} +--- +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + {{- with (include "reposilite.httpRoute.annotations" . | fromYaml) }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with (include "reposilite.httpRoute.labels" . | fromYaml) }} + labels: + {{- toYaml . | nindent 4 }} + {{- end }} + name: {{ include "reposilite.fullname" . }} + namespace: {{ .Release.Namespace }} +spec: + {{- with .Values.gatewayAPI.core.httpRoute.hostnames }} + hostnames: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.gatewayAPI.core.httpRoute.parentRefs }} + parentRefs: + {{- toYaml . | nindent 4 }} + {{- end }} + rules: + - backendRefs: + - kind: Service + name: {{ include "reposilite.service.name" . }} + namespace: {{ .Release.Namespace }} + port: {{ .Values.service.port }} + weight: 1 + {{- with .Values.gatewayAPI.core.httpRoute.matches }} + matches: + {{- toYaml . | nindent 6 }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/unittests/httpRoute/httpRoute.yaml b/unittests/httpRoute/httpRoute.yaml new file mode 100644 index 0000000..8ce4831 --- /dev/null +++ b/unittests/httpRoute/httpRoute.yaml @@ -0,0 +1,194 @@ +chart: + appVersion: 0.1.0 + version: 0.1.0 +suite: HTTPRoute template +release: + name: reposilite-unittest + namespace: testing +templates: +- templates/httpRoute.yaml +tests: +- it: Skip rendering when disabled 1/6 + set: + gatewayAPI.enabled: false + gatewayAPI.core.httpRoute.enabled: false + service.enabled: false + asserts: + - hasDocuments: + count: 0 + +- it: Skip rendering when disabled 2/6 + set: + gatewayAPI.enabled: true + gatewayAPI.core.httpRoute.enabled: false + service.enabled: false + asserts: + - hasDocuments: + count: 0 + +- it: Skip rendering when disabled 3/6 + set: + gatewayAPI.enabled: false + gatewayAPI.core.httpRoute.enabled: true + service.enabled: false + asserts: + - hasDocuments: + count: 0 + +- it: Skip rendering when disabled 4/6 + set: + gatewayAPI.enabled: false + gatewayAPI.core.httpRoute.enabled: false + service.enabled: true + asserts: + - hasDocuments: + count: 0 + +- it: Skip rendering when disabled 5/6 + set: + gatewayAPI.enabled: true + gatewayAPI.core.httpRoute.enabled: false + service.enabled: true + asserts: + - hasDocuments: + count: 0 + +- it: Skip rendering when disabled 6/6 + set: + gatewayAPI.enabled: true + gatewayAPI.core.httpRoute.enabled: true + service.enabled: false + asserts: + - hasDocuments: + count: 0 + +- it: Rendering default values + set: + gatewayAPI.enabled: true + gatewayAPI.core.httpRoute.enabled: true + service.enabled: true + asserts: + - hasDocuments: + count: 1 + - containsDocument: + apiVersion: gateway.networking.k8s.io/v1 + kind: HTTPRoute + name: reposilite-unittest + namespace: testing + - notExists: + path: metadata.annotations + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: reposilite-unittest + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: reposilite + app.kubernetes.io/version: 0.1.0 + helm.sh/chart: reposilite-0.1.0 + - notExists: + path: spec.hostnames + - notExists: + path: spec.parentRefs + - contains: + path: spec.rules[0].backendRefs + content: + kind: Service + name: reposilite-unittest + namespace: testing + port: 8080 + weight: 1 + - contains: + path: spec.rules[0].matches + content: + path: + type: PathPrefix + value: / + +- it: Rendering custom annotations and labels + set: + gatewayAPI.enabled: true + gatewayAPI.core.httpRoute: + enabled: true + annotations: + foo: bar + labels: + bar: foo + service.enabled: true + asserts: + - hasDocuments: + count: 1 + - equal: + path: metadata.annotations + value: + foo: bar + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: reposilite-unittest + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: reposilite + app.kubernetes.io/version: 0.1.0 + bar: foo + helm.sh/chart: reposilite-0.1.0 + +- it: Rendering custom service port + set: + gatewayAPI.enabled: true + gatewayAPI.core.httpRoute.enabled: true + service: + enabled: true + port: 9090 + asserts: + - equal: + path: spec.rules[0].backendRefs[0].port + value: 9090 + +- it: Rendering custom matches + set: + gatewayAPI.enabled: true + gatewayAPI.core.httpRoute: + enabled: true + matches: + - path: + type: PathPrefix + value: /foo + service.enabled: true + asserts: + - contains: + path: spec.rules[0].matches + content: + path: + type: PathPrefix + value: /foo + +- it: Rendering custom hostnames and parentRefs + set: + gatewayAPI.enabled: true + gatewayAPI.core.httpRoute: + enabled: true + hostnames: + - reposilite.example.local + parentRefs: + - name: gateway + namespace: testing + kind: Gateway + sectionName: reposilite-debug-gateway + service.enabled: true + asserts: + - lengthEqual: + path: spec.hostnames + count: 1 + - contains: + path: spec.hostnames + content: + reposilite.example.local + - lengthEqual: + path: spec.parentRefs + count: 1 + - contains: + path: spec.parentRefs + content: + name: gateway + namespace: testing + kind: Gateway + sectionName: reposilite-debug-gateway diff --git a/values.yaml b/values.yaml index 45523a1..1fcf9e0 100644 --- a/values.yaml +++ b/values.yaml @@ -229,6 +229,68 @@ deployment: # secretName: my-secret +## @section GatewayAPI +gatewayAPI: + ## @param gatewayAPI.enabled Enable the Gateway API resources. Requires Kubernetes v1.19 or higher, the CRD's and a compatible gateway controller. + core: + ## @param gatewayAPI.core.backendTLSPolicy.enabled Enable the BackendTLSPolicy resource. Requires also `gatewayAPI.enabled` to be `true`. + ## @param gatewayAPI.core.backendTLSPolicy.annotations Additional annotations for the BackendTLSPolicy. + ## @param gatewayAPI.core.backendTLSPolicy.labels Additional labels for the BackendTLSPolicy. + ## @param gatewayAPI.core.backendTLSPolicy.validation Validation configuration for the BackendTLSPolicy. For example, you can specify a trusted CA certificate to validate the TLS connection between the gateway and the Reposilite pod. + backendTLSPolicy: + enabled: false + annotations: {} + labels: {} + validation: {} + # caCertificateRefs: + # - group: "" + # kind: Secret + # name: "reposilite-tls" + + ## @param gatewayAPI.core.httpRoute.enabled Enable the HTTPRoute resource. Requires also `gatewayAPI.enabled` and `service.enabled` to be `true`. + ## @param gatewayAPI.core.httpRoute.annotations Additional annotations for the HTTPRoute. + ## @param gatewayAPI.core.httpRoute.labels Additional labels for the HTTPRoute. + ## @param gatewayAPI.core.httpRoute.hostnames Hostnames for the HTTPRoute. + ## @param gatewayAPI.core.httpRoute.matches Match conditions for the HTTPRoute. You can specify path based match conditions to route traffic to the Reposilite service. + ## @param gatewayAPI.core.httpRoute.parentRefs ParentRefs for the HTTPRoute. You can specify parentRefs to bind the HTTPRoute to specific Gateway resources. + httpRoute: + enabled: false + annotations: {} + labels: {} + hostnames: [] + matches: + - path: + type: PathPrefix + value: / + parentRefs: [] + # - name: gateway + # kind: Gateway + # group: gateway.networking.k8s.io + # namespace: default + # sectionName: reposilite-http + + nginx: + ## @param gatewayAPI.nginx.clientSettingsPolicy.enabled Enable the ClientSettingsPolicy resource. Requires also `gatewayAPI.enabled` to be `true`. + ## @param gatewayAPI.nginx.clientSettingsPolicy.annotations Additional annotations for the ClientSettingsPolicy. + ## @param gatewayAPI.nginx.clientSettingsPolicy.labels Additional labels for the ClientSettingsPolicy. + ## @param gatewayAPI.nginx.clientSettingsPolicy.clientMaxBodySize ClientMaxBodySize sets the maximum allowed size of the client request body. If not specified, the default of the nginx gateway controller is used. + ## @param gatewayAPI.nginx.clientSettingsPolicy.clientBodyTimeout ClientBodyTimeout sets the timeout for reading the client request body. If not specified, the default of the nginx gateway controller is used. + ## @param gatewayAPI.nginx.clientSettingsPolicy.keepaliveRequests KeepaliveRequests sets the maximum number of requests that can be served through one keepalive connection. If not specified, the default of the nginx gateway controller is used. + ## @param gatewayAPI.nginx.clientSettingsPolicy.keepaliveTime KeepaliveTime sets the time a keepalive connection is kept open. If not specified, the default of the nginx gateway controller is used. + ## @param gatewayAPI.nginx.clientSettingsPolicy.keepaliveTimeout KeepaliveTimeout sets the time a client has to wait for the response of a request until the connection is closed. If not specified, the default of the nginx gateway controller is used. + ## @param gatewayAPI.nginx.clientSettingsPolicy.keepaliveMinTimeout KeepaliveMinTimeout sets the minimum time a client has to wait for the response of a request until the connection is closed. If not specified, the default of the nginx gateway controller is used. + clientSettingsPolicy: + enabled: false + annotations: {} + labels: {} + clientMaxBodySize: "" + clientBodyTimeout: "" + keepaliveRequests: + keepaliveTime: "" + keepaliveTimeout: "" + keepaliveMinTimeout: "" + + ## @section Horizontal Pod Autoscaler (HPA) # In order for the HPA to function successfully, a metric server is required, especially for resource consumption. The # metric server enables the CPU and memory utilisation to be recorded. If such a metric server is not available, the HPA