Skip to content

Commit

Permalink
Revert "Propagate ports from main container service to additional ser…
Browse files Browse the repository at this point in the history
…vices for the same container (acorn-io#2006)"

This reverts commit 2e8339a.
  • Loading branch information
g-linville committed Aug 4, 2023
1 parent c564a35 commit 208b1b5
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 170 deletions.
4 changes: 0 additions & 4 deletions pkg/controller/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,3 @@ func TestCustomCertsShouldNotSetCertManager(t *testing.T) {
func TestCustomCertsWithAnnonationsShouldNotSetCertManagerDefaultIssuer(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/ingress/customdomainwithannotations", RenderServices)
}

func TestContainerService(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/service/container", RenderServices)
}
42 changes: 0 additions & 42 deletions pkg/controller/service/testdata/service/container/existing.yaml

This file was deleted.

66 changes: 0 additions & 66 deletions pkg/controller/service/testdata/service/container/expected.golden

This file was deleted.

23 changes: 0 additions & 23 deletions pkg/controller/service/testdata/service/container/input.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions pkg/ports/ports.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ports

import (
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -83,10 +82,3 @@ func RemoveNonHTTPPorts(ports []corev1.ServicePort) []corev1.ServicePort {
}
return result
}

func SortPorts(ports []corev1.ServicePort) []corev1.ServicePort {
sort.Slice(ports, func(i, j int) bool {
return ports[i].Port < ports[j].Port
})
return ports
}
31 changes: 4 additions & 27 deletions pkg/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,7 @@ func toContainerLabelsService(service *v1.ServiceInstance) (result []kclient.Obj
return
}

func toContainerService(ctx context.Context, c kclient.Client, service *v1.ServiceInstance) (result []kclient.Object, err error) {
svcPorts := ports.ToServicePorts(service.Spec.Ports)

// Check whether this is the main ServiceInstance for this container.
if service.Spec.Container != service.Name {
// Return an error if there are any non-HTTP ports defined. This could maybe cause problems with Istio.
for _, port := range service.Spec.Ports {
if port.Protocol != v1.ProtocolHTTP {
return nil, fmt.Errorf("container service %s has non-HTTP port %d\nservices defined for existing containers must contain only HTTP ports", service.Name, port.Port)
}
}

// Get the main ServiceInstance for this container.
mainService := &v1.ServiceInstance{}
if err = c.Get(ctx, kclient.ObjectKey{Name: service.Spec.Container, Namespace: service.Namespace}, mainService); err == nil {
// Take the HTTP ports from the main ServiceInstance and put them on this one too.
// If we don't do this, Istio might incorrectly route traffic.
svcPorts = ports.SortPorts(ports.DedupPorts(append(svcPorts, ports.RemoveNonHTTPPorts(ports.ToServicePorts(mainService.Spec.Ports))...)))
} else if !apierrors.IsNotFound(err) {
return nil, err
}
}

func toContainerService(service *v1.ServiceInstance) (result []kclient.Object) {
newService := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: service.Name,
Expand All @@ -72,14 +50,14 @@ func toContainerService(ctx context.Context, c kclient.Client, service *v1.Servi
Annotations: service.Spec.Annotations,
},
Spec: corev1.ServiceSpec{
Ports: svcPorts,
Ports: ports.ToServicePorts(service.Spec.Ports),
Type: corev1.ServiceTypeClusterIP,
Selector: labels.ManagedByApp(service.Spec.AppNamespace,
service.Spec.AppName, labels.AcornContainerName, service.Spec.Container),
},
}
result = append(result, newService)
return result, nil
return
}

func toAddressService(service *v1.ServiceInstance) (result []kclient.Object) {
Expand Down Expand Up @@ -263,8 +241,7 @@ func ToK8sService(req router.Request, service *v1.ServiceInstance) (result []kcl
} else if service.Spec.Address != "" {
return toAddressService(service), nil, nil
} else if service.Spec.Container != "" {
portList, err := toContainerService(req.Ctx, req.Client, service)
return portList, nil, err
return toContainerService(service), nil, nil
} else if len(service.Spec.ContainerLabels) > 0 {
return toContainerLabelsService(service), nil, nil
}
Expand Down

0 comments on commit 208b1b5

Please sign in to comment.