Skip to content

Commit

Permalink
Revert "ingress: getAddresses algo returning CNames"
Browse files Browse the repository at this point in the history
This reverts commit b51de88.
  • Loading branch information
morpheu committed Jul 11, 2022
1 parent b51de88 commit 3417c59
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 47 deletions.
30 changes: 4 additions & 26 deletions kubernetes/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 0 additions & 21 deletions kubernetes/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 3417c59

Please sign in to comment.