Skip to content

Commit 7a40031

Browse files
committed
add flag for set to 443
1 parent 8bc1e63 commit 7a40031

File tree

8 files changed

+178
-104
lines changed

8 files changed

+178
-104
lines changed

functional_tests/empty_cluster_with_private_ip.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"properties": {
1717
"cookieBasedAffinity": "Disabled",
1818
"pickHostNameFromBackendAddress": false,
19-
"port": 80,
19+
"port": 443,
2020
"probe": {
21-
"id": "/subscriptions/--subscription--/resourceGroups/--resource-group--/providers/Microsoft.Network/applicationGateways/--app-gw-name--/probes/defaultprobe-Http"
21+
"id": "/subscriptions/--subscription--/resourceGroups/--resource-group--/providers/Microsoft.Network/applicationGateways/--app-gw-name--/probes/defaultprobe-Https"
2222
},
23-
"protocol": "Http",
23+
"protocol": "Https",
2424
"requestTimeout": 30
2525
}
2626
}
@@ -71,16 +71,16 @@
7171
],
7272
"probes": [
7373
{
74-
"id": "/subscriptions/--subscription--/resourceGroups/--resource-group--/providers/Microsoft.Network/applicationGateways/--app-gw-name--/probes/defaultprobe-Http",
75-
"name": "defaultprobe-Http",
74+
"id": "/subscriptions/--subscription--/resourceGroups/--resource-group--/providers/Microsoft.Network/applicationGateways/--app-gw-name--/probes/defaultprobe-Https",
75+
"name": "defaultprobe-Https",
7676
"properties": {
7777
"host": "localhost",
7878
"interval": 30,
7979
"match": {},
8080
"minServers": 0,
8181
"path": "/",
8282
"pickHostNameFromBackendHttpSettings": false,
83-
"protocol": "Http",
83+
"protocol": "Https",
8484
"timeout": 30,
8585
"unhealthyThreshold": 3
8686
}

pkg/appgw/backendhttpsettings.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ func (c *appGwConfigBuilder) getBackendsAndSettingsMap(cbCtx *ConfigBuilderConte
7474
}
7575

7676
defaultHTTPSetting := defaultBackendHTTPSettings(c.appGwIdentifier, n.ApplicationGatewayProtocolHTTP)
77+
if cbCtx.EnvVariables.SetDefaultHTTPSettingProbePortTo443 {
78+
defaultHTTPSetting = defaultBackendHTTPSettings(c.appGwIdentifier, n.ApplicationGatewayProtocolHTTPS)
79+
}
80+
7781
serviceBackendPairMap := make(map[backendIdentifier]serviceBackendPortPair)
7882
backendHTTPSettingsMap := make(map[backendIdentifier]*n.ApplicationGatewayBackendHTTPSettings)
7983
httpSettingsCollection := make(map[string]n.ApplicationGatewayBackendHTTPSettings)

pkg/appgw/backendhttpsettings_test.go

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
networking "k8s.io/api/networking/v1"
2020

2121
"github.com/Azure/application-gateway-kubernetes-ingress/pkg/annotations"
22+
"github.com/Azure/application-gateway-kubernetes-ingress/pkg/environment"
2223
"github.com/Azure/application-gateway-kubernetes-ingress/pkg/tests"
2324
"github.com/Azure/application-gateway-kubernetes-ingress/pkg/utils"
2425
)
@@ -63,6 +64,9 @@ var _ = Describe("Test the creation of Backend http settings from Ingress defini
6364
ServiceList: []*v1.Service{service},
6465
DefaultAddressPoolID: to.StringPtr("xx"),
6566
DefaultHTTPSettingsID: to.StringPtr("yy"),
67+
EnvVariables: environment.EnvVariables{
68+
SetDefaultHTTPSettingProbePortTo443: true,
69+
},
6670
}
6771

6872
// Action
@@ -72,8 +76,8 @@ var _ = Describe("Test the creation of Backend http settings from Ingress defini
7276

7377
for _, setting := range httpSettings {
7478
if *setting.Name == DefaultBackendHTTPSettingsName {
75-
Expect(setting.Protocol).To(Equal(n.ApplicationGatewayProtocolHTTP), "default backend %s should have %s", *setting.Name, n.ApplicationGatewayProtocolHTTP)
76-
Expect(probes[utils.GetLastChunkOfSlashed(*setting.Probe.ID)].Protocol).To(Equal(n.ApplicationGatewayProtocolHTTP), "default probe should have http")
79+
Expect(setting.Protocol).To(Equal(n.ApplicationGatewayProtocolHTTPS), "default backend %s should have %s", *setting.Name, n.ApplicationGatewayProtocolHTTPS)
80+
Expect(probes[utils.GetLastChunkOfSlashed(*setting.Probe.ID)].Protocol).To(Equal(n.ApplicationGatewayProtocolHTTPS), "default probe should have http")
7781
continue
7882
}
7983

@@ -105,6 +109,9 @@ var _ = Describe("Test the creation of Backend http settings from Ingress defini
105109
ServiceList: []*v1.Service{service},
106110
DefaultAddressPoolID: to.StringPtr("xx"),
107111
DefaultHTTPSettingsID: to.StringPtr("yy"),
112+
EnvVariables: environment.EnvVariables{
113+
SetDefaultHTTPSettingProbePortTo443: true,
114+
},
108115
}
109116

110117
// Action
@@ -114,8 +121,8 @@ var _ = Describe("Test the creation of Backend http settings from Ingress defini
114121

115122
for _, setting := range httpSettings {
116123
if *setting.Name == DefaultBackendHTTPSettingsName {
117-
Expect(setting.Protocol).To(Equal(n.ApplicationGatewayProtocolHTTP), "default backend %s should have %s", *setting.Name, n.ApplicationGatewayProtocolHTTP)
118-
Expect(probes[utils.GetLastChunkOfSlashed(*setting.Probe.ID)].Protocol).To(Equal(n.ApplicationGatewayProtocolHTTP), "default probe should have http")
124+
Expect(setting.Protocol).To(Equal(n.ApplicationGatewayProtocolHTTPS), "default backend %s should have %s", *setting.Name, n.ApplicationGatewayProtocolHTTP)
125+
Expect(probes[utils.GetLastChunkOfSlashed(*setting.Probe.ID)].Protocol).To(Equal(n.ApplicationGatewayProtocolHTTPS), "default probe should have http")
119126
continue
120127
}
121128

@@ -142,6 +149,9 @@ var _ = Describe("Test the creation of Backend http settings from Ingress defini
142149
ServiceList: []*v1.Service{service},
143150
DefaultAddressPoolID: to.StringPtr("xx"),
144151
DefaultHTTPSettingsID: to.StringPtr("yy"),
152+
EnvVariables: environment.EnvVariables{
153+
SetDefaultHTTPSettingProbePortTo443: true,
154+
},
145155
}
146156

147157
configBuilder.mem = memoization{}
@@ -154,7 +164,7 @@ var _ = Describe("Test the creation of Backend http settings from Ingress defini
154164

155165
for _, setting := range httpSettings {
156166
if *setting.Name == DefaultBackendHTTPSettingsName {
157-
Expect(int32(80)).To(Equal(*setting.Port), "default backend port %d should be 80", *setting.Port)
167+
Expect(int32(443)).To(Equal(*setting.Port), "default backend port %d should be 80", *setting.Port)
158168
} else if strings.Contains(*setting.Name, strconv.Itoa(int(tests.ContainerPort))) {
159169
// http setting for ingress with service port as 80
160170
Expect(tests.ContainerPort).To(Equal(*setting.Port), "setting %s backend port %d should be 9876", *setting.Name, *setting.Port)
@@ -177,6 +187,9 @@ var _ = Describe("Test the creation of Backend http settings from Ingress defini
177187
ServiceList: []*v1.Service{service},
178188
DefaultAddressPoolID: to.StringPtr("xx"),
179189
DefaultHTTPSettingsID: to.StringPtr("yy"),
190+
EnvVariables: environment.EnvVariables{
191+
SetDefaultHTTPSettingProbePortTo443: true,
192+
},
180193
}
181194

182195
configBuilder.mem = memoization{}
@@ -189,7 +202,7 @@ var _ = Describe("Test the creation of Backend http settings from Ingress defini
189202

190203
for _, setting := range httpSettings {
191204
if *setting.Name == DefaultBackendHTTPSettingsName {
192-
Expect(int32(80)).To(Equal(*setting.Port), "default backend port %d should be 80", *setting.Port)
205+
Expect(int32(443)).To(Equal(*setting.Port), "default backend port %d should be 80", *setting.Port)
193206
} else if strings.Contains(*setting.Name, strconv.Itoa(int(tests.ContainerPort))) {
194207
// http setting for ingress with service port as 80
195208
Expect(tests.ContainerPort).To(Equal(*setting.Port), "setting %s backend port %d should be 9876", *setting.Name, *setting.Port)
@@ -226,6 +239,9 @@ var _ = Describe("Test the creation of Backend http settings from Ingress defini
226239
ServiceList: []*v1.Service{service},
227240
DefaultAddressPoolID: to.StringPtr("xx"),
228241
DefaultHTTPSettingsID: to.StringPtr("yy"),
242+
EnvVariables: environment.EnvVariables{
243+
SetDefaultHTTPSettingProbePortTo443: true,
244+
},
229245
}
230246

231247
configBuilder.mem = memoization{}
@@ -238,7 +254,7 @@ var _ = Describe("Test the creation of Backend http settings from Ingress defini
238254

239255
for _, setting := range httpSettings {
240256
if *setting.Name == DefaultBackendHTTPSettingsName {
241-
Expect(int32(80)).To(Equal(*setting.Port), "default backend port %d should be 80", *setting.Port)
257+
Expect(int32(443)).To(Equal(*setting.Port), "default backend port %d should be 80", *setting.Port)
242258
} else if strings.Contains(*setting.Name, strconv.Itoa(int(tests.ContainerPort))) {
243259
// http setting for ingress with service port as 80
244260
Expect(tests.ContainerPort).To(Equal(*setting.Port), "setting %s backend port %d should be 9876", *setting.Name, *setting.Port)
@@ -254,4 +270,31 @@ var _ = Describe("Test the creation of Backend http settings from Ingress defini
254270
})
255271
})
256272

273+
Context("when env variable for set port to 443 is false", func() {
274+
cbCtx := &ConfigBuilderContext{
275+
IngressList: []*networking.Ingress{ingress},
276+
ServiceList: []*v1.Service{service},
277+
DefaultAddressPoolID: to.StringPtr("xx"),
278+
DefaultHTTPSettingsID: to.StringPtr("yy"),
279+
EnvVariables: environment.EnvVariables{
280+
SetDefaultHTTPSettingProbePortTo443: false,
281+
},
282+
}
283+
284+
configBuilder.mem = memoization{}
285+
configBuilder.newProbesMap(cbCtx)
286+
httpSettings, _, _, _ := configBuilder.getBackendsAndSettingsMap(cbCtx)
287+
288+
It("should create the default with port 80", func() {
289+
expectedhttpSettingsLen := 3
290+
Expect(expectedhttpSettingsLen).To(Equal(len(httpSettings)), "httpSetting count %d should be %d", len(httpSettings), expectedhttpSettingsLen)
291+
292+
for _, setting := range httpSettings {
293+
if *setting.Name == DefaultBackendHTTPSettingsName {
294+
Expect(int32(80)).To(Equal(*setting.Port), "default backend port %d should be 80", *setting.Port)
295+
break
296+
}
297+
}
298+
})
299+
})
257300
})

pkg/appgw/configbuilder_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,11 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {
489489
-- "properties": {
490490
-- "cookieBasedAffinity": "Disabled",
491491
-- "pickHostNameFromBackendAddress": false,
492-
-- "port": 80,
492+
-- "port": 443,
493493
-- "probe": {
494-
-- "id": "/subscriptions/--subscription--/resourceGroups/--resource-group--/providers/Microsoft.Network/applicationGateways/--app-gw-name--/probes/defaultprobe-Http"
494+
-- "id": "/subscriptions/--subscription--/resourceGroups/--resource-group--/providers/Microsoft.Network/applicationGateways/--app-gw-name--/probes/defaultprobe-Https"
495495
-- },
496-
-- "protocol": "Http",
496+
-- "protocol": "Https",
497497
-- "requestTimeout": 30
498498
-- }
499499
-- }
@@ -557,6 +557,21 @@ var _ = Describe("Tests `appgw.ConfigBuilder`", func() {
557557
-- "timeout": 30,
558558
-- "unhealthyThreshold": 3
559559
-- }
560+
-- },
561+
-- {
562+
-- "id": "/subscriptions/--subscription--/resourceGroups/--resource-group--/providers/Microsoft.Network/applicationGateways/--app-gw-name--/probes/defaultprobe-Https",
563+
-- "name": "defaultprobe-Https",
564+
-- "properties": {
565+
-- "host": "localhost",
566+
-- "interval": 30,
567+
-- "match": {},
568+
-- "minServers": 0,
569+
-- "path": "/",
570+
-- "pickHostNameFromBackendHttpSettings": false,
571+
-- "protocol": "Https",
572+
-- "timeout": 30,
573+
-- "unhealthyThreshold": 3
574+
-- }
560575
-- }
561576
-- ],
562577
-- "redirectConfigurations": [],

pkg/appgw/internaltypes.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ func defaultProbeName(protocol n.ApplicationGatewayProtocol) string {
180180
func defaultBackendHTTPSettings(appGWIdentifier Identifier, protocol n.ApplicationGatewayProtocol) n.ApplicationGatewayBackendHTTPSettings {
181181
defHTTPSettingsName := DefaultBackendHTTPSettingsName
182182
defHTTPSettingsPort := int32(80)
183+
if protocol == n.ApplicationGatewayProtocolHTTPS {
184+
defHTTPSettingsPort = int32(443)
185+
}
186+
183187
return n.ApplicationGatewayBackendHTTPSettings{
184188
Name: &defHTTPSettingsName,
185189
ID: to.StringPtr(appGWIdentifier.HTTPSettingsID(defHTTPSettingsName)),

0 commit comments

Comments
 (0)