From 3417c59fcf6a3d4938f8256c0952339e2bee99d9 Mon Sep 17 00:00:00 2001 From: Paulo Sousa Date: Mon, 11 Jul 2022 10:04:12 -0300 Subject: [PATCH] Revert "ingress: getAddresses algo returning CNames" This reverts commit b51de88ad5e4efa2c7f3e11190d20b53d5edba7c. --- kubernetes/ingress.go | 30 ++++-------------------------- kubernetes/ingress_test.go | 21 --------------------- 2 files changed, 4 insertions(+), 47 deletions(-) diff --git a/kubernetes/ingress.go b/kubernetes/ingress.go index 5cdb190..4d7789a 100644 --- a/kubernetes/ingress.go +++ b/kubernetes/ingress.go @@ -404,20 +404,6 @@ func (k *IngressService) GetAddresses(ctx context.Context, id router.InstanceID) } return nil, err } - urls := k.getAddressesURLs(ingress) - if cnames, found := ingress.Annotations[AnnotationsCNames]; found && cnames != "" { - for _, cname := range strings.Split(cnames, ",") { - ingressCName, err := k.getCName(ctx, id, cname) - if err != nil { - return nil, err - } - urls = append(urls, k.getAddressesURLs(ingressCName)...) - } - } - return urls, nil -} - -func (k *IngressService) getAddressesURLs(ingress *networkingV1.Ingress) []string { hosts := []string{} urls := []string{} for _, rule := range ingress.Spec.Rules { @@ -434,9 +420,9 @@ func (k *IngressService) getAddressesURLs(ingress *networkingV1.Ingress) []strin } } if len(urls) > 0 { - return urls + return urls, nil } - return hosts + return hosts, nil } func (k *IngressService) GetStatus(ctx context.Context, id router.InstanceID) (router.BackendStatus, string, error) { ingress, err := k.get(ctx, id) @@ -466,19 +452,11 @@ func (k *IngressService) get(ctx context.Context, id router.InstanceID) (*networ if err != nil { return nil, err } - return client.Get(ctx, k.ingressName(id), metav1.GetOptions{}) -} - -func (k *IngressService) getCName(ctx context.Context, id router.InstanceID, cname string) (*networkingV1.Ingress, error) { - ns, err := k.getAppNamespace(ctx, id.AppName) - if err != nil { - return nil, err - } - client, err := k.ingressClient(ns) + ingress, err := client.Get(ctx, k.ingressName(id), metav1.GetOptions{}) if err != nil { return nil, err } - return client.Get(ctx, k.ingressCName(id, cname), metav1.GetOptions{}) + return ingress, nil } func (k *IngressService) ingressClient(namespace string) (networkingTypedV1.IngressInterface, error) { diff --git a/kubernetes/ingress_test.go b/kubernetes/ingress_test.go index 717cb45..a2c4f24 100644 --- a/kubernetes/ingress_test.go +++ b/kubernetes/ingress_test.go @@ -891,28 +891,7 @@ func TestIngressGetAddressTLS(t *testing.T) { require.NoError(t, err) assert.Equal(t, []string{"https://test.apps.example.org"}, addrs) } -func TestIngressGetAddressAndCNames(t *testing.T) { - svc := createFakeService() - svc.DomainSuffix = "apps.example.org" - svc.Labels = map[string]string{"controller": "my-controller", "XPTO": "true"} - svc.Annotations = map[string]string{"ann1": "val1", "ann2": "val2"} - err := svc.Ensure(ctx, idForApp("test"), router.EnsureBackendOpts{ - Prefixes: []router.BackendPrefix{ - { - Target: router.BackendTarget{ - Service: "test-web", - Namespace: "default", - }, - }, - }, - CNames: []string{"cname.test.com"}, - }) - require.NoError(t, err) - addrs, err := svc.GetAddresses(ctx, idForApp("test")) - require.NoError(t, err) - assert.Equal(t, []string{"test.apps.example.org", "cname.test.com"}, addrs) -} func TestIngressGetMultipleAddresses(t *testing.T) { client := fake.NewSimpleClientset() err := createAppWebService(client, "default", "test")