mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
Fixed RESTCreate/Update interface methods
This commit is contained in:
parent
69d1d235cd
commit
ff86ae0705
@ -56,7 +56,7 @@ func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
store.CreateStrategy = persistentvolume.Strategy
|
store.CreateStrategy = persistentvolume.Strategy
|
||||||
store.UpdateStrategy = persistentvolume.StatusStrategy
|
store.UpdateStrategy = persistentvolume.Strategy
|
||||||
store.ReturnDeletedObject = true
|
store.ReturnDeletedObject = true
|
||||||
|
|
||||||
statusStore := *store
|
statusStore := *store
|
||||||
|
@ -38,34 +38,43 @@ type persistentvolumeStrategy struct {
|
|||||||
// objects via the REST API.
|
// objects via the REST API.
|
||||||
var Strategy = persistentvolumeStrategy{api.Scheme, api.SimpleNameGenerator}
|
var Strategy = persistentvolumeStrategy{api.Scheme, api.SimpleNameGenerator}
|
||||||
|
|
||||||
// NamespaceScoped is false for persistentvolumes.
|
|
||||||
func (persistentvolumeStrategy) NamespaceScoped() bool {
|
func (persistentvolumeStrategy) NamespaceScoped() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetBeforeCreate clears fields that are not allowed to be set by end users on creation.
|
// ResetBeforeCreate clears the Status field which is not allowed to be set by end users on creation.
|
||||||
func (persistentvolumeStrategy) PrepareForCreate(obj runtime.Object) {
|
func (persistentvolumeStrategy) PrepareForCreate(obj runtime.Object) {
|
||||||
pv := obj.(*api.PersistentVolume)
|
pv := obj.(*api.PersistentVolume)
|
||||||
pv.Status = api.PersistentVolumeStatus{}
|
pv.Status = api.PersistentVolumeStatus{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates a new persistentvolume.
|
|
||||||
func (persistentvolumeStrategy) Validate(ctx api.Context, obj runtime.Object) fielderrors.ValidationErrorList {
|
func (persistentvolumeStrategy) Validate(ctx api.Context, obj runtime.Object) fielderrors.ValidationErrorList {
|
||||||
persistentvolume := obj.(*api.PersistentVolume)
|
persistentvolume := obj.(*api.PersistentVolume)
|
||||||
return validation.ValidatePersistentVolume(persistentvolume)
|
return validation.ValidatePersistentVolume(persistentvolume)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AllowCreateOnUpdate is false for persistentvolumes.
|
|
||||||
func (persistentvolumeStrategy) AllowCreateOnUpdate() bool {
|
func (persistentvolumeStrategy) AllowCreateOnUpdate() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PrepareForUpdate sets the Status fields which is not allowed to be set by an end user updating a PV
|
||||||
|
func (persistentvolumeStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
||||||
|
newPv := obj.(*api.PersistentVolume)
|
||||||
|
oldPv := obj.(*api.PersistentVolume)
|
||||||
|
newPv.Status = oldPv.Status
|
||||||
|
}
|
||||||
|
|
||||||
|
func (persistentvolumeStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||||||
|
return validation.ValidatePersistentVolumeUpdate(obj.(*api.PersistentVolume), old.(*api.PersistentVolume))
|
||||||
|
}
|
||||||
|
|
||||||
type persistentvolumeStatusStrategy struct {
|
type persistentvolumeStatusStrategy struct {
|
||||||
persistentvolumeStrategy
|
persistentvolumeStrategy
|
||||||
}
|
}
|
||||||
|
|
||||||
var StatusStrategy = persistentvolumeStatusStrategy{Strategy}
|
var StatusStrategy = persistentvolumeStatusStrategy{Strategy}
|
||||||
|
|
||||||
|
// PrepareForUpdate sets the Spec field which is not allowed to be changed when updating a PV's Status
|
||||||
func (persistentvolumeStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
func (persistentvolumeStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
||||||
newPv := obj.(*api.PersistentVolume)
|
newPv := obj.(*api.PersistentVolume)
|
||||||
oldPv := obj.(*api.PersistentVolume)
|
oldPv := obj.(*api.PersistentVolume)
|
||||||
|
@ -56,7 +56,7 @@ func NewStorage(h tools.EtcdHelper) *REST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
store.CreateStrategy = persistentvolumeclaim.Strategy
|
store.CreateStrategy = persistentvolumeclaim.Strategy
|
||||||
store.UpdateStrategy = persistentvolumeclaim.StatusStrategy
|
store.UpdateStrategy = persistentvolumeclaim.Strategy
|
||||||
store.ReturnDeletedObject = true
|
store.ReturnDeletedObject = true
|
||||||
|
|
||||||
return &REST{store}
|
return &REST{store}
|
||||||
|
@ -38,49 +38,34 @@ type persistentvolumeclaimStrategy struct {
|
|||||||
// objects via the REST API.
|
// objects via the REST API.
|
||||||
var Strategy = persistentvolumeclaimStrategy{api.Scheme, api.SimpleNameGenerator}
|
var Strategy = persistentvolumeclaimStrategy{api.Scheme, api.SimpleNameGenerator}
|
||||||
|
|
||||||
// NamespaceScoped is true for persistentvolumeclaims.
|
|
||||||
func (persistentvolumeclaimStrategy) NamespaceScoped() bool {
|
func (persistentvolumeclaimStrategy) NamespaceScoped() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetBeforeCreate clears fields that are not allowed to be set by end users on creation.
|
// PrepareForCreate clears the Status field which is not allowed to be set by end users on creation.
|
||||||
func (persistentvolumeclaimStrategy) PrepareForCreate(obj runtime.Object) {
|
func (persistentvolumeclaimStrategy) PrepareForCreate(obj runtime.Object) {
|
||||||
pv := obj.(*api.PersistentVolumeClaim)
|
pv := obj.(*api.PersistentVolumeClaim)
|
||||||
pv.Status = api.PersistentVolumeClaimStatus{}
|
pv.Status = api.PersistentVolumeClaimStatus{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
func (persistentvolumeclaimStrategy) Validate(ctx api.Context, obj runtime.Object) fielderrors.ValidationErrorList {
|
||||||
|
pvc := obj.(*api.PersistentVolumeClaim)
|
||||||
|
return validation.ValidatePersistentVolumeClaim(pvc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (persistentvolumeclaimStrategy) AllowCreateOnUpdate() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrepareForUpdate sets the Status field which is not allowed to be set by end users on update
|
||||||
func (persistentvolumeclaimStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
func (persistentvolumeclaimStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
||||||
newPvc := obj.(*api.PersistentVolumeClaim)
|
newPvc := obj.(*api.PersistentVolumeClaim)
|
||||||
oldPvc := obj.(*api.PersistentVolumeClaim)
|
oldPvc := obj.(*api.PersistentVolumeClaim)
|
||||||
newPvc.Status = oldPvc.Status
|
newPvc.Status = oldPvc.Status
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates a new persistentvolumeclaim.
|
func (persistentvolumeclaimStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||||||
func (persistentvolumeclaimStrategy) Validate(ctx api.Context, obj runtime.Object) fielderrors.ValidationErrorList {
|
return validation.ValidatePersistentVolumeClaimUpdate(obj.(*api.PersistentVolumeClaim), old.(*api.PersistentVolumeClaim))
|
||||||
pvc := obj.(*api.PersistentVolumeClaim)
|
|
||||||
return validation.ValidatePersistentVolumeClaim(pvc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AllowCreateOnUpdate is false for persistentvolumeclaims.
|
|
||||||
func (persistentvolumeclaimStrategy) AllowCreateOnUpdate() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
type persistentvolumeclaimStatusStrategy struct {
|
|
||||||
persistentvolumeclaimStrategy
|
|
||||||
}
|
|
||||||
|
|
||||||
var StatusStrategy = persistentvolumeclaimStatusStrategy{Strategy}
|
|
||||||
|
|
||||||
func (persistentvolumeclaimStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
|
||||||
newPvc := obj.(*api.PersistentVolumeClaim)
|
|
||||||
oldPvc := obj.(*api.PersistentVolumeClaim)
|
|
||||||
newPvc.Spec = oldPvc.Spec
|
|
||||||
}
|
|
||||||
|
|
||||||
func (persistentvolumeclaimStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
|
||||||
return validation.ValidatePersistentVolumeClaimStatusUpdate(obj.(*api.PersistentVolumeClaim), old.(*api.PersistentVolumeClaim))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MatchPersistentVolumeClaim returns a generic matcher for a given label and field selector.
|
// MatchPersistentVolumeClaim returns a generic matcher for a given label and field selector.
|
||||||
|
Loading…
Reference in New Issue
Block a user