From 7975ef796dc5e5369fe32da048f34c4dd4b8dc37 Mon Sep 17 00:00:00 2001 From: Yi Chen <69284638+yi-portainer@users.noreply.github.com> Date: Thu, 17 Dec 2020 13:33:45 +1300 Subject: [PATCH] Revert "feat(docker/stacks): add creation and update dates (#4418)" (#4606) This reverts commit bd98b8956a2ce64bd9cb416b3e2f489c6948a1c7. --- .../handler/stacks/create_compose_stack.go | 46 ++++++++-------- api/http/handler/stacks/create_swarm_stack.go | 52 +++++++++---------- api/http/handler/stacks/stack_update.go | 3 -- api/portainer.go | 2 - .../stacks-datatable/stacksDatatable.html | 24 +-------- app/portainer/helpers/stackHelper.js | 16 +++--- app/portainer/models/stack.js | 5 +- app/portainer/services/api/stackService.js | 12 ++--- 8 files changed, 61 insertions(+), 99 deletions(-) diff --git a/api/http/handler/stacks/create_compose_stack.go b/api/http/handler/stacks/create_compose_stack.go index fb3688dbf..6ceab991c 100644 --- a/api/http/handler/stacks/create_compose_stack.go +++ b/api/http/handler/stacks/create_compose_stack.go @@ -7,7 +7,6 @@ import ( "regexp" "strconv" "strings" - "time" "github.com/asaskevich/govalidator" httperror "github.com/portainer/libhttp/error" @@ -61,14 +60,13 @@ func (handler *Handler) createComposeStackFromFileContent(w http.ResponseWriter, stackID := handler.DataStore.Stack().GetNextIdentifier() stack := &portainer.Stack{ - ID: portainer.StackID(stackID), - Name: payload.Name, - Type: portainer.DockerComposeStack, - EndpointID: endpoint.ID, - EntryPoint: filesystem.ComposeFileDefaultName, - Env: payload.Env, - Status: portainer.StackStatusActive, - CreationDate: time.Now().Unix(), + ID: portainer.StackID(stackID), + Name: payload.Name, + Type: portainer.DockerComposeStack, + EndpointID: endpoint.ID, + EntryPoint: filesystem.ComposeFileDefaultName, + Env: payload.Env, + Status: portainer.StackStatusActive, } stackFolder := strconv.Itoa(int(stack.ID)) @@ -148,14 +146,13 @@ func (handler *Handler) createComposeStackFromGitRepository(w http.ResponseWrite stackID := handler.DataStore.Stack().GetNextIdentifier() stack := &portainer.Stack{ - ID: portainer.StackID(stackID), - Name: payload.Name, - Type: portainer.DockerComposeStack, - EndpointID: endpoint.ID, - EntryPoint: payload.ComposeFilePathInRepository, - Env: payload.Env, - Status: portainer.StackStatusActive, - CreationDate: time.Now().Unix(), + ID: portainer.StackID(stackID), + Name: payload.Name, + Type: portainer.DockerComposeStack, + EndpointID: endpoint.ID, + EntryPoint: payload.ComposeFilePathInRepository, + Env: payload.Env, + Status: portainer.StackStatusActive, } projectPath := handler.FileService.GetStackProjectPath(strconv.Itoa(int(stack.ID))) @@ -245,14 +242,13 @@ func (handler *Handler) createComposeStackFromFileUpload(w http.ResponseWriter, stackID := handler.DataStore.Stack().GetNextIdentifier() stack := &portainer.Stack{ - ID: portainer.StackID(stackID), - Name: payload.Name, - Type: portainer.DockerComposeStack, - EndpointID: endpoint.ID, - EntryPoint: filesystem.ComposeFileDefaultName, - Env: payload.Env, - Status: portainer.StackStatusActive, - CreationDate: time.Now().Unix(), + ID: portainer.StackID(stackID), + Name: payload.Name, + Type: portainer.DockerComposeStack, + EndpointID: endpoint.ID, + EntryPoint: filesystem.ComposeFileDefaultName, + Env: payload.Env, + Status: portainer.StackStatusActive, } stackFolder := strconv.Itoa(int(stack.ID)) diff --git a/api/http/handler/stacks/create_swarm_stack.go b/api/http/handler/stacks/create_swarm_stack.go index bd65f3e3b..0113e8a41 100644 --- a/api/http/handler/stacks/create_swarm_stack.go +++ b/api/http/handler/stacks/create_swarm_stack.go @@ -6,7 +6,6 @@ import ( "path" "strconv" "strings" - "time" "github.com/asaskevich/govalidator" httperror "github.com/portainer/libhttp/error" @@ -56,15 +55,14 @@ func (handler *Handler) createSwarmStackFromFileContent(w http.ResponseWriter, r stackID := handler.DataStore.Stack().GetNextIdentifier() stack := &portainer.Stack{ - ID: portainer.StackID(stackID), - Name: payload.Name, - Type: portainer.DockerSwarmStack, - SwarmID: payload.SwarmID, - EndpointID: endpoint.ID, - EntryPoint: filesystem.ComposeFileDefaultName, - Env: payload.Env, - Status: portainer.StackStatusActive, - CreationDate: time.Now().Unix(), + ID: portainer.StackID(stackID), + Name: payload.Name, + Type: portainer.DockerSwarmStack, + SwarmID: payload.SwarmID, + EndpointID: endpoint.ID, + EntryPoint: filesystem.ComposeFileDefaultName, + Env: payload.Env, + Status: portainer.StackStatusActive, } stackFolder := strconv.Itoa(int(stack.ID)) @@ -147,15 +145,14 @@ func (handler *Handler) createSwarmStackFromGitRepository(w http.ResponseWriter, stackID := handler.DataStore.Stack().GetNextIdentifier() stack := &portainer.Stack{ - ID: portainer.StackID(stackID), - Name: payload.Name, - Type: portainer.DockerSwarmStack, - SwarmID: payload.SwarmID, - EndpointID: endpoint.ID, - EntryPoint: payload.ComposeFilePathInRepository, - Env: payload.Env, - Status: portainer.StackStatusActive, - CreationDate: time.Now().Unix(), + ID: portainer.StackID(stackID), + Name: payload.Name, + Type: portainer.DockerSwarmStack, + SwarmID: payload.SwarmID, + EndpointID: endpoint.ID, + EntryPoint: payload.ComposeFilePathInRepository, + Env: payload.Env, + Status: portainer.StackStatusActive, } projectPath := handler.FileService.GetStackProjectPath(strconv.Itoa(int(stack.ID))) @@ -252,15 +249,14 @@ func (handler *Handler) createSwarmStackFromFileUpload(w http.ResponseWriter, r stackID := handler.DataStore.Stack().GetNextIdentifier() stack := &portainer.Stack{ - ID: portainer.StackID(stackID), - Name: payload.Name, - Type: portainer.DockerSwarmStack, - SwarmID: payload.SwarmID, - EndpointID: endpoint.ID, - EntryPoint: filesystem.ComposeFileDefaultName, - Env: payload.Env, - Status: portainer.StackStatusActive, - CreationDate: time.Now().Unix(), + ID: portainer.StackID(stackID), + Name: payload.Name, + Type: portainer.DockerSwarmStack, + SwarmID: payload.SwarmID, + EndpointID: endpoint.ID, + EntryPoint: filesystem.ComposeFileDefaultName, + Env: payload.Env, + Status: portainer.StackStatusActive, } stackFolder := strconv.Itoa(int(stack.ID)) diff --git a/api/http/handler/stacks/stack_update.go b/api/http/handler/stacks/stack_update.go index 4ee04f5f9..df4178f8f 100644 --- a/api/http/handler/stacks/stack_update.go +++ b/api/http/handler/stacks/stack_update.go @@ -4,7 +4,6 @@ import ( "errors" "net/http" "strconv" - "time" "github.com/asaskevich/govalidator" httperror "github.com/portainer/libhttp/error" @@ -124,7 +123,6 @@ func (handler *Handler) updateComposeStack(r *http.Request, stack *portainer.Sta } stack.Env = payload.Env - stack.UpdateDate = time.Now().Unix() stackFolder := strconv.Itoa(int(stack.ID)) _, err = handler.FileService.StoreStackFileFromBytes(stackFolder, stack.EntryPoint, []byte(payload.StackFileContent)) @@ -153,7 +151,6 @@ func (handler *Handler) updateSwarmStack(r *http.Request, stack *portainer.Stack } stack.Env = payload.Env - stack.UpdateDate = time.Now().Unix() stackFolder := strconv.Itoa(int(stack.ID)) _, err = handler.FileService.StoreStackFileFromBytes(stackFolder, stack.EntryPoint, []byte(payload.StackFileContent)) diff --git a/api/portainer.go b/api/portainer.go index 4a98d4d89..e68e0c223 100644 --- a/api/portainer.go +++ b/api/portainer.go @@ -554,8 +554,6 @@ type ( Env []Pair `json:"Env"` ResourceControl *ResourceControl `json:"ResourceControl"` Status StackStatus `json:"Status"` - CreationDate int64 `json:"CreationDate"` - UpdateDate int64 `json:"UpdateDate"` ProjectPath string } diff --git a/app/portainer/components/datatables/stacks-datatable/stacksDatatable.html b/app/portainer/components/datatables/stacks-datatable/stacksDatatable.html index a2ff2eb58..1bd2c313d 100644 --- a/app/portainer/components/datatables/stacks-datatable/stacksDatatable.html +++ b/app/portainer/components/datatables/stacks-datatable/stacksDatatable.html @@ -117,20 +117,6 @@ Control - - - Created - - - - - - - Updated - - - - Ownership @@ -168,14 +154,6 @@ Total - - {{ item.CreationDate | getisodatefromtimestamp }} - - - - - {{ item.UpdateDate | getisodatefromtimestamp }} - - - @@ -187,7 +165,7 @@ Loading... - No stack available. + No stack available. diff --git a/app/portainer/helpers/stackHelper.js b/app/portainer/helpers/stackHelper.js index d5c06501b..b9beb6172 100644 --- a/app/portainer/helpers/stackHelper.js +++ b/app/portainer/helpers/stackHelper.js @@ -5,31 +5,31 @@ angular.module('portainer.app').factory('StackHelper', [ 'use strict'; var helper = {}; - helper.getExternalStacksFromContainers = function (containers) { - var stacks = []; + helper.getExternalStackNamesFromContainers = function (containers) { + var stackNames = []; for (var i = 0; i < containers.length; i++) { var container = containers[i]; if (!container.Labels || !container.Labels['com.docker.compose.project']) continue; var stackName = container.Labels['com.docker.compose.project']; - stacks.push({ stackName, creationDate: container.Created }); + stackNames.push(stackName); } - return _.uniq(stacks); + return _.uniq(stackNames); }; - helper.getExternalStacksFromServices = function (services) { - var stacks = []; + helper.getExternalStackNamesFromServices = function (services) { + var stackNames = []; for (var i = 0; i < services.length; i++) { var service = services[i]; if (!service.Labels || !service.Labels['com.docker.stack.namespace']) continue; var stackName = service.Labels['com.docker.stack.namespace']; - stacks.push({ stackName, creationDate: service.Created }); + stackNames.push(stackName); } - return _.uniq(stacks); + return _.uniq(stackNames); }; return helper; diff --git a/app/portainer/models/stack.js b/app/portainer/models/stack.js index 6bcb826f9..ef28f97e3 100644 --- a/app/portainer/models/stack.js +++ b/app/portainer/models/stack.js @@ -13,14 +13,11 @@ export function StackViewModel(data) { } this.External = false; this.Status = data.Status; - this.CreationDate = data.CreationDate; - this.UpdateDate = data.UpdateDate; } -export function ExternalStackViewModel(name, type, creationDate) { +export function ExternalStackViewModel(name, type) { this.Name = name; this.Type = type; this.External = true; this.Checked = false; - this.CreationDate = creationDate; } diff --git a/app/portainer/services/api/stackService.js b/app/portainer/services/api/stackService.js index ad6519903..68bebbd56 100644 --- a/app/portainer/services/api/stackService.js +++ b/app/portainer/services/api/stackService.js @@ -123,9 +123,9 @@ angular.module('portainer.app').factory('StackService', [ ServiceService.services() .then(function success(data) { var services = data; - var stackDatas = StackHelper.getExternalStacksFromServices(services); - var stacks = stackDatas.map(function (stack) { - return new ExternalStackViewModel(stack.stackName, 1, stack.creationDate); + var stackNames = StackHelper.getExternalStackNamesFromServices(services); + var stacks = stackNames.map(function (name) { + return new ExternalStackViewModel(name, 1); }); deferred.resolve(stacks); }) @@ -142,9 +142,9 @@ angular.module('portainer.app').factory('StackService', [ ContainerService.containers(1) .then(function success(data) { var containers = data; - var stacksDatas = StackHelper.getExternalStacksFromContainers(containers); - var stacks = stacksDatas.map(function (stack) { - return new ExternalStackViewModel(stack.stackName, 2, stack.creationDate); + var stackNames = StackHelper.getExternalStackNamesFromContainers(containers); + var stacks = stackNames.map(function (name) { + return new ExternalStackViewModel(name, 2); }); deferred.resolve(stacks); })