1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00

fix(pending-actions): correctly detect unreachable/down cluster [EE-7049] (#11809)
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run

This commit is contained in:
Matt Hook 2024-05-16 09:03:10 +12:00 committed by GitHub
parent 42d9dfba36
commit 00ab9e949a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 2 deletions

View file

@ -0,0 +1,7 @@
package cli
import "k8s.io/apimachinery/pkg/version"
func (kcl *KubeClient) ServerVersion() (*version.Info, error) {
return kcl.cli.Discovery().ServerVersion()
}

View file

@ -73,8 +73,16 @@ func (service *PendingActionsService) Execute(id portainer.EndpointID) {
return return
} }
} else { } else {
// For Kubernetes endpoints, we need to check if the client can be created // For Kubernetes endpoints, we need to check if the endpoint is up by
if _, err := service.kubeFactory.GetKubeClient(endpoint); err != nil { // creating a kube client and performing a simple operation
client, err := service.kubeFactory.GetKubeClient(endpoint)
if err != nil {
log.Debug().Msgf("failed to create Kubernetes client for environment %d: %v", id, err)
return
}
if _, err = client.ServerVersion(); err != nil {
log.Debug().Err(err).Msgf("Environment %q (id: %d) is not up", endpoint.Name, id)
return return
} }
} }

View file

@ -14,6 +14,7 @@ import (
"github.com/portainer/portainer/pkg/featureflags" "github.com/portainer/portainer/pkg/featureflags"
"golang.org/x/oauth2" "golang.org/x/oauth2"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/version"
) )
type ( type (
@ -1487,6 +1488,8 @@ type (
// KubeClient represents a service used to query a Kubernetes environment(endpoint) // KubeClient represents a service used to query a Kubernetes environment(endpoint)
KubeClient interface { KubeClient interface {
ServerVersion() (*version.Info, error)
SetupUserServiceAccount(userID int, teamIDs []int, restrictDefaultNamespace bool) error SetupUserServiceAccount(userID int, teamIDs []int, restrictDefaultNamespace bool) error
IsRBACEnabled() (bool, error) IsRBACEnabled() (bool, error)
GetServiceAccount(tokendata *TokenData) (*v1.ServiceAccount, error) GetServiceAccount(tokendata *TokenData) (*v1.ServiceAccount, error)