Skip to content

Commit

Permalink
fix e2e (#5302)
Browse files Browse the repository at this point in the history
  • Loading branch information
r2k1 authored Nov 20, 2024
1 parent f40de5b commit ac9dabf
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions e2e/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"bytes"
"context"
"fmt"
"strconv"
"strings"
"testing"

"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/remotecommand"
)
Expand Down Expand Up @@ -109,11 +109,6 @@ func extractClusterParameters(ctx context.Context, t *testing.T, kube *Kubeclien
require.NoError(t, err)

bootstrapConfig := execResult.stdout.Bytes()
bootstrapToken, err := extractKeyValuePair("token", string(bootstrapConfig))
require.NoError(t, err)

bootstrapToken, err = strconv.Unquote(bootstrapToken)
require.NoError(t, err)

server, err := extractKeyValuePair("server", string(bootstrapConfig))
require.NoError(t, err)
Expand All @@ -128,11 +123,28 @@ func extractClusterParameters(ctx context.Context, t *testing.T, kube *Kubeclien

return ClusterParams{
CACert: caCert.stdout.Bytes(),
BootstrapToken: bootstrapToken,
BootstrapToken: getBootstrapToken(ctx, t, kube),
FQDN: fqdn,
}
}

func getBootstrapToken(ctx context.Context, t *testing.T, kube *Kubeclient) string {
secrets, err := kube.Typed.CoreV1().Secrets("kube-system").List(ctx, metav1.ListOptions{})
require.NoError(t, err)
secret := func() *corev1.Secret {
for _, secret := range secrets.Items {
if strings.HasPrefix(secret.Name, "bootstrap-token-") {
return &secret
}
}
t.Fatal("could not find secret with bootstrap-token- prefix")
return nil
}()
id := secret.Data["token-id"]
token := secret.Data["token-secret"]
return fmt.Sprintf("%s.%s", id, token)
}

func execOnVM(ctx context.Context, kube *Kubeclient, vmPrivateIP, jumpboxPodName, sshPrivateKey, command string, isShellBuiltIn bool) (*podExecResult, error) {
sshCommand := fmt.Sprintf(sshCommandTemplate, sshPrivateKey, strings.ReplaceAll(vmPrivateIP, ".", ""), vmPrivateIP)
if !isShellBuiltIn {
Expand Down

0 comments on commit ac9dabf

Please sign in to comment.