Skip to content

Commit 7b68fb4

Browse files
mads-hartmannroboquat
authored andcommitted
Use slices instead of maps for service ports to control ordering
1 parent caa5572 commit 7b68fb4

File tree

14 files changed

+68
-42
lines changed

14 files changed

+68
-42
lines changed

install/installer/pkg/common/objects.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,18 @@ func DefaultServiceAccount(component string) RenderFunc {
4040
}
4141

4242
type ServicePort struct {
43+
Name string
4344
ContainerPort int32
4445
ServicePort int32
4546
}
4647

47-
func GenerateService(component string, ports map[string]ServicePort, mod ...func(spec *corev1.Service)) RenderFunc {
48+
func GenerateService(component string, ports []ServicePort, mod ...func(spec *corev1.Service)) RenderFunc {
4849
return func(cfg *RenderContext) ([]runtime.Object, error) {
4950
var servicePorts []corev1.ServicePort
50-
for name, port := range ports {
51+
for _, port := range ports {
5152
servicePorts = append(servicePorts, corev1.ServicePort{
5253
Protocol: *TCPProtocol,
53-
Name: name,
54+
Name: port.Name,
5455
Port: port.ServicePort,
5556
TargetPort: intstr.IntOrString{IntVal: port.ContainerPort},
5657
})

install/installer/pkg/components/blobserve/objects.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ var Objects = common.CompositeRenderFunc(
1111
deployment,
1212
networkpolicy,
1313
rolebinding,
14-
common.GenerateService(Component, map[string]common.ServicePort{
15-
ServicePortName: {
14+
common.GenerateService(Component, []common.ServicePort{
15+
{
16+
Name: ServicePortName,
1617
ContainerPort: ContainerPort,
1718
ServicePort: ServicePort,
1819
},

install/installer/pkg/components/content-service/objects.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ var Objects = common.CompositeRenderFunc(
1111
deployment,
1212
networkpolicy,
1313
rolebinding,
14-
common.GenerateService(Component, map[string]common.ServicePort{
15-
RPCServiceName: {
14+
common.GenerateService(Component, []common.ServicePort{
15+
{
16+
Name: RPCServiceName,
1617
ContainerPort: RPCPort,
1718
ServicePort: RPCPort,
1819
},
19-
PrometheusName: {
20+
{
21+
Name: PrometheusName,
2022
ContainerPort: PrometheusPort,
2123
ServicePort: PrometheusPort,
2224
},

install/installer/pkg/components/dashboard/objects.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ var Objects = common.CompositeRenderFunc(
1010
deployment,
1111
networkpolicy,
1212
rolebinding,
13-
common.GenerateService(Component, map[string]common.ServicePort{
14-
PortName: {
13+
common.GenerateService(Component, []common.ServicePort{
14+
{
15+
Name: PortName,
1516
ContainerPort: ContainerPort,
1617
ServicePort: ServicePort,
1718
},

install/installer/pkg/components/database/cloudsql/objects.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ var Objects = common.CompositeRenderFunc(
1414
dbinit.Objects,
1515
rolebinding,
1616
common.DefaultServiceAccount(Component),
17-
common.GenerateService(Component, map[string]common.ServicePort{
18-
Component: {
17+
common.GenerateService(Component, []common.ServicePort{
18+
{
19+
Name: Component,
1920
ContainerPort: Port,
2021
ServicePort: Port,
2122
},

install/installer/pkg/components/ide-proxy/service.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ func service(ctx *common.RenderContext) ([]runtime.Object, error) {
2121
return nil
2222
})
2323

24-
ports := map[string]common.ServicePort{
25-
PortName: {
24+
ports := []common.ServicePort{
25+
{
26+
Name: PortName,
2627
ContainerPort: ContainerPort,
2728
ServicePort: ServicePort,
2829
},

install/installer/pkg/components/image-builder-mk3/objects.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ var Objects = common.CompositeRenderFunc(
1212
deployment,
1313
networkpolicy,
1414
rolebinding,
15-
common.GenerateService(Component, map[string]common.ServicePort{
16-
RPCPortName: {
15+
common.GenerateService(Component, []common.ServicePort{
16+
{
17+
Name: RPCPortName,
1718
ContainerPort: RPCPort,
1819
ServicePort: RPCPort,
1920
},

install/installer/pkg/components/openvsx-proxy/service.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ func service(ctx *common.RenderContext) ([]runtime.Object, error) {
2121
return nil
2222
})
2323

24-
ports := map[string]common.ServicePort{
25-
PortName: {
24+
ports := []common.ServicePort{
25+
{
26+
Name: PortName,
2627
ContainerPort: ContainerPort,
2728
ServicePort: ServicePort,
2829
},
29-
PrometheusPortName: {
30+
{
31+
Name: PrometheusPortName,
3032
ContainerPort: PrometheusPort,
3133
ServicePort: PrometheusPort,
3234
},

install/installer/pkg/components/proxy/service.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,29 @@ func service(ctx *common.RenderContext) ([]runtime.Object, error) {
3131
return nil
3232
})
3333

34-
ports := map[string]common.ServicePort{
35-
ContainerHTTPName: {
34+
ports := []common.ServicePort{
35+
{
36+
Name: ContainerHTTPName,
3637
ContainerPort: ContainerHTTPPort,
3738
ServicePort: ContainerHTTPPort,
3839
},
39-
ContainerHTTPSName: {
40+
{
41+
Name: ContainerHTTPSName,
4042
ContainerPort: ContainerHTTPSPort,
4143
ServicePort: ContainerHTTPSPort,
4244
},
43-
MetricsContainerName: {
45+
{
46+
Name: MetricsContainerName,
4447
ContainerPort: PrometheusPort,
4548
ServicePort: PrometheusPort,
4649
},
4750
}
4851
if ctx.Config.SSHGatewayHostKey != nil {
49-
ports[ContainerSSHName] = common.ServicePort{
52+
ports = append(ports, common.ServicePort{
53+
Name: ContainerSSHName,
5054
ContainerPort: ContainerSSHPort,
5155
ServicePort: ContainerSSHPort,
52-
}
56+
})
5357
}
5458

5559
return common.GenerateService(Component, ports, func(service *corev1.Service) {

install/installer/pkg/components/public-api-server/service.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99
)
1010

1111
func service(ctx *common.RenderContext) ([]runtime.Object, error) {
12-
return common.GenerateService(Component, map[string]common.ServicePort{
13-
GRPCPortName: {
12+
return common.GenerateService(Component, []common.ServicePort{
13+
{
14+
Name: GRPCPortName,
1415
ContainerPort: GRPCContainerPort,
1516
ServicePort: GRPCServicePort,
1617
},

install/installer/pkg/components/registry-facade/objects.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ var Objects = common.CompositeRenderFunc(
1616
podsecuritypolicy,
1717
rolebinding,
1818
certificate,
19-
common.GenerateService(Component, map[string]common.ServicePort{
20-
ContainerPortName: {
19+
common.GenerateService(Component, []common.ServicePort{
20+
{
21+
Name: ContainerPortName,
2122
ContainerPort: ContainerPort,
2223
ServicePort: ServicePort,
2324
},

install/installer/pkg/components/server/objects.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,29 @@ var Objects = common.CompositeRenderFunc(
1616
networkpolicy,
1717
role,
1818
rolebinding,
19-
common.GenerateService(Component, map[string]common.ServicePort{
20-
ContainerPortName: {
19+
common.GenerateService(Component, []common.ServicePort{
20+
{
21+
Name: ContainerPortName,
2122
ContainerPort: ContainerPort,
2223
ServicePort: ServicePort,
2324
},
24-
PrometheusPortName: {
25+
{
26+
Name: PrometheusPortName,
2527
ContainerPort: PrometheusPort,
2628
ServicePort: PrometheusPort,
2729
},
28-
InstallationAdminName: {
30+
{
31+
Name: InstallationAdminName,
2932
ContainerPort: InstallationAdminPort,
3033
ServicePort: InstallationAdminPort,
3134
},
32-
DebugPortName: {
35+
{
36+
Name: DebugPortName,
3337
ContainerPort: common.DebugPort,
3438
ServicePort: common.DebugPort,
3539
},
36-
DebugNodePortName: {
40+
{
41+
Name: DebugNodePortName,
3742
ContainerPort: common.DebugNodePort,
3843
ServicePort: common.DebugNodePort,
3944
},

install/installer/pkg/components/ws-manager/objects.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ var Objects = common.CompositeRenderFunc(
1515
role,
1616
rolebinding,
1717
common.DefaultServiceAccount(Component),
18-
common.GenerateService(Component, map[string]common.ServicePort{
19-
RPCPortName: {
18+
common.GenerateService(Component, []common.ServicePort{
19+
{
20+
Name: RPCPortName,
2021
ContainerPort: RPCPort,
2122
ServicePort: RPCPort,
2223
},

install/installer/pkg/components/ws-proxy/objects.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,24 @@ var Objects = common.CompositeRenderFunc(
1818
rolebinding,
1919
role,
2020
func(cfg *common.RenderContext) ([]runtime.Object, error) {
21-
ports := map[string]common.ServicePort{
22-
HTTPProxyPortName: {
21+
ports := []common.ServicePort{
22+
{
23+
Name: HTTPProxyPortName,
2324
ContainerPort: HTTPProxyPort,
2425
ServicePort: HTTPProxyPort,
2526
},
26-
HTTPSProxyPortName: {
27+
{
28+
Name: HTTPSProxyPortName,
2729
ContainerPort: HTTPSProxyPort,
2830
ServicePort: HTTPSProxyPort,
2931
},
30-
MetricsPortName: {
32+
{
33+
Name: MetricsPortName,
3134
ContainerPort: MetricsPort,
3235
ServicePort: MetricsPort,
3336
},
34-
SSHPortName: {
37+
{
38+
Name: SSHPortName,
3539
ContainerPort: SSHTargetPort,
3640
ServicePort: SSHServicePort,
3741
},

0 commit comments

Comments
 (0)