Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.8.9] - 2025-01-10

### Added

- A service can specify that its base domain should redirect to a www. domain by adding the `redirectHostToWWW` key with the base domain as the value. e.g. if your hostnames list includes www.example.com you can specify `redirectHostToWWW: example.com` in order to set the ALB rules to do this. At the moment this is only supported for one hostname per service definition.

## [1.8.8] - 2025-01-03

### Added
Expand Down
2 changes: 1 addition & 1 deletion charts/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ apiVersion: v2
description: Common service chart
name: common
type: library
version: 1.8.8
version: 1.8.9
maintainers:
- name: DevOps
24 changes: 24 additions & 0 deletions charts/common/templates/_ingress.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@
{{- $_ := required (printf "You must specify rootDomain in the ingress or global section") $rootDomain }}
{{- end }}

{{- $wwwRedirect := "" }}
{{- if hasKey $v "redirectHostToWWW" }}
{{- if ne $v.ingressClass "alb" }}
{{- $_ := required (printf "www redirect is only supported for ALB ingresses") }}
{{- end }}
{{- $wwwRedirect = printf "www.%s" $v.redirectHostToWWW }}
{{- if $v.imperva }}
{{- $wwwRedirect = printf "origin-%s" $wwwRedirect }}
{{- end }}
{{- end }}

---
apiVersion: networking.k8s.io/v1
kind: Ingress
Expand All @@ -104,6 +115,10 @@ metadata:
{{- if and (hasKey $.root.Values "spec" ) (hasKey $.root.Values.spec "clusterName") }}
external-dns.alpha.kubernetes.io/set-identifier: {{ $.root.Values.spec.clusterName }}
{{- end }}
{{- if $wwwRedirect }}
alb.ingress.kubernetes.io/actions.rule-redirect-www: '{"Type":"redirect","RedirectConfig":{"Host":"www.{{ $v.redirectHostToWWW }}","Port":"443","Protocol":"HTTPS","StatusCode":"HTTP_301"}}'
alb.ingress.kubernetes.io/conditions.rule-redirect-www: '[{"Field":"host-header","HostHeaderConfig":{"Values":["{{ $v.redirectHostToWWW }}"]}}]'
{{- end }}
labels:
{{- include "common.helper.labels" (dict "global" $global.labels "override" $v.labels) | nindent 4 }}
spec:
Expand All @@ -120,6 +135,15 @@ spec:
name: {{ $v.service.name }}
port:
number: {{ $v.service.port }}
{{- if and $wwwRedirect (eq $wwwRedirect $entry) }}
- path: /
pathType: {{ $v.pathType | default "Prefix" }}
backend:
service:
name: rule-redirect-www
port:
name: use-annotation
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/Chart.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies:
- name: common
repository: file://../../../charts/common
version: 1.8.8
digest: sha256:70b1f2648a660ec5bb3adea1161dd333104cdbf3845f545c4c3d89b4d105680e
generated: "2025-01-03T13:35:32.223025-06:00"
version: 1.8.9
digest: sha256:1a11fa30499ad830bd5aefc1258d5681fdf662062d3ab69e3ec5d1b5c6c4d5b5
generated: "2025-01-10T14:56:56.181732-05:00"
2 changes: 1 addition & 1 deletion test/fixtures/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ version: 1.0.0
dependencies:
- name: common
repository: file://../../../charts/common
version: "1.8.8"
version: "1.8.9"
21 changes: 21 additions & 0 deletions test/fixtures/ingresses/values-redirect-to-www.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
global:
awsAccountId: "123456789"
image: docker.io/image:abcd1234
annotations:
provi.repository: https://github.com/example/repo
provi.slack: my-cool-team
labels:
team: cool-team

ingresses:
dummy:
service:
port: 8080
name: web
scheme: internet-facing
ingressClass: "alb"
hostnames:
- subdomain.example.com
- www.example.com
redirectHostToWWW: example.com
certificateArn: "arn:aws:acm:us-east-2:123456789:certificate/abcd1234-1a2b-3c4d-5e6f-987654abcd123"
38 changes: 38 additions & 0 deletions test/test_ingresses.bats
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,41 @@ teardown() {
run helm template -f test/fixtures/ingresses/values-alb-aliases.yaml test/fixtures/ingresses/
assert_output --partial "alb.ingress.kubernetes.io/conditions.cool_foo_service: '[{\"Field\":\"host-header\",\"HostHeaderConfig\":{\"Values\":[\"test-ingresses.example.com\",\"alias-subdomain1.example.com\",\"alias-subdomain2.example.com\"]}}]'"
}

# bats test_tags=tag:www-redirect
@test "www-redirect: creates annotations to redirect base domain to www" {
run helm template -f test/fixtures/ingresses/values-redirect-to-www.yaml test/fixtures/ingresses/
assert_output --partial "alb.ingress.kubernetes.io/conditions.rule-redirect-www: '[{\"Field\":\"host-header\",\"HostHeaderConfig\":{\"Values\":[\"example.com\"]}}]'"
assert_output --partial "alb.ingress.kubernetes.io/actions.rule-redirect-www: '{\"Type\":\"redirect\",\"RedirectConfig\":{\"Host\":\"www.example.com\",\"Port\":\"443\",\"Protocol\":\"HTTPS\",\"StatusCode\":\"HTTP_301\"}}'"

# check that subdomain.example.com is unchanged
assert_output --partial "
rules:
- host: \"subdomain.example.com\"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 8080
- host: \"www.example.com\"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 8080
- path: /
pathType: Prefix
backend:
service:
name: rule-redirect-www
port:
name: use-annotation"
}