Minions should have common logic with create

TODO: disable / document generate names for cluster scoped resources.
This commit is contained in:
Clayton Coleman
2015-01-28 21:56:57 -05:00
parent 0a87f0332b
commit e485dc93ca
5 changed files with 112 additions and 12 deletions

View File

@@ -24,6 +24,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
kerrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
@@ -54,12 +55,10 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
return nil, fmt.Errorf("not a minion: %#v", obj)
}
if errs := validation.ValidateMinion(minion); len(errs) > 0 {
return nil, kerrors.NewInvalid("minion", minion.Name, errs)
if err := rest.BeforeCreate(rest.Nodes, ctx, obj); err != nil {
return nil, err
}
api.FillObjectMetaSystemFields(ctx, &minion.ObjectMeta)
return apiserver.MakeAsync(func() (runtime.Object, error) {
err := rs.registry.CreateMinion(ctx, minion)
if err != nil {

View File

@@ -21,6 +21,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest/resttest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
)
@@ -107,11 +108,14 @@ func TestMinionRegistryValidUpdate(t *testing.T) {
}
}
var (
validSelector = map[string]string{"a": "b"}
invalidSelector = map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"}
)
func TestMinionRegistryValidatesCreate(t *testing.T) {
storage := NewREST(registrytest.NewMinionRegistry([]string{"foo", "bar"}, api.NodeResources{}))
ctx := api.NewContext()
validSelector := map[string]string{"a": "b"}
invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"}
failureCases := map[string]api.Node{
"zero-length Name": {
ObjectMeta: api.ObjectMeta{
@@ -148,3 +152,20 @@ func contains(nodes *api.NodeList, nodeID string) bool {
}
return false
}
func TestCreate(t *testing.T) {
test := resttest.New(t, NewREST(registrytest.NewMinionRegistry([]string{"foo", "bar"}, api.NodeResources{}))).ClusterScope()
test.TestCreate(
// valid
&api.Node{
Status: api.NodeStatus{
HostIP: "something",
},
},
// invalid
&api.Node{
ObjectMeta: api.ObjectMeta{
Labels: invalidSelector,
},
})
}