mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 23:09:41 +02:00
fix(edge): show edge environment in edge views [EE-2997] (#6795)
This commit is contained in:
parent
141a530e28
commit
bbb096412d
7 changed files with 92 additions and 29 deletions
|
@ -97,6 +97,9 @@ func (m *Migrator) Migrate() error {
|
||||||
newMigration(35, m.migrateDBVersionToDB35),
|
newMigration(35, m.migrateDBVersionToDB35),
|
||||||
|
|
||||||
newMigration(36, m.migrateDBVersionToDB36),
|
newMigration(36, m.migrateDBVersionToDB36),
|
||||||
|
|
||||||
|
// Portainer 2.13
|
||||||
|
newMigration(40, m.migrateDBVersionToDB40),
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastDbVersion int
|
var lastDbVersion int
|
||||||
|
|
31
api/datastore/migrator/migrate_dbversion40.go
Normal file
31
api/datastore/migrator/migrate_dbversion40.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package migrator
|
||||||
|
|
||||||
|
import "github.com/portainer/portainer/api/internal/endpointutils"
|
||||||
|
|
||||||
|
func (m *Migrator) migrateDBVersionToDB40() error {
|
||||||
|
if err := m.trustCurrentEdgeEndpointsDB40(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Migrator) trustCurrentEdgeEndpointsDB40() error {
|
||||||
|
migrateLog.Info("- trusting current edge endpoints")
|
||||||
|
endpoints, err := m.endpointService.Endpoints()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, endpoint := range endpoints {
|
||||||
|
if endpointutils.IsEdgeEndpoint(&endpoint) {
|
||||||
|
endpoint.UserTrusted = true
|
||||||
|
err = m.endpointService.UpdateEndpoint(endpoint.ID, &endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -21,6 +21,7 @@ const (
|
||||||
EdgeDeviceFilterAll = "all"
|
EdgeDeviceFilterAll = "all"
|
||||||
EdgeDeviceFilterTrusted = "trusted"
|
EdgeDeviceFilterTrusted = "trusted"
|
||||||
EdgeDeviceFilterUntrusted = "untrusted"
|
EdgeDeviceFilterUntrusted = "untrusted"
|
||||||
|
EdgeDeviceFilterNone = "none"
|
||||||
)
|
)
|
||||||
|
|
||||||
var endpointGroupNames map[portainer.EndpointGroupID]string
|
var endpointGroupNames map[portainer.EndpointGroupID]string
|
||||||
|
@ -43,7 +44,7 @@ var endpointGroupNames map[portainer.EndpointGroupID]string
|
||||||
// @param tagIds query []int false "search environments(endpoints) with these tags (depends on tagsPartialMatch)"
|
// @param tagIds query []int false "search environments(endpoints) with these tags (depends on tagsPartialMatch)"
|
||||||
// @param tagsPartialMatch query bool false "If true, will return environment(endpoint) which has one of tagIds, if false (or missing) will return only environments(endpoints) that has all the tags"
|
// @param tagsPartialMatch query bool false "If true, will return environment(endpoint) which has one of tagIds, if false (or missing) will return only environments(endpoints) that has all the tags"
|
||||||
// @param endpointIds query []int false "will return only these environments(endpoints)"
|
// @param endpointIds query []int false "will return only these environments(endpoints)"
|
||||||
// @param edgeDeviceFilter query string false "will return only these edge devices" Enum("all", "trusted", "untrusted")
|
// @param edgeDeviceFilter query string false "will return only these edge environments, none will return only regular edge environments" Enum("all", "trusted", "untrusted", "none")
|
||||||
// @success 200 {array} portainer.Endpoint "Endpoints"
|
// @success 200 {array} portainer.Endpoint "Endpoints"
|
||||||
// @failure 500 "Server error"
|
// @failure 500 "Server error"
|
||||||
// @router /endpoints [get]
|
// @router /endpoints [get]
|
||||||
|
@ -334,10 +335,6 @@ func filterEndpointsByTypes(endpoints []portainer.Endpoint, endpointTypes []int)
|
||||||
func filterEndpointsByEdgeDevice(endpoints []portainer.Endpoint, edgeDeviceFilter string) []portainer.Endpoint {
|
func filterEndpointsByEdgeDevice(endpoints []portainer.Endpoint, edgeDeviceFilter string) []portainer.Endpoint {
|
||||||
filteredEndpoints := make([]portainer.Endpoint, 0)
|
filteredEndpoints := make([]portainer.Endpoint, 0)
|
||||||
|
|
||||||
if edgeDeviceFilter != EdgeDeviceFilterAll && edgeDeviceFilter != EdgeDeviceFilterTrusted && edgeDeviceFilter != EdgeDeviceFilterUntrusted {
|
|
||||||
return endpoints
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, endpoint := range endpoints {
|
for _, endpoint := range endpoints {
|
||||||
if shouldReturnEdgeDevice(endpoint, edgeDeviceFilter) {
|
if shouldReturnEdgeDevice(endpoint, edgeDeviceFilter) {
|
||||||
filteredEndpoints = append(filteredEndpoints, endpoint)
|
filteredEndpoints = append(filteredEndpoints, endpoint)
|
||||||
|
@ -347,7 +344,12 @@ func filterEndpointsByEdgeDevice(endpoints []portainer.Endpoint, edgeDeviceFilte
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldReturnEdgeDevice(endpoint portainer.Endpoint, edgeDeviceFilter string) bool {
|
func shouldReturnEdgeDevice(endpoint portainer.Endpoint, edgeDeviceFilter string) bool {
|
||||||
if !endpoint.IsEdgeDevice {
|
// none - return all endpoints that are not edge devices
|
||||||
|
if edgeDeviceFilter == EdgeDeviceFilterNone && !endpoint.IsEdgeDevice {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if !endpointutils.IsEdgeEndpoint(&endpoint) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,27 +17,36 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type endpointListEdgeDeviceTest struct {
|
type endpointListEdgeDeviceTest struct {
|
||||||
|
title string
|
||||||
expected []portainer.EndpointID
|
expected []portainer.EndpointID
|
||||||
filter string
|
filter string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_endpointList(t *testing.T) {
|
func Test_endpointList(t *testing.T) {
|
||||||
|
var err error
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
_, store, teardown := datastore.MustNewTestStore(true, true)
|
_, store, teardown := datastore.MustNewTestStore(true, true)
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
trustedEndpoint := portainer.Endpoint{ID: 1, UserTrusted: true, IsEdgeDevice: true, GroupID: 1}
|
trustedEndpoint := portainer.Endpoint{ID: 1, UserTrusted: true, IsEdgeDevice: true, GroupID: 1, Type: portainer.EdgeAgentOnDockerEnvironment}
|
||||||
err := store.Endpoint().Create(&trustedEndpoint)
|
untrustedEndpoint := portainer.Endpoint{ID: 2, UserTrusted: false, IsEdgeDevice: true, GroupID: 1, Type: portainer.EdgeAgentOnDockerEnvironment}
|
||||||
is.NoError(err, "error creating environment")
|
regularUntrustedEdgeEndpoint := portainer.Endpoint{ID: 3, UserTrusted: false, IsEdgeDevice: false, GroupID: 1, Type: portainer.EdgeAgentOnDockerEnvironment}
|
||||||
|
regularTrustedEdgeEndpoint := portainer.Endpoint{ID: 4, UserTrusted: true, IsEdgeDevice: false, GroupID: 1, Type: portainer.EdgeAgentOnDockerEnvironment}
|
||||||
|
regularEndpoint := portainer.Endpoint{ID: 5, UserTrusted: false, IsEdgeDevice: false, GroupID: 1, Type: portainer.DockerEnvironment}
|
||||||
|
|
||||||
untrustedEndpoint := portainer.Endpoint{ID: 2, UserTrusted: false, IsEdgeDevice: true, GroupID: 1}
|
endpoints := []portainer.Endpoint{
|
||||||
err = store.Endpoint().Create(&untrustedEndpoint)
|
trustedEndpoint,
|
||||||
is.NoError(err, "error creating environment")
|
untrustedEndpoint,
|
||||||
|
regularUntrustedEdgeEndpoint,
|
||||||
|
regularTrustedEdgeEndpoint,
|
||||||
|
regularEndpoint,
|
||||||
|
}
|
||||||
|
|
||||||
regularEndpoint := portainer.Endpoint{ID: 3, IsEdgeDevice: false, GroupID: 1}
|
for _, endpoint := range endpoints {
|
||||||
err = store.Endpoint().Create(®ularEndpoint)
|
err = store.Endpoint().Create(&endpoint)
|
||||||
is.NoError(err, "error creating environment")
|
is.NoError(err, "error creating environment")
|
||||||
|
}
|
||||||
|
|
||||||
err = store.User().Create(&portainer.User{Username: "admin", Role: portainer.AdministratorRole})
|
err = store.User().Create(&portainer.User{Username: "admin", Role: portainer.AdministratorRole})
|
||||||
is.NoError(err, "error creating a user")
|
is.NoError(err, "error creating a user")
|
||||||
|
@ -49,33 +58,45 @@ func Test_endpointList(t *testing.T) {
|
||||||
|
|
||||||
tests := []endpointListEdgeDeviceTest{
|
tests := []endpointListEdgeDeviceTest{
|
||||||
{
|
{
|
||||||
[]portainer.EndpointID{trustedEndpoint.ID, untrustedEndpoint.ID},
|
"should show all edge endpoints",
|
||||||
|
[]portainer.EndpointID{trustedEndpoint.ID, untrustedEndpoint.ID, regularUntrustedEdgeEndpoint.ID, regularTrustedEdgeEndpoint.ID},
|
||||||
EdgeDeviceFilterAll,
|
EdgeDeviceFilterAll,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]portainer.EndpointID{trustedEndpoint.ID},
|
"should show only trusted edge devices",
|
||||||
|
[]portainer.EndpointID{trustedEndpoint.ID, regularTrustedEdgeEndpoint.ID},
|
||||||
EdgeDeviceFilterTrusted,
|
EdgeDeviceFilterTrusted,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]portainer.EndpointID{untrustedEndpoint.ID},
|
"should show only untrusted edge devices",
|
||||||
|
[]portainer.EndpointID{untrustedEndpoint.ID, regularUntrustedEdgeEndpoint.ID},
|
||||||
EdgeDeviceFilterUntrusted,
|
EdgeDeviceFilterUntrusted,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"should show no edge devices",
|
||||||
|
[]portainer.EndpointID{regularEndpoint.ID, regularUntrustedEdgeEndpoint.ID, regularTrustedEdgeEndpoint.ID},
|
||||||
|
EdgeDeviceFilterNone,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
req := buildEndpointListRequest(test.filter)
|
t.Run(test.title, func(t *testing.T) {
|
||||||
resp, err := doEndpointListRequest(req, h, is)
|
is := assert.New(t)
|
||||||
is.NoError(err)
|
|
||||||
|
|
||||||
is.Equal(len(test.expected), len(resp))
|
req := buildEndpointListRequest(test.filter)
|
||||||
|
resp, err := doEndpointListRequest(req, h, is)
|
||||||
|
is.NoError(err)
|
||||||
|
|
||||||
respIds := []portainer.EndpointID{}
|
is.Equal(len(test.expected), len(resp))
|
||||||
|
|
||||||
for _, endpoint := range resp {
|
respIds := []portainer.EndpointID{}
|
||||||
respIds = append(respIds, endpoint.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
is.Equal(test.expected, respIds, "response should contain all edge devices")
|
for _, endpoint := range resp {
|
||||||
|
respIds = append(respIds, endpoint.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
is.ElementsMatch(test.expected, respIds)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,12 @@ export function EdgeDevicesViewController($q, $async, EndpointService, GroupServ
|
||||||
this.getEnvironments = function () {
|
this.getEnvironments = function () {
|
||||||
return $async(async () => {
|
return $async(async () => {
|
||||||
try {
|
try {
|
||||||
const [endpointsResponse, groups] = await Promise.all([getEndpoints(0, 100, { edgeDeviceFilter: 'trusted' }), GroupService.groups()]);
|
const [endpointsResponse, groups] = await Promise.all([
|
||||||
|
getEndpoints(0, 100, {
|
||||||
|
edgeDeviceFilter: 'trusted',
|
||||||
|
}),
|
||||||
|
GroupService.groups(),
|
||||||
|
]);
|
||||||
ctrl.groups = groups;
|
ctrl.groups = groups;
|
||||||
ctrl.edgeDevices = endpointsResponse.value;
|
ctrl.edgeDevices = endpointsResponse.value;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -21,10 +21,10 @@ export interface EnvironmentsQueryParams {
|
||||||
endpointIds?: EnvironmentId[];
|
endpointIds?: EnvironmentId[];
|
||||||
tagsPartialMatch?: boolean;
|
tagsPartialMatch?: boolean;
|
||||||
groupIds?: EnvironmentGroupId[];
|
groupIds?: EnvironmentGroupId[];
|
||||||
edgeDeviceFilter?: 'all' | 'trusted' | 'untrusted';
|
|
||||||
status?: EnvironmentStatus[];
|
status?: EnvironmentStatus[];
|
||||||
sort?: string;
|
sort?: string;
|
||||||
order?: 'asc' | 'desc';
|
order?: 'asc' | 'desc';
|
||||||
|
edgeDeviceFilter?: 'all' | 'trusted' | 'untrusted' | 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getEndpoints(
|
export async function getEndpoints(
|
||||||
|
|
|
@ -132,6 +132,7 @@ export function EnvironmentList({ onClickItem, onRefresh }: Props) {
|
||||||
groupIds: groupFilter,
|
groupIds: groupFilter,
|
||||||
sort: sortByFilter,
|
sort: sortByFilter,
|
||||||
order: sortByDescending ? 'desc' : 'asc',
|
order: sortByDescending ? 'desc' : 'asc',
|
||||||
|
edgeDeviceFilter: 'none',
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue