Skip to content

Commit

Permalink
Remove direct mode handling in the golang API
Browse files Browse the repository at this point in the history
Summary:
As direct mode is now being removed, the golang APIs no longer needs
to handle connecting to the viziers directly.

Test Plan: The golang API should continue to be able to talk to vizier.

Reviewers: michelle, zasgar, philkuz

Reviewed By: philkuz

JIRA Issues: PP-3338

Signed-off-by: Vihang Mehta <[email protected]>

Differential Revision: https://phab.corp.pixielabs.ai/D11076

GitOrigin-RevId: 2471b1e869949876acc15df0a18a106e116c3908
  • Loading branch information
vihangm authored and copybaranaut committed Apr 1, 2022
1 parent 0dd1197 commit 2b04c19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 47 deletions.
28 changes: 1 addition & 27 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"context"
"crypto/tls"
"fmt"
"net/url"
"strings"

"google.golang.org/grpc"
Expand Down Expand Up @@ -122,33 +121,8 @@ func (c *Client) cloudCtxWithMD(ctx context.Context) context.Context {

// NewVizierClient creates a new vizier client, for the passed in vizierID.
func (c *Client) NewVizierClient(ctx context.Context, vizierID string) (*VizierClient, error) {
vizier, err := c.GetVizierInfo(ctx, vizierID)
if err != nil {
return nil, err
}

var err error
vzConn := c.grpcConn
if vizier.DirectAccess {
connInfo, err := c.getConnectionInfo(ctx, vizierID)
if err != nil {
return nil, err
}

c.bearerAuth = connInfo.Token
parsedURL, err := url.Parse(connInfo.IPAddress)
if err != nil {
return nil, err
}

tlsConfig := &tls.Config{InsecureSkipVerify: false}
creds := credentials.NewTLS(tlsConfig)

conn, err := grpc.Dial(parsedURL.Host, grpc.WithTransportCredentials(creds))
if err != nil {
return nil, err
}
vzConn = conn
}

var encOpts, decOpts *vizierpb.ExecuteScriptRequest_EncryptionOptions
if c.useEncryption {
Expand Down
28 changes: 8 additions & 20 deletions cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ type VizierInfo struct {
Status VizierStatus
// Version of the installed vizier.
Version string
// DirectAccess says the cluster has direct access mode enabled. This means the data transfer will bypass the cloud.
DirectAccess bool
}

func clusterStatusToVizierStatus(status cloudpb.ClusterStatus) VizierStatus {
Expand Down Expand Up @@ -78,11 +76,10 @@ func (c *Client) ListViziers(ctx context.Context) ([]*VizierInfo, error) {
viziers := make([]*VizierInfo, 0)
for _, v := range res.Clusters {
viziers = append(viziers, &VizierInfo{
Name: v.ClusterName,
ID: utils.ProtoToUUIDStr(v.ID),
Version: v.VizierVersion,
Status: clusterStatusToVizierStatus(v.Status),
DirectAccess: !v.Config.PassthroughEnabled,
Name: v.ClusterName,
ID: utils.ProtoToUUIDStr(v.ID),
Version: v.VizierVersion,
Status: clusterStatusToVizierStatus(v.Status),
})
}

Expand All @@ -106,22 +103,13 @@ func (c *Client) GetVizierInfo(ctx context.Context, clusterID string) (*VizierIn
v := res.Clusters[0]

return &VizierInfo{
Name: v.ClusterName,
ID: utils.ProtoToUUIDStr(v.ID),
Version: v.VizierVersion,
Status: clusterStatusToVizierStatus(v.Status),
DirectAccess: !v.Config.PassthroughEnabled,
Name: v.ClusterName,
ID: utils.ProtoToUUIDStr(v.ID),
Version: v.VizierVersion,
Status: clusterStatusToVizierStatus(v.Status),
}, nil
}

// getConnectionInfo gets the connection info for a cluster using direct mode.
func (c *Client) getConnectionInfo(ctx context.Context, clusterID string) (*cloudpb.GetClusterConnectionInfoResponse, error) {
req := &cloudpb.GetClusterConnectionInfoRequest{
ID: utils.ProtoFromUUIDStrOrNil(clusterID),
}
return c.cmClient.GetClusterConnectionInfo(c.cloudCtxWithMD(ctx), req)
}

// CreateDeployKey creates a new deploy key, with an optional description.
func (c *Client) CreateDeployKey(ctx context.Context, desc string) (*cloudpb.DeploymentKey, error) {
keyMgr := cloudpb.NewVizierDeploymentKeyManagerClient(c.grpcConn)
Expand Down

0 comments on commit 2b04c19

Please sign in to comment.