Skip to content

Commit

Permalink
Bumped drivercore to 0.2.0
Browse files Browse the repository at this point in the history
Added UsesPerClusterNetworking checks where required.
Added IPAddress and SSHAddress properties to nodes.
  • Loading branch information
rajch committed May 29, 2022
1 parent 03d55b4 commit 5cc4535
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 39 deletions.
16 changes: 9 additions & 7 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,17 @@ func (c *Cluster) DeleteNode(nodename string, force bool) error {
}
}

// Unmap ports
kuttilog.Println(kuttilog.Info, "Unmapping ports...")
for key := range n.ports {
err := n.host.UnforwardPort(key)
if err != nil {
kuttilog.Printf(kuttilog.Quiet, "Error while unmapping ports for node '%s': %v.", nodename, err)
if c.Driver().UsesNATNetworking() {
// Unmap ports
kuttilog.Println(kuttilog.Info, "Unmapping ports...")
for key := range n.ports {
err := n.host.UnforwardPort(key)
if err != nil {
kuttilog.Printf(kuttilog.Quiet, "Error while unmapping ports for node '%s': %v.", nodename, err)
}
}
kuttilog.Println(kuttilog.Info, "Ports unmapped.")
}
kuttilog.Println(kuttilog.Info, "Ports unmapped.")

return c.deletenode(nodename, force)
}
Expand Down
28 changes: 18 additions & 10 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
// driverdata is a data-only representation of the Driver type,
// used for serialization and output.
type driverdata struct {
Name string
Description string
UsesNATNetworking bool
Status string
Error string
Name string
Description string
UsesPerClusterNetworking bool
UsesNATNetworking bool
Status string
Error string
}

// Driver is a kutti driver
Expand All @@ -37,6 +38,12 @@ func (d *Driver) Description() string {
return d.vmdriver.Description()
}

// UsesPerClusterNetworking returns true if the driver creates virtual networks
// per cluster.
func (d *Driver) UsesPerClusterNetworking() bool {
return d.vmdriver.UsesPerClusterNetworking()
}

// UsesNATNetworking returns true if the driver's networks use NAT,
// and therefore require node ports to be forwarded.
func (d *Driver) UsesNATNetworking() bool {
Expand All @@ -56,11 +63,12 @@ func (d *Driver) Error() string {
// MarshalJSON returns the JSON encoding of the driver.
func (d *Driver) MarshalJSON() ([]byte, error) {
savedata := driverdata{
Name: d.Name(),
Description: d.Description(),
UsesNATNetworking: d.UsesNATNetworking(),
Status: d.Status(),
Error: d.Error(),
Name: d.Name(),
Description: d.Description(),
UsesPerClusterNetworking: d.UsesPerClusterNetworking(),
UsesNATNetworking: d.UsesNATNetworking(),
Status: d.Status(),
Error: d.Error(),
}

return json.Marshal(savedata)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/kuttiproject/kuttilib
go 1.16

require (
github.com/kuttiproject/drivercore v0.1.2
github.com/kuttiproject/drivercore v0.2.0
github.com/kuttiproject/kuttilog v0.1.2
github.com/kuttiproject/workspace v0.2.2
)

retract [v0.1.0,v0.1.1] // Broke compatibility with original kutti
retract [v0.1.0, v0.1.1] // Broke compatibility with original kutti
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/kuttiproject/drivercore v0.1.2 h1:t/AKAh48130SgOGi2kNmuoi3KkaIpHZx+vL6tqKsPGY=
github.com/kuttiproject/drivercore v0.1.2/go.mod h1:1C1TMGfQ4u/5ltHUtl4hL7gYzXZyZQVhkOha4GuOzk0=
github.com/kuttiproject/drivercore v0.2.0 h1:RZI/azMsyI8gPidXzHPcZXqajHPdq+zaRg3W4x9ASC0=
github.com/kuttiproject/drivercore v0.2.0/go.mod h1:1C1TMGfQ4u/5ltHUtl4hL7gYzXZyZQVhkOha4GuOzk0=
github.com/kuttiproject/kuttilog v0.1.2 h1:VEqVWrR3M6RME6aoUuVwXNO3bRpHKNp0ISAP/vqncpg=
github.com/kuttiproject/kuttilog v0.1.2/go.mod h1:OO3dHpXm1/Pjlc57R4c0e/C+ZWkYlY3Fd9Ikn8xPXi4=
github.com/kuttiproject/workspace v0.2.2 h1:1eNdMooB6Oq7jq2wodbuaY+IVZSYcEuXnqY3e00s64Y=
Expand Down
44 changes: 24 additions & 20 deletions kuttilib-clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,24 @@ func DeleteCluster(clustername string, force bool) error {
return errClusterNotEmpty
}

kuttilog.Println(kuttilog.Info, "Deleting network...")
err := cluster.deletenetwork()
if err != nil {
if !force {
return err
if cluster.Driver().UsesPerClusterNetworking() {
kuttilog.Println(kuttilog.Info, "Deleting network...")
err := cluster.deletenetwork()
if err != nil {
if !force {
return err
}

kuttilog.Printf(
kuttilog.Quiet,
"Warning: Errors returned while deleting network: %v. Some artifacts may need manual cleanup.",
err,
)
}

kuttilog.Printf(
kuttilog.Quiet,
"Warning: Errors returned while deleting network: %v. Some artifacts may need manual cleanup.",
err,
)
kuttilog.Println(kuttilog.Info, "Network deleted.")
}

kuttilog.Println(kuttilog.Info, "Network deleted.")

delete(config.Clusters, clustername)

return clusterconfigmanager.Save()
Expand All @@ -104,15 +106,17 @@ func newunmanagedcluster(name string, k8sversion string, drivername string) (*Cl
}

// Create Network
kuttilog.Println(kuttilog.Info, "Creating network...")
err = newCluster.createnetwork()
if err != nil {
return newCluster, err
}
if newCluster.Driver().UsesPerClusterNetworking() {
kuttilog.Println(kuttilog.Info, "Creating network...")
err = newCluster.createnetwork()
if err != nil {
return newCluster, err
}

newCluster.clustertype = "Unmanaged"
newCluster.status = "Ready"
kuttilog.Println(kuttilog.Info, "Network created.")
newCluster.clustertype = "Unmanaged"
newCluster.status = "Ready"
kuttilog.Println(kuttilog.Info, "Network created.")
}

return newCluster, nil
}
Expand Down
32 changes: 32 additions & 0 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kuttilib

import (
"encoding/json"
"fmt"
"time"

"github.com/kuttiproject/kuttilog"
Expand Down Expand Up @@ -66,6 +67,37 @@ func (n *Node) Ports() map[int]int {
return n.ports
}

// IPAddress returns the IP address of the node if it is running,
// or an empty string if not.
func (n *Node) IPAddress() string {
err := n.ensurehost()
if err != nil {
return ""
}

return n.host.IPAddress()
}

// SSHAddress returns the address to SSH into the node.
// The return value is in "HOST:PORT" format if the node
// is running, or an empty string if not.
func (n *Node) SSHAddress() string {
if n.Cluster().Driver().UsesNATNetworking() {
port, ok := n.Ports()[22]
if !ok {
return ""
}
return fmt.Sprintf("localhost:%v", port)

}
err := n.ensurehost()
if err != nil {
return ""
}

return n.host.SSHAddress()
}

// Cluster returns the Cluster this node belongs to.
func (n *Node) Cluster() *Cluster {
if n.cluster == nil {
Expand Down

0 comments on commit 5cc4535

Please sign in to comment.