2022-09-22 20:05:10 +00:00
|
|
|
package migrator
|
|
|
|
|
|
|
|
import (
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
2022-09-28 17:56:32 +00:00
|
|
|
|
2022-09-23 01:15:26 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2022-09-22 20:05:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (m *Migrator) migrateDBVersionToDB70() error {
|
2022-11-18 00:18:09 +00:00
|
|
|
log.Info().Msg("add IngressAvailabilityPerNamespace field")
|
2022-10-24 20:41:30 +00:00
|
|
|
if err := m.updateIngressFieldsForEnvDB70(); err != nil {
|
2022-09-26 19:43:24 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-09-22 20:05:10 +00:00
|
|
|
endpoints, err := m.endpointService.Endpoints()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, endpoint := range endpoints {
|
|
|
|
// copy snapshots to new object
|
2022-09-23 01:15:26 +00:00
|
|
|
log.Info().Msg("moving snapshots from endpoint to new object")
|
2022-09-22 20:05:10 +00:00
|
|
|
snapshot := portainer.Snapshot{EndpointID: endpoint.ID}
|
|
|
|
|
|
|
|
if len(endpoint.Snapshots) > 0 {
|
|
|
|
snapshot.Docker = &endpoint.Snapshots[len(endpoint.Snapshots)-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(endpoint.Kubernetes.Snapshots) > 0 {
|
|
|
|
snapshot.Kubernetes = &endpoint.Kubernetes.Snapshots[len(endpoint.Kubernetes.Snapshots)-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
// save new object
|
|
|
|
err = m.snapshotService.Create(&snapshot)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// set to nil old fields
|
2022-09-23 01:15:26 +00:00
|
|
|
log.Info().Msg("deleting snapshot from endpoint")
|
2022-09-22 20:05:10 +00:00
|
|
|
endpoint.Snapshots = []portainer.DockerSnapshot{}
|
|
|
|
endpoint.Kubernetes.Snapshots = []portainer.KubernetesSnapshot{}
|
|
|
|
|
|
|
|
// update endpoint
|
|
|
|
err = m.endpointService.UpdateEndpoint(endpoint.ID, &endpoint)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2022-09-26 19:43:24 +00:00
|
|
|
|
2022-10-24 20:41:30 +00:00
|
|
|
func (m *Migrator) updateIngressFieldsForEnvDB70() error {
|
2022-09-26 19:43:24 +00:00
|
|
|
endpoints, err := m.endpointService.Endpoints()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, endpoint := range endpoints {
|
|
|
|
endpoint.Kubernetes.Configuration.IngressAvailabilityPerNamespace = true
|
2022-10-24 20:41:30 +00:00
|
|
|
endpoint.Kubernetes.Configuration.AllowNoneIngressClass = false
|
2022-11-01 22:17:32 +00:00
|
|
|
endpoint.PostInitMigrations.MigrateIngresses = true
|
2022-09-26 19:43:24 +00:00
|
|
|
|
|
|
|
err = m.endpointService.UpdateEndpoint(endpoint.ID, &endpoint)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|