Skip to content

Commit

Permalink
tbs: reuse getSwitchIP for vlab ssh
Browse files Browse the repository at this point in the history
Signed-off-by: Pau Capdevila <[email protected]>
  • Loading branch information
pau-hedgehog authored and Ubuntu committed Jan 12, 2025
1 parent f23d4b4 commit e30949e
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions pkg/hhfab/vlabhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,9 @@ func (c *Config) VLABAccess(ctx context.Context, vlab *VLAB, t VLABAccessType, n
} else if entry.IsSwitch {
slog.Debug("SSH through control node", "name", name, "type", "switch")

kubeconfig := filepath.Join(c.WorkDir, VLABDir, VLABKubeConfig)
kube, err := kubeutil.NewClientWithCache(ctx, kubeconfig, wiringapi.SchemeBuilder)
swIP, err := c.getSwitchIP(ctx, name)
if err != nil {
return fmt.Errorf("creating kube client: %w", err)
}

sw := &wiringapi.Switch{}
if err := kube.Get(ctx, client.ObjectKey{Name: name, Namespace: metav1.NamespaceDefault}, sw); err != nil {
return fmt.Errorf("getting switch: %w", err)
}

if sw.Spec.IP == "" {
return fmt.Errorf("switch IP not found: %s", name) //nolint:goerr113
}

swIP, err := netip.ParsePrefix(sw.Spec.IP)
if err != nil {
return fmt.Errorf("parsing switch IP: %w", err)
return fmt.Errorf("getting switch IP: %w", err)
}

proxyCmd := fmt.Sprintf("ssh %s -i %s -W %%h:%%p -p %d [email protected]",
Expand All @@ -144,7 +129,7 @@ func (c *Config) VLABAccess(ctx context.Context, vlab *VLAB, t VLABAccessType, n
args = append(SSHQuietFlags,
"-i", filepath.Join(VLABDir, VLABSSHKeyFile),
"-o", "ProxyCommand="+proxyCmd,
"admin@"+swIP.Addr().String(),
"admin@"+swIP,
)
} else {
return fmt.Errorf("SSH not available: %s", name) //nolint:goerr113
Expand Down

0 comments on commit e30949e

Please sign in to comment.