Skip to content

Commit cf644a5

Browse files
private-link cli: render server-provided DNS (#807)
1 parent 03df8b2 commit cf644a5

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

cmd/lk/agent_private_link.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ func buildCreatePrivateLinkRequest(name, region string, port uint32, endpoint st
9696
}
9797
}
9898

99-
func privateLinkServiceDNS(name, projectID string) string {
100-
return fmt.Sprintf("%s-%s.plg.svc", name, projectID)
101-
}
102-
10399
func buildPrivateLinkListRows(links []*lkproto.PrivateLink, healthByID map[string]*lkproto.PrivateLinkStatus, healthErrByID map[string]error) [][]string {
104100
var rows [][]string
105101
for _, link := range links {
@@ -119,12 +115,17 @@ func buildPrivateLinkListRows(links []*lkproto.PrivateLink, healthByID map[strin
119115
updatedAt = health.UpdatedAt.AsTime().UTC().Format("2006-01-02T15:04:05Z07:00")
120116
}
121117
}
118+
dns := link.Endpoint
119+
if dns == "" {
120+
dns = "-"
121+
}
122122

123123
rows = append(rows, []string{
124124
link.PrivateLinkId,
125125
link.Name,
126126
link.Region,
127127
strconv.FormatUint(uint64(link.Port), 10),
128+
dns,
128129
status,
129130
updatedAt,
130131
})
@@ -157,8 +158,8 @@ func createPrivateLink(ctx context.Context, cmd *cli.Command) error {
157158
}
158159

159160
fmt.Printf("Created private link [%s]\n", util.Accented(resp.PrivateLink.PrivateLinkId))
160-
if project != nil && project.ProjectId != "" {
161-
fmt.Printf("Gateway DNS [%s]\n", util.Accented(privateLinkServiceDNS(req.Name, project.ProjectId)))
161+
if resp.PrivateLink.Endpoint != "" {
162+
fmt.Printf("Gateway DNS [%s]\n", util.Accented(resp.PrivateLink.Endpoint))
162163
}
163164
return nil
164165
}
@@ -217,7 +218,7 @@ func listPrivateLinks(ctx context.Context, cmd *cli.Command) error {
217218
}
218219

219220
rows := buildPrivateLinkListRows(resp.Items, healthByID, healthErrByID)
220-
table := util.CreateTable().Headers("ID", "Name", "Region", "Port", "Health", "Updated At").Rows(rows...)
221+
table := util.CreateTable().Headers("ID", "Name", "Region", "Port", "DNS", "Health", "Updated At").Rows(rows...)
221222
fmt.Println(table)
222223
return nil
223224
}

cmd/lk/agent_private_link_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ func TestBuildCreatePrivateLinkRequest_HappyPath(t *testing.T) {
5555
assert.Equal(t, "com.amazonaws.vpce.us-east-1.vpce-svc-abc123", req.Endpoint)
5656
}
5757

58-
func TestPrivateLinkServiceDNS(t *testing.T) {
59-
assert.Equal(t, "orders-db-prj_123.plg.svc", privateLinkServiceDNS("orders-db", "prj_123"))
60-
}
61-
6258
func TestBuildPrivateLinkListRows_EmptyList(t *testing.T) {
6359
rows := buildPrivateLinkListRows([]*lkproto.PrivateLink{}, map[string]*lkproto.PrivateLinkStatus{}, map[string]error{})
6460
assert.Empty(t, rows)
@@ -71,6 +67,7 @@ func TestBuildPrivateLinkListRows_OnePrivateLink(t *testing.T) {
7167
Name: "orders-db",
7268
Region: "us-east-1",
7369
Port: 6379,
70+
Endpoint: "orders-db-p123.link",
7471
},
7572
}
7673

@@ -88,7 +85,8 @@ func TestBuildPrivateLinkListRows_OnePrivateLink(t *testing.T) {
8885
assert.Equal(t, "orders-db", rows[0][1])
8986
assert.Equal(t, "us-east-1", rows[0][2])
9087
assert.Equal(t, "6379", rows[0][3])
91-
assert.Equal(t, lkproto.PrivateLinkStatus_PRIVATE_LINK_STATUS_AVAILABLE.String(), rows[0][4])
88+
assert.Equal(t, "orders-db-p123.link", rows[0][4])
89+
assert.Equal(t, lkproto.PrivateLinkStatus_PRIVATE_LINK_STATUS_AVAILABLE.String(), rows[0][5])
9290
}
9391

9492
func TestBuildPrivateLinkListRows_TwoPrivateLinksDifferentRegions(t *testing.T) {
@@ -98,12 +96,14 @@ func TestBuildPrivateLinkListRows_TwoPrivateLinksDifferentRegions(t *testing.T)
9896
Name: "orders-db",
9997
Region: "us-east-1",
10098
Port: 6379,
99+
Endpoint: "orders-db-p123.link",
101100
},
102101
{
103102
PrivateLinkId: "pl-2",
104103
Name: "cache",
105104
Region: "eu-west-1",
106105
Port: 6380,
106+
Endpoint: "cache-p123.link",
107107
},
108108
}
109109

@@ -121,6 +121,8 @@ func TestBuildPrivateLinkListRows_TwoPrivateLinksDifferentRegions(t *testing.T)
121121

122122
assert.Equal(t, "us-east-1", rows[0][2])
123123
assert.Equal(t, "eu-west-1", rows[1][2])
124-
assert.Equal(t, lkproto.PrivateLinkStatus_PRIVATE_LINK_STATUS_AVAILABLE.String(), rows[0][4])
125-
assert.Equal(t, lkproto.PrivateLinkStatus_PRIVATE_LINK_STATUS_AVAILABLE.String(), rows[1][4])
124+
assert.Equal(t, "orders-db-p123.link", rows[0][4])
125+
assert.Equal(t, "cache-p123.link", rows[1][4])
126+
assert.Equal(t, lkproto.PrivateLinkStatus_PRIVATE_LINK_STATUS_AVAILABLE.String(), rows[0][5])
127+
assert.Equal(t, lkproto.PrivateLinkStatus_PRIVATE_LINK_STATUS_AVAILABLE.String(), rows[1][5])
126128
}

0 commit comments

Comments
 (0)