mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 05:19:39 +02:00
* use error check func, wrap db object not found * add errorlint and fix all the linting errors * add exportloopref linter and fix errors * fix incorrect error details returned on an api * fix new errors * increase linter timeout * increase timeout to 10minutes * increase timeout to 10minutes * rebase and fix new lint errors * make CE match EE * fix govet issue
44 lines
960 B
Go
44 lines
960 B
Go
package migrator
|
|
|
|
import (
|
|
portainer "github.com/portainer/portainer/api"
|
|
"github.com/portainer/portainer/api/dataservices"
|
|
"github.com/portainer/portainer/api/stacks/stackutils"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func (m *Migrator) updateStackResourceControlToDB27() error {
|
|
log.Info().Msg("updating stack resource controls")
|
|
|
|
resourceControls, err := m.resourceControlService.ResourceControls()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, resource := range resourceControls {
|
|
if resource.Type != portainer.StackResourceControl {
|
|
continue
|
|
}
|
|
|
|
stackName := resource.ResourceID
|
|
|
|
stack, err := m.stackService.StackByName(stackName)
|
|
if err != nil {
|
|
if dataservices.IsErrObjectNotFound(err) {
|
|
continue
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
resource.ResourceID = stackutils.ResourceControlID(stack.EndpointID, stack.Name)
|
|
|
|
err = m.resourceControlService.UpdateResourceControl(resource.ID, &resource)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|