Fix environment recovery
As the environment is no longer stored in the meta information, Poseidon wasn't able to recover environments. It expected the environment id to be found in the meta data. We now recover the environment id from the job id.
This commit is contained in:
@ -100,11 +100,15 @@ func (m *NomadEnvironmentManager) Load() error {
|
||||
jobLogger.Infof("Couldn't convert pool size to int: %v, skipping ...", err)
|
||||
continue
|
||||
}
|
||||
environmentID, err := runner.NewEnvironmentID(configTaskGroup.Meta[nomad.ConfigMetaEnvironmentKey])
|
||||
environmentIDString, err := runner.EnvironmentIDFromTemplateJobID(*job.ID)
|
||||
if err != nil {
|
||||
jobLogger.WithField("environmentID", configTaskGroup.Meta[nomad.ConfigMetaEnvironmentKey]).
|
||||
jobLogger.WithError(err).Error("Couldn't retrieve environment id from template job")
|
||||
}
|
||||
environmentID, err := runner.NewEnvironmentID(environmentIDString)
|
||||
if err != nil {
|
||||
jobLogger.WithField("environmentID", environmentIDString).
|
||||
WithError(err).
|
||||
Error("Couldn't convert environment id of template job to int")
|
||||
Error("Couldn't retrieve environmentID from string")
|
||||
continue
|
||||
}
|
||||
_, err = m.runnerManager.CreateOrUpdateEnvironment(environmentID, uint(desiredIdleRunnersCount), job, false)
|
||||
@ -112,6 +116,7 @@ func (m *NomadEnvironmentManager) Load() error {
|
||||
jobLogger.WithError(err).Info("Could not recover job.")
|
||||
continue
|
||||
}
|
||||
jobLogger.Info("Successfully recovered environment")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -355,3 +355,11 @@ func IsEnvironmentTemplateID(jobID string) bool {
|
||||
parts := strings.Split(jobID, "-")
|
||||
return len(parts) == 2 && parts[0] == nomad.TemplateJobPrefix
|
||||
}
|
||||
|
||||
func EnvironmentIDFromTemplateJobID(id string) (string, error) {
|
||||
parts := strings.Split(id, "-")
|
||||
if len(parts) < 2 {
|
||||
return "", fmt.Errorf("invalid template job id: %w", ErrorInvalidJobID)
|
||||
}
|
||||
return parts[1], nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user