extend
This commit is contained in:
parent
bd39336b29
commit
ff98343420
@ -22,8 +22,10 @@ THE SOFTWARE.
|
|||||||
package cluster
|
package cluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
k3drt "github.com/rancher/k3d/pkg/runtimes"
|
k3drt "github.com/rancher/k3d/pkg/runtimes"
|
||||||
k3d "github.com/rancher/k3d/pkg/types"
|
k3d "github.com/rancher/k3d/pkg/types"
|
||||||
@ -125,8 +127,32 @@ func CreateCluster(cluster *k3d.Cluster, runtime k3drt.Runtime) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
masterCount++
|
masterCount++
|
||||||
|
|
||||||
|
// wait for the initnode to come up before doing anything else
|
||||||
|
for {
|
||||||
|
log.Debugln("Waiting for initializing master node...")
|
||||||
|
logreader, err := runtime.GetNodeLogs(cluster.InitNode)
|
||||||
|
defer logreader.Close()
|
||||||
|
if err != nil {
|
||||||
|
logreader.Close()
|
||||||
|
log.Errorln(err)
|
||||||
|
log.Errorln("Failed to get logs from the initializig master node.. waiting for 3 seconds instead")
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
goto initNodeFinished
|
||||||
|
}
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
nRead, _ := buf.ReadFrom(logreader)
|
||||||
|
logreader.Close()
|
||||||
|
if nRead > 0 && strings.Contains(buf.String(), "Running kubelet") {
|
||||||
|
log.Debugln("Initializing master node is up... continuing")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(time.Second) // TODO: timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
initNodeFinished:
|
||||||
// create all other nodes, but skip the init node
|
// create all other nodes, but skip the init node
|
||||||
for _, node := range cluster.Nodes {
|
for _, node := range cluster.Nodes {
|
||||||
if node.Role == k3d.MasterRole {
|
if node.Role == k3d.MasterRole {
|
||||||
|
|||||||
@ -24,6 +24,7 @@ package containerd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
@ -119,3 +120,8 @@ func (d Containerd) GetNodesByLabel(labels map[string]string) ([]*k3d.Node, erro
|
|||||||
func (d Containerd) GetNode(node *k3d.Node) (*k3d.Node, error) {
|
func (d Containerd) GetNode(node *k3d.Node) (*k3d.Node, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetNodeLogs returns the logs from a given node
|
||||||
|
func (d Containerd) GetNodeLogs(node *k3d.Node) (io.ReadCloser, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -25,6 +25,7 @@ package docker
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
@ -185,3 +186,28 @@ func (d Docker) GetNode(node *k3d.Node) (*k3d.Node, error) {
|
|||||||
return node, nil
|
return node, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetNodeLogs returns the logs from a given node
|
||||||
|
func (d Docker) GetNodeLogs(node *k3d.Node) (io.ReadCloser, error) {
|
||||||
|
// get the container for the given node
|
||||||
|
container, err := getNodeContainer(node)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// create docker client
|
||||||
|
ctx := context.Background()
|
||||||
|
docker, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln("Failed to create docker client")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
logreader, err := docker.ContainerLogs(ctx, container.ID, types.ContainerLogsOptions{ShowStdout: true, ShowStderr: true})
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Failed to get logs from node '%s' (container '%s')", node.Name, container.ID)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return logreader, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -49,7 +49,7 @@ type Runtime interface {
|
|||||||
StopNode(*k3d.Node) error
|
StopNode(*k3d.Node) error
|
||||||
// ExecContainer() error
|
// ExecContainer() error
|
||||||
// DeleteContainer() error
|
// DeleteContainer() error
|
||||||
// GetContainerLogs() error
|
GetNodeLogs(*k3d.Node) (io.ReadCloser, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRuntime checks, if a given name is represented by an implemented k3d runtime and returns it
|
// GetRuntime checks, if a given name is represented by an implemented k3d runtime and returns it
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user