-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Expand the generic registry #4419
Changes from all commits
abe8adc
78385b1
23d199d
8440310
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,59 @@ | ||
/* | ||
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/api/errors" | ||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" | ||
) | ||
|
||
// RESTUpdateStrategy defines the minimum validation, accepted input, and | ||
// name generation behavior to update an object that follows Kubernetes | ||
// API conventions. A resource may have many UpdateStrategies, depending on | ||
// the call pattern in use. | ||
type RESTUpdateStrategy interface { | ||
runtime.ObjectTyper | ||
// NamespaceScoped returns true if the object must be within a namespace. | ||
NamespaceScoped() bool | ||
// AllowCreateOnUpdate returns true if the object can be created by a PUT. | ||
AllowCreateOnUpdate() bool | ||
// ValidateUpdate is invoked after default fields in the object have been filled in before | ||
// the object is persisted. | ||
ValidateUpdate(obj, old runtime.Object) errors.ValidationErrorList | ||
} | ||
|
||
// BeforeUpdate ensures that common operations for all resources are performed on update. It only returns | ||
// errors that can be converted to api.Status. It will invoke update validation with the provided existing | ||
// and updated objects. | ||
func BeforeUpdate(strategy RESTUpdateStrategy, ctx api.Context, obj, old runtime.Object) error { | ||
objectMeta, kind, kerr := objectMetaAndKind(strategy, obj) | ||
if kerr != nil { | ||
return kerr | ||
} | ||
if strategy.NamespaceScoped() { | ||
if !api.ValidNamespace(ctx, objectMeta) { | ||
return errors.NewBadRequest("the namespace of the provided object does not match the namespace sent on the request") | ||
} | ||
} else { | ||
objectMeta.Namespace = api.NamespaceNone | ||
} | ||
if errs := strategy.ValidateUpdate(obj, old); len(errs) > 0 { | ||
return errors.NewInvalid(kind, objectMeta.Name, errs) | ||
} | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -561,7 +561,8 @@ func ValidatePodSpec(spec *api.PodSpec) errs.ValidationErrorList { | |
return allErrs | ||
} | ||
|
||
// ValidatePodUpdate tests to see if the update is legal | ||
// ValidatePodUpdate tests to see if the update is legal for an end user to make. newPod is updated with fields | ||
// that cannot be changed. | ||
func ValidatePodUpdate(newPod, oldPod *api.Pod) errs.ValidationErrorList { | ||
allErrs := errs.ValidationErrorList{} | ||
|
||
|
@@ -584,6 +585,7 @@ func ValidatePodUpdate(newPod, oldPod *api.Pod) errs.ValidationErrorList { | |
allErrs = append(allErrs, errs.NewFieldInvalid("spec.containers", newPod.Spec.Containers, "some fields are immutable")) | ||
} | ||
|
||
newPod.Status = oldPod.Status | ||
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 was just a bug? 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 probably could be moved into 4248 - it's still correct, but 4248 is where the reset really needs to happen. 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. Please do. 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. Nevermind. |
||
return allErrs | ||
} | ||
|
||
|
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.
Is Strategy still the right name for this? It's an ObjectTyper and NameGenerator? Why are these separate, anyhow?
Could we please adopt a convention for declaring what interfaces receivers implement? #2992
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.
Also, aren't these included in RESTCreateStrategy directly? Should RESTCreateStrategy use this strategy? Does RESTUpdateStrategy invoke RESTCreateStrategy for the create-on-put case?
I'm not getting the big picture of the organization we're moving towards.
Don't get me wrong -- this is better than what we have. But, I'm still not seeing the forest through the trees.
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.
In my later pull I moved this class to
pkg/registry/pod/types.go
as "pod.Strategy". So this is the default implementation of the basic pod strategy. I can add the comments here to make that clear.RESTCreate and RESTUpdate are separate. There would be a different RESTUpdateStrategy for updating the pods as a regular user (PUT /pods/foo) vs updating status (PUT /pods/foo/status -> RESTStatusUpdateStrategy). The separate strategy implementation there is just so we can guarantee type safety (the reflective implementation doesn't buy us a lot).
smarterclayton@dc4c9da#diff-189461deaff2db4ed8975a0bd74f9b4fR43
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.
I'll add that convention into #4248 since it's moved.
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.
I'm open to better names - Creater or Updater might confuse people with apiserver.RESTCreater, but there is a parallel.
----- Original Message -----
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.
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.
Thanks. I'll look at the later pulls next.