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

feat(snapshots): separate snapshots from endpoint DB struct EE-4099 (#7614)

This commit is contained in:
matias-portainer 2022-09-22 17:05:10 -03:00 committed by GitHub
parent 4fe2a7c750
commit 6e0f83b99e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 393 additions and 136 deletions

View file

@ -119,27 +119,59 @@ func (service *Service) SnapshotEndpoint(endpoint *portainer.Endpoint) error {
return service.snapshotDockerEndpoint(endpoint)
}
func (service *Service) snapshotKubernetesEndpoint(endpoint *portainer.Endpoint) error {
snapshot, err := service.kubernetesSnapshotter.CreateSnapshot(endpoint)
func (service *Service) Create(snapshot portainer.Snapshot) error {
return service.dataStore.Snapshot().Create(&snapshot)
}
func (service *Service) FillSnapshotData(endpoint *portainer.Endpoint) error {
snapshot, err := service.dataStore.Snapshot().Snapshot(endpoint.ID)
if service.dataStore.IsErrObjectNotFound(err) {
endpoint.Snapshots = []portainer.DockerSnapshot{}
endpoint.Kubernetes.Snapshots = []portainer.KubernetesSnapshot{}
return nil
}
if err != nil {
return err
}
if snapshot != nil {
endpoint.Kubernetes.Snapshots = []portainer.KubernetesSnapshot{*snapshot}
if snapshot.Docker != nil {
endpoint.Snapshots = []portainer.DockerSnapshot{*snapshot.Docker}
}
if snapshot.Kubernetes != nil {
endpoint.Kubernetes.Snapshots = []portainer.KubernetesSnapshot{*snapshot.Kubernetes}
}
return nil
}
func (service *Service) snapshotKubernetesEndpoint(endpoint *portainer.Endpoint) error {
kubernetesSnapshot, err := service.kubernetesSnapshotter.CreateSnapshot(endpoint)
if err != nil {
return err
}
if kubernetesSnapshot != nil {
snapshot := &portainer.Snapshot{EndpointID: endpoint.ID, Kubernetes: kubernetesSnapshot}
return service.dataStore.Snapshot().Create(snapshot)
}
return nil
}
func (service *Service) snapshotDockerEndpoint(endpoint *portainer.Endpoint) error {
snapshot, err := service.dockerSnapshotter.CreateSnapshot(endpoint)
dockerSnapshot, err := service.dockerSnapshotter.CreateSnapshot(endpoint)
if err != nil {
return err
}
if snapshot != nil {
endpoint.Snapshots = []portainer.DockerSnapshot{*snapshot}
if dockerSnapshot != nil {
snapshot := &portainer.Snapshot{EndpointID: endpoint.ID, Docker: dockerSnapshot}
return service.dataStore.Snapshot().Create(snapshot)
}
return nil
@ -203,8 +235,6 @@ func (service *Service) snapshotEndpoints() error {
latestEndpointReference.Status = portainer.EndpointStatusDown
}
latestEndpointReference.Snapshots = endpoint.Snapshots
latestEndpointReference.Kubernetes.Snapshots = endpoint.Kubernetes.Snapshots
latestEndpointReference.Agent.Version = endpoint.Agent.Version
err = service.dataStore.Endpoint().UpdateEndpoint(latestEndpointReference.ID, latestEndpointReference)

View file

@ -25,6 +25,7 @@ type testDatastore struct {
role dataservices.RoleService
sslSettings dataservices.SSLSettingsService
settings dataservices.SettingsService
snapshot dataservices.SnapshotService
stack dataservices.StackService
tag dataservices.TagService
teamMembership dataservices.TeamMembershipService
@ -69,6 +70,7 @@ func (d *testDatastore) APIKeyRepository() dataservices.APIKeyRepository {
return d.apiKeyRepositoryService
}
func (d *testDatastore) Settings() dataservices.SettingsService { return d.settings }
func (d *testDatastore) Snapshot() dataservices.SnapshotService { return d.snapshot }
func (d *testDatastore) SSLSettings() dataservices.SSLSettingsService { return d.sslSettings }
func (d *testDatastore) Stack() dataservices.StackService { return d.stack }
func (d *testDatastore) Tag() dataservices.TagService { return d.tag }