mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 13:55:21 +02:00
feat: improve diagnostics stability - develop (#355)
This commit is contained in:
parent
1b2dc6a133
commit
935c7dd496
4 changed files with 115 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
package endpoints
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/go-version"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
)
|
||||
|
||||
|
@ -15,6 +16,11 @@ func IsEdgeEndpoint(endpoint *portainer.Endpoint) bool {
|
|||
return endpoint.Type == portainer.EdgeAgentOnDockerEnvironment || endpoint.Type == portainer.EdgeAgentOnKubernetesEnvironment
|
||||
}
|
||||
|
||||
// IsStandardEdgeEndpoint returns true if this is a standard Edge endpoint and not in async mode on either Docker or Kubernetes
|
||||
func IsStandardEdgeEndpoint(endpoint *portainer.Endpoint) bool {
|
||||
return (endpoint.Type == portainer.EdgeAgentOnDockerEnvironment || endpoint.Type == portainer.EdgeAgentOnKubernetesEnvironment) && !endpoint.Edge.AsyncMode
|
||||
}
|
||||
|
||||
// IsAssociatedEdgeEndpoint returns true if the environment is an Edge environment
|
||||
// and has a set EdgeID and UserTrusted is true.
|
||||
func IsAssociatedEdgeEndpoint(endpoint *portainer.Endpoint) bool {
|
||||
|
@ -26,3 +32,11 @@ func IsAssociatedEdgeEndpoint(endpoint *portainer.Endpoint) bool {
|
|||
func HasDirectConnectivity(endpoint *portainer.Endpoint) bool {
|
||||
return !IsEdgeEndpoint(endpoint) || (IsAssociatedEdgeEndpoint(endpoint) && !endpoint.Edge.AsyncMode)
|
||||
}
|
||||
|
||||
// IsNewerThan225 returns true if the agent version is newer than 2.25.0
|
||||
// this is used to check if the agent is compatible with the new diagnostics feature
|
||||
func IsNewerThan225(agentVersion string) bool {
|
||||
v1, _ := version.NewVersion(agentVersion)
|
||||
v2, _ := version.NewVersion("2.25.0")
|
||||
return v1.GreaterThanOrEqual(v2)
|
||||
}
|
||||
|
|
|
@ -202,3 +202,61 @@ func TestHasDirectConnectivity(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsStandardEdgeEndpoint(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
endpoint *portainer.Endpoint
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "StandardEdgeEndpoint",
|
||||
endpoint: &portainer.Endpoint{
|
||||
Type: portainer.EdgeAgentOnDockerEnvironment,
|
||||
Edge: portainer.EnvironmentEdgeSettings{AsyncMode: false},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "AsyncEdgeEndpoint",
|
||||
endpoint: &portainer.Endpoint{
|
||||
Type: portainer.EdgeAgentOnDockerEnvironment,
|
||||
Edge: portainer.EnvironmentEdgeSettings{AsyncMode: true},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := IsStandardEdgeEndpoint(tt.endpoint)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsNewerThan225(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
version string
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "NewerThan225",
|
||||
version: "2.25.1",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "OlderThan225",
|
||||
version: "2.24.0",
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := IsNewerThan225(tt.version)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue