| 1 |
/* |
| 2 |
Copyright 2019 The Kubernetes Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package rest |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
|
| 22 |
"k8s.io/apimachinery/pkg/runtime" |
| 23 |
"k8s.io/apimachinery/pkg/util/validation/field" |
| 24 |
) |
| 25 |
|
| 26 |
// RESTCreateUpdateStrategy is a union of RESTUpdateStrategy and RESTCreateStrategy, |
| 27 |
// and it defines the minimum validation, accepted input, and name generation |
| 28 |
// behavior to create and update an object that follows Kubernetes API conventions. |
| 29 |
type RESTCreateUpdateStrategy interface { |
| 30 |
RESTCreateStrategy |
| 31 |
// AllowCreateOnUpdate returns true if the object can be created by a PUT. |
| 32 |
AllowCreateOnUpdate() bool |
| 33 |
// PrepareForUpdate is invoked on update before validation to normalize |
| 34 |
// the object. For example: remove fields that are not to be persisted, |
| 35 |
// sort order-insensitive list fields, etc. This should not remove fields |
| 36 |
// whose presence would be considered a validation error. |
| 37 |
PrepareForUpdate(ctx context.Context, obj, old runtime.Object) |
| 38 |
// ValidateUpdate is invoked after default fields in the object have been |
| 39 |
// filled in before the object is persisted. This method should not mutate |
| 40 |
// the object. |
| 41 |
ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList |
| 42 |
// WarningsOnUpdate returns warnings to the client performing the update. |
| 43 |
// WarningsOnUpdate is invoked after default fields in the object have been filled in |
| 44 |
// and after ValidateUpdate has passed, before Canonicalize is called, and before the object is persisted. |
| 45 |
// This method must not mutate either object. |
| 46 |
// |
| 47 |
// Be brief; limit warnings to 120 characters if possible. |
| 48 |
// Don't include a "Warning:" prefix in the message (that is added by clients on output). |
| 49 |
// Warnings returned about a specific field should be formatted as "path.to.field: message". |
| 50 |
// For example: `spec.imagePullSecrets[0].name: invalid empty name ""` |
| 51 |
// |
| 52 |
// Use warning messages to describe problems the client making the API request should correct or be aware of. |
| 53 |
// For example: |
| 54 |
// - use of deprecated fields/labels/annotations that will stop working in a future release |
| 55 |
// - use of obsolete fields/labels/annotations that are non-functional |
| 56 |
// - malformed or invalid specifications that prevent successful handling of the submitted object, |
| 57 |
// but are not rejected by validation for compatibility reasons |
| 58 |
// |
| 59 |
// Warnings should not be returned for fields which cannot be resolved by the caller. |
| 60 |
// For example, do not warn about spec fields in a status update. |
| 61 |
WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string |
| 62 |
// AllowUnconditionalUpdate returns true if the object can be updated |
| 63 |
// unconditionally (irrespective of the latest resource version), when |
| 64 |
// there is no resource version specified in the object. |
| 65 |
AllowUnconditionalUpdate() bool |
| 66 |
} |
| 67 |
|
| 68 |
// Ensure that RESTCreateUpdateStrategy extends RESTCreateStrategy |
| 69 |
var _ RESTCreateStrategy = (RESTCreateUpdateStrategy)(nil) |
| 70 |
|
| 71 |
// Ensure that RESTCreateUpdateStrategy extends RESTUpdateStrategy |
| 72 |
var _ RESTUpdateStrategy = (RESTCreateUpdateStrategy)(nil) |