diff --git a/.github/workflows/tests/test_stac.py b/.github/workflows/tests/test_stac.py index 6b142fdc..5506787f 100644 --- a/.github/workflows/tests/test_stac.py +++ b/.github/workflows/tests/test_stac.py @@ -14,6 +14,15 @@ def test_stac_api(stac_endpoint): # Ping assert client.get(f"{stac_endpoint}/_mgmt/ping").status_code == 200 + # Landing page + resp = client.get(stac_endpoint) + assert resp.status_code == 200 + landing = resp.json() + # Verify landing page links have correct base path + for link in landing["links"]: + if link["href"].startswith("/"): + assert link["href"].startswith(stac_endpoint.split("://")[1]) + # viewer #assert client.get(f"{stac_endpoint}/index.html").status_code == 200 assert client.get(f"{stac_endpoint}/index.html").status_code == 404 @@ -26,11 +35,21 @@ def test_stac_api(stac_endpoint): ids = [c["id"] for c in collections] assert "noaa-emergency-response" in ids + # Verify collection links have correct base path + for collection in collections: + for link in collection["links"]: + if link["href"].startswith("/"): + assert link["href"].startswith(stac_endpoint.split("://")[1]) + # items resp = client.get(f"{stac_endpoint}/collections/noaa-emergency-response/items") assert resp.status_code == 200 - items = resp.json()["features"] - assert len(items) == 10 + items = resp.json() + # Verify item links have correct base path + for feature in items["features"]: + for link in feature["links"]: + if link["href"].startswith("/"): + assert link["href"].startswith(stac_endpoint.split("://")[1]) # item resp = client.get( @@ -51,6 +70,45 @@ def test_stac_to_raster(stac_endpoint): #assert resp.status_code == 307 assert resp.status_code == 404 +def test_stac_custom_path(stac_endpoint): + """test stac with custom ingress path.""" + # If we're using a custom path (e.g., /api instead of /stac) + base_path = stac_endpoint.split("://")[1] + + # Landing page + resp = client.get(stac_endpoint) + assert resp.status_code == 200 + landing = resp.json() + + # All links should use the custom path + for link in landing["links"]: + if link["href"].startswith("/"): + assert link["href"].startswith(base_path), \ + f"Link {link['href']} doesn't start with {base_path}" + + # Collections should also use the custom path + resp = client.get(f"{stac_endpoint}/collections") + assert resp.status_code == 200 + collections = resp.json()["collections"] + + for collection in collections: + for link in collection["links"]: + if link["href"].startswith("/"): + assert link["href"].startswith(base_path), \ + f"Collection link {link['href']} doesn't start with {base_path}" + + # Test a specific item + resp = client.get(f"{stac_endpoint}/collections/noaa-emergency-response/items") + assert resp.status_code == 200 + items = resp.json() + + # Item links should also use the custom path + for feature in items["features"]: + for link in feature["links"]: + if link["href"].startswith("/"): + assert link["href"].startswith(base_path), \ + f"Item link {link['href']} doesn't start with {base_path}" + # viewer resp = client.get( f"{stac_endpoint}/collections/noaa-emergency-response/items/20200307aC0853300w361200/viewer", diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..082b1943 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "makefile.configureOnOpen": false +} \ No newline at end of file diff --git a/helm-chart/eoapi/templates/services/browser/deployment.yaml b/helm-chart/eoapi/templates/services/browser/deployment.yaml index ac11ff7a..e542dbf4 100644 --- a/helm-chart/eoapi/templates/services/browser/deployment.yaml +++ b/helm-chart/eoapi/templates/services/browser/deployment.yaml @@ -20,5 +20,5 @@ spec: - containerPort: 8080 env: - name: SB_catalogUrl - value: "/stac" + value: "{{ .Values.stac.ingress.path }}" {{- end }} diff --git a/helm-chart/eoapi/templates/services/ingress.yaml b/helm-chart/eoapi/templates/services/ingress.yaml index 16093175..1798c9e3 100644 --- a/helm-chart/eoapi/templates/services/ingress.yaml +++ b/helm-chart/eoapi/templates/services/ingress.yaml @@ -36,7 +36,7 @@ spec: paths: {{- if and .Values.raster.enabled (or (not (hasKey .Values.raster "ingress")) .Values.raster.ingress.enabled) }} - pathType: {{ if eq .Values.ingress.className "nginx" }}ImplementationSpecific{{ else }}Prefix{{ end }} - path: /raster{{ if eq .Values.ingress.className "nginx" }}(/|$)(.*){{ end }} + path: {{ .Values.raster.ingress.path }}{{ if eq .Values.ingress.className "nginx" }}(/|$)(.*){{ end }} backend: service: name: raster-{{ $.Release.Name }} @@ -46,7 +46,7 @@ spec: {{- if and .Values.stac.enabled (or (not (hasKey .Values.stac "ingress")) .Values.stac.ingress.enabled) }} - pathType: {{ if eq .Values.ingress.className "nginx" }}ImplementationSpecific{{ else }}Prefix{{ end }} - path: /stac{{ if eq .Values.ingress.className "nginx" }}(/|$)(.*){{ end }} + path: {{ .Values.stac.ingress.path }}{{ if eq .Values.ingress.className "nginx" }}(/|$)(.*){{ end }} backend: service: name: stac-{{ $.Release.Name }} @@ -56,7 +56,7 @@ spec: {{- if and .Values.vector.enabled (or (not (hasKey .Values.vector "ingress")) .Values.vector.ingress.enabled) }} - pathType: {{ if eq .Values.ingress.className "nginx" }}ImplementationSpecific{{ else }}Prefix{{ end }} - path: /vector{{ if eq .Values.ingress.className "nginx" }}(/|$)(.*){{ end }} + path: {{ .Values.vector.ingress.path }}{{ if eq .Values.ingress.className "nginx" }}(/|$)(.*){{ end }} backend: service: name: vector-{{ $.Release.Name }} @@ -66,7 +66,7 @@ spec: {{- if and .Values.multidim.enabled (or (not (hasKey .Values.multidim "ingress")) .Values.multidim.ingress.enabled) }} - pathType: {{ if eq .Values.ingress.className "nginx" }}ImplementationSpecific{{ else }}Prefix{{ end }} - path: /multidim{{ if eq .Values.ingress.className "nginx" }}(/|$)(.*){{ end }} + path: {{ .Values.multidim.ingress.path }}{{ if eq .Values.ingress.className "nginx" }}(/|$)(.*){{ end }} backend: service: name: multidim-{{ $.Release.Name }} diff --git a/helm-chart/eoapi/templates/services/multidim/deployment.yaml b/helm-chart/eoapi/templates/services/multidim/deployment.yaml index 0cf7ae36..0938bf41 100644 --- a/helm-chart/eoapi/templates/services/multidim/deployment.yaml +++ b/helm-chart/eoapi/templates/services/multidim/deployment.yaml @@ -40,7 +40,7 @@ spec: {{- if (and (.Values.ingress.className) (or (eq .Values.ingress.className "nginx") (eq .Values.ingress.className "traefik"))) }} - "--proxy-headers" - "--forwarded-allow-ips=*" - - "--root-path=/multidim" + - "--root-path={{ .Values.multidim.ingress.path }}" {{- end }}{{/* needed for proxies and path rewrites on NLB */}} livenessProbe: tcpSocket: diff --git a/helm-chart/eoapi/templates/services/raster/deployment.yaml b/helm-chart/eoapi/templates/services/raster/deployment.yaml index 5b1c6922..b7ebda23 100644 --- a/helm-chart/eoapi/templates/services/raster/deployment.yaml +++ b/helm-chart/eoapi/templates/services/raster/deployment.yaml @@ -40,7 +40,7 @@ spec: {{- if (and (.Values.ingress.className) (or (eq .Values.ingress.className "nginx") (eq .Values.ingress.className "traefik"))) }} - "--proxy-headers" - "--forwarded-allow-ips=*" - - "--root-path=/raster" + - "--root-path={{ .Values.raster.ingress.path }}" {{- end }}{{/* needed for proxies and path rewrites on NLB */}} livenessProbe: tcpSocket: diff --git a/helm-chart/eoapi/templates/services/stac/deployment.yaml b/helm-chart/eoapi/templates/services/stac/deployment.yaml index 6443694d..669c1ad8 100644 --- a/helm-chart/eoapi/templates/services/stac/deployment.yaml +++ b/helm-chart/eoapi/templates/services/stac/deployment.yaml @@ -40,7 +40,7 @@ spec: {{- if (and (.Values.ingress.className) (or (eq .Values.ingress.className "nginx") (eq .Values.ingress.className "traefik"))) }} - "--proxy-headers" - "--forwarded-allow-ips=*" - - "--root-path=/stac" + - "--root-path={{ .Values.stac.ingress.path }}" {{- end }}{{/* needed for proxies and path rewrites on NLB */}} livenessProbe: tcpSocket: diff --git a/helm-chart/eoapi/templates/services/traefik-middleware.yaml b/helm-chart/eoapi/templates/services/traefik-middleware.yaml index 2e252cce..274b6035 100644 --- a/helm-chart/eoapi/templates/services/traefik-middleware.yaml +++ b/helm-chart/eoapi/templates/services/traefik-middleware.yaml @@ -8,15 +8,15 @@ spec: stripPrefix: prefixes: {{- if .Values.raster.enabled }} - - /raster + - {{ .Values.raster.ingress.path }} {{- end }} {{- if .Values.stac.enabled }} - - /stac + - {{ .Values.stac.ingress.path }} {{- end }} {{- if .Values.vector.enabled }} - - /vector + - {{ .Values.vector.ingress.path }} {{- end }} {{- if .Values.multidim.enabled }} - - /multidim + - {{ .Values.multidim.ingress.path }} {{- end }} {{- end }} diff --git a/helm-chart/eoapi/templates/services/vector/deployment.yaml b/helm-chart/eoapi/templates/services/vector/deployment.yaml index bf22a897..dc1ca728 100644 --- a/helm-chart/eoapi/templates/services/vector/deployment.yaml +++ b/helm-chart/eoapi/templates/services/vector/deployment.yaml @@ -40,7 +40,7 @@ spec: {{- if (and (.Values.ingress.className) (or (eq .Values.ingress.className "nginx") (eq .Values.ingress.className "traefik"))) }} - "--proxy-headers" - "--forwarded-allow-ips=*" - - "--root-path=/vector" + - "--root-path={{ .Values.vector.ingress.path }}" {{- end }}{{/* needed for proxies and path rewrites on NLB */}} livenessProbe: tcpSocket: diff --git a/helm-chart/eoapi/tests/ingress_tests.yaml b/helm-chart/eoapi/tests/ingress_tests.yaml index ae5e6657..ae9bfb14 100644 --- a/helm-chart/eoapi/tests/ingress_tests.yaml +++ b/helm-chart/eoapi/tests/ingress_tests.yaml @@ -91,3 +91,65 @@ tests: - equal: path: spec.rules[0].http.paths[1].backend.service.name value: doc-server-RELEASE-NAME + + - it: "custom paths for multiple services with nginx controller" + set: + ingress.className: "nginx" + raster.enabled: true + raster.ingress.path: "/titiler" + stac.enabled: true + stac.ingress.path: "/api" + vector.enabled: true + vector.ingress.path: "/features" + multidim.enabled: false + browser.enabled: false + asserts: + - isKind: + of: Ingress + - equal: + path: spec.rules[0].http.paths[0].path + value: "/titiler(/|$)(.*)" + - equal: + path: spec.rules[0].http.paths[1].path + value: "/api(/|$)(.*)" + - equal: + path: spec.rules[0].http.paths[2].path + value: "/features(/|$)(.*)" + - equal: + path: spec.rules[0].http.paths[0].pathType + value: "ImplementationSpecific" + - equal: + path: spec.rules[0].http.paths[1].pathType + value: "ImplementationSpecific" + - equal: + path: spec.rules[0].http.paths[2].pathType + value: "ImplementationSpecific" + - equal: + path: metadata.annotations + value: + nginx.ingress.kubernetes.io/use-regex: "true" + nginx.ingress.kubernetes.io/rewrite-target: /$2 + + - it: "custom paths with traefik controller" + set: + ingress.className: "traefik" + raster.enabled: false + stac.enabled: true + stac.ingress.path: "/api" + vector.enabled: false + multidim.enabled: false + browser.enabled: false + asserts: + - isKind: + of: Ingress + - equal: + path: spec.rules[0].http.paths[0].path + value: "/api" + - equal: + path: spec.rules[0].http.paths[0].pathType + value: "Prefix" + - equal: + path: metadata.annotations + value: + traefik.ingress.kubernetes.io/router.entrypoints: web + traefik.ingress.kubernetes.io/router.middlewares: NAMESPACE-strip-prefix-middleware-RELEASE-NAME@kubernetescrd diff --git a/helm-chart/eoapi/values.yaml b/helm-chart/eoapi/values.yaml index 0472c0c0..c6bb4c01 100644 --- a/helm-chart/eoapi/values.yaml +++ b/helm-chart/eoapi/values.yaml @@ -190,6 +190,7 @@ raster: enabled: true ingress: enabled: true # Control ingress specifically for raster service + path: "/raster" # Configurable path prefix for the raster service autoscaling: # NOTE: to have autoscaling working you'll need to install the `eoapi-support` chart # see ../../../docs/autoscaling.md for more information @@ -261,6 +262,7 @@ multidim: enabled: false # disabled by default ingress: enabled: true # Control ingress specifically for multidim service + path: "/multidim" # Configurable path prefix for the multidim service autoscaling: # NOTE: to have autoscaling working you'll need to install the `eoapi-support` chart # see ../../../docs/autoscaling.md for more information @@ -332,6 +334,7 @@ stac: enabled: true ingress: enabled: true # Control ingress specifically for stac service + path: "/stac" # Configurable path prefix for the stac service autoscaling: # NOTE: to have autoscaling working you'll need to install the `eoapi-support` chart # see ../../../docs/autoscaling.md for more information @@ -391,6 +394,7 @@ vector: enabled: true ingress: enabled: true # Control ingress specifically for vector service + path: "/vector" # Configurable path prefix for the vector service autoscaling: # NOTE: to have autoscaling working you'll need to install the `eoapi-support` chart # see ../../../docs/autoscaling.md for more information @@ -473,4 +477,4 @@ docServer: # prefer to set it in the command line # helm upgrade --set previousVersion=$PREVIOUS_VERSION # or in the CI/CD pipeline -previousVersion: "" \ No newline at end of file +previousVersion: ""