-
Notifications
You must be signed in to change notification settings - Fork 40k
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 graceful deletion of resources #5085
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,51 @@ | ||
/* | ||
Copyright 2014 Google Inc. All rights reserved. | ||
|
||
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 rest | ||
|
||
import ( | ||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" | ||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" | ||
) | ||
|
||
// RESTDeleteStrategy defines deletion behavior on an object that follows Kubernetes | ||
// API conventions. | ||
type RESTDeleteStrategy interface { | ||
runtime.ObjectTyper | ||
|
||
// CheckGracefulDelete should return true if the object can be gracefully deleted and set | ||
// any default values on the DeleteOptions. | ||
CheckGracefulDelete(obj runtime.Object, options *api.DeleteOptions) bool | ||
} | ||
|
||
// BeforeDelete tests whether the object can be gracefully deleted. If graceful is set the object | ||
// should be gracefully deleted, if gracefulPending is set the object has already been gracefully deleted | ||
// (and the provided grace period is longer than the time to deletion), and an error is returned if the | ||
// condition cannot be checked or the gracePeriodSeconds is invalid. The options argument may be updated with | ||
// default values if graceful is true. | ||
func BeforeDelete(strategy RESTDeleteStrategy, ctx api.Context, obj runtime.Object, options *api.DeleteOptions) (graceful, gracefulPending bool, err error) { | ||
if strategy == nil { | ||
return false, false, nil | ||
} | ||
_, _, kerr := objectMetaAndKind(strategy, obj) | ||
if kerr != nil { | ||
return false, false, kerr | ||
} | ||
if !strategy.CheckGracefulDelete(obj, options) { | ||
return false, false, nil | ||
} | ||
return true, false, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,17 @@ type ObjectMeta struct { | |
// Clients may not set this value. It is represented in RFC3339 form and is in UTC. | ||
CreationTimestamp util.Time `json:"creationTimestamp,omitempty"` | ||
|
||
// DeletionTimestamp is the time after which this resource will be deleted. This | ||
// field is set by the server when a graceful deletion is requested by the user, and is not | ||
// directly settable by a client. The resource will be deleted (no longer visible from | ||
// resource lists, and not reachable by name) after the time in this field. Once set, this | ||
// value may not be unset or be set further into the future, although it may be shortened | ||
// or the resource may be deleted prior to this time. For example, a user may request that | ||
// a pod is deleted in 30 seconds. The Kubelet will react by sending a graceful termination | ||
// signal to the containers in the pod. Once the resource is deleted in the API, the Kubelet | ||
// will send a hard termination signal to the container. | ||
DeletionTimestamp *util.Time `json:"deletionTimestamp,omitempty"` | ||
|
||
// Labels are key value pairs that may be used to scope and select individual resources. | ||
// Label keys are of the form: | ||
// label-key ::= prefixed-name | name | ||
|
@@ -995,6 +1006,16 @@ type Binding struct { | |
Target ObjectReference `json:"target"` | ||
} | ||
|
||
// DeleteOptions may be provided when deleting an API object | ||
type DeleteOptions struct { | ||
TypeMeta `json:",inline"` | ||
|
||
// Optional duration in seconds before the object should be deleted. Value must be non-negative integer. | ||
// The value zero indicates delete immediately. If this value is nil, the default grace period for the | ||
// specified type will be used. | ||
GracePeriodSeconds *int64 `json:"gracePeriodSeconds"` | ||
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. This is a pointer so we can distinguish Go defaulting from the user specifying 0? 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. Correct. All the other constructs were more awkward (struct wrapped type, etc).
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. Brainstorming other options:
I maybe could get on board with time.Duration (here and elsewhere). It would be similar in spirit to the resource quantity type. 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. Current approach is acceptable, too. 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. It's versioned so before we introduce the first consumer we can rev it. |
||
} | ||
|
||
// Status is a return value for calls that don't return other objects. | ||
// TODO: this could go in apiserver, but I'm including it here so clients needn't | ||
// import both. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,17 @@ type ObjectMeta struct { | |
// Clients may not set this value. It is represented in RFC3339 form and is in UTC. | ||
CreationTimestamp util.Time `json:"creationTimestamp,omitempty" description:"RFC 3339 date and time at which the object was created; populated by the system, read-only; null for lists"` | ||
|
||
// DeletionTimestamp is the time after which this resource will be deleted. This | ||
// field is set by the server when a graceful deletion is requested by the user, and is not | ||
// directly settable by a client. The resource will be deleted (no longer visible from | ||
// resource lists, and not reachable by name) after the time in this field. Once set, this | ||
// value may not be unset or be set further into the future, although it may be shortened | ||
// or the resource may be deleted prior to this time. For example, a user may request that | ||
// a pod is deleted in 30 seconds. The Kubelet will react by sending a graceful termination | ||
// signal to the containers in the pod. Once the resource is deleted in the API, the Kubelet | ||
// will send a hard termination signal to the container. | ||
DeletionTimestamp *util.Time `json:"deletionTimestamp,omitempty" description:"RFC 3339 date and time at which the object will be deleted; populated by the system when a graceful deletion is requested, read-only; if not set, graceful deletion of the object has not been requested"` | ||
|
||
// Labels are key value pairs that may be used to scope and select individual resources. | ||
// TODO: replace map[string]string with labels.LabelSet type | ||
Labels map[string]string `json:"labels,omitempty" description:"map of string keys and values that can be used to organize and categorize objects; may match selectors of replication controllers and services"` | ||
|
@@ -982,6 +993,16 @@ type Binding struct { | |
Target ObjectReference `json:"target" description:"an object to bind to"` | ||
} | ||
|
||
// DeleteOptions may be provided when deleting an API object | ||
type DeleteOptions struct { | ||
TypeMeta `json:",inline"` | ||
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. This is kind and version of the object being deleted? But not namespace, name, etc.? Why are the kind and version needed? I suppose even Status has TypeMeta and ListMeta, but I don't think we need to be able to serialize DeleteOptions, such as in config files. Actually, it would be nice to at least be able to specify uid and resourceVersion, to facilitate preconditions. 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. Kind and version are needed so that we can properly version this struct when it comes in from the API. All objects have to be versioned. I'll add ObjectMeta so this is consistent with Bindings. 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. I know it has to be versioned, but I imagine we'll typically just infer the version from the URL path. I'm fine with ObjectMeta, however. 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. ObjectMeta not needed for this PR. |
||
|
||
// Optional duration in seconds before the object should be deleted. Value must be non-negative integer. | ||
// The value zero indicates delete immediately. If this value is nil, the default grace period for the | ||
// specified type will be used. | ||
GracePeriodSeconds *int64 `json:"gracePeriodSeconds" description:"the duration in seconds to wait before deleting this object; defaults to a per object value if not specified; zero means delete immediately"` | ||
} | ||
|
||
// Status is a return value for calls that don't return other objects. | ||
type Status struct { | ||
TypeMeta `json:",inline"` | ||
|
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.
Why
&grace
?