You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/api/internal/nodes/nodes.go

32 lines
679 B

package status
import (
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/internal/endpointutils"
)
// NodesCount returns the total node number of all environments
func NodesCount(endpoints []portainer.Endpoint) int {
nodes := 0
for _, env := range endpoints {
if !endpointutils.IsEdgeEndpoint(&env) || env.UserTrusted {
nodes += countNodes(&env)
}
}
return nodes
}
func countNodes(endpoint *portainer.Endpoint) int {
if len(endpoint.Snapshots) == 1 {
return max(endpoint.Snapshots[0].NodeCount, 1)
}
if len(endpoint.Kubernetes.Snapshots) == 1 {
return max(endpoint.Kubernetes.Snapshots[0].NodeCount, 1)
}
return 1
}