2021-02-23 20:18:05 +00:00
|
|
|
package migrator
|
|
|
|
|
|
|
|
import (
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
2023-05-05 00:19:47 +00:00
|
|
|
"github.com/portainer/portainer/api/dataservices"
|
2022-10-05 09:33:59 +00:00
|
|
|
"github.com/portainer/portainer/api/stacks/stackutils"
|
2022-09-16 16:18:44 +00:00
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
2021-02-23 20:18:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (m *Migrator) updateStackResourceControlToDB27() error {
|
2022-09-16 16:18:44 +00:00
|
|
|
log.Info().Msg("updating stack resource controls")
|
|
|
|
|
2023-06-22 21:28:07 +00:00
|
|
|
resourceControls, err := m.resourceControlService.ReadAll()
|
2021-02-23 20:18:05 +00:00
|
|
|
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 {
|
2023-05-05 00:19:47 +00:00
|
|
|
if dataservices.IsErrObjectNotFound(err) {
|
2021-02-24 21:27:49 +00:00
|
|
|
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
|
|
|
|
2023-06-22 21:28:07 +00:00
|
|
|
err = m.resourceControlService.Update(resource.ID, &resource)
|
2021-02-23 20:18:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|