Skip to content

Commit

Permalink
feat(connector): create destination as soon as possible
Browse files Browse the repository at this point in the history
Update the connector to create itself as quickly as possible instead of
waiting for a valid connection. This is mainly due to LoadBalancer
potentially taking a significant amount of time to initialize. Creating
the destination quickly allows the user to continue without waiting.

Update UI and CLI to output status == "Pending" when the destination is
disconnected and does not have a connection URL.
  • Loading branch information
mxyng committed Oct 4, 2022
1 parent cd983f2 commit 9321a7a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion api/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type DestinationConnection struct {

func (r DestinationConnection) ValidationRules() []validate.ValidationRule {
return []validate.ValidationRule{
validate.Required("url", r.URL),
validate.Required("ca", r.CA),
}
}

Expand Down
10 changes: 8 additions & 2 deletions internal/cmd/destinations.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

const (
DestinationStatusConnected = "Connected"
DestinationStatusPending = "Pending"
DestinationStatusDisconnected = "Disconnected"
)

Expand Down Expand Up @@ -79,8 +80,13 @@ func newDestinationsListCmd(cli *CLI) *cobra.Command {

var rows []row
for _, d := range destinations {
status := DestinationStatusDisconnected
if d.Connected {
var status string
switch {
case !d.Connected:
status = DestinationStatusDisconnected
case d.Connection.URL == "":
status = DestinationStatusPending
default:
status = DestinationStatusConnected
}

Expand Down
28 changes: 16 additions & 12 deletions internal/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,23 +297,26 @@ func httpTransportFromOptions(opts ServerOptions) *http.Transport {
func syncDestination(con connector) error {
endpoint, err := getEndpointHostPort(con.k8s, con.options)
if err != nil {
return err
logging.L.Warn().Err(err).Msg("could not get host")
}

if ipAddr := net.ParseIP(endpoint.Host); ipAddr == nil {
// wait for DNS resolution if endpoint is not an IP address
if _, err := net.LookupIP(endpoint.Host); err != nil {
return fmt.Errorf("host could not be resolved: %w", err)
if endpoint.Host != "" {
if ipAddr := net.ParseIP(endpoint.Host); ipAddr == nil {
// wait for DNS resolution if endpoint is not an IP address
if _, err := net.LookupIP(endpoint.Host); err != nil {
logging.L.Warn().Err(err).Msg("host could not be resolved")
endpoint.Host = ""
}
}
}

// update certificates if the host changed
_, err = con.certCache.AddHost(endpoint.Host)
if err != nil {
return fmt.Errorf("could not update self-signed certificates: %w", err)
}
// update certificates if the host changed
_, err = con.certCache.AddHost(endpoint.Host)
if err != nil {
return fmt.Errorf("could not update self-signed certificates: %w", err)
}

logging.L.Debug().Str("addr", endpoint.String()).Msg("connector endpoint address")
logging.L.Debug().Str("addr", endpoint.String()).Msg("connector endpoint address")
}

namespaces, err := con.k8s.Namespaces()
if err != nil {
Expand Down Expand Up @@ -370,6 +373,7 @@ func getEndpointHostPort(k8s *kubernetes.Kubernetes, opts Options) (types.HostPo
if err != nil {
return types.HostPort{}, fmt.Errorf("failed to lookup endpoint: %w", err)
}

return types.HostPort{Host: host, Port: port}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/server/destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestAPI_CreateDestination(t *testing.T) {
assert.NilError(t, err)

expected := []api.FieldError{
{FieldName: "connection.url", Errors: []string{"is required"}},
{FieldName: "connection.ca", Errors: []string{"is required"}},
{FieldName: "name", Errors: []string{"is required"}},
{FieldName: "uniqueID", Errors: []string{"is required"}},
}
Expand Down
8 changes: 4 additions & 4 deletions internal/server/testdata/openapi3.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
}
},
"required": [
"url"
"ca"
],
"type": "object"
},
Expand Down Expand Up @@ -403,7 +403,7 @@
}
},
"required": [
"url"
"ca"
],
"type": "object"
},
Expand Down Expand Up @@ -1671,7 +1671,7 @@
}
},
"required": [
"url"
"ca"
],
"type": "object"
},
Expand Down Expand Up @@ -2010,7 +2010,7 @@
}
},
"required": [
"url"
"ca"
],
"type": "object"
},
Expand Down
10 changes: 8 additions & 2 deletions ui/pages/destinations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,18 @@ export default function Destinations() {
<div
className={`h-2 w-2 flex-none rounded-full border ${
info.getValue()
? ' border-teal-500/50 bg-teal-400'
? info.row.original.connection.url === ''
? 'animate-pulse border-yellow-600 bg-yellow-500'
: 'border-teal-500/50 bg-teal-400'
: 'border-gray-300 bg-gray-200'
}`}
/>
<span className='flex-none px-2'>
{info.getValue() ? 'Connected' : 'Disconnected'}
{info.getValue()
? info.row.original.connection.url === ''
? 'Pending'
: 'Connected'
: 'Disconnected'}
</span>
</div>
),
Expand Down

0 comments on commit 9321a7a

Please sign in to comment.