mirror of
https://github.com/portainer/portainer.git
synced 2025-08-04 21:35:23 +02:00
fix(pendingactions): refactor pending actions [EE-7011] (#11780)
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
This commit is contained in:
parent
9685e260ea
commit
5a5a10821d
20 changed files with 380 additions and 293 deletions
73
api/pendingactions/handlers/delete_k8s_registry_secrets.go
Normal file
73
api/pendingactions/handlers/delete_k8s_registry_secrets.go
Normal file
|
@ -0,0 +1,73 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/dataservices"
|
||||
"github.com/portainer/portainer/api/internal/authorization"
|
||||
kubecli "github.com/portainer/portainer/api/kubernetes/cli"
|
||||
"github.com/portainer/portainer/api/pendingactions/actions"
|
||||
)
|
||||
|
||||
type (
|
||||
HandlerDeleteK8sRegistrySecrets struct {
|
||||
authorizationService *authorization.Service
|
||||
dataStore dataservices.DataStore
|
||||
kubeFactory *kubecli.ClientFactory
|
||||
}
|
||||
|
||||
deleteK8sRegistrySecretsData struct {
|
||||
RegistryID portainer.RegistryID `json:"RegistryID"`
|
||||
Namespaces []string `json:"Namespaces"`
|
||||
}
|
||||
)
|
||||
|
||||
// NewDeleteK8sRegistrySecrets creates a new DeleteK8sRegistrySecrets pending action
|
||||
func NewDeleteK8sRegistrySecrets(endpointID portainer.EndpointID, registryID portainer.RegistryID, namespaces []string) portainer.PendingAction {
|
||||
return portainer.PendingAction{
|
||||
EndpointID: endpointID,
|
||||
Action: actions.DeleteK8sRegistrySecrets,
|
||||
ActionData: &deleteK8sRegistrySecretsData{
|
||||
RegistryID: registryID,
|
||||
Namespaces: namespaces,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// NewHandlerDeleteRegistrySecrets creates a new handler to execute DeleteK8sRegistrySecrets pending action
|
||||
func NewHandlerDeleteRegistrySecrets(
|
||||
authorizationService *authorization.Service,
|
||||
dataStore dataservices.DataStore,
|
||||
kubeFactory *kubecli.ClientFactory,
|
||||
) *HandlerDeleteK8sRegistrySecrets {
|
||||
return &HandlerDeleteK8sRegistrySecrets{
|
||||
authorizationService: authorizationService,
|
||||
dataStore: dataStore,
|
||||
kubeFactory: kubeFactory,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *HandlerDeleteK8sRegistrySecrets) Execute(pa portainer.PendingAction, endpoint *portainer.Endpoint) error {
|
||||
if endpoint == nil || pa.ActionData == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var registryData deleteK8sRegistrySecretsData
|
||||
err := pa.UnmarshallActionData(®istryData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
kubeClient, err := h.kubeFactory.GetKubeClient(endpoint)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, namespace := range registryData.Namespaces {
|
||||
err = kubeClient.DeleteRegistrySecret(registryData.RegistryID, namespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue