Skip to content

Commit

Permalink
simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Jul 25, 2023
1 parent 7e7f6ba commit b408eff
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 42 deletions.
65 changes: 32 additions & 33 deletions cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1780,47 +1780,46 @@ func (c *config) clusterMachineSSH(args []string, console bool) error {
ms := shoot.Payload.Machines
ms = append(ms, shoot.Payload.Firewalls...)
for _, m := range ms {
if *m.ID == mid {
if *m.ID != mid {
continue
}
if console {
fmt.Printf("access console via ssh\n")
authContext, err := api.GetAuthContext(viper.GetString("kubeconfig"))
if err != nil {
return fmt.Errorf("unable determine home directory:%w", err)
}
if console {
fmt.Printf("access console via ssh\n")
authContext, err := api.GetAuthContext(viper.GetString("kubeconfig"))
if err != nil {
return err
}
bmcConsolePort := 5222
err = c.sshClient(mid, c.consoleHost, keypair.privatekey, bmcConsolePort, &authContext.IDToken)
return err
}
networks := m.Allocation.Networks
switch *m.Allocation.Role {
case "firewall":
if keypair.vpn != nil {
return c.firewallSSHViaVPN(*m.ID, keypair.privatekey, keypair.vpn)
}
bmcConsolePort := 5222
err = c.sshClient(mid, c.consoleHost, keypair.privatekey, bmcConsolePort, &authContext.IDToken)
return err
}
networks := m.Allocation.Networks
switch *m.Allocation.Role {
case "firewall":
if keypair.vpn != nil {
return c.firewallSSHViaVPN(*m.ID, keypair.privatekey, keypair.vpn)
}

for _, nw := range networks {
if *nw.Underlay || *nw.Private {
continue
}
for _, ip := range nw.Ips {
if portOpen(ip, "22", time.Second) {
err := c.sshClient("metal", ip, keypair.privatekey, 22, nil)
return err
}
for _, nw := range networks {
if *nw.Underlay || *nw.Private {
continue
}
for _, ip := range nw.Ips {
if portOpen(ip, "22", time.Second) {
err := c.sshClient("metal", ip, keypair.privatekey, 22, nil)
return err
}
}
return fmt.Errorf("no ip with a open ssh port found")
case "machine":
// FIXME metal user is not allowed to execute
// ip vrf exec <tenantvrf> ssh <machineip>
return fmt.Errorf("machine access via ssh not implemented")
default:
return fmt.Errorf("unknown machine role:%s", *m.Allocation.Role)
}
return fmt.Errorf("no ip with a open ssh port found")
case "machine":
// FIXME metal user is not allowed to execute
// ip vrf exec <tenantvrf> ssh <machineip>
return fmt.Errorf("machine access via ssh not implemented")
default:
return fmt.Errorf("unknown machine role:%s", *m.Allocation.Role)
}

}

return fmt.Errorf("machine:%s not found in cluster:%s", mid, cid)
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/gosimple/slug v1.13.1
github.com/jinzhu/now v1.1.5
github.com/metal-stack/duros-go v0.4.2
github.com/metal-stack/metal-lib v0.12.5-0.20230724081620-b0e9ecfec092
github.com/metal-stack/metal-lib v0.12.5-0.20230725053447-68ecc2192a5e
github.com/metal-stack/updater v1.1.5
github.com/metal-stack/v v1.0.3
github.com/olekukonko/tablewriter v0.0.5
Expand Down Expand Up @@ -105,11 +105,11 @@ require (
github.com/illarion/gonotify v1.0.1 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/insomniacslk/dhcp v0.0.0-20230407062729-974c6f05fe16 // indirect
github.com/insomniacslk/dhcp v0.0.0-20230720093626-5648422c16cd // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 // indirect
github.com/jsimonetti/rtnetlink v1.3.3 // indirect
github.com/jsimonetti/rtnetlink v1.3.4 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+h
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/insomniacslk/dhcp v0.0.0-20230407062729-974c6f05fe16 h1:+aAGyK41KRn8jbF2Q7PLL0Sxwg6dShGcQSeCC7nZQ8E=
github.com/insomniacslk/dhcp v0.0.0-20230407062729-974c6f05fe16/go.mod h1:IKrnDWs3/Mqq5n0lI+RxA2sB7MvN/vbMBP3ehXg65UI=
github.com/insomniacslk/dhcp v0.0.0-20230720093626-5648422c16cd h1:D772X7igTag7yKErVWAR7boXpOml3fqqBzH1wNaD/jk=
github.com/insomniacslk/dhcp v0.0.0-20230720093626-5648422c16cd/go.mod h1:7474bZ1YNCvarT6WFKie4kEET6J0KYRDC4XJqqXzQW4=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
Expand All @@ -392,8 +392,8 @@ github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFF
github.com/josharian/native v1.0.1-0.20221213033349-c1e37c09b531/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 h1:elKwZS1OcdQ0WwEDBeqxKwb7WB62QX8bvZ/FJnVXIfk=
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86/go.mod h1:aFAMtuldEgx/4q7iSGazk22+IcgvtiC+HIimFO9XlS8=
github.com/jsimonetti/rtnetlink v1.3.3 h1:ycpm3z8XlAzmaacVRjdUT3x6MM1o3YBXsXc7DXSRNCE=
github.com/jsimonetti/rtnetlink v1.3.3/go.mod h1:mW4xSP3wkiqWxHMlfG/gOufp3XnhAxu7EhfABmrWSh8=
github.com/jsimonetti/rtnetlink v1.3.4 h1:uUcd9SE8sQe/enLBEVaWDkgGYWNsX3EU4eIxbEZYmF0=
github.com/jsimonetti/rtnetlink v1.3.4/go.mod h1:jGCNm5lJdGplEXKCVwqhQ5tRIGV0dNREhLyNWVzBxHc=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
Expand Down Expand Up @@ -465,8 +465,8 @@ github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U
github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA=
github.com/metal-stack/duros-go v0.4.2 h1:AhehmgutauVQDxVhl4YTkKx1TSPZG47coFW2XnEADZ0=
github.com/metal-stack/duros-go v0.4.2/go.mod h1:M0n5ZgeXny9iasQPzWEdmR8E1sfg2Vvmvx3KmAZMOz8=
github.com/metal-stack/metal-lib v0.12.5-0.20230724081620-b0e9ecfec092 h1:YeQXI0I/0sHnRkg+uCP/ma6o31k2oP64CZ9ldEgewrE=
github.com/metal-stack/metal-lib v0.12.5-0.20230724081620-b0e9ecfec092/go.mod h1:CQJtE4P80jCIXN8Mbv3Hi5gf736/4jO9C0+oj+UukyQ=
github.com/metal-stack/metal-lib v0.12.5-0.20230725053447-68ecc2192a5e h1:YLj0xmXDK2dKYmg2+74l73HZyJI54PdQf5WjMHBK3pc=
github.com/metal-stack/metal-lib v0.12.5-0.20230725053447-68ecc2192a5e/go.mod h1:DjbUlYWVxWl/24dbwv8zZytwBzpFpQO5y5hzL+zwtp0=
github.com/metal-stack/security v0.6.6 h1:KSPNN8YZd2EJEjsJ0xCBcd5o53uU0iFupahHA9Twuh0=
github.com/metal-stack/security v0.6.6/go.mod h1:WchPm3+2Xjj1h7AxM+DsnR9EWgLw+ktoGCl/0gcmgSA=
github.com/metal-stack/updater v1.1.5 h1:+Q4yyqQ50t+lQTjNkkQhCk7p//a+p+nyD0jt+DjIXFk=
Expand Down

0 comments on commit b408eff

Please sign in to comment.