Skip to content

Commit

Permalink
fix(hatchery): double check flag need registration (#5752)
Browse files Browse the repository at this point in the history
* fix(hatchery): double check flag need registration

close #5750

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Mar 8, 2021
1 parent c547ca2 commit 7adfafa
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion engine/hatchery/kubernetes/kill_workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (h *HatcheryKubernetes) killAwolWorkers(ctx context.Context) error {
}
}

if err := hatchery.CheckWorkerModelRegister(h, modelPath); err != nil {
if err := hatchery.CheckWorkerModelRegister(ctx, h, modelPath); err != nil {
var spawnErr = sdk.SpawnErrorForm{
Error: err.Error(),
}
Expand Down
2 changes: 1 addition & 1 deletion engine/hatchery/marathon/marathon.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ func (h *HatcheryMarathon) killAwolWorkers() error {
// If its a worker "register", check registration before deleting it
if strings.HasPrefix(app.ID, "register-") && app.Env != nil {
model := (*app.Env)["CDS_MODEL_PATH"]
if err := hatchery.CheckWorkerModelRegister(h, model); err != nil {
if err := hatchery.CheckWorkerModelRegister(ctx, h, model); err != nil {
var spawnErr = sdk.SpawnErrorForm{
Error: err.Error(),
}
Expand Down
2 changes: 1 addition & 1 deletion engine/hatchery/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func (h *HatcheryOpenstack) deleteServer(ctx context.Context, s servers.Server)
if err != nil {
log.Error(ctx, "killAndRemove> unable to get console log from registering server %s: %v", s.Name, err)
}
if err := hatchery.CheckWorkerModelRegister(h, modelPath); err != nil {
if err := hatchery.CheckWorkerModelRegister(ctx, h, modelPath); err != nil {
var spawnErr = sdk.SpawnErrorForm{
Error: err.Error(),
Logs: []byte(consoleLog),
Expand Down
2 changes: 1 addition & 1 deletion engine/hatchery/swarm/swarm_util_kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (h *HatcherySwarm) killAndRemove(ctx context.Context, dockerClient *dockerC
if strings.HasPrefix(container.Name, "/register-") {
modelPath := container.Config.Labels["worker_model_path"]

if err := hatchery.CheckWorkerModelRegister(h, modelPath); err != nil {
if err := hatchery.CheckWorkerModelRegister(ctx, h, modelPath); err != nil {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*2)
defer cancel()
logsOpts := types.ContainerLogsOptions{
Expand Down
2 changes: 1 addition & 1 deletion engine/hatchery/vsphere/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (h *HatcheryVSphere) deleteServer(ctx context.Context, s mo.VirtualMachine)
}

if strings.HasPrefix(s.Name, "register-") {
if err := hatchery.CheckWorkerModelRegister(h, annot.WorkerModelPath); err != nil {
if err := hatchery.CheckWorkerModelRegister(ctx, h, annot.WorkerModelPath); err != nil {
var spawnErr = sdk.SpawnErrorForm{
Error: err.Error(),
}
Expand Down
27 changes: 26 additions & 1 deletion sdk/hatchery/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,40 @@ loopModels:
}

// CheckWorkerModelRegister checks if a model has been registered, if not it raises an error on the API
func CheckWorkerModelRegister(h Interface, modelPath string) error {
func CheckWorkerModelRegister(ctx context.Context, h Interface, modelPath string) error {
var sendError bool
for i := range models {
if models[i].Group.Name+"/"+models[i].Name == modelPath {
sendError = models[i].NeedRegistration
break
}
}
if !sendError {
// need registration is false, no error to return
return nil
}

// it's need registration = true ->
// perhaps that the models list is not up to date
// so, we call a fresh model list to re-check the flag need registration known by the api
hWithModels, isWithModels := h.(InterfaceWithModels)
if isWithModels {
modelsFresh, errwm := hWithModels.WorkerModelsEnabled()
if errwm != nil {
log.Error(ctx, "error on h.CheckWorkerModelRegister(): %v", errwm)
return errwm
}

for i := range modelsFresh {
if modelsFresh[i].Group.Name+"/"+modelsFresh[i].Name == modelPath {
sendError = modelsFresh[i].NeedRegistration
break
}
}
}

if sendError {
// need registration stay to true, even after a fresh call to api -> error
return sdk.WithStack(sdk.ErrWorkerModelDeploymentFailed)
}
return nil
Expand Down

0 comments on commit 7adfafa

Please sign in to comment.