Merge pull request #6597 from fabioy/kubectl-validate

Add "kubectl validate" command to do a cluster health check.
This commit is contained in:
Brendan Burns
2015-04-20 11:21:06 -07:00
56 changed files with 760 additions and 137 deletions

View File

@@ -43,6 +43,7 @@ type Interface interface {
NamespacesInterface
PersistentVolumesInterface
PersistentVolumeClaimsNamespacer
ComponentStatusesInterface
}
func (c *Client) ReplicationControllers(namespace string) ReplicationControllerInterface {
@@ -92,6 +93,10 @@ func (c *Client) PersistentVolumeClaims(namespace string) PersistentVolumeClaimI
return newPersistentVolumeClaims(c, namespace)
}
func (c *Client) ComponentStatuses() ComponentStatusInterface {
return newComponentStatuses(c)
}
// VersionInterface has a method to retrieve the server version.
type VersionInterface interface {
ServerVersion() (*version.Info, error)
@@ -137,6 +142,25 @@ func (c *Client) ServerAPIVersions() (*api.APIVersions, error) {
return &v, nil
}
type ComponentValidatorInterface interface {
ValidateComponents() (*api.ComponentStatusList, error)
}
// ValidateComponents retrieves and parses the master's self-monitored cluster state.
// TODO: This should hit the versioned endpoint when that is implemented.
func (c *Client) ValidateComponents() (*api.ComponentStatusList, error) {
body, err := c.Get().AbsPath("/validate").DoRaw()
if err != nil {
return nil, err
}
statuses := []api.ComponentStatus{}
if err := json.Unmarshal(body, &statuses); err != nil {
return nil, fmt.Errorf("got '%s': %v", string(body), err)
}
return &api.ComponentStatusList{Items: statuses}, nil
}
// IsTimeout tests if this is a timeout error in the underlying transport.
// This is unbelievably ugly.
// See: http://stackoverflow.com/questions/23494950/specifically-check-for-timeout-error for details

View File

@@ -0,0 +1,63 @@
/*
Copyright 2015 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package client
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
)
type ComponentStatusesInterface interface {
ComponentStatuses() ComponentStatusInterface
}
// ComponentStatusInterface contains methods to retrieve ComponentStatus
type ComponentStatusInterface interface {
List(label labels.Selector, field fields.Selector) (*api.ComponentStatusList, error)
Get(name string) (*api.ComponentStatus, error)
// TODO: It'd be nice to have watch support at some point
//Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error)
}
// componentStatuses implements ComponentStatusesInterface
type componentStatuses struct {
client *Client
}
func newComponentStatuses(c *Client) *componentStatuses {
return &componentStatuses{c}
}
func (c *componentStatuses) List(label labels.Selector, field fields.Selector) (result *api.ComponentStatusList, err error) {
result = &api.ComponentStatusList{}
err = c.client.Get().
Resource("componentStatuses").
LabelsSelectorParam(label).
FieldsSelectorParam(field).
Do().
Into(result)
return result, err
}
func (c *componentStatuses) Get(name string) (result *api.ComponentStatus, err error) {
result = &api.ComponentStatus{}
err = c.client.Get().Resource("componentStatuses").Name(name).Do().Into(result)
return
}

View File

@@ -0,0 +1,47 @@
/*
Copyright 2015 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package testclient
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
)
// Fake implements ComponentStatusInterface.
type FakeComponentStatuses struct {
Fake *Fake
}
func (c *FakeComponentStatuses) List(label labels.Selector, field fields.Selector) (result *api.ComponentStatusList, err error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "list-componentstatuses"}, &api.ComponentStatusList{})
return obj.(*api.ComponentStatusList), err
}
func (c *FakeComponentStatuses) Get(name string) (*api.ComponentStatus, error) {
obj, err := c.Fake.Invokes(FakeAction{Action: "get-componentstatus", Value: name}, &api.ComponentStatus{})
// c.Actions = append(c.Actions, FakeAction{Action: "get-componentstatuses", Value: nil})
// testStatus := &api.ComponentStatus{
// Name: "test",
// Health: "ok",
// HealthCode: int(probe.Success),
// Message: "ok",
// Error: "",
// }
// return &api.ComponentStatusList{Items: []api.ComponentStatus{*testStatus}}, nil
return obj.(*api.ComponentStatus), err
}

View File

@@ -125,3 +125,7 @@ func (c *Fake) ServerAPIVersions() (*api.APIVersions, error) {
c.Actions = append(c.Actions, FakeAction{Action: "get-apiversions", Value: nil})
return &api.APIVersions{Versions: []string{"v1beta1", "v1beta2"}}, nil
}
func (c *Fake) ComponentStatuses() client.ComponentStatusInterface {
return &FakeComponentStatuses{Fake: c}
}