mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Register Eviction v1
This commit is contained in:
parent
d7355278b3
commit
40f8fb2224
@ -73,7 +73,7 @@ var _ = rest.GroupVersionKindProvider(&EvictionREST{})
|
||||
|
||||
// GroupVersionKind specifies a particular GroupVersionKind to discovery
|
||||
func (r *EvictionREST) GroupVersionKind(containingGV schema.GroupVersion) schema.GroupVersionKind {
|
||||
return schema.GroupVersionKind{Group: "policy", Version: "v1beta1", Kind: "Eviction"}
|
||||
return schema.GroupVersionKind{Group: "policy", Version: "v1", Kind: "Eviction"}
|
||||
}
|
||||
|
||||
// New creates a new eviction resource
|
||||
|
@ -44,6 +44,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
|
||||
scheme.AddKnownTypes(SchemeGroupVersion,
|
||||
&PodDisruptionBudget{},
|
||||
&PodDisruptionBudgetList{},
|
||||
&Eviction{},
|
||||
)
|
||||
// Add the watch version that applies
|
||||
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
|
||||
|
@ -148,3 +148,22 @@ type PodDisruptionBudgetList struct {
|
||||
// Items is a list of PodDisruptionBudgets
|
||||
Items []PodDisruptionBudget `json:"items" protobuf:"bytes,2,rep,name=items"`
|
||||
}
|
||||
|
||||
// +genclient
|
||||
// +genclient:noVerbs
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
|
||||
// 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.
|
||||
type Eviction struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
|
||||
// ObjectMeta describes the pod that is being evicted.
|
||||
// +optional
|
||||
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
|
||||
|
||||
// DeleteOptions may be provided
|
||||
// +optional
|
||||
DeleteOptions *metav1.DeleteOptions `json:"deleteOptions,omitempty" protobuf:"bytes,2,opt,name=deleteOptions"`
|
||||
}
|
||||
|
@ -24,7 +24,8 @@ import (
|
||||
"strings"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
policy "k8s.io/api/policy/v1beta1"
|
||||
policyv1 "k8s.io/api/policy/v1"
|
||||
policyv1beta1 "k8s.io/api/policy/v1beta1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
@ -78,7 +79,23 @@ func (c *FakePods) GetLogs(name string, opts *v1.PodLogOptions) *restclient.Requ
|
||||
return fakeClient.Request()
|
||||
}
|
||||
|
||||
func (c *FakePods) Evict(ctx context.Context, eviction *policy.Eviction) error {
|
||||
func (c *FakePods) Evict(ctx context.Context, eviction *policyv1beta1.Eviction) error {
|
||||
return c.EvictV1beta1(ctx, eviction)
|
||||
}
|
||||
|
||||
func (c *FakePods) EvictV1(ctx context.Context, eviction *policyv1.Eviction) error {
|
||||
action := core.CreateActionImpl{}
|
||||
action.Verb = "create"
|
||||
action.Namespace = c.ns
|
||||
action.Resource = podsResource
|
||||
action.Subresource = "eviction"
|
||||
action.Object = eviction
|
||||
|
||||
_, err := c.Fake.Invokes(action, eviction)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *FakePods) EvictV1beta1(ctx context.Context, eviction *policyv1beta1.Eviction) error {
|
||||
action := core.CreateActionImpl{}
|
||||
action.Verb = "create"
|
||||
action.Namespace = c.ns
|
||||
|
@ -20,7 +20,8 @@ import (
|
||||
"context"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
policy "k8s.io/api/policy/v1beta1"
|
||||
policyv1 "k8s.io/api/policy/v1"
|
||||
policyv1beta1 "k8s.io/api/policy/v1beta1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/net"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
@ -30,7 +31,16 @@ import (
|
||||
// The PodExpansion interface allows manually adding extra methods to the PodInterface.
|
||||
type PodExpansion interface {
|
||||
Bind(ctx context.Context, binding *v1.Binding, opts metav1.CreateOptions) error
|
||||
Evict(ctx context.Context, eviction *policy.Eviction) error
|
||||
// Evict submits a policy/v1beta1 Eviction request to the pod's eviction subresource.
|
||||
// Equivalent to calling EvictV1beta1.
|
||||
// Deprecated: Use EvictV1() (supported in 1.22+) or EvictV1beta1().
|
||||
Evict(ctx context.Context, eviction *policyv1beta1.Eviction) error
|
||||
// EvictV1 submits a policy/v1 Eviction request to the pod's eviction subresource.
|
||||
// Supported in 1.22+.
|
||||
EvictV1(ctx context.Context, eviction *policyv1.Eviction) error
|
||||
// EvictV1beta1 submits a policy/v1beta1 Eviction request to the pod's eviction subresource.
|
||||
// Supported in 1.22+.
|
||||
EvictV1beta1(ctx context.Context, eviction *policyv1beta1.Eviction) error
|
||||
GetLogs(name string, opts *v1.PodLogOptions) *restclient.Request
|
||||
ProxyGet(scheme, name, port, path string, params map[string]string) restclient.ResponseWrapper
|
||||
}
|
||||
@ -40,7 +50,18 @@ func (c *pods) Bind(ctx context.Context, binding *v1.Binding, opts metav1.Create
|
||||
return c.client.Post().Namespace(c.ns).Resource("pods").Name(binding.Name).VersionedParams(&opts, scheme.ParameterCodec).SubResource("binding").Body(binding).Do(ctx).Error()
|
||||
}
|
||||
|
||||
func (c *pods) Evict(ctx context.Context, eviction *policy.Eviction) error {
|
||||
// Evict submits a policy/v1beta1 Eviction request to the pod's eviction subresource.
|
||||
// Equivalent to calling EvictV1beta1.
|
||||
// Deprecated: Use EvictV1() (supported in 1.22+) or EvictV1beta1().
|
||||
func (c *pods) Evict(ctx context.Context, eviction *policyv1beta1.Eviction) error {
|
||||
return c.client.Post().Namespace(c.ns).Resource("pods").Name(eviction.Name).SubResource("eviction").Body(eviction).Do(ctx).Error()
|
||||
}
|
||||
|
||||
func (c *pods) EvictV1beta1(ctx context.Context, eviction *policyv1beta1.Eviction) error {
|
||||
return c.client.Post().Namespace(c.ns).Resource("pods").Name(eviction.Name).SubResource("eviction").Body(eviction).Do(ctx).Error()
|
||||
}
|
||||
|
||||
func (c *pods) EvictV1(ctx context.Context, eviction *policyv1.Eviction) error {
|
||||
return c.client.Post().Namespace(c.ns).Resource("pods").Name(eviction.Name).SubResource("eviction").Body(eviction).Do(ctx).Error()
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright 2021 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 v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
policy "k8s.io/api/policy/v1"
|
||||
)
|
||||
|
||||
// The EvictionExpansion interface allows manually adding extra methods to the ScaleInterface.
|
||||
type EvictionExpansion interface {
|
||||
Evict(ctx context.Context, eviction *policy.Eviction) error
|
||||
}
|
||||
|
||||
func (c *evictions) Evict(ctx context.Context, eviction *policy.Eviction) error {
|
||||
return c.client.Post().
|
||||
AbsPath("/api/v1").
|
||||
Namespace(eviction.Namespace).
|
||||
Resource("pods").
|
||||
Name(eviction.Name).
|
||||
SubResource("eviction").
|
||||
Body(eviction).
|
||||
Do(ctx).
|
||||
Error()
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Copyright 2021 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 (
|
||||
"context"
|
||||
|
||||
policy "k8s.io/api/policy/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeEvictions) Evict(ctx context.Context, eviction *policy.Eviction) error {
|
||||
action := core.CreateActionImpl{}
|
||||
action.Verb = "create"
|
||||
action.Namespace = c.ns
|
||||
action.Resource = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
|
||||
action.Subresource = "eviction"
|
||||
action.Object = eviction
|
||||
|
||||
_, err := c.Fake.Invokes(action, eviction)
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue
Block a user