Skip to content

Commit a0561ee

Browse files
committed
Add annotation to ingress
The new annotation corresponds to the "Override with new host name" option in the backend settings blade in the Azure Portal.
1 parent e26b8ee commit a0561ee

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pkg/annotations/ingress_annotations.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const (
2727
// Null means Host specified in the request to Application Gateway is used to connect to the backend.
2828
BackendHostNameKey = ApplicationGatewayPrefix + "/backend-hostname"
2929

30+
// OverrideBackendHostNameKey defines the key to enable/disable host name overriding.
31+
OverrideBackendHostNameKey = ApplicationGatewayPrefix + "/override-backend-host"
32+
3033
// HealthProbeHostKey defines the key for Host which should be used as a target for health probe.
3134
HealthProbeHostKey = ApplicationGatewayPrefix + "/health-probe-hostname"
3235

@@ -158,11 +161,16 @@ func BackendPathPrefix(ing *networking.Ingress) (string, error) {
158161
return parseString(ing, BackendPathPrefixKey)
159162
}
160163

161-
// BackendHostName override hostname
164+
// BackendHostName specific domain name to override the backend hostname with
162165
func BackendHostName(ing *networking.Ingress) (string, error) {
163166
return parseString(ing, BackendHostNameKey)
164167
}
165168

169+
// OverrideBackendHostName whether to override the backend hostname or not
170+
func OverrideBackendHostName(ing *networking.Ingress) (string, error) {
171+
return parseBool(ing, OverrideBackendHostNameKey)
172+
}
173+
166174
// HealthProbeHostName probe hostname override
167175
func HealthProbeHostName(ing *networking.Ingress) (string, error) {
168176
return parseString(ing, HealthProbeHostKey)

pkg/annotations/ingress_annotations_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var _ = Describe("Test ingress annotation functions", func() {
4848
"appgw.ingress.kubernetes.io/connection-draining-timeout": "3456",
4949
"appgw.ingress.kubernetes.io/backend-path-prefix": "prefix-here",
5050
"appgw.ingress.kubernetes.io/backend-hostname": "www.backend.com",
51+
"appgw.ingress.kubernetes.io/overrride-backend-hostname": "true",
5152
"appgw.ingress.kubernetes.io/hostname-extension": "www.bye.com, www.b*.com",
5253
"appgw.ingress.kubernetes.io/appgw-ssl-certificate": "appgw-cert",
5354
"appgw.ingress.kubernetes.io/appgw-ssl-profile": "legacy-tls",
@@ -340,6 +341,20 @@ var _ = Describe("Test ingress annotation functions", func() {
340341
})
341342
})
342343

344+
Context("test OverrideBackendHostName", func() {
345+
It("returns error when ingress has no annotations", func() {
346+
ing := &networking.Ingress{}
347+
actual, err := OverrideBackendHostName(ing)
348+
Expect(err).To(HaveOccurred())
349+
Expect(actual).To(Equal(""))
350+
})
351+
It("returns the hostname", func() {
352+
actual, err := OverrideBackendHostName(ing)
353+
Expect(err).ToNot(HaveOccurred())
354+
Expect(actual).To(Equal(true))
355+
})
356+
})
357+
343358
Context("test IsSslRedirect", func() {
344359
It("returns error when ingress has no annotations", func() {
345360
ing := &networking.Ingress{}

0 commit comments

Comments
 (0)