Skip to content

Commit e459c4f

Browse files
authored
Introduced a list to avoid hardcoding of api service names. (#180)
1 parent 656dc20 commit e459c4f

File tree

9 files changed

+36
-14
lines changed

9 files changed

+36
-14
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ ingest:
3636
@command -v bash >/dev/null 2>&1 || { echo "bash is required but not installed"; exit 1; }
3737
@./ingest.sh || { echo "Ingestion failed."; exit 1; }
3838

39+
tests:
40+
@echo "Running tests."
41+
@command -v helm >/dev/null 2>&1 || { echo "helm is required but not installed"; exit 1; }
42+
@helm unittest helm-chart/eoapi -f 'tests/*.yaml' -v helm-chart/eoapi/test-helm-values.yaml
43+
3944
help:
4045
@echo "Makefile commands:"
4146
@echo " make deploy - Install eoAPI on a cluster kubectl is connected to."

helm-chart/eoapi/templates/_helpers.tpl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,23 @@ so we use this helper function to check autoscaling rules
159159
{{- define "eoapi.validateAutoscaleRules" -}}
160160
{{- if and .Values.ingress.enabled (ne .Values.ingress.className "nginx") }}
161161
{{/* "requestRate" cannot be enabled for any service if not "nginx" so give feedback and fail */}}
162-
{{- if (or (and .Values.raster.autoscaling.enabled (eq .Values.raster.autoscaling.type "requestRate")) (and .Values.stac.autoscaling.enabled (eq .Values.stac.autoscaling.type "requestRate")) (and .Values.vector.autoscaling.enabled (eq .Values.vector.autoscaling.type "requestRate")) ) }}
162+
{{- $requestRateEnabled := false }}
163+
{{- range .Values.apiServices }}
164+
{{- if and (index $.Values . "autoscaling" "enabled") (eq (index $.Values . "autoscaling" "type") "requestRate") }}
165+
{{- $requestRateEnabled = true }}
166+
{{- end }}
167+
{{- end }}
168+
{{- if $requestRateEnabled }}
163169
{{- fail "When using an 'ingress.className' other than 'nginx' you cannot enable autoscaling by 'requestRate' at this time b/c it's solely an nginx metric" }}
164170
{{- end }}
165171
{{/* "both" cannot be enabled for any service if not "nginx" so give feedback and fail */}}
166-
{{- if (or (and .Values.raster.autoscaling.enabled (eq .Values.raster.autoscaling.type "both")) (and .Values.stac.autoscaling.enabled (eq .Values.stac.autoscaling.type "both")) (and .Values.vector.autoscaling.enabled (eq .Values.vector.autoscaling.type "both")) ) }}
172+
{{- $bothEnabled := false }}
173+
{{- range .Values.apiServices }}
174+
{{- if and (index $.Values . "autoscaling" "enabled") (eq (index $.Values . "autoscaling" "type") "both") }}
175+
{{- $bothEnabled = true }}
176+
{{- end }}
177+
{{- end }}
178+
{{- if $bothEnabled }}
167179
{{- fail "When using an 'ingress.className' other than 'nginx' you cannot enable autoscaling by 'both' at this time b/c 'requestRate' is solely an nginx metric" }}
168180
{{- end }}
169181
{{- end }}

helm-chart/eoapi/templates/services/configmap.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{- range $serviceName, $v := .Values -}}
2-
{{- if (or (eq $serviceName "raster") (eq $serviceName "stac") (eq $serviceName "vector")) }}
2+
{{- if has $serviceName $.Values.apiServices }}
33
{{- if index $v "enabled" }}
44
apiVersion: v1
55
kind: ConfigMap
@@ -12,7 +12,7 @@ data:
1212
---
1313
{{/* END: if index $v "enabled" */}}
1414
{{- end }}
15-
{{/* END: if (or (eq $serviceName "raster") (eq $serviceName "stac") (eq $serviceName "vector")) */}}
15+
{{/* END: if has $serviceName $.Values.apiServices */}}
1616
{{- end }}
1717
{{/* END: range $serviceName, $v := .Values*/}}
1818
{{- end }}

helm-chart/eoapi/templates/services/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{ include "eoapi.validateTempDB" . }}
22
{{- range $serviceName, $v := .Values -}}
3-
{{- if (or (eq $serviceName "raster") (eq $serviceName "stac") (eq $serviceName "vector")) }}
3+
{{- if has $serviceName $.Values.apiServices }}
44
{{- if index $v "enabled" }}
55
apiVersion: apps/v1
66
kind: Deployment
@@ -82,7 +82,7 @@ spec:
8282
---
8383
{{/* END: if index $v "enabled" */}}
8484
{{- end }}
85-
{{/* END: if (or (eq $serviceName "raster") (eq $serviceName "stac") (eq $serviceName "vector")) */}}
85+
{{/* END: if has $serviceName $.Values.apiServices */}}
8686
{{- end }}
8787
{{/* END: range $serviceName, $v := .Values*/}}
8888
{{- end }}

