Skip to content

Commit

Permalink
fix(pending-actions): correctly detect unreachable/down cluster [EE-7…
Browse files Browse the repository at this point in the history
…049] (#11809)
  • Loading branch information
hookenz committed May 15, 2024
1 parent 42d9dfb commit 00ab9e9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions api/kubernetes/cli/server_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cli

import "k8s.io/apimachinery/pkg/version"

func (kcl *KubeClient) ServerVersion() (*version.Info, error) {
return kcl.cli.Discovery().ServerVersion()
}
12 changes: 10 additions & 2 deletions api/pendingactions/pendingactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,16 @@ func (service *PendingActionsService) Execute(id portainer.EndpointID) {
return
}
} else {
// For Kubernetes endpoints, we need to check if the client can be created
if _, err := service.kubeFactory.GetKubeClient(endpoint); err != nil {
// For Kubernetes endpoints, we need to check if the endpoint is up by
// 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
}
}
Expand Down
3 changes: 3 additions & 0 deletions api/portainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/portainer/portainer/pkg/featureflags"
"golang.org/x/oauth2"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/version"
)

type (
Expand Down Expand Up @@ -1487,6 +1488,8 @@ type (

// KubeClient represents a service used to query a Kubernetes environment(endpoint)
KubeClient interface {
ServerVersion() (*version.Info, error)

SetupUserServiceAccount(userID int, teamIDs []int, restrictDefaultNamespace bool) error
IsRBACEnabled() (bool, error)
GetServiceAccount(tokendata *TokenData) (*v1.ServiceAccount, error)
Expand Down

0 comments on commit 00ab9e9

Please sign in to comment.