예제 #1
0
// Create satisfies the RESTStorage interface.
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RESTResult, error) {
	minion, ok := obj.(*api.Node)
	if !ok {
		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)
	}

	api.FillObjectMetaSystemFields(ctx, &minion.ObjectMeta)

	return apiserver.MakeAsync(func() (runtime.Object, error) {
		err := rs.registry.CreateMinion(ctx, minion)
		if err != nil {
			return nil, err
		}
		return minion, nil
	}), nil
}
예제 #2
0
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RESTResult, error) {
	minion, ok := obj.(*api.Minion)
	if !ok {
		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)
	}

	api.FillObjectMetaSystemFields(ctx, &minion.ObjectMeta)

	return apiserver.MakeAsync(func() (runtime.Object, error) {
		// TODO: Need to fill in any server-set fields (uid, timestamp, etc) before
		// returning minion. Can't do it properly at the moment because the registry
		// healthchecking, which might cause it to not return the minion at all. Fix
		// this after we move the healthchecking out of the minion registry.
		err := rs.registry.CreateMinion(ctx, minion)
		if err != nil {
			return nil, err
		}
		return minion, nil
	}), nil
}
// Validate validates a new node.
func (nodeStrategy) Validate(obj runtime.Object) errors.ValidationErrorList {
	node := obj.(*api.Node)
	return validation.ValidateMinion(node)
}