Skip to content

Commit 72a11d5

Browse files
authored
fix: join should use same logic as install to determine network interface if unspecified (#2128)
* f * f * f * f
1 parent fd3d57c commit 72a11d5

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

cmd/installer/cli/join.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ func preRunJoin(flags *JoinCmdFlags) error {
116116

117117
flags.isAirgap = flags.airgapBundle != ""
118118

119+
// if a network interface flag was not provided, attempt to discover it
120+
if flags.networkInterface == "" {
121+
autoInterface, err := determineBestNetworkInterface()
122+
if err == nil {
123+
flags.networkInterface = autoInterface
124+
}
125+
}
126+
119127
return nil
120128
}
121129

pkg/dryrun/kotsadm.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ func (c *Kotsadm) setResponse(resp interface{}, err error, methodName string, ar
4545
return nil
4646
}
4747

48-
// SetGetJoinTokenResponse sets the response for the GetJoinToken method, based on the provided baseURL and shortToken.
49-
func (c *Kotsadm) SetGetJoinTokenResponse(baseURL, shortToken string, resp *join.JoinCommandResponse, err error) {
50-
mockErr := c.setResponse(resp, err, "GetJoinToken", baseURL, shortToken)
48+
// SetGetJoinTokenResponse sets the response for the GetJoinToken method, based on the provided address and shortToken.
49+
func (c *Kotsadm) SetGetJoinTokenResponse(address, shortToken string, resp *join.JoinCommandResponse, err error) {
50+
mockErr := c.setResponse(resp, err, "GetJoinToken", address, shortToken)
5151
if mockErr != nil {
5252
panic(mockErr)
5353
}
5454
}
5555

5656
// GetJoinToken issues a request to the kots api to get the actual join command
5757
// based on the short token provided by the user.
58-
func (c *Kotsadm) GetJoinToken(ctx context.Context, baseURL, shortToken string) (*join.JoinCommandResponse, error) {
59-
key := strings.Join([]string{"GetJoinToken", baseURL, shortToken}, ":")
58+
func (c *Kotsadm) GetJoinToken(ctx context.Context, address, shortToken string) (*join.JoinCommandResponse, error) {
59+
key := strings.Join([]string{"GetJoinToken", address, shortToken}, ":")
6060
if handler, ok := c.mockHandlers[key]; ok {
6161
return handler.resp.(*join.JoinCommandResponse), handler.err
6262
} else {
63-
return nil, fmt.Errorf("no response set for GetJoinToken, baseURL: %s, shortToken: %s", baseURL, shortToken)
63+
return nil, fmt.Errorf("no response set for GetJoinToken, address: %s, shortToken: %s", address, shortToken)
6464
}
6565
}

pkg/kotsadm/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type Client struct{}
1717

1818
// GetJoinToken issues a request to the kots api to get the actual join command
1919
// based on the short token provided by the user.
20-
func (c *Client) GetJoinToken(ctx context.Context, baseURL, shortToken string) (*join.JoinCommandResponse, error) {
21-
url := fmt.Sprintf("https://%s/api/v1/embedded-cluster/join?token=%s", baseURL, shortToken)
20+
func (c *Client) GetJoinToken(ctx context.Context, address, shortToken string) (*join.JoinCommandResponse, error) {
21+
url := fmt.Sprintf("https://%s/api/v1/embedded-cluster/join?token=%s", address, shortToken)
2222
ctx, cancel := context.WithTimeout(ctx, time.Minute)
2323
defer cancel()
2424
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)

pkg/kotsadm/interface.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ func Set(kotsadm ClientInterface) {
1919
}
2020

2121
type ClientInterface interface {
22-
GetJoinToken(ctx context.Context, baseURL, shortToken string) (*join.JoinCommandResponse, error)
22+
GetJoinToken(ctx context.Context, address, shortToken string) (*join.JoinCommandResponse, error)
2323
}
2424

2525
// Convenience functions
2626

2727
// GetJoinToken is a helper function that issues a request to the kots api to get the actual join command
2828
// based on the short token provided by the user.
29-
func GetJoinToken(ctx context.Context, baseURL, shortToken string) (*join.JoinCommandResponse, error) {
30-
return _kotsadm.GetJoinToken(ctx, baseURL, shortToken)
29+
func GetJoinToken(ctx context.Context, address, shortToken string) (*join.JoinCommandResponse, error) {
30+
return _kotsadm.GetJoinToken(ctx, address, shortToken)
3131
}

0 commit comments

Comments
 (0)