Skip to content

Commit

Permalink
fix: endpoint url to bypass lookup service if envoy sidecar enabled
Browse files Browse the repository at this point in the history
EndpointURL returns FQDN:443 as endpoint url even if envoy sidecar enabled.
This MR updates to bypass lookup service if envoy sidecar enabled.
  • Loading branch information
ramineni authored and dougm committed Mar 27, 2024
1 parent f9e1a48 commit 9c5fca6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lookup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"crypto/x509"
"encoding/base64"
"fmt"
"log"
"net/url"

Expand Down Expand Up @@ -119,6 +120,10 @@ func (c *Client) SiteID(ctx context.Context) (string, error) {
// If the endpoint is found, its TLS certificate is also added to the vim25.Client's trusted host thumbprints.
// If the Lookup Service is not available, the given path is returned as the default.
func EndpointURL(ctx context.Context, c *vim25.Client, path string, filter *types.LookupServiceRegistrationFilter) string {
// Services running on vCenter can bypass lookup service.
if useSidecar := internal.UsingEnvoySidecar(c); useSidecar {
return fmt.Sprintf("http://%s%s", c.URL().Host, path)
}
if lu, err := NewClient(ctx, c); err == nil {
info, _ := lu.List(ctx, filter)
if len(info) != 0 && len(info[0].ServiceEndpoints) != 0 {
Expand Down
21 changes: 20 additions & 1 deletion lookup/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ package lookup_test

import (
"context"
"fmt"
"net/http"
"net/url"
"os"
"strings"
"testing"

"github.com/stretchr/testify/require"

"github.com/vmware/govmomi/lookup"
"github.com/vmware/govmomi/simulator"
"github.com/vmware/govmomi/ssoadmin"
"github.com/vmware/govmomi/sts"
Expand Down Expand Up @@ -69,7 +74,6 @@ func TestEndpointURL(t *testing.T) {
}
}
})

// these client calls should not fail
simulator.Test(func(ctx context.Context, vc *vim25.Client) {
{
Expand All @@ -96,4 +100,19 @@ func TestEndpointURL(t *testing.T) {
}
}
})

t.Run("With Envoy sidecar and a malfunctioning lookup service, endpoint url should still succeed", func(t *testing.T) {
model := simulator.VPX()
model.Create()
simulator.Test(func(ctx context.Context, vc *vim25.Client) {
lsim.BreakLookupServiceURLs()
// Map Envoy sidecar on the same port as the vcsim client.
os.Setenv("GOVMOMI_ENVOY_SIDECAR_PORT", vc.Client.URL().Port())
os.Setenv("GOVMOMI_ENVOY_SIDECAR_HOST", vc.Client.URL().Hostname())
testPath := "/fake/path"
expectedUrl := fmt.Sprintf("http://%s%s", vc.Client.URL().Host, testPath)
url := lookup.EndpointURL(ctx, vc, testPath, nil)
require.Equal(t, expectedUrl, url)
}, model)
})
}

0 comments on commit 9c5fca6

Please sign in to comment.