1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-04 21:35:23 +02:00

fix(code): remove code that is no longer necessary EE-6078 (#10256)

This commit is contained in:
andres-portainer 2023-09-05 22:35:16 -03:00 committed by GitHub
parent c748385879
commit 4a39122415
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 33 additions and 224 deletions

View file

@ -3,6 +3,7 @@ package endpoints
import (
"errors"
"net/http"
"slices"
"strconv"
portainer "github.com/portainer/portainer/api"
@ -117,9 +118,11 @@ func (handler *Handler) deleteEndpoint(tx dataservices.DataStoreTx, endpointID p
}
for _, edgeGroup := range edgeGroups {
edgeGroup.Endpoints = removeElement(edgeGroup.Endpoints, endpoint.ID)
tx.EdgeGroup().Update(edgeGroup.ID, &edgeGroup)
edgeGroup.Endpoints = slices.DeleteFunc(edgeGroup.Endpoints, func(e portainer.EndpointID) bool {
return e == endpoint.ID
})
err = tx.EdgeGroup().Update(edgeGroup.ID, &edgeGroup)
if err != nil {
log.Warn().Err(err).Msgf("Unable to update edge group")
}
@ -183,15 +186,3 @@ func (handler *Handler) deleteEndpoint(tx dataservices.DataStoreTx, endpointID p
return nil
}
func removeElement(slice []portainer.EndpointID, elem portainer.EndpointID) []portainer.EndpointID {
for i, id := range slice {
if id == elem {
slice[i] = slice[len(slice)-1]
return slice[:len(slice)-1]
}
}
return slice
}

View file

@ -3,6 +3,7 @@ package endpoints
import (
"fmt"
"net/http"
"slices"
"strconv"
"strings"
"time"
@ -12,7 +13,6 @@ import (
"github.com/portainer/portainer/api/http/handler/edgegroups"
"github.com/portainer/portainer/api/internal/edge"
"github.com/portainer/portainer/api/internal/endpointutils"
"github.com/portainer/portainer/api/internal/slices"
"github.com/portainer/portainer/api/internal/unique"
"github.com/portainer/portainer/pkg/libhttp/request"

View file

@ -7,6 +7,7 @@ import (
"github.com/portainer/portainer/api/datastore"
"github.com/portainer/portainer/api/internal/slices"
"github.com/portainer/portainer/api/internal/testhelpers"
"github.com/stretchr/testify/assert"
)

View file

@ -1,11 +1,12 @@
package endpoints
import (
"slices"
"github.com/pkg/errors"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/dataservices"
"github.com/portainer/portainer/api/internal/set"
"github.com/portainer/portainer/api/internal/slices"
)
func updateEnvironmentEdgeGroups(tx dataservices.DataStoreTx, newEdgeGroups []portainer.EdgeGroupID, environmentID portainer.EndpointID) (bool, error) {
@ -52,7 +53,7 @@ func updateEnvironmentEdgeGroups(tx dataservices.DataStoreTx, newEdgeGroups []po
removeEdgeGroups := environmentEdgeGroupsSet.Difference(newEdgeGroupsSet)
err = updateSet(removeEdgeGroups, func(edgeGroup *portainer.EdgeGroup) {
edgeGroup.Endpoints = slices.RemoveItem(edgeGroup.Endpoints, func(eID portainer.EndpointID) bool {
edgeGroup.Endpoints = slices.DeleteFunc(edgeGroup.Endpoints, func(eID portainer.EndpointID) bool {
return eID == environmentID
})
})