Skip to content

Commit

Permalink
fix(hatchery): check hostname prerequisiste
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
  • Loading branch information
yesnault committed Jan 17, 2020
1 parent bf49500 commit 5e4b94d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
10 changes: 10 additions & 0 deletions engine/hatchery/kubernetes/kubernetes.go
Expand Up @@ -228,6 +228,16 @@ func (h *HatcheryKubernetes) WorkerModelsEnabled() ([]sdk.Model, error) {
// CanSpawn return wether or not hatchery can spawn model.
// requirements are not supported
func (h *HatcheryKubernetes) CanSpawn(ctx context.Context, model *sdk.Model, jobID int64, requirements []sdk.Requirement) bool {
// Service and Hostname requirement are not supported
for _, r := range requirements {
if r.Type == sdk.ServiceRequirement {
log.Debug("CanSpawn> Job %d has a service requirement. Kubernetes can't spawn a worker for this job", jobID)
return false
} else if r.Type == sdk.HostnameRequirement {
log.Debug("CanSpawn> Job %d has a hostname requirement. Kubernetes can't spawn a worker for this job", jobID)
return false
}
}
return true
}

Expand Down
6 changes: 6 additions & 0 deletions engine/hatchery/local/local.go
Expand Up @@ -369,6 +369,12 @@ func (h *HatcheryLocal) checkRequirement(r sdk.Requirement) (bool, error) {
}
conn.Close()
return true, nil
case sdk.HostnameRequirement:
h, err := os.Hostname()
if err != nil {
return false, err
}
return h == r.Value, nil
default:
log.Debug("checkRequirement> %v don't work on this hatchery", r.Type)
return false, nil
Expand Down
5 changes: 4 additions & 1 deletion engine/hatchery/marathon/marathon.go
Expand Up @@ -166,11 +166,14 @@ func (h *HatcheryMarathon) WorkerModelsEnabled() ([]sdk.Model, error) {
// CanSpawn return wether or not hatchery can spawn model
// requirements services are not supported
func (h *HatcheryMarathon) CanSpawn(ctx context.Context, model *sdk.Model, jobID int64, requirements []sdk.Requirement) bool {
//Service requirement are not supported
// Service and Hostname requirement are not supported
for _, r := range requirements {
if r.Type == sdk.ServiceRequirement {
log.Debug("CanSpawn> Job %d has a service requirement. Marathon can't spawn a worker for this job", jobID)
return false
} else if r.Type == sdk.HostnameRequirement {
log.Debug("CanSpawn> Job %d has a hostname requirement. Marathon can't spawn a worker for this job", jobID)
return false
}
}

Expand Down
2 changes: 1 addition & 1 deletion engine/hatchery/openstack/openstack.go
Expand Up @@ -166,7 +166,7 @@ func (h *HatcheryOpenstack) WorkerModelsEnabled() ([]sdk.Model, error) {
// requirements are not supported
func (h *HatcheryOpenstack) CanSpawn(ctx context.Context, model *sdk.Model, jobID int64, requirements []sdk.Requirement) bool {
for _, r := range requirements {
if r.Type == sdk.ServiceRequirement || r.Type == sdk.MemoryRequirement {
if r.Type == sdk.ServiceRequirement || r.Type == sdk.MemoryRequirement || r.Type == sdk.HostnameRequirement {
return false
}
}
Expand Down
9 changes: 9 additions & 0 deletions engine/hatchery/swarm/swarm.go
Expand Up @@ -454,6 +454,13 @@ const (
// CanSpawn checks if the model can be spawned by this hatchery
// it checks on every docker engine is one of the docker has availability
func (h *HatcherySwarm) CanSpawn(ctx context.Context, model *sdk.Model, jobID int64, requirements []sdk.Requirement) bool {
// Hostname requirement are not supported
for _, r := range requirements {
if r.Type == sdk.HostnameRequirement {
log.Debug("CanSpawn> Job %d has a hostname requirement. Swarm can't spawn a worker for this job", jobID)
return false
}
}
for dockerName, dockerClient := range h.dockerClients {
//List all containers to check if we can spawn a new one
cs, errList := h.getContainers(dockerClient, types.ContainerListOptions{All: true})
Expand Down Expand Up @@ -633,6 +640,7 @@ func (h *HatcherySwarm) listAwolWorkers(dockerClientName string, containers []ty

//If there isn't any worker registered on the API. Kill the container
if len(apiworkers) == 0 {
log.Debug("hatchery> swarm> listAwolWorkers> no apiworkers returned by api container %s will be deleted", c.Names[0])
oldContainers = append(oldContainers, c)
continue
}
Expand All @@ -652,6 +660,7 @@ func (h *HatcherySwarm) listAwolWorkers(dockerClientName string, containers []ty
}
//If the container doesn't match any worker : Kill it.
if !found {
log.Debug("hatchery> swarm> listAwolWorkers> container %s not found on apiworkers", c.Names[0])
oldContainers = append(oldContainers, c)
}
}
Expand Down
2 changes: 1 addition & 1 deletion engine/hatchery/vsphere/vsphere.go
Expand Up @@ -118,7 +118,7 @@ func (h *HatcheryVSphere) CheckConfiguration(cfg interface{}) error {
// requirements are not supported
func (h *HatcheryVSphere) CanSpawn(ctx context.Context, model *sdk.Model, jobID int64, requirements []sdk.Requirement) bool {
for _, r := range requirements {
if r.Type == sdk.ServiceRequirement || r.Type == sdk.MemoryRequirement {
if r.Type == sdk.ServiceRequirement || r.Type == sdk.MemoryRequirement || r.Type == sdk.HostnameRequirement {
return false
}
}
Expand Down

0 comments on commit 5e4b94d

Please sign in to comment.