Skip to content

Commit

Permalink
correctly detect unreachable
Browse files Browse the repository at this point in the history
  • Loading branch information
hookenz committed May 9, 2024
1 parent 27e3097 commit 1b5a990
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 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()
}
9 changes: 5 additions & 4 deletions api/pendingactions/pendingactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ func (service *PendingActionsService) Execute(id portainer.EndpointID) error {

// For Kubernetes endpoints, we need to check if the endpoint is up by creating a kube client
if isKubernetesEndpoint {
_, err := service.kubeFactory.GetKubeClient(endpoint)
if err != nil {
log.Debug().Err(err).Msgf("Environment %q (id: %d) is not up", endpoint.Name, id)
return fmt.Errorf("environment %q (id: %d) is not up", endpoint.Name, id)
if client, _ := service.kubeFactory.GetKubeClient(endpoint); client != nil {
if _, err = client.ServerVersion(); err != nil {
log.Debug().Err(err).Msgf("Environment %q (id: %d) is not up", endpoint.Name, id)
return fmt.Errorf("environment %q (id: %d) is not up", endpoint.Name, id)
}
}
}

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 1b5a990

Please sign in to comment.