Add WarningsOnCreate,WarningsOnUpdate
Kubernetes-commit: 8c8a4cf3e4a18e97359ce750530a4fa27bbd3b88
This commit is contained in:
parent
fb91318663
commit
8dd82c2391
|
|
@ -115,9 +115,15 @@ func (t *testRESTStrategy) PrepareForUpdate(ctx context.Context, obj, old runtim
|
|||
func (t *testRESTStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
|
||||
return nil
|
||||
}
|
||||
func (t *testRESTStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
|
||||
return nil
|
||||
}
|
||||
func (t *testRESTStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return nil
|
||||
}
|
||||
func (t *testRESTStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
|
||||
return nil
|
||||
}
|
||||
func (t *testRESTStrategy) Canonicalize(obj runtime.Object) {}
|
||||
|
||||
func NewTestGenericStoreRegistry(t *testing.T) (factory.DestroyFunc, *Store) {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import (
|
|||
"k8s.io/apiserver/pkg/features"
|
||||
"k8s.io/apiserver/pkg/storage/names"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/apiserver/pkg/warning"
|
||||
)
|
||||
|
||||
// RESTCreateStrategy defines the minimum validation, accepted input, and
|
||||
|
|
@ -59,6 +60,26 @@ type RESTCreateStrategy interface {
|
|||
// before the object is persisted. This method should not mutate the
|
||||
// object.
|
||||
Validate(ctx context.Context, obj runtime.Object) field.ErrorList
|
||||
// WarningsOnCreate returns warnings to the client performing a create.
|
||||
// WarningsOnCreate is invoked after default fields in the object have been filled in
|
||||
// and after Validate has passed, before Canonicalize is called, and the object is persisted.
|
||||
// This method must not mutate the object.
|
||||
//
|
||||
// Be brief; limit warnings to 120 characters if possible.
|
||||
// Don't include a "Warning:" prefix in the message (that is added by clients on output).
|
||||
// Warnings returned about a specific field should be formatted as "path.to.field: message".
|
||||
// For example: `spec.imagePullSecrets[0].name: invalid empty name ""`
|
||||
//
|
||||
// Use warning messages to describe problems the client making the API request should correct or be aware of.
|
||||
// For example:
|
||||
// - use of deprecated fields/labels/annotations that will stop working in a future release
|
||||
// - use of obsolete fields/labels/annotations that are non-functional
|
||||
// - malformed or invalid specifications that prevent successful handling of the submitted object,
|
||||
// but are not rejected by validation for compatibility reasons
|
||||
//
|
||||
// Warnings should not be returned for fields which cannot be resolved by the caller.
|
||||
// For example, do not warn about spec fields in a subresource creation request.
|
||||
WarningsOnCreate(ctx context.Context, obj runtime.Object) []string
|
||||
// Canonicalize allows an object to be mutated into a canonical form. This
|
||||
// ensures that code that operates on these objects can rely on the common
|
||||
// form for things like comparison. Canonicalize is invoked after
|
||||
|
|
@ -113,6 +134,10 @@ func BeforeCreate(strategy RESTCreateStrategy, ctx context.Context, obj runtime.
|
|||
return errors.NewInvalid(kind.GroupKind(), objectMeta.GetName(), errs)
|
||||
}
|
||||
|
||||
for _, w := range strategy.WarningsOnCreate(ctx, obj) {
|
||||
warning.AddWarning(ctx, "", w)
|
||||
}
|
||||
|
||||
strategy.Canonicalize(obj)
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -39,6 +39,26 @@ type RESTCreateUpdateStrategy interface {
|
|||
// filled in before the object is persisted. This method should not mutate
|
||||
// the object.
|
||||
ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList
|
||||
// WarningsOnUpdate returns warnings to the client performing the update.
|
||||
// WarningsOnUpdate is invoked after default fields in the object have been filled in
|
||||
// and after ValidateUpdate has passed, before Canonicalize is called, and before the object is persisted.
|
||||
// This method must not mutate either object.
|
||||
//
|
||||
// Be brief; limit warnings to 120 characters if possible.
|
||||
// Don't include a "Warning:" prefix in the message (that is added by clients on output).
|
||||
// Warnings returned about a specific field should be formatted as "path.to.field: message".
|
||||
// For example: `spec.imagePullSecrets[0].name: invalid empty name ""`
|
||||
//
|
||||
// Use warning messages to describe problems the client making the API request should correct or be aware of.
|
||||
// For example:
|
||||
// - use of deprecated fields/labels/annotations that will stop working in a future release
|
||||
// - use of obsolete fields/labels/annotations that are non-functional
|
||||
// - malformed or invalid specifications that prevent successful handling of the submitted object,
|
||||
// but are not rejected by validation for compatibility reasons
|
||||
//
|
||||
// Warnings should not be returned for fields which cannot be resolved by the caller.
|
||||
// For example, do not warn about spec fields in a status update.
|
||||
WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string
|
||||
// AllowUnconditionalUpdate returns true if the object can be updated
|
||||
// unconditionally (irrespective of the latest resource version), when
|
||||
// there is no resource version specified in the object.
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
"k8s.io/apiserver/pkg/admission"
|
||||
"k8s.io/apiserver/pkg/features"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/apiserver/pkg/warning"
|
||||
)
|
||||
|
||||
// RESTUpdateStrategy defines the minimum validation, accepted input, and
|
||||
|
|
@ -51,6 +52,26 @@ type RESTUpdateStrategy interface {
|
|||
// filled in before the object is persisted. This method should not mutate
|
||||
// the object.
|
||||
ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList
|
||||
// WarningsOnUpdate returns warnings to the client performing the update.
|
||||
// WarningsOnUpdate is invoked after default fields in the object have been filled in
|
||||
// and after ValidateUpdate has passed, before Canonicalize is called, and before the object is persisted.
|
||||
// This method must not mutate either object.
|
||||
//
|
||||
// Be brief; limit warnings to 120 characters if possible.
|
||||
// Don't include a "Warning:" prefix in the message (that is added by clients on output).
|
||||
// Warnings returned about a specific field should be formatted as "path.to.field: message".
|
||||
// For example: `spec.imagePullSecrets[0].name: invalid empty name ""`
|
||||
//
|
||||
// Use warning messages to describe problems the client making the API request should correct or be aware of.
|
||||
// For example:
|
||||
// - use of deprecated fields/labels/annotations that will stop working in a future release
|
||||
// - use of obsolete fields/labels/annotations that are non-functional
|
||||
// - malformed or invalid specifications that prevent successful handling of the submitted object,
|
||||
// but are not rejected by validation for compatibility reasons
|
||||
//
|
||||
// Warnings should not be returned for fields which cannot be resolved by the caller.
|
||||
// For example, do not warn about spec fields in a status update.
|
||||
WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string
|
||||
// Canonicalize allows an object to be mutated into a canonical form. This
|
||||
// ensures that code that operates on these objects can rely on the common
|
||||
// form for things like comparison. Canonicalize is invoked after
|
||||
|
|
@ -144,6 +165,10 @@ func BeforeUpdate(strategy RESTUpdateStrategy, ctx context.Context, obj, old run
|
|||
return errors.NewInvalid(kind.GroupKind(), objectMeta.GetName(), errs)
|
||||
}
|
||||
|
||||
for _, w := range strategy.WarningsOnUpdate(ctx, obj, old) {
|
||||
warning.AddWarning(ctx, "", w)
|
||||
}
|
||||
|
||||
strategy.Canonicalize(obj)
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Reference in New Issue