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
Support eviction and statefulset in kubectl drain #35483
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Copyright 2016 The Kubernetes Authors. | ||
|
||
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 internalversion | ||
|
||
import ( | ||
restclient "k8s.io/kubernetes/pkg/client/restclient" | ||
) | ||
|
||
// EvictionsGetter has a method to return a EvictionInterface. | ||
// A group's client should implement this interface. | ||
type EvictionsGetter interface { | ||
Evictions(namespace string) EvictionInterface | ||
} | ||
|
||
// EvictionInterface has methods to work with Eviction resources. | ||
type EvictionInterface interface { | ||
EvictionExpansion | ||
} | ||
|
||
// evictions implements EvictionInterface | ||
type evictions struct { | ||
client restclient.Interface | ||
ns string | ||
} | ||
|
||
// newEvictions returns a Evictions | ||
func newEvictions(c *PolicyClient, namespace string) *evictions { | ||
return &evictions{ | ||
client: c.RESTClient(), | ||
ns: namespace, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Copyright 2016 The Kubernetes Authors. | ||
|
||
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 internalversion | ||
|
||
import ( | ||
policy "k8s.io/kubernetes/pkg/apis/policy" | ||
) | ||
|
||
// The EvictionExpansion interface allows manually adding extra methods to the ScaleInterface. | ||
type EvictionExpansion interface { | ||
Evict(eviction *policy.Eviction) error | ||
} | ||
|
||
func (c *evictions) Evict(eviction *policy.Eviction) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't hack the pkg/restclient. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How are we posting scale subresources to different API groups? I'd expect evict to be done similarly. Hard coding policy API version and pods eviction subresources here seems wrong, and exporting the versioned URL from rest client definitely seems wrong There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @caesarxuchao Correct me if I'm wrong. |
||
return c.client.Post(). | ||
AbsPath("/api/v1"). | ||
Namespace(eviction.Namespace). | ||
Resource("pods"). | ||
Name(eviction.Name). | ||
SubResource("eviction"). | ||
Body(eviction). | ||
Do(). | ||
Error() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Copyright 2016 The Kubernetes Authors. | ||
|
||
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 fake | ||
|
||
// FakeEvictions implements EvictionInterface | ||
type FakeEvictions struct { | ||
Fake *FakePolicy | ||
ns string | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright 2016 The Kubernetes Authors. | ||
|
||
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 fake | ||
|
||
import ( | ||
unversioned "k8s.io/kubernetes/pkg/api/unversioned" | ||
policy "k8s.io/kubernetes/pkg/apis/policy" | ||
core "k8s.io/kubernetes/pkg/client/testing/core" | ||
) | ||
|
||
func (c *FakeEvictions) Evict(eviction *policy.Eviction) error { | ||
action := core.GetActionImpl{} | ||
action.Verb = "post" | ||
action.Namespace = c.ns | ||
action.Resource = unversioned.GroupVersionResource{Group: "", Version: "", Resource: "pods"} | ||
action.Subresource = "eviction" | ||
_, err := c.Fake.Invokes(action, eviction) | ||
return err | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
Copyright 2016 The Kubernetes Authors. | ||
|
||
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. | ||
*/ | ||
|
||
// This file was automatically generated by lister-gen with arguments: --input-dirs=[k8s.io/kubernetes/pkg/api,k8s.io/kubernetes/pkg/api/v1,k8s.io/kubernetes/pkg/apis/abac,k8s.io/kubernetes/pkg/apis/abac/v0,k8s.io/kubernetes/pkg/apis/abac/v1beta1,k8s.io/kubernetes/pkg/apis/apps,k8s.io/kubernetes/pkg/apis/apps/v1beta1,k8s.io/kubernetes/pkg/apis/authentication,k8s.io/kubernetes/pkg/apis/authentication/v1beta1,k8s.io/kubernetes/pkg/apis/authorization,k8s.io/kubernetes/pkg/apis/authorization/v1beta1,k8s.io/kubernetes/pkg/apis/autoscaling,k8s.io/kubernetes/pkg/apis/autoscaling/v1,k8s.io/kubernetes/pkg/apis/batch,k8s.io/kubernetes/pkg/apis/batch/v1,k8s.io/kubernetes/pkg/apis/batch/v2alpha1,k8s.io/kubernetes/pkg/apis/certificates,k8s.io/kubernetes/pkg/apis/certificates/v1alpha1,k8s.io/kubernetes/pkg/apis/componentconfig,k8s.io/kubernetes/pkg/apis/componentconfig/v1alpha1,k8s.io/kubernetes/pkg/apis/extensions,k8s.io/kubernetes/pkg/apis/extensions/v1beta1,k8s.io/kubernetes/pkg/apis/imagepolicy,k8s.io/kubernetes/pkg/apis/imagepolicy/v1alpha1,k8s.io/kubernetes/pkg/apis/policy,k8s.io/kubernetes/pkg/apis/policy/v1alpha1,k8s.io/kubernetes/pkg/apis/policy/v1beta1,k8s.io/kubernetes/pkg/apis/rbac,k8s.io/kubernetes/pkg/apis/rbac/v1alpha1,k8s.io/kubernetes/pkg/apis/storage,k8s.io/kubernetes/pkg/apis/storage/v1beta1] | ||
|
||
package internalversion | ||
|
||
import ( | ||
"k8s.io/kubernetes/pkg/api/errors" | ||
policy "k8s.io/kubernetes/pkg/apis/policy" | ||
"k8s.io/kubernetes/pkg/client/cache" | ||
"k8s.io/kubernetes/pkg/labels" | ||
) | ||
|
||
// EvictionLister helps list Evictions. | ||
type EvictionLister interface { | ||
// List lists all Evictions in the indexer. | ||
List(selector labels.Selector) (ret []*policy.Eviction, err error) | ||
// Evictions returns an object that can list and get Evictions. | ||
Evictions(namespace string) EvictionNamespaceLister | ||
EvictionListerExpansion | ||
} | ||
|
||
// evictionLister implements the EvictionLister interface. | ||
type evictionLister struct { | ||
indexer cache.Indexer | ||
} | ||
|
||
// NewEvictionLister returns a new EvictionLister. | ||
func NewEvictionLister(indexer cache.Indexer) EvictionLister { | ||
return &evictionLister{indexer: indexer} | ||
} | ||
|
||
// List lists all Evictions in the indexer. | ||
func (s *evictionLister) List(selector labels.Selector) (ret []*policy.Eviction, err error) { | ||
err = cache.ListAll(s.indexer, selector, func(m interface{}) { | ||
ret = append(ret, m.(*policy.Eviction)) | ||
}) | ||
return ret, err | ||
} | ||
|
||
// Evictions returns an object that can list and get Evictions. | ||
func (s *evictionLister) Evictions(namespace string) EvictionNamespaceLister { | ||
return evictionNamespaceLister{indexer: s.indexer, namespace: namespace} | ||
} | ||
|
||
// EvictionNamespaceLister helps list and get Evictions. | ||
type EvictionNamespaceLister interface { | ||
// List lists all Evictions in the indexer for a given namespace. | ||
List(selector labels.Selector) (ret []*policy.Eviction, err error) | ||
// Get retrieves the Eviction from the indexer for a given namespace and name. | ||
Get(name string) (*policy.Eviction, error) | ||
EvictionNamespaceListerExpansion | ||
} | ||
|
||
// evictionNamespaceLister implements the EvictionNamespaceLister | ||
// interface. | ||
type evictionNamespaceLister struct { | ||
indexer cache.Indexer | ||
namespace string | ||
} | ||
|
||
// List lists all Evictions in the indexer for a given namespace. | ||
func (s evictionNamespaceLister) List(selector labels.Selector) (ret []*policy.Eviction, err error) { | ||
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { | ||
ret = append(ret, m.(*policy.Eviction)) | ||
}) | ||
return ret, err | ||
} | ||
|
||
// Get retrieves the Eviction from the indexer for a given namespace and name. | ||
func (s evictionNamespaceLister) Get(name string) (*policy.Eviction, error) { | ||
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !exists { | ||
return nil, errors.NewNotFound(policy.Resource("eviction"), name) | ||
} | ||
return obj.(*policy.Eviction), nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I missed something, why can't this be written in the same way as the functions above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
TooManyRequest
error returned in this case only has a status code with emptyReason
field.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, could you open any issue and paste the err your received?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created #36409.