Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Check if vcluster is reachable with the additional flags provided as input in vcluster connect command #2408

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions pkg/cli/connect_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ func (cmd *connectHelm) connect(ctx context.Context, vCluster *find.VCluster, co
return err
}

if !cmd.ConnectOptions.Print {
// check if vcluster is ready
err = cmd.waitForVCluster(ctx, *kubeConfig, cmd.errorChan)
if err != nil {
return fmt.Errorf("failed connecting to vcluster, verify connection arguments: %w ", err)
}
}
kale-amruta marked this conversation as resolved.
Show resolved Hide resolved

// check if we should execute command
if len(command) > 0 {
if !cmd.portForwarding {
Expand Down Expand Up @@ -650,12 +658,14 @@ func getLocalVClusterConfig(vKubeConfig clientcmdapi.Config, options *ConnectOpt
vKubeConfig = *vKubeConfig.DeepCopy()

// update vCluster server address in case of OSS vClusters only
if options.LocalPort != 0 {
for _, cluster := range vKubeConfig.Clusters {
if cluster == nil {
continue
if options.Server == "" {
if options.LocalPort != 0 {
for _, cluster := range vKubeConfig.Clusters {
if cluster == nil {
continue
}
cluster.Server = "https://localhost:" + strconv.Itoa(options.LocalPort)
}
cluster.Server = "https://localhost:" + strconv.Itoa(options.LocalPort)
}
}

Expand Down Expand Up @@ -689,6 +699,9 @@ func (cmd *connectHelm) waitForVCluster(ctx context.Context, vKubeConfig clientc
default:
// check if service account exists
_, err = vKubeClient.CoreV1().ServiceAccounts("default").Get(ctx, "default", metav1.GetOptions{})
if err != nil {
cmd.Log.Debugf("failed to list default service account %v", err)
}
return err == nil, nil
}
})
Expand Down
11 changes: 11 additions & 0 deletions test/e2e_cli/connect/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,15 @@ var _ = ginkgo.Describe("Connect to vCluster", func() {
err := connectCmd.Execute()
framework.ExpectNoError(err)
})

ginkgo.It("should fail saying the client timeout exceeded", func() {
connectCmd := cmd.NewConnectCmd(&flags.GlobalFlags{})
connectCmd.SetArgs([]string{f.VclusterName})
err := connectCmd.Flags().Set("kube-config", f.VClusterKubeConfigFile.Name())
framework.ExpectNoError(err)
err = connectCmd.Flags().Set("server", "testdomain.org")
framework.ExpectNoError(err)
err = connectCmd.Execute()
framework.ExpectError(err)
})
})