mirror of https://github.com/portainer/portainer
ix(pendingactions): fix deadlock and reduce needless debug logging [EE-7049] (#11869)
parent
0c870bf37b
commit
5c6c66f010
|
@ -55,12 +55,17 @@ func (service *PendingActionsService) Create(action portainer.PendingAction) err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (service *PendingActionsService) Execute(id portainer.EndpointID) {
|
func (service *PendingActionsService) Execute(id portainer.EndpointID) {
|
||||||
|
// Run in a goroutine to avoid blocking the main thread due to db tx =
|
||||||
|
go service.execute(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (service *PendingActionsService) execute(environmentID portainer.EndpointID) {
|
||||||
service.mu.Lock()
|
service.mu.Lock()
|
||||||
defer service.mu.Unlock()
|
defer service.mu.Unlock()
|
||||||
|
|
||||||
endpoint, err := service.dataStore.Endpoint().Endpoint(id)
|
endpoint, err := service.dataStore.Endpoint().Endpoint(environmentID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug().Msgf("failed to retrieve environment %d: %v", id, err)
|
log.Debug().Msgf("failed to retrieve environment %d: %v", environmentID, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,12 +82,12 @@ func (service *PendingActionsService) Execute(id portainer.EndpointID) {
|
||||||
// creating a kube client and performing a simple operation
|
// creating a kube client and performing a simple operation
|
||||||
client, err := service.kubeFactory.GetKubeClient(endpoint)
|
client, err := service.kubeFactory.GetKubeClient(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug().Msgf("failed to create Kubernetes client for environment %d: %v", id, err)
|
log.Debug().Msgf("failed to create Kubernetes client for environment %d: %v", environmentID, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = client.ServerVersion(); err != nil {
|
if _, err = client.ServerVersion(); err != nil {
|
||||||
log.Debug().Err(err).Msgf("Environment %q (id: %d) is not up", endpoint.Name, id)
|
log.Debug().Err(err).Msgf("Environment %q (id: %d) is not up", endpoint.Name, environmentID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,20 +98,29 @@ func (service *PendingActionsService) Execute(id portainer.EndpointID) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Msgf("Executing pending actions for environment %d", id)
|
if len(pendingActions) > 0 {
|
||||||
for _, pendingAction := range pendingActions {
|
log.Debug().Msgf("Found %d pending actions", len(pendingActions))
|
||||||
if pendingAction.EndpointID == id {
|
log.Debug().Msgf("PendingActions %+v", pendingActions)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, pendingAction := range pendingActions {
|
||||||
|
if pendingAction.EndpointID == environmentID {
|
||||||
|
if i == 0 {
|
||||||
|
// We have at least 1 pending action for this environment
|
||||||
|
log.Debug().Msgf("Executing pending actions for environment %d", environmentID)
|
||||||
|
}
|
||||||
|
|
||||||
log.Debug().Msgf("executing pending action id=%d, action=%s", pendingAction.ID, pendingAction.Action)
|
log.Debug().Msgf("executing pending action id=%d, action=%s", pendingAction.ID, pendingAction.Action)
|
||||||
err := service.executePendingAction(pendingAction, endpoint)
|
err := service.executePendingAction(pendingAction, endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Msgf("failed to execute pending action: %v", err)
|
log.Warn().Msgf("failed to execute pending action: %v", err)
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err = service.dataStore.PendingActions().Delete(pendingAction.ID)
|
err = service.dataStore.PendingActions().Delete(pendingAction.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Msgf("failed to delete pending action: %v", err)
|
log.Warn().Msgf("failed to delete pending action: %v", err)
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Msgf("pending action %d finished", pendingAction.ID)
|
log.Debug().Msgf("pending action %d finished", pendingAction.ID)
|
||||||
|
|
Loading…
Reference in New Issue