Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e tests for eviction subresource. #31722

Merged
merged 2 commits into from Sep 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -18,6 +18,7 @@ package fake

import (
"k8s.io/kubernetes/pkg/api/v1"
policy "k8s.io/kubernetes/pkg/apis/policy/v1alpha1"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/testing/core"
)
Expand All @@ -44,3 +45,14 @@ func (c *FakePods) GetLogs(name string, opts *v1.PodLogOptions) *restclient.Requ
_, _ = c.Fake.Invokes(action, &v1.Pod{})
return &restclient.Request{}
}

func (c *FakePods) Evict(eviction *policy.Eviction) error {
action := core.CreateActionImpl{}
action.Verb = "create"
action.Resource = podsResource
action.Subresource = "evictions"
action.Object = eviction

_, err := c.Fake.Invokes(action, eviction)
return err
}
Expand Up @@ -19,12 +19,14 @@ package v1
import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/v1"
policy "k8s.io/kubernetes/pkg/apis/policy/v1alpha1"
"k8s.io/kubernetes/pkg/client/restclient"
)

// The PodExpansion interface allows manually adding extra methods to the PodInterface.
type PodExpansion interface {
Bind(binding *v1.Binding) error
Evict(eviction *policy.Eviction) error
GetLogs(name string, opts *v1.PodLogOptions) *restclient.Request
}

Expand All @@ -33,6 +35,10 @@ func (c *pods) Bind(binding *v1.Binding) error {
return c.client.Post().Namespace(c.ns).Resource("pods").Name(binding.Name).SubResource("binding").Body(binding).Do().Error()
}

func (c *pods) Evict(eviction *policy.Eviction) error {
return c.client.Post().Namespace(c.ns).Resource("pods").Name(eviction.Name).SubResource("eviction").Body(eviction).Do().Error()
}

// Get constructs a request for getting the logs for a pod
func (c *pods) GetLogs(name string, opts *v1.PodLogOptions) *restclient.Request {
return c.client.Get().Namespace(c.ns).Name(name).Resource("pods").SubResource("log").VersionedParams(opts, api.ParameterCodec)
Expand Down
2 changes: 1 addition & 1 deletion staging/src/k8s.io/client-go/1.4/Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -18,6 +18,7 @@ package fake

import (
"k8s.io/client-go/1.4/pkg/api/v1"
policy "k8s.io/client-go/1.4/pkg/apis/policy/v1alpha1"
"k8s.io/client-go/1.4/rest"
"k8s.io/client-go/1.4/testing"
)
Expand All @@ -44,3 +45,14 @@ func (c *FakePods) GetLogs(name string, opts *v1.PodLogOptions) *rest.Request {
_, _ = c.Fake.Invokes(action, &v1.Pod{})
return &rest.Request{}
}

func (c *FakePods) Evict(eviction *policy.Eviction) error {
action := testing.CreateActionImpl{}
action.Verb = "create"
action.Resource = podsResource
action.Subresource = "evictions"
action.Object = eviction

_, err := c.Fake.Invokes(action, eviction)
return err
}
Expand Up @@ -19,12 +19,14 @@ package v1
import (
"k8s.io/client-go/1.4/pkg/api"
"k8s.io/client-go/1.4/pkg/api/v1"
policy "k8s.io/client-go/1.4/pkg/apis/policy/v1alpha1"
"k8s.io/client-go/1.4/rest"
)

// The PodExpansion interface allows manually adding extra methods to the PodInterface.
type PodExpansion interface {
Bind(binding *v1.Binding) error
Evict(eviction *policy.Eviction) error
GetLogs(name string, opts *v1.PodLogOptions) *rest.Request
}

Expand All @@ -33,6 +35,10 @@ func (c *pods) Bind(binding *v1.Binding) error {
return c.client.Post().Namespace(c.ns).Resource("pods").Name(binding.Name).SubResource("binding").Body(binding).Do().Error()
}

func (c *pods) Evict(eviction *policy.Eviction) error {
return c.client.Post().Namespace(c.ns).Resource("pods").Name(eviction.Name).SubResource("eviction").Body(eviction).Do().Error()
}

// Get constructs a request for getting the logs for a pod
func (c *pods) GetLogs(name string, opts *v1.PodLogOptions) *rest.Request {
return c.client.Get().Namespace(c.ns).Name(name).Resource("pods").SubResource("log").VersionedParams(opts, api.ParameterCodec)
Expand Down
Expand Up @@ -3435,9 +3435,11 @@ func validateEndpointAddress(address *api.EndpointAddress, fldPath *field.Path,
if len(address.Hostname) > 0 {
allErrs = append(allErrs, ValidateDNS1123Label(address.Hostname, fldPath.Child("hostname"))...)
}
// During endpoint update, validate NodeName is DNS1123 compliant and transition rules allow the update
// During endpoint update, verify that NodeName is a DNS subdomain and transition rules allow the update
if address.NodeName != nil {
allErrs = append(allErrs, ValidateDNS1123Label(*address.NodeName, fldPath.Child("nodeName"))...)
for _, msg := range ValidateNodeName(*address.NodeName, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("nodeName"), *address.NodeName, msg))
}
}
allErrs = append(allErrs, validateEpAddrNodeNameTransition(address, ipToNodeName, fldPath.Child("nodeName"))...)
if len(allErrs) > 0 {
Expand Down
1 change: 1 addition & 0 deletions staging/src/k8s.io/client-go/1.4/pkg/apis/apps/register.go
Expand Up @@ -50,6 +50,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&PetSet{},
&PetSetList{},
&api.ListOptions{},
&api.DeleteOptions{},
)
return nil
}
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// +groupName=certificates.k8s.io
// +k8s:deepcopy-gen=package,register

