Skip to content

Use slices instead of maps for service ports to control ordering #10344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2022
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
7 changes: 4 additions & 3 deletions install/installer/pkg/common/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ func DefaultServiceAccount(component string) RenderFunc {
}

type ServicePort struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct is now very close to the underlying corev1.ServicePort. We could consider using that instead as the extra struct isn't adding much anymore.

Name string
ContainerPort int32
ServicePort int32
}

func GenerateService(component string, ports map[string]ServicePort, mod ...func(spec *corev1.Service)) RenderFunc {
func GenerateService(component string, ports []ServicePort, mod ...func(spec *corev1.Service)) RenderFunc {
return func(cfg *RenderContext) ([]runtime.Object, error) {
var servicePorts []corev1.ServicePort
for name, port := range ports {
for _, port := range ports {
servicePorts = append(servicePorts, corev1.ServicePort{
Protocol: *TCPProtocol,
Name: name,
Name: port.Name,
Port: port.ServicePort,
TargetPort: intstr.IntOrString{IntVal: port.ContainerPort},
})
Expand Down
5 changes: 3 additions & 2 deletions install/installer/pkg/components/blobserve/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ var Objects = common.CompositeRenderFunc(
deployment,
networkpolicy,
rolebinding,
common.GenerateService(Component, map[string]common.ServicePort{
ServicePortName: {
common.GenerateService(Component, []common.ServicePort{
{
Name: ServicePortName,
ContainerPort: ContainerPort,
ServicePort: ServicePort,
},
Expand Down
8 changes: 5 additions & 3 deletions install/installer/pkg/components/content-service/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ var Objects = common.CompositeRenderFunc(
deployment,
networkpolicy,
rolebinding,
common.GenerateService(Component, map[string]common.ServicePort{
RPCServiceName: {
common.GenerateService(Component, []common.ServicePort{
{
Name: RPCServiceName,
ContainerPort: RPCPort,
ServicePort: RPCPort,
},
PrometheusName: {
{
Name: PrometheusName,
ContainerPort: PrometheusPort,
ServicePort: PrometheusPort,
},
Expand Down
5 changes: 3 additions & 2 deletions install/installer/pkg/components/dashboard/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ var Objects = common.CompositeRenderFunc(
deployment,
networkpolicy,
rolebinding,
common.GenerateService(Component, map[string]common.ServicePort{
PortName: {
common.GenerateService(Component, []common.ServicePort{
{
Name: PortName,
ContainerPort: ContainerPort,
ServicePort: ServicePort,
},
Expand Down
5 changes: 3 additions & 2 deletions install/installer/pkg/components/database/cloudsql/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ var Objects = common.CompositeRenderFunc(
dbinit.Objects,
rolebinding,
common.DefaultServiceAccount(Component),
common.GenerateService(Component, map[string]common.ServicePort{
Component: {
common.GenerateService(Component, []common.ServicePort{
{
Name: Component,
ContainerPort: Port,
ServicePort: Port,
},
Expand Down
5 changes: 3 additions & 2 deletions install/installer/pkg/components/ide-proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ func service(ctx *common.RenderContext) ([]runtime.Object, error) {
return nil
})

ports := map[string]common.ServicePort{
PortName: {
ports := []common.ServicePort{
{
Name: PortName,
ContainerPort: ContainerPort,
ServicePort: ServicePort,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ var Objects = common.CompositeRenderFunc(
deployment,
networkpolicy,
rolebinding,
common.GenerateService(Component, map[string]common.ServicePort{
RPCPortName: {
common.GenerateService(Component, []common.ServicePort{
{
Name: RPCPortName,
ContainerPort: RPCPort,
ServicePort: RPCPort,
},
Expand Down
8 changes: 5 additions & 3 deletions install/installer/pkg/components/openvsx-proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ func service(ctx *common.RenderContext) ([]runtime.Object, error) {
return nil
})

ports := map[string]common.ServicePort{
PortName: {
ports := []common.ServicePort{
{
Name: PortName,
ContainerPort: ContainerPort,
ServicePort: ServicePort,
},
PrometheusPortName: {
{
Name: PrometheusPortName,
ContainerPort: PrometheusPort,
ServicePort: PrometheusPort,
},
Expand Down
16 changes: 10 additions & 6 deletions install/installer/pkg/components/proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,29 @@ func service(ctx *common.RenderContext) ([]runtime.Object, error) {
return nil
})

ports := map[string]common.ServicePort{
ContainerHTTPName: {
ports := []common.ServicePort{
{
Name: ContainerHTTPName,
ContainerPort: ContainerHTTPPort,
ServicePort: ContainerHTTPPort,
},
ContainerHTTPSName: {
{
Name: ContainerHTTPSName,
ContainerPort: ContainerHTTPSPort,
ServicePort: ContainerHTTPSPort,
},
MetricsContainerName: {
{
Name: MetricsContainerName,
ContainerPort: PrometheusPort,
ServicePort: PrometheusPort,
},
}
if ctx.Config.SSHGatewayHostKey != nil {
ports[ContainerSSHName] = common.ServicePort{
ports = append(ports, common.ServicePort{
Name: ContainerSSHName,
ContainerPort: ContainerSSHPort,
ServicePort: ContainerSSHPort,
}
})
}

return common.GenerateService(Component, ports, func(service *corev1.Service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
)

func service(ctx *common.RenderContext) ([]runtime.Object, error) {
return common.GenerateService(Component, map[string]common.ServicePort{
GRPCPortName: {
return common.GenerateService(Component, []common.ServicePort{
{
Name: GRPCPortName,
ContainerPort: GRPCContainerPort,
ServicePort: GRPCServicePort,
},
Expand Down
5 changes: 3 additions & 2 deletions install/installer/pkg/components/registry-facade/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ var Objects = common.CompositeRenderFunc(
podsecuritypolicy,
rolebinding,
certificate,
common.GenerateService(Component, map[string]common.ServicePort{
ContainerPortName: {
common.GenerateService(Component, []common.ServicePort{
{
Name: ContainerPortName,
ContainerPort: ContainerPort,
ServicePort: ServicePort,
},
Expand Down
17 changes: 11 additions & 6 deletions install/installer/pkg/components/server/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,29 @@ var Objects = common.CompositeRenderFunc(
networkpolicy,
role,
rolebinding,
common.GenerateService(Component, map[string]common.ServicePort{
ContainerPortName: {
common.GenerateService(Component, []common.ServicePort{
{
Name: ContainerPortName,
ContainerPort: ContainerPort,
ServicePort: ServicePort,
},
PrometheusPortName: {
{
Name: PrometheusPortName,
ContainerPort: PrometheusPort,
ServicePort: PrometheusPort,
},
InstallationAdminName: {
{
Name: InstallationAdminName,
ContainerPort: InstallationAdminPort,
ServicePort: InstallationAdminPort,
},
DebugPortName: {
{
Name: DebugPortName,
ContainerPort: common.DebugPort,
ServicePort: common.DebugPort,
},
DebugNodePortName: {
{
Name: DebugNodePortName,
ContainerPort: common.DebugNodePort,
ServicePort: common.DebugNodePort,
},
Expand Down
5 changes: 3 additions & 2 deletions install/installer/pkg/components/ws-manager/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ var Objects = common.CompositeRenderFunc(
role,
rolebinding,
common.DefaultServiceAccount(Component),
common.GenerateService(Component, map[string]common.ServicePort{
RPCPortName: {
common.GenerateService(Component, []common.ServicePort{
{
Name: RPCPortName,
ContainerPort: RPCPort,
ServicePort: RPCPort,
},
Expand Down
14 changes: 9 additions & 5 deletions install/installer/pkg/components/ws-proxy/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@ var Objects = common.CompositeRenderFunc(
rolebinding,
role,
func(cfg *common.RenderContext) ([]runtime.Object, error) {
ports := map[string]common.ServicePort{
HTTPProxyPortName: {
ports := []common.ServicePort{
{
Name: HTTPProxyPortName,
ContainerPort: HTTPProxyPort,
ServicePort: HTTPProxyPort,
},
HTTPSProxyPortName: {
{
Name: HTTPSProxyPortName,
ContainerPort: HTTPSProxyPort,
ServicePort: HTTPSProxyPort,
},
MetricsPortName: {
{
Name: MetricsPortName,
ContainerPort: MetricsPort,
ServicePort: MetricsPort,
},
SSHPortName: {
{
Name: SSHPortName,
ContainerPort: SSHTargetPort,
ServicePort: SSHServicePort,
},
Expand Down