1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-23 15:29:42 +02:00

feat(edge): EE-4570 allow pre-pull images with edge stack deployment (#8210)

Co-authored-by: Matt Hook <hookenz@gmail.com>
This commit is contained in:
cmeng 2022-12-21 13:18:51 +13:00 committed by GitHub
parent 7fe0712b61
commit 919a854d93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 234 additions and 53 deletions

View file

@ -36,29 +36,29 @@ func (m *Migrator) Migrate() error {
if schemaVersion.Equal(apiVersion) {
// detect and run migrations when the versions are the same.
// e.g. development builds
latestMigrations := m.latestMigrations()
if latestMigrations.version.Equal(schemaVersion) &&
version.MigratorCount != len(latestMigrations.migrationFuncs) {
err := runMigrations(latestMigrations.migrationFuncs)
latestMigrations := m.LatestMigrations()
if latestMigrations.Version.Equal(schemaVersion) &&
version.MigratorCount != len(latestMigrations.MigrationFuncs) {
err := runMigrations(latestMigrations.MigrationFuncs)
if err != nil {
return err
}
newMigratorCount = len(latestMigrations.migrationFuncs)
newMigratorCount = len(latestMigrations.MigrationFuncs)
}
} else {
// regular path when major/minor/patch versions differ
for _, migration := range m.migrations {
if schemaVersion.LessThan(migration.version) {
if schemaVersion.LessThan(migration.Version) {
log.Info().Msgf("migrating data to %s", migration.version.String())
err := runMigrations(migration.migrationFuncs)
log.Info().Msgf("migrating data to %s", migration.Version.String())
err := runMigrations(migration.MigrationFuncs)
if err != nil {
return err
}
}
if apiVersion.Equal(migration.version) {
newMigratorCount = len(migration.migrationFuncs)
if apiVersion.Equal(migration.Version) {
newMigratorCount = len(migration.MigrationFuncs)
}
}
}
@ -107,9 +107,9 @@ func (m *Migrator) NeedsMigration() bool {
}
// Check if we have any migrations for the current version
latestMigrations := m.latestMigrations()
if latestMigrations.version.Equal(semver.MustParse(portainer.APIVersion)) {
if m.currentDBVersion.MigratorCount != len(latestMigrations.migrationFuncs) {
latestMigrations := m.LatestMigrations()
if latestMigrations.Version.Equal(semver.MustParse(portainer.APIVersion)) {
if m.currentDBVersion.MigratorCount != len(latestMigrations.MigrationFuncs) {
return true
}
} else {

View file

@ -0,0 +1,47 @@
package migrator
import (
portainer "github.com/portainer/portainer/api"
"github.com/rs/zerolog/log"
)
func (m *Migrator) migrateDBVersionToDB80() error {
return m.updateEdgeStackStatusForDB80()
}
func (m *Migrator) updateEdgeStackStatusForDB80() error {
log.Info().Msg("transfer type field to details field for edge stack status")
edgeStacks, err := m.edgeStackService.EdgeStacks()
if err != nil {
return err
}
for _, edgeStack := range edgeStacks {
for endpointId, status := range edgeStack.Status {
switch status.Type {
case portainer.EdgeStackStatusPending:
status.Details.Pending = true
case portainer.EdgeStackStatusOk:
status.Details.Ok = true
case portainer.EdgeStackStatusError:
status.Details.Error = true
case portainer.EdgeStackStatusAcknowledged:
status.Details.Acknowledged = true
case portainer.EdgeStackStatusRemove:
status.Details.Remove = true
case portainer.EdgeStackStatusRemoteUpdateSuccess:
status.Details.RemoteUpdateSuccess = true
}
edgeStack.Status[endpointId] = status
}
err = m.edgeStackService.UpdateEdgeStack(edgeStack.ID, &edgeStack)
if err != nil {
return err
}
}
return nil
}

View file

@ -3,6 +3,8 @@ package migrator
import (
"errors"
"github.com/portainer/portainer/api/dataservices/edgestack"
"github.com/Masterminds/semver"
"github.com/rs/zerolog/log"
@ -53,6 +55,7 @@ type (
fileService portainer.FileService
authorizationService *authorization.Service
dockerhubService *dockerhub.Service
edgeStackService *edgestack.Service
}
// MigratorParameters represents the required parameters to create a new Migrator instance.
@ -77,6 +80,7 @@ type (
FileService portainer.FileService
AuthorizationService *authorization.Service
DockerhubService *dockerhub.Service
EdgeStackService *edgestack.Service
}
)
@ -103,6 +107,7 @@ func NewMigrator(parameters *MigratorParameters) *Migrator {
fileService: parameters.FileService,
authorizationService: parameters.AuthorizationService,
dockerhubService: parameters.DockerhubService,
edgeStackService: parameters.EdgeStackService,
}
migrator.initMigrations()
@ -128,12 +133,12 @@ func (m *Migrator) CurrentSemanticDBVersion() *semver.Version {
func (m *Migrator) addMigrations(v string, funcs ...func() error) {
m.migrations = append(m.migrations, Migrations{
version: semver.MustParse(v),
migrationFuncs: funcs,
Version: semver.MustParse(v),
MigrationFuncs: funcs,
})
}
func (m *Migrator) latestMigrations() Migrations {
func (m *Migrator) LatestMigrations() Migrations {
return m.migrations[len(m.migrations)-1]
}
@ -146,8 +151,8 @@ func (m *Migrator) latestMigrations() Migrations {
// ! This increases the migration funcs count and so they all run again.
type Migrations struct {
version *semver.Version
migrationFuncs MigrationFuncs
Version *semver.Version
MigrationFuncs MigrationFuncs
}
type MigrationFuncs []func() error
@ -199,6 +204,7 @@ func (m *Migrator) initMigrations() {
m.addMigrations("2.15", m.migrateDBVersionToDB60)
m.addMigrations("2.16", m.migrateDBVersionToDB70)
m.addMigrations("2.16.1", m.migrateDBVersionToDB71)
m.addMigrations("2.17", m.migrateDBVersionToDB80)
// Add new migrations below...
// One function per migration, each versions migration funcs in the same file.