mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
feat(dataservices): unify access methods and abstract away redundant code [EE-5628] (#9115)
This commit is contained in:
parent
4c6bbe9a2f
commit
4cc96b4b30
171 changed files with 714 additions and 1590 deletions
|
@ -28,7 +28,7 @@ func (e *StackAuthorMissingErr) Error() string {
|
|||
func RedeployWhenChanged(stackID portainer.StackID, deployer StackDeployer, datastore dataservices.DataStore, gitService portainer.GitService) error {
|
||||
log.Debug().Int("stack_id", int(stackID)).Msg("redeploying stack")
|
||||
|
||||
stack, err := datastore.Stack().Stack(stackID)
|
||||
stack, err := datastore.Stack().Read(stackID)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "failed to get the stack %v", stackID)
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ func RedeployWhenChanged(stackID portainer.StackID, deployer StackDeployer, data
|
|||
return errors.Errorf("cannot update stack, type %v is unsupported", stack.Type)
|
||||
}
|
||||
|
||||
if err := datastore.Stack().UpdateStack(stack.ID, stack); err != nil {
|
||||
if err := datastore.Stack().Update(stack.ID, stack); err != nil {
|
||||
return errors.WithMessagef(err, "failed to update the stack %v", stack.ID)
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ func RedeployWhenChanged(stackID portainer.StackID, deployer StackDeployer, data
|
|||
}
|
||||
|
||||
func getUserRegistries(datastore dataservices.DataStore, user *portainer.User, endpointID portainer.EndpointID) ([]portainer.Registry, error) {
|
||||
registries, err := datastore.Registry().Registries()
|
||||
registries, err := datastore.Registry().ReadAll()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "unable to retrieve registries from the database")
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ func Test_redeployWhenChanged(t *testing.T) {
|
|||
|
||||
t.Run("can deploy docker compose stack", func(t *testing.T) {
|
||||
stack.Type = portainer.DockerComposeStack
|
||||
store.Stack().UpdateStack(stack.ID, &stack)
|
||||
store.Stack().Update(stack.ID, &stack)
|
||||
|
||||
err = RedeployWhenChanged(1, &noopDeployer{}, store, testhelpers.NewGitService(nil, "newHash"))
|
||||
assert.NoError(t, err)
|
||||
|
@ -170,7 +170,7 @@ func Test_redeployWhenChanged(t *testing.T) {
|
|||
|
||||
t.Run("can deploy docker swarm stack", func(t *testing.T) {
|
||||
stack.Type = portainer.DockerSwarmStack
|
||||
store.Stack().UpdateStack(stack.ID, &stack)
|
||||
store.Stack().Update(stack.ID, &stack)
|
||||
|
||||
err = RedeployWhenChanged(1, &noopDeployer{}, store, testhelpers.NewGitService(nil, "newHash"))
|
||||
assert.NoError(t, err)
|
||||
|
@ -178,7 +178,7 @@ func Test_redeployWhenChanged(t *testing.T) {
|
|||
|
||||
t.Run("can deploy kube app", func(t *testing.T) {
|
||||
stack.Type = portainer.KubernetesStack
|
||||
store.Stack().UpdateStack(stack.ID, &stack)
|
||||
store.Stack().Update(stack.ID, &stack)
|
||||
|
||||
err = RedeployWhenChanged(1, &noopDeployer{}, store, testhelpers.NewGitService(nil, "newHash"))
|
||||
assert.NoError(t, err)
|
||||
|
|
|
@ -24,12 +24,12 @@ type ComposeStackDeploymentConfig struct {
|
|||
}
|
||||
|
||||
func CreateComposeStackDeploymentConfig(securityContext *security.RestrictedRequestContext, stack *portainer.Stack, endpoint *portainer.Endpoint, dataStore dataservices.DataStore, fileService portainer.FileService, deployer StackDeployer, forcePullImage, forceCreate bool) (*ComposeStackDeploymentConfig, error) {
|
||||
user, err := dataStore.User().User(securityContext.UserID)
|
||||
user, err := dataStore.User().Read(securityContext.UserID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to load user information from the database: %w", err)
|
||||
}
|
||||
|
||||
registries, err := dataStore.Registry().Registries()
|
||||
registries, err := dataStore.Registry().ReadAll()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to retrieve registries from the database: %w", err)
|
||||
}
|
||||
|
|
|
@ -24,12 +24,12 @@ type SwarmStackDeploymentConfig struct {
|
|||
}
|
||||
|
||||
func CreateSwarmStackDeploymentConfig(securityContext *security.RestrictedRequestContext, stack *portainer.Stack, endpoint *portainer.Endpoint, dataStore dataservices.DataStore, fileService portainer.FileService, deployer StackDeployer, prune bool, pullImage bool) (*SwarmStackDeploymentConfig, error) {
|
||||
user, err := dataStore.User().User(securityContext.UserID)
|
||||
user, err := dataStore.User().Read(securityContext.UserID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to load user information from the database: %w", err)
|
||||
}
|
||||
|
||||
registries, err := dataStore.Registry().Registries()
|
||||
registries, err := dataStore.Registry().ReadAll()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to retrieve registries from the database: %w", err)
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func StartStackSchedules(scheduler *scheduler.Scheduler, stackdeployer StackDepl
|
|||
})
|
||||
|
||||
stack.AutoUpdate.JobID = jobID
|
||||
if err := datastore.Stack().UpdateStack(stack.ID, &stack); err != nil {
|
||||
if err := datastore.Stack().Update(stack.ID, &stack); err != nil {
|
||||
return errors.Wrap(err, "failed to update stack job id")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue