Make sure not to treat the instance as a docker host always, as it might
not be one.
This commit is contained in:
@@ -10,6 +10,9 @@ type checkSwarmStatusTask struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c checkSwarmStatusTask) Run(i *Instance) error {
|
func (c checkSwarmStatusTask) Run(i *Instance) error {
|
||||||
|
if i.docker == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if info, err := i.docker.GetDaemonInfo(); err == nil {
|
if info, err := i.docker.GetDaemonInfo(); err == nil {
|
||||||
if info.Swarm.LocalNodeState != swarm.LocalNodeStateInactive && info.Swarm.LocalNodeState != swarm.LocalNodeStateLocked {
|
if info.Swarm.LocalNodeState != swarm.LocalNodeStateInactive && info.Swarm.LocalNodeState != swarm.LocalNodeStateLocked {
|
||||||
i.IsManager = &info.Swarm.ControlAvailable
|
i.IsManager = &info.Swarm.ControlAvailable
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ type checkSwarmUsedPortsTask struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c checkSwarmUsedPortsTask) Run(i *Instance) error {
|
func (c checkSwarmUsedPortsTask) Run(i *Instance) error {
|
||||||
|
if i.docker == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if i.IsManager != nil && *i.IsManager {
|
if i.IsManager != nil && *i.IsManager {
|
||||||
sessionPrefix := i.session.Id[:8]
|
sessionPrefix := i.session.Id[:8]
|
||||||
// This is a swarm manager instance, then check for ports
|
// This is a swarm manager instance, then check for ports
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ type checkUsedPortsTask struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c checkUsedPortsTask) Run(i *Instance) error {
|
func (c checkUsedPortsTask) Run(i *Instance) error {
|
||||||
|
if i.docker == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if ports, err := i.docker.GetPorts(); err == nil {
|
if ports, err := i.docker.GetPorts(); err == nil {
|
||||||
for _, p := range ports {
|
for _, p := range ports {
|
||||||
i.setUsedPort(uint16(p))
|
i.setUsedPort(uint16(p))
|
||||||
|
|||||||
@@ -35,26 +35,27 @@ func (p UInt16Slice) Less(i, j int) bool { return p[i] < p[j] }
|
|||||||
func (p UInt16Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
func (p UInt16Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
||||||
|
|
||||||
type Instance struct {
|
type Instance struct {
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname"`
|
||||||
IP string `json:"ip"`
|
IP string `json:"ip"`
|
||||||
IsManager *bool `json:"is_manager"`
|
IsManager *bool `json:"is_manager"`
|
||||||
Mem string `json:"mem"`
|
Mem string `json:"mem"`
|
||||||
Cpu string `json:"cpu"`
|
Cpu string `json:"cpu"`
|
||||||
Alias string `json:"alias"`
|
Alias string `json:"alias"`
|
||||||
ServerCert []byte `json:"server_cert"`
|
ServerCert []byte `json:"server_cert"`
|
||||||
ServerKey []byte `json:"server_key"`
|
ServerKey []byte `json:"server_key"`
|
||||||
CACert []byte `json:"ca_cert"`
|
CACert []byte `json:"ca_cert"`
|
||||||
Cert []byte `json:"cert"`
|
Cert []byte `json:"cert"`
|
||||||
Key []byte `json:"key"`
|
Key []byte `json:"key"`
|
||||||
session *Session `json:"-"`
|
IsDockerHost bool `json:"is_docker_host"`
|
||||||
conn net.Conn `json:"-"`
|
session *Session `json:"-"`
|
||||||
ctx context.Context `json:"-"`
|
conn net.Conn `json:"-"`
|
||||||
docker docker.DockerApi `json:"-"`
|
ctx context.Context `json:"-"`
|
||||||
tempPorts []uint16 `json:"-"`
|
docker docker.DockerApi `json:"-"`
|
||||||
Ports UInt16Slice
|
tempPorts []uint16 `json:"-"`
|
||||||
rw sync.Mutex
|
Ports UInt16Slice
|
||||||
|
rw sync.Mutex
|
||||||
}
|
}
|
||||||
type InstanceConfig struct {
|
type InstanceConfig struct {
|
||||||
ImageName string
|
ImageName string
|
||||||
@@ -236,6 +237,8 @@ func (p *pwd) InstanceNew(session *Session, conf InstanceConfig) (*Instance, err
|
|||||||
instance.ServerKey = conf.ServerKey
|
instance.ServerKey = conf.ServerKey
|
||||||
instance.CACert = conf.CACert
|
instance.CACert = conf.CACert
|
||||||
instance.session = session
|
instance.session = session
|
||||||
|
// For now this condition holds through. In the future we might need a more complex logic.
|
||||||
|
instance.IsDockerHost = opts.Privileged
|
||||||
|
|
||||||
if session.Instances == nil {
|
if session.Instances == nil {
|
||||||
session.Instances = make(map[string]*Instance)
|
session.Instances = make(map[string]*Instance)
|
||||||
|
|||||||
@@ -61,12 +61,13 @@ func TestInstanceNew(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
expectedInstance := Instance{
|
expectedInstance := Instance{
|
||||||
Name: fmt.Sprintf("%s_node1", session.Id[:8]),
|
Name: fmt.Sprintf("%s_node1", session.Id[:8]),
|
||||||
Hostname: "node1",
|
Hostname: "node1",
|
||||||
IP: "10.0.0.1",
|
IP: "10.0.0.1",
|
||||||
Alias: "",
|
Alias: "",
|
||||||
Image: config.GetDindImageName(),
|
Image: config.GetDindImageName(),
|
||||||
session: session,
|
IsDockerHost: true,
|
||||||
|
session: session,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, expectedInstance, *instance)
|
assert.Equal(t, expectedInstance, *instance)
|
||||||
@@ -108,12 +109,13 @@ func TestInstanceNew_WithNotAllowedImage(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
expectedInstance := Instance{
|
expectedInstance := Instance{
|
||||||
Name: fmt.Sprintf("%s_node1", session.Id[:8]),
|
Name: fmt.Sprintf("%s_node1", session.Id[:8]),
|
||||||
Hostname: "node1",
|
Hostname: "node1",
|
||||||
IP: "10.0.0.1",
|
IP: "10.0.0.1",
|
||||||
Alias: "",
|
Alias: "",
|
||||||
Image: "redis",
|
Image: "redis",
|
||||||
session: session,
|
IsDockerHost: false,
|
||||||
|
session: session,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, expectedInstance, *instance)
|
assert.Equal(t, expectedInstance, *instance)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func (sch *scheduler) Schedule(s *Session) {
|
|||||||
wg.Add(len(s.Instances))
|
wg.Add(len(s.Instances))
|
||||||
for _, ins := range s.Instances {
|
for _, ins := range s.Instances {
|
||||||
var i *Instance = ins
|
var i *Instance = ins
|
||||||
if i.docker == nil {
|
if i.docker == nil && i.IsDockerHost {
|
||||||
// Need to create client to the DinD docker daemon
|
// Need to create client to the DinD docker daemon
|
||||||
|
|
||||||
// We check if the client needs to use TLS
|
// We check if the client needs to use TLS
|
||||||
|
|||||||
Reference in New Issue
Block a user