test interface implementations

pull/227/head
iwilltry42 5 years ago
parent a34bbc3ef7
commit 6b7de5cab6
  1. 4
      cmd/create/create.go
  2. 9
      cmd/create/createCluster.go
  3. 19
      pkg/cluster/cluster.go
  4. 7
      pkg/runtimes/docker/container.go
  5. 6
      pkg/runtimes/docker/docker.go
  6. 10
      pkg/runtimes/runtime.go

@ -22,8 +22,6 @@ THE SOFTWARE.
package create
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@ -36,7 +34,7 @@ func NewCmdCreate() *cobra.Command {
Short: "Create a resource [cluster, node].",
Long: `Create a resource [cluster, node].`,
Run: func(cmd *cobra.Command, args []string) {
log.Debugln("create called")
cmd.Help()
},
}

@ -39,8 +39,12 @@ func NewCmdCreateCluster() *cobra.Command {
Short: "Create a new k3s cluster in docker",
Long: `Create a new k3s cluster with containerized nodes (k3s in docker).`,
Run: func(cmd *cobra.Command, args []string) {
cluster.CreateCluster()
log.Debugln("create cluster called")
c := types.Cluster{} // TODO: fill
rt, err := cmd.Flags().GetString("runtime")
if err != nil {
log.Debugln("runtime not defined")
}
cluster.CreateCluster(&c, rt)
},
}
@ -48,6 +52,7 @@ func NewCmdCreateCluster() *cobra.Command {
cmd.Flags().StringP("name", "n", types.DefaultClusterName, "Set a name for the cluster")
cmd.Flags().StringP("api-port", "a", "6443", "Specify the Kubernetes cluster API server port (Format: `--api-port [host:]port`")
cmd.Flags().IntP("workers", "w", 0, "Specify how many workers you want to create")
cmd.Flags().StringP("runtime", "r", "docker", "Choose a container runtime environment [docker, containerd]")
// add subcommands

@ -22,12 +22,27 @@ THE SOFTWARE.
package cluster
import (
"github.com/rancher/k3d/pkg/types"
k3drt "github.com/rancher/k3d/pkg/runtimes"
k3dContainerd "github.com/rancher/k3d/pkg/runtimes/containerd"
k3dDocker "github.com/rancher/k3d/pkg/runtimes/docker"
k3d "github.com/rancher/k3d/pkg/types"
log "github.com/sirupsen/logrus"
)
// CreateCluster creates a new cluster consisting of
// - some containerized k3s nodes
// - a docker network
func CreateCluster(cluster *types.Cluster) error {
func CreateCluster(cluster *k3d.Cluster, runtimeChoice string) error {
var runtime k3drt.Runtime
if runtimeChoice == "docker" {
runtime = k3dDocker.Docker{}
} else {
runtime = k3dContainerd.Containerd{}
}
if err := runtime.CreateContainer(&k3d.Node{}); err != nil {
log.Println("...failed")
}
log.Println("...success")
return nil
}

@ -28,8 +28,15 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
k3d "github.com/rancher/k3d/pkg/types"
log "github.com/sirupsen/logrus"
)
func (d Docker) CreateContainer(nodeSpec *k3d.Node) error {
log.Println("docker.CreateContainer...")
return nil
}
// createContainer creates a new docker container
// @return containerID, error
func createContainer(types.Container) (string, error) {

@ -22,8 +22,4 @@ THE SOFTWARE.
package docker
type docker struct{}
func New() *Runtime {
}
type Docker struct{}

@ -28,9 +28,9 @@ import (
// Runtime defines an interface that can be implemented for various container runtime environments (docker, containerd, etc.)
type Runtime interface {
CreateContainer(*k3d.Node) error
StartContainer() error
ExecContainer() error
StopContainer() error
DeleteContainer() error
GetContainerLogs() error
// StartContainer() error
// ExecContainer() error
// StopContainer() error
// DeleteContainer() error
// GetContainerLogs() error
}

Loading…
Cancel
Save