2021-02-23 20:18:05 +00:00
|
|
|
package migrator
|
|
|
|
|
|
|
|
import (
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
2021-02-24 21:27:49 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/errors"
|
|
|
|
"github.com/portainer/portainer/api/internal/stackutils"
|
2021-02-23 20:18:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (m *Migrator) updateStackResourceControlToDB27() error {
|
2021-11-24 02:58:43 +00:00
|
|
|
migrateLog.Info("Updating stack resource controls")
|
2021-02-23 20:18:05 +00:00
|
|
|
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 {
|
2021-02-24 21:27:49 +00:00
|
|
|
if err == errors.ErrObjectNotFound {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-02-23 20:18:05 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-24 21:27:49 +00:00
|
|
|
resource.ResourceID = stackutils.ResourceControlID(stack.EndpointID, stack.Name)
|
2021-02-23 20:18:05 +00:00
|
|
|
|
|
|
|
err = m.resourceControlService.UpdateResourceControl(resource.ID, &resource)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|