Commit f9046e0b authored by lukasburgey's avatar lukasburgey
Browse files

Report when we were unable to schedule a deployment

parent bae91cf9
Pipeline #110364 passed with stages
in 41 seconds
......@@ -38,6 +38,26 @@ var (
httpClient = &http.Client{}
)
// completeReply fills in the UserCredentialStates if they are not provided in the script output
func completeReply(dep deps.Dep, reply deps.Reply) deps.Reply {
if reply.UserCredentialStates == nil {
var userCredentialStates = make(scripts.UserCredentialStates)
for credType, credList := range dep.User.Credentials {
for _, credential := range credList {
if stateMap, ok := userCredentialStates[credType]; !ok {
userCredentialStates[credType] = map[string]scripts.State{
credential.Name: reply.State,
}
} else {
stateMap[credential.Name] = reply.State
}
}
}
reply.UserCredentialStates = userCredentialStates
}
return reply
}
func (sink *Sink) depServices(dep deps.Dep) (services []config.Service, err error) {
// find the matching service
if dep.Service != (config.Service{}) {
......@@ -49,7 +69,7 @@ func (sink *Sink) depServices(dep deps.Dep) (services []config.Service, err erro
}
}
err = fmt.Errorf("Dep has no service")
err = fmt.Errorf("Service for Dep does not exist: '%s'", dep.Service.Name)
return
}
......@@ -168,23 +188,6 @@ func (sink *Sink) handleDep(dep deps.Dep) (output scripts.Output, err error) {
return
}
// if the script does not provide any credential specific states we expect all
// credentials to have the same state as the whole execution (output.State)
if output.UserCredentialStates == nil {
var userCredentialStates = make(scripts.UserCredentialStates)
for credType, credList := range dep.User.Credentials {
for _, credential := range credList {
if stateMap, ok := userCredentialStates[credType]; !ok {
userCredentialStates[credType] = map[string]scripts.State{
credential.Name: output.State,
}
} else {
stateMap[credential.Name] = output.State
}
}
}
output.UserCredentialStates = userCredentialStates
}
return
}
......@@ -218,6 +221,7 @@ func (sink *Sink) depHandler() {
if output.Credentials != nil && output.State == scripts.Deployed {
reply.Credentials = output.Credentials
}
reply = completeReply(dep, reply)
sink.Replies <- reply
}()
......@@ -316,15 +320,25 @@ func (sink *Sink) Connect(src <-chan deps.Dep) (err error) {
// the responder finishes when sink.Replies closes
go sink.depResponder()
// the handler finishes when sink.Schedule closes
// the handler finishes when sink.Scheduled closes
go sink.depHandler()
go func() {
// schedule until the src runs out
var err error
for deps := range src {
err = sink.scheduleDep(deps)
for dep := range src {
err = sink.scheduleDep(dep)
if err != nil {
// we reply to the portal that we couldn't schedule this deployment
go func() {
reply := deps.Reply{
ID: dep.ID,
State: scripts.Rejected,
Msg: fmt.Sprintf("Error scheduling execution of this deployment: %s", err),
}
reply = completeReply(dep, reply) // fill in UserCredentialStates
sink.Replies <- reply
}()
log.Printf("[Sink] Error scheduling: %v", err)
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment