mirror of https://github.com/portainer/portainer
remove *Endpoint in execute to allow it to be imported into EE
parent
6a51b6b41e
commit
2b31f0ea42
|
@ -13,7 +13,7 @@ type (
|
|||
}
|
||||
|
||||
PendingActionHandler interface {
|
||||
Execute(PendingAction, *Endpoint) error
|
||||
Execute(PendingAction) error
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -48,14 +48,20 @@ func NewHandlerCleanNAPWithOverridePolicies(
|
|||
}
|
||||
}
|
||||
|
||||
func (h *HandlerCleanNAPWithOverridePolicies) Execute(pendingAction portainer.PendingAction, endpoint *portainer.Endpoint) error {
|
||||
if pendingAction.ActionData == nil {
|
||||
func (h *HandlerCleanNAPWithOverridePolicies) Execute(pa portainer.PendingAction) error {
|
||||
endpoint, err := h.dataStore.Endpoint().Endpoint(pa.EndpointID)
|
||||
if err != nil {
|
||||
log.Debug().Msgf("failed to retrieve environment %d: %v", pa.EndpointID, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
if pa.ActionData == nil {
|
||||
h.authorizationService.CleanNAPWithOverridePolicies(h.dataStore, endpoint, nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
var payload cleanNAPWithOverridePolicies
|
||||
err := pendingAction.UnmarshallActionData(&payload)
|
||||
err = pa.UnmarshallActionData(&payload)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("Error unmarshalling endpoint group ID for cleaning NAP with override policies for environment %d", endpoint.ID)
|
||||
return fmt.Errorf("failed to unmarshal endpoint group ID for cleaning NAP with override policies for environment %d: %w", endpoint.ID, err)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/portainer/portainer/api/internal/authorization"
|
||||
kubecli "github.com/portainer/portainer/api/kubernetes/cli"
|
||||
"github.com/portainer/portainer/api/pendingactions/actions"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type (
|
||||
|
@ -46,13 +47,19 @@ func NewHandlerDeleteRegistrySecrets(
|
|||
}
|
||||
}
|
||||
|
||||
func (h *HandlerDeleteK8sRegistrySecrets) Execute(pa portainer.PendingAction, endpoint *portainer.Endpoint) error {
|
||||
if endpoint == nil || pa.ActionData == nil {
|
||||
func (h *HandlerDeleteK8sRegistrySecrets) Execute(pa portainer.PendingAction) error {
|
||||
if pa.ActionData == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
endpoint, err := h.dataStore.Endpoint().Endpoint(pa.EndpointID)
|
||||
if err != nil {
|
||||
log.Debug().Msgf("failed to retrieve environment %d: %v", pa.EndpointID, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
var registryData deleteK8sRegistrySecretsData
|
||||
err := pa.UnmarshallActionData(®istryData)
|
||||
err = pa.UnmarshallActionData(®istryData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -40,7 +40,13 @@ func NewHandlerPostInitMigrateEnvironment(
|
|||
}
|
||||
}
|
||||
|
||||
func (h *HandlerPostInitMigrateEnvironment) Execute(_ portainer.PendingAction, endpoint *portainer.Endpoint) error {
|
||||
func (h *HandlerPostInitMigrateEnvironment) Execute(pa portainer.PendingAction) error {
|
||||
endpoint, err := h.dataStore.Endpoint().Endpoint(pa.EndpointID)
|
||||
if err != nil {
|
||||
log.Debug().Msgf("failed to retrieve environment %d: %v", pa.EndpointID, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
postInitMigrator := postinit.NewPostInitMigrator(
|
||||
h.kubeFactory,
|
||||
h.dockerFactory,
|
||||
|
@ -48,7 +54,7 @@ func (h *HandlerPostInitMigrateEnvironment) Execute(_ portainer.PendingAction, e
|
|||
h.assetsPath,
|
||||
h.kubernetesDeployer,
|
||||
)
|
||||
err := postInitMigrator.MigrateEnvironment(endpoint)
|
||||
err = postInitMigrator.MigrateEnvironment(endpoint)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("Error running post-init migrations for edge environment %d", endpoint.ID)
|
||||
return fmt.Errorf("failed running post-init migrations for edge environment %d: %w", endpoint.ID, err)
|
||||
|
|
|
@ -89,7 +89,7 @@ func (service *PendingActionsService) Execute(id portainer.EndpointID) {
|
|||
for _, pendingAction := range pendingActions {
|
||||
if pendingAction.EndpointID == id {
|
||||
log.Debug().Msgf("executing pending action id=%d, action=%s", pendingAction.ID, pendingAction.Action)
|
||||
err := service.executePendingAction(pendingAction, endpoint)
|
||||
err := service.executePendingAction(pendingAction)
|
||||
if err != nil {
|
||||
log.Warn().Msgf("failed to execute pending action: %v", err)
|
||||
return
|
||||
|
@ -106,7 +106,7 @@ func (service *PendingActionsService) Execute(id portainer.EndpointID) {
|
|||
}
|
||||
}
|
||||
|
||||
func (service *PendingActionsService) executePendingAction(pendingAction portainer.PendingAction, endpoint *portainer.Endpoint) error {
|
||||
func (service *PendingActionsService) executePendingAction(pendingAction portainer.PendingAction) error {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Error().Msgf("recovered from panic while executing pending action %s for environment %d: %v", pendingAction.Action, pendingAction.EndpointID, r)
|
||||
|
@ -119,5 +119,5 @@ func (service *PendingActionsService) executePendingAction(pendingAction portain
|
|||
return nil
|
||||
}
|
||||
|
||||
return handler.Execute(pendingAction, endpoint)
|
||||
return handler.Execute(pendingAction)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue