From 87dda810fc499e2dfb3a20284df286ebcd7acbac Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Mon, 10 Jan 2022 11:36:46 +0200 Subject: [PATCH] fix(edgestacks): create new stack [EE-2178] (#6311) * fix(edgestacks): create new stack [EE-2178] [EE-2178] * refactor(edgestacks): id is required on create --- api/dataservices/edgestack/edgestack.go | 15 ++++++++------- api/dataservices/interface.go | 2 +- api/http/handler/edgestacks/edgestack_create.go | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/api/dataservices/edgestack/edgestack.go b/api/dataservices/edgestack/edgestack.go index 627868adc..78b7a4f4b 100644 --- a/api/dataservices/edgestack/edgestack.go +++ b/api/dataservices/edgestack/edgestack.go @@ -67,14 +67,15 @@ func (service *Service) EdgeStack(ID portainer.EdgeStackID) (*portainer.EdgeStac return &stack, nil } -// CreateEdgeStack assign an ID to a new Edge stack and saves it. -func (service *Service) Create(edgeStack *portainer.EdgeStack) error { - return service.connection.CreateObject( +// CreateEdgeStack saves an Edge stack object to db. +func (service *Service) Create(id portainer.EdgeStackID, edgeStack *portainer.EdgeStack) error { + + edgeStack.ID = id + + return service.connection.CreateObjectWithId( BucketName, - func(id uint64) (int, interface{}) { - edgeStack.ID = portainer.EdgeStackID(id) - return int(edgeStack.ID), edgeStack - }, + int(edgeStack.ID), + edgeStack, ) } diff --git a/api/dataservices/interface.go b/api/dataservices/interface.go index 4c54ec1ee..dff951282 100644 --- a/api/dataservices/interface.go +++ b/api/dataservices/interface.go @@ -84,7 +84,7 @@ type ( EdgeStackService interface { EdgeStacks() ([]portainer.EdgeStack, error) EdgeStack(ID portainer.EdgeStackID) (*portainer.EdgeStack, error) - Create(edgeStack *portainer.EdgeStack) error + Create(id portainer.EdgeStackID, edgeStack *portainer.EdgeStack) error UpdateEdgeStack(ID portainer.EdgeStackID, edgeStack *portainer.EdgeStack) error DeleteEdgeStack(ID portainer.EdgeStackID) error GetNextIdentifier() int diff --git a/api/http/handler/edgestacks/edgestack_create.go b/api/http/handler/edgestacks/edgestack_create.go index 0ecccecd5..9c7344d77 100644 --- a/api/http/handler/edgestacks/edgestack_create.go +++ b/api/http/handler/edgestacks/edgestack_create.go @@ -159,7 +159,7 @@ func (handler *Handler) createSwarmStackFromFileContent(r *http.Request) (*porta return nil, fmt.Errorf("Unable to update endpoint relations: %w", err) } - err = handler.DataStore.EdgeStack().Create(stack) + err = handler.DataStore.EdgeStack().Create(stack.ID, stack) if err != nil { return nil, err } @@ -274,7 +274,7 @@ func (handler *Handler) createSwarmStackFromGitRepository(r *http.Request) (*por return nil, fmt.Errorf("Unable to update endpoint relations: %w", err) } - err = handler.DataStore.EdgeStack().Create(stack) + err = handler.DataStore.EdgeStack().Create(stack.ID, stack) if err != nil { return nil, err } @@ -381,7 +381,7 @@ func (handler *Handler) createSwarmStackFromFileUpload(r *http.Request) (*portai return nil, fmt.Errorf("Unable to update endpoint relations: %w", err) } - err = handler.DataStore.EdgeStack().Create(stack) + err = handler.DataStore.EdgeStack().Create(stack.ID, stack) if err != nil { return nil, err }