Skip to content

Commit 3911a5b

Browse files
authored
Add Azure PrivateLink support for Flink & SR (#3136)
1 parent 47ee611 commit 3911a5b

24 files changed

+142
-27
lines changed

internal/flink/command_endpoint_list.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ package flink
22

33
import (
44
"fmt"
5+
"slices"
56
"sort"
67
"strings"
78

89
"github.com/spf13/cobra"
910

1011
networkingprivatelinkv1 "github.com/confluentinc/ccloud-sdk-go-v2/networking-privatelink/v1"
12+
networkingv1 "github.com/confluentinc/ccloud-sdk-go-v2/networking/v1"
1113

14+
pcloud "github.com/confluentinc/cli/v4/pkg/cloud"
1215
pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
1316
"github.com/confluentinc/cli/v4/pkg/errors"
1417
"github.com/confluentinc/cli/v4/pkg/examples"
@@ -102,9 +105,18 @@ func (c *command) endpointList(cmd *cobra.Command, _ []string) error {
102105

103106
// 3 - List all the CCN endpoint with the list of "READY" network domains
104107
// Note the cloud and region have to be empty slice instead of `nil` in case of no filter
105-
networks, err := c.V2Client.ListNetworks(environmentId, nil, []string{cloud}, []string{region}, nil, []string{"READY"}, nil)
106-
if err != nil {
107-
return fmt.Errorf("unable to list Flink endpoint, failed to list networks: %w", err)
108+
// These endpoints are currently only available for AWS and Azure (with PrivateLink connection type), so we filter accordingly
109+
// TODO: Remove these restrictions once we support more connection types
110+
var networks []networkingv1.NetworkingV1Network
111+
if cloud != pcloud.Gcp {
112+
networks, err = c.V2Client.ListNetworks(environmentId, nil, []string{cloud}, []string{region}, nil, []string{"READY"}, nil)
113+
if err != nil {
114+
return fmt.Errorf("unable to list Flink endpoint, failed to list networks: %w", err)
115+
}
116+
117+
if cloud == pcloud.Azure {
118+
networks = filterPrivateLinkNetworks(networks)
119+
}
108120
}
109121

110122
for _, network := range networks {
@@ -171,3 +183,14 @@ func buildCloudRegionKeyFilterMapFromPrivateLinkAttachments(platts []networkingp
171183
}
172184
return result
173185
}
186+
187+
// We filter locally to get around a query parameter bug: https://confluentinc.atlassian.net/browse/TRAFFIC-19819
188+
func filterPrivateLinkNetworks(networks []networkingv1.NetworkingV1Network) []networkingv1.NetworkingV1Network {
189+
var filteredNetworks []networkingv1.NetworkingV1Network
190+
for _, network := range networks {
191+
if slices.Contains(network.Spec.GetConnectionTypes(), "PRIVATELINK") || slices.Contains(network.Spec.GetConnectionTypes(), "privatelink") {
192+
filteredNetworks = append(filteredNetworks, network)
193+
}
194+
}
195+
return filteredNetworks
196+
}

internal/flink/command_endpoint_use.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66

77
"github.com/spf13/cobra"
88

9+
networkingv1 "github.com/confluentinc/ccloud-sdk-go-v2/networking/v1"
10+
11+
pcloud "github.com/confluentinc/cli/v4/pkg/cloud"
912
"github.com/confluentinc/cli/v4/pkg/errors"
1013
"github.com/confluentinc/cli/v4/pkg/examples"
1114
"github.com/confluentinc/cli/v4/pkg/log"
@@ -72,9 +75,6 @@ func (c *command) endpointUse(_ *cobra.Command, args []string) error {
7275
// 3. Private endpoints associated with Confluent Cloud Networks
7376
// Returns true if the endpoint is valid, false otherwise.
7477
func validateUserProvidedFlinkEndpoint(endpoint, cloud, region string, c *command) bool {
75-
if c.Config.IsTest {
76-
return true
77-
}
7878
if endpoint == "" {
7979
log.CliLogger.Debug("Invalid input: given endpoint is empty")
8080
return false
@@ -116,10 +116,19 @@ func validateUserProvidedFlinkEndpoint(endpoint, cloud, region string, c *comman
116116
}
117117

118118
// Check if the endpoint is PRIVATE associated with CCN
119-
networks, err := c.V2Client.ListNetworks(c.Context.GetCurrentEnvironment(), nil, []string{cloud}, []string{region}, nil, []string{"READY"}, nil)
120-
if err != nil {
121-
log.CliLogger.Debugf("Error listing networks: %v", err)
122-
return false
119+
// These endpoints are currently only available for AWS and Azure (with PrivateLink connection type), so we filter accordingly
120+
// TODO: Remove these restrictions once we support more connection types
121+
var networks []networkingv1.NetworkingV1Network
122+
if cloud != pcloud.Gcp {
123+
networks, err = c.V2Client.ListNetworks(c.Context.GetCurrentEnvironment(), nil, []string{cloud}, []string{region}, nil, []string{"READY"}, nil)
124+
if err != nil {
125+
log.CliLogger.Debugf("Error listing networks: %v", err)
126+
return false
127+
}
128+
129+
if cloud == pcloud.Azure {
130+
networks = filterPrivateLinkNetworks(networks)
131+
}
123132
}
124133

125134
for _, network := range networks {

internal/schema-registry/command_endpoint_list.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package schemaregistry
22

33
import (
44
"fmt"
5+
"slices"
56

67
"github.com/spf13/cobra"
78

9+
networkingv1 "github.com/confluentinc/ccloud-sdk-go-v2/networking/v1"
10+
811
"github.com/confluentinc/cli/v4/pkg/cloud"
912
pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
1013
"github.com/confluentinc/cli/v4/pkg/output"
@@ -53,11 +56,18 @@ func (c *command) endpointList(cmd *cobra.Command, _ []string) error {
5356
}
5457

5558
// Note the region has to be empty slice instead of `nil` in case of no filter
56-
// Filter out non-AWS networks for initial release
57-
networks, err := c.V2Client.ListNetworks(environmentId, nil, []string{cloud.Aws}, []string{}, nil, []string{"READY"}, nil)
59+
awsNetworks, err := c.V2Client.ListNetworks(environmentId, nil, []string{cloud.Aws}, []string{}, nil, []string{"READY"}, nil)
60+
if err != nil {
61+
return fmt.Errorf("unable to list Schema Registry endpoints: failed to list AWS networks: %w", err)
62+
}
63+
// Filter out non-PrivateLink networks for Azure
64+
azureNetworks, err := c.V2Client.ListNetworks(environmentId, nil, []string{cloud.Azure}, []string{}, nil, []string{"READY"}, nil)
5865
if err != nil {
59-
return fmt.Errorf("unable to list Schema Registry endpoints: failed to list networks: %w", err)
66+
return fmt.Errorf("unable to list Schema Registry endpoints: failed to list Azure PrivateLink networks: %w", err)
6067
}
68+
azureNetworks = filterPrivateLinkNetworks(azureNetworks)
69+
70+
networks := append(awsNetworks, azureNetworks...)
6171
for _, network := range networks {
6272
suffix := network.Status.GetEndpointSuffix()
6373
if suffix == "-" {
@@ -77,3 +87,14 @@ func (c *command) endpointList(cmd *cobra.Command, _ []string) error {
7787

7888
return table.Print()
7989
}
90+
91+
// We filter locally to get around a query parameter bug: https://confluentinc.atlassian.net/browse/TRAFFIC-19819
92+
func filterPrivateLinkNetworks(networks []networkingv1.NetworkingV1Network) []networkingv1.NetworkingV1Network {
93+
var filteredNetworks []networkingv1.NetworkingV1Network
94+
for _, network := range networks {
95+
if slices.Contains(network.Spec.GetConnectionTypes(), "PRIVATELINK") || slices.Contains(network.Spec.GetConnectionTypes(), "privatelink") {
96+
filteredNetworks = append(filteredNetworks, network)
97+
}
98+
}
99+
return filteredNetworks
100+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Current | Endpoint | Cloud | Region | Type
2+
----------+-----------------------------------------------------+-------+---------+----------
3+
| https://flink-n-abcde2.eastus.azure.confluent.cloud | AZURE | eastus2 | PRIVATE
4+
| http://127.0.0.1:1026 | AZURE | eastus2 | PUBLIC
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Error: Flink endpoint "https://flink-n-abcde7.eastus.azure.confluent.cloud" is invalid for cloud = "azure" and region = "eastus2"
2+
3+
Suggestions:
4+
Please run "confluent flink endpoint list" to see all available Flink endpoints, or "confluent flink region use" to switch to a different cloud or region.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Using Flink endpoint "https://flink-n-abcde2.eastus.azure.confluent.cloud".
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The current Flink endpoint has been unset due to the cloud or region change.
2+
Using Flink region "Virginia (eastus2)".

test/fixtures/output/network/delete-autocomplete.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
n-abcde1 prod-gcp-us-central1
22
n-abcde2 prod-azure-eastus2
3+
n-abcde7 prod-azure-eastus2
34
n-abcde3 prod-aws-us-east1
45
n-abcde4 prod-aws-us-east1
56
n-abcde5

test/fixtures/output/network/describe-autocomplete.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
n-abcde1 prod-gcp-us-central1
22
n-abcde2 prod-azure-eastus2
3+
n-abcde7 prod-azure-eastus2
34
n-abcde3 prod-aws-us-east1
45
n-abcde4 prod-aws-us-east1
56
n-abcde5

test/fixtures/output/network/link/endpoint/create-autocomplete.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
n-abcde1 prod-gcp-us-central1
22
n-abcde2 prod-azure-eastus2
3+
n-abcde7 prod-azure-eastus2
34
n-abcde3 prod-aws-us-east1
45
n-abcde4 prod-aws-us-east1
56
n-abcde5

0 commit comments

Comments
 (0)