Add IsReachable to /pkg/kube/client to see if connected to the internet

Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
pull/6255/head
Vibhav Bobade 5 years ago
parent 27e70c8f1d
commit 5a07055645

@ -63,6 +63,16 @@ func New(getter genericclioptions.RESTClientGetter) *Client {
var nopLogger = func(_ string, _ ...interface{}) {}
// Test connectivity to the Client
func (c *Client) IsReachable() error {
client, _ := c.Factory.KubernetesClientSet()
_, err := client.ServerVersion()
if err != nil {
return errors.New("Kubernetes cluster unreachable")
}
return nil
}
// Create creates Kubernetes resources specified in the resource list.
func (c *Client) Create(resources ResourceList) (*Result, error) {
c.Log("creating %d resource(s)", len(resources))

@ -33,6 +33,11 @@ type PrintingKubeClient struct {
Out io.Writer
}
// isReachable checks if the cluster is reachable
func (p *PrintingKubeClient) IsReachable() error {
return nil
}
// Create prints the values of what would be created with a real KubeClient.
func (p *PrintingKubeClient) Create(resources kube.ResourceList) (*kube.Result, error) {
_, err := io.Copy(p.Out, bufferize(resources))

@ -56,6 +56,9 @@ type Interface interface {
// WaitAndGetCompletedPodPhase waits up to a timeout until a pod enters a completed phase
// and returns said phase (PodSucceeded or PodFailed qualify).
WaitAndGetCompletedPodPhase(name string, timeout time.Duration) (v1.PodPhase, error)
// isReachable checks whether the client is able to connect to the cluster
IsReachable() error
}
var _ Interface = (*Client)(nil)

Loading…
Cancel
Save