1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-25 08:19:40 +02:00

fix(kubernetes): kube env permissions when down [EE-5427] (#10327)

This commit is contained in:
Prabhat Khera 2023-09-19 08:57:27 +12:00 committed by GitHub
parent cc37ccfe4d
commit 14853f6da0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 282 additions and 103 deletions

View file

@ -10,9 +10,8 @@ import (
"github.com/portainer/portainer/api/agent"
"github.com/portainer/portainer/api/crypto"
"github.com/portainer/portainer/api/dataservices"
"github.com/portainer/portainer/api/http/utils"
"github.com/portainer/portainer/api/internal/authorization"
"github.com/portainer/portainer/api/internal/endpointutils"
"github.com/portainer/portainer/api/pendingactions"
"github.com/rs/zerolog/log"
)
@ -27,10 +26,18 @@ type Service struct {
dockerSnapshotter portainer.DockerSnapshotter
kubernetesSnapshotter portainer.KubernetesSnapshotter
shutdownCtx context.Context
pendingActionsService *pendingactions.PendingActionsService
}
// NewService creates a new instance of a service
func NewService(snapshotIntervalFromFlag string, dataStore dataservices.DataStore, dockerSnapshotter portainer.DockerSnapshotter, kubernetesSnapshotter portainer.KubernetesSnapshotter, shutdownCtx context.Context) (*Service, error) {
func NewService(
snapshotIntervalFromFlag string,
dataStore dataservices.DataStore,
dockerSnapshotter portainer.DockerSnapshotter,
kubernetesSnapshotter portainer.KubernetesSnapshotter,
shutdownCtx context.Context,
pendingActionsService *pendingactions.PendingActionsService,
) (*Service, error) {
interval, err := parseSnapshotFrequency(snapshotIntervalFromFlag, dataStore)
if err != nil {
return nil, err
@ -43,6 +50,7 @@ func NewService(snapshotIntervalFromFlag string, dataStore dataservices.DataStor
dockerSnapshotter: dockerSnapshotter,
kubernetesSnapshotter: kubernetesSnapshotter,
shutdownCtx: shutdownCtx,
pendingActionsService: pendingActionsService,
}, nil
}
@ -263,7 +271,7 @@ func (service *Service) snapshotEndpoints() error {
snapshotError := service.SnapshotEndpoint(&endpoint)
service.dataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
updateEndpointStatus(tx, &endpoint, snapshotError)
updateEndpointStatus(tx, &endpoint, snapshotError, service.pendingActionsService)
return nil
})
}
@ -271,7 +279,7 @@ func (service *Service) snapshotEndpoints() error {
return nil
}
func updateEndpointStatus(tx dataservices.DataStoreTx, endpoint *portainer.Endpoint, snapshotError error) {
func updateEndpointStatus(tx dataservices.DataStoreTx, endpoint *portainer.Endpoint, snapshotError error, pendingActionsService *pendingactions.PendingActionsService) {
latestEndpointReference, err := tx.Endpoint().Endpoint(endpoint.ID)
if latestEndpointReference == nil {
log.Debug().
@ -304,7 +312,7 @@ func updateEndpointStatus(tx dataservices.DataStoreTx, endpoint *portainer.Endpo
// Run the pending actions
if latestEndpointReference.Status == portainer.EndpointStatusUp {
utils.RunPendingActions(latestEndpointReference, tx, authorization.NewService(tx))
pendingActionsService.Execute(endpoint.ID)
}
}