helm-chart/eoapi/templates/services/hpa.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{- include "eoapi.validateAutoscaleRules" . -}}
22
{{- range $serviceName, $v := .Values -}}
3-
{{- if (or (eq $serviceName "raster") (eq $serviceName "stac") (eq $serviceName "vector")) }}
3+
{{- if has $serviceName $.Values.apiServices }}
44
{{- if index $v "autoscaling" "enabled" }}
55
apiVersion: autoscaling/v2
66
kind: HorizontalPodAutoscaler
@@ -44,7 +44,7 @@ spec:
4444
---
4545
{{/* END: if index $v "autoscaling" "enabled" */}}
4646
{{- end }}
47-
{{/* END: if (or (eq $serviceName "raster") (eq $serviceName "stac") (eq $serviceName "vector")) */}}
47+
{{/* END: if has $serviceName $.Values.apiServices */}}
4848
{{- end }}
4949
{{/* END: range $serviceName, $v := .Values*/}}
5050
{{- end }}

helm-chart/eoapi/templates/services/ingress-nginx.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ spec:
3131
- http:
3232
paths:
3333
{{- range $serviceName, $v := .Values }}
34-
{{- if (or (eq $serviceName "raster") (eq $serviceName "stac") (eq $serviceName "vector")) }}
34+
{{- if has $serviceName $.Values.apiServices }}
3535
{{- if (and (index $v "enabled") (not $.Values.testing)) }}
3636
- pathType: Prefix
3737
path: "/{{ $serviceName }}(/|$)(.*)"
@@ -49,7 +49,7 @@ spec:
4949
port:
5050
number: {{ $.Values.service.port }}
5151
{{- end }}{{/* END: if index $v "enabled" */}}
52-
{{- end }}{{/* END: if (or (eq $serviceName "raster") (eq $serviceName "stac") (eq $serviceName "vector")) */}}
52+
{{- end }}{{/* END: if has $serviceName $.Values.apiServices */}}
5353
{{- end }}{{/* END: range $serviceName, $v := .Values*/}}
5454
{{- if (and (not $.Values.testing) (.Values.docServer.enabled)) }}
5555
- pathType: Prefix

helm-chart/eoapi/templates/services/ingress-traefik.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ spec:
4141
- http:
4242
paths:
4343
{{- range $serviceName, $v := .Values }}
44-
{{- if (or (eq $serviceName "raster") (eq $serviceName "stac") (eq $serviceName "vector")) }}
44+
{{- if has $serviceName $.Values.apiServices }}
4545
{{- if (and (index $v "enabled") (not $.Values.testing)) }}
4646
- pathType: Prefix
4747
path: "/{{ $serviceName }}"
@@ -59,7 +59,7 @@ spec:
5959
port:
6060
number: {{ $.Values.service.port }}
6161
{{- end }}{{/* END: if index $v "enabled" */}}
62-
{{- end }}{{/* END: if (or (eq $serviceName "raster") (eq $serviceName "stac") (eq $serviceName "vector")) */}}
62+
{{- end }}{{/* END: if has $serviceName $.Values.apiServices */}}
6363
{{- end }}{{/* END: range $serviceName, $v := .Values*/}}
6464
{{- if (and (not $.Values.testing) (.Values.docServer.enabled)) }}
6565
- pathType: Prefix

helm-chart/eoapi/templates/services/service.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{- range $serviceName, $v := .Values -}}
2-
{{- if (or (eq $serviceName "raster") (eq $serviceName "stac") (eq $serviceName "vector")) }}
2+
{{- if has $serviceName $.Values.apiServices }}
33
{{- if index $v "enabled" }}
44
apiVersion: v1
55
kind: Service
@@ -28,7 +28,7 @@ spec:
2828
---
2929
{{/* END: if index $v "enabled" */}}
3030
{{- end }}
31-
{{/* END: if (or (eq $serviceName "raster") (eq $serviceName "stac") (eq $serviceName "vector")) */}}
31+
{{/* END: if has $serviceName $.Values.externalServices */}}
3232
{{- end }}
3333
{{/* END: range $serviceName, $v := .Values*/}}
3434
{{- end }}

helm-chart/eoapi/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ pgstacBootstrap:
170170
######################
171171
# API SERVICES
172172
######################
173+
apiServices:
174+
- raster
175+
- stac
176+
- vector
177+
173178
raster:
174179
enabled: true
175180
autoscaling:

0 commit comments

Comments
 (0)