diff --git a/cmd/get/getCluster.go b/cmd/get/getCluster.go index f8dd638a..962c93ae 100644 --- a/cmd/get/getCluster.go +++ b/cmd/get/getCluster.go @@ -42,9 +42,17 @@ func NewCmdGetCluster() *cobra.Command { log.Debugln("get cluster called") c, rt := parseGetClusterCmd(cmd, args) if c == nil { - cluster.GetClusters(rt) + existingClusters, err := cluster.GetClusters(rt) + if err != nil { + log.Fatalln(err) // TODO: log something here as well? + } + log.Debugln(existingClusters) } else { - cluster.GetCluster(c, rt) + existingCluster, err := cluster.GetCluster(c, rt) + if err != nil { + log.Fatalln(err) // TODO: log something here as well? + } + log.Debugln(existingCluster) } }, } diff --git a/go.mod b/go.mod index 4c2dcb88..6b969fb2 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/containerd/typeurl v0.0.0-20190911142611-5eb25027c9fd // indirect github.com/docker/distribution v0.0.0-20190905152932-14b96e55d84c // indirect github.com/docker/docker v1.4.2-0.20190905191220-3b23f9033967 - github.com/docker/go-connections v0.4.0 // indirect + github.com/docker/go-connections v0.4.0 github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect github.com/gogo/googleapis v1.3.0 // indirect github.com/golang/protobuf v1.3.1 // indirect diff --git a/go.sum b/go.sum index 796bc1e9..b558d5ef 100644 --- a/go.sum +++ b/go.sum @@ -50,7 +50,6 @@ github.com/docker/distribution v0.0.0-20190905152932-14b96e55d84c h1:6L6qod4JzOm github.com/docker/distribution v0.0.0-20190905152932-14b96e55d84c/go.mod h1:0+TTO4EOBfRPhZXAeF1Vu+W3hHZ8eLp8PgKVZlcvtFY= github.com/docker/docker v1.4.2-0.20190905191220-3b23f9033967 h1:hqs6DQFz659/085bXwClBRGefVf+kWCTsQR6wwkOMiU= github.com/docker/docker v1.4.2-0.20190905191220-3b23f9033967/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= -github.com/docker/docker v1.13.1 h1:IkZjBSIc8hBjLpqeAbeE5mca5mNgeatLHBy3GO78BWo= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c h1:+pKlWGMw7gf6bQ+oDZB4KHQFypsfjYlq/C4rfL7D3g8= diff --git a/pkg/runtimes/docker/translate.go b/pkg/runtimes/docker/translate.go index 1d01bfe4..bb81623e 100644 --- a/pkg/runtimes/docker/translate.go +++ b/pkg/runtimes/docker/translate.go @@ -24,6 +24,7 @@ package docker import ( docker "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/network" "github.com/docker/go-connections/nat" k3d "github.com/rancher/k3d/pkg/types" ) @@ -33,12 +34,42 @@ func TranslateNodeToContainer(node *k3d.Node) (docker.Config, error) { container := docker.Config{} container.Hostname = node.Name container.Image = node.Image - //container.Ports = // TODO: translate from what we have to []docker.Port - container.Labels = node.Labels - container.ExposedPorts = nat.PortSet{} // TODO: - container.Env = []string{} // TODO: - container.Cmd = []string{} // TODO: dependent on role and extra args - container.Volumes = map[string]struct{}{} // TODO: + container.Labels = node.Labels // has to include the role + container.Env = []string{} // TODO: + container.Cmd = []string{} // TODO: dependent on role and extra args + hostConfig := docker.HostConfig{} + + /* Auto-Restart */ + if node.Restart { + hostConfig.RestartPolicy = docker.RestartPolicy{ + Name: "unless-stopped", + } + } + + // TODO: do we need this or can the default be a map with empty values already? + hostConfig.Tmpfs = make(map[string]string) + for _, mnt := range k3d.DefaultTmpfsMounts { + hostConfig.Tmpfs[mnt] = "" + } + + hostConfig.Privileged = true + + /* Volumes */ + // TODO: image volume + hostConfig.Binds = []string{} + container.Volumes = map[string]struct{}{} // TODO: which one do we use? + + /* Ports */ + container.ExposedPorts = nat.PortSet{} // TODO: + hostConfig.PortBindings = nat.PortMap{} // TODO: this and exposedPorts required? + + /* Network */ + networkingConfig := &network.NetworkingConfig{} + networkingConfig.EndpointsConfig = map[string]*network.EndpointSettings{ + "": { // TODO: fill + Aliases: []string{""}, // TODO: fill + }, + } return container, nil } diff --git a/pkg/types/types.go b/pkg/types/types.go index f206d037..cd2089b3 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -46,6 +46,12 @@ var DefaultObjectLabels = map[string]string{ "app": "k3d", } +// DefaultTmpfsMounts specifies tmpfs mounts that are required for all k3d nodes +var DefaultTmpfsMounts = []string{ + "/run", + "/var/run", +} + // Cluster describes a k3d cluster type Cluster struct { Name string `yaml:"name" json:"name,omitempty"`