// +groupName=certificates.k8s.io
package certificates
2 changes: 1 addition & 1 deletion staging/src/k8s.io/client-go/1.4/pkg/apis/policy/types.go
Expand Up @@ -72,7 +72,7 @@ type PodDisruptionBudgetList struct {

// Eviction evicts a pod from its node subject to certain policies and safety constraints.
// This is a subresource of Pod. A request to cause such an eviction is
// created by POSTing to .../pods/foo/evictions.
// created by POSTing to .../pods/<pod name>/evictions.
type Eviction struct {
unversioned.TypeMeta `json:",inline"`

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -71,7 +71,7 @@ type PodDisruptionBudgetList struct {

// Eviction evicts a pod from its node subject to certain policies and safety constraints.
// This is a subresource of Pod. A request to cause such an eviction is
// created by POSTing to .../pods/foo/evictions.
// created by POSTing to .../pods/<pod name>/evictions.
type Eviction struct {
unversioned.TypeMeta `json:",inline"`

Expand Down
Expand Up @@ -28,7 +28,7 @@ package v1alpha1

// AUTO-GENERATED FUNCTIONS START HERE
var map_Eviction = map[string]string{
"": "Eviction evicts a pod from its node subject to certain policies and safety constraints. This is a subresource of Pod. A request to cause such an eviction is created by POSTing to .../pods/foo/evictions.",
"": "Eviction evicts a pod from its node subject to certain policies and safety constraints. This is a subresource of Pod. A request to cause such an eviction is created by POSTing to .../pods/<pod name>/evictions.",
"metadata": "ObjectMeta describes the pod that is being evicted.",
"deleteOptions": "DeleteOptions may be provided",
}
Expand Down
14 changes: 13 additions & 1 deletion staging/src/k8s.io/client-go/1.4/pkg/util/errors/errors.go
Expand Up @@ -31,11 +31,23 @@ type Aggregate interface {
// NewAggregate converts a slice of errors into an Aggregate interface, which
// is itself an implementation of the error interface. If the slice is empty,
// this returns nil.
// It will check if any of the element of input error list is nil, to avoid
// nil pointer panic when call Error().
func NewAggregate(errlist []error) Aggregate {
if len(errlist) == 0 {
return nil
}
return aggregate(errlist)
// In case of input error list contains nil
var errs []error
for _, e := range errlist {
if e != nil {
errs = append(errs, e)
}
}
if len(errs) == 0 {
return nil
}
return aggregate(errs)
}

// This helper implements the error and Errors interfaces. Keeping it private
Expand Down
12 changes: 6 additions & 6 deletions staging/src/k8s.io/client-go/1.4/testing/fake.go
Expand Up @@ -55,28 +55,28 @@ type Reactor interface {
type WatchReactor interface {
// Handles indicates whether or not this Reactor deals with a given action
Handles(action Action) bool
// React handles a watch action and returns results. It may choose to delegate by indicated handled=false
// React handles a watch action and returns results. It may choose to delegate by indicating handled=false
React(action Action) (handled bool, ret watch.Interface, err error)
}

// ProxyReactor is an interface to allow the composition of proxy get functions.
type ProxyReactor interface {
// Handles indicates whether or not this Reactor deals with a given action
Handles(action Action) bool
// React handles a watch action and returns results. It may choose to delegate by indicated handled=false
// React handles a watch action and returns results. It may choose to delegate by indicating handled=false
React(action Action) (handled bool, ret rest.ResponseWrapper, err error)
}

// ReactionFunc is a function that returns an object or error for a given Action. If "handled" is false,
// then the test client will continue ignore the results and continue to the next ReactionFunc
// then the test client will ignore the results and continue to the next ReactionFunc
type ReactionFunc func(action Action) (handled bool, ret runtime.Object, err error)

// WatchReactionFunc is a function that returns a watch interface. If "handled" is false,
// then the test client will continue ignore the results and continue to the next ReactionFunc
// then the test client will ignore the results and continue to the next ReactionFunc
type WatchReactionFunc func(action Action) (handled bool, ret watch.Interface, err error)

// ProxyReactionFunc is a function that returns a ResponseWrapper interface for a given Action. If "handled" is false,
// then the test client will continue ignore the results and continue to the next ProxyReactionFunc
// then the test client will ignore the results and continue to the next ProxyReactionFunc
type ProxyReactionFunc func(action Action) (handled bool, ret rest.ResponseWrapper, err error)

// AddReactor appends a reactor to the end of the chain
Expand Down Expand Up @@ -184,7 +184,7 @@ func (c *Fake) ClearActions() {
c.actions = make([]Action, 0)
}

// Actions returns a chronologically ordered slice fake actions called on the fake client
// Actions returns a chronologically ordered slice fake actions called on the fake client.
func (c *Fake) Actions() []Action {
c.RLock()
defer c.RUnlock()
Expand Down