mirror of https://github.com/k3s-io/k3s
Fixed RESTCreate/Update interface methods
parent
69d1d235cd
commit
ff86ae0705
|
@ -56,7 +56,7 @@ func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
|
|||
}
|
||||
|
||||
store.CreateStrategy = persistentvolume.Strategy
|
||||
store.UpdateStrategy = persistentvolume.StatusStrategy
|
||||
store.UpdateStrategy = persistentvolume.Strategy
|
||||
store.ReturnDeletedObject = true
|
||||
|
||||
statusStore := *store
|
||||
|
|
|
@ -38,34 +38,43 @@ type persistentvolumeStrategy struct {
|
|||
// objects via the REST API.
|
||||
var Strategy = persistentvolumeStrategy{api.Scheme, api.SimpleNameGenerator}
|
||||
|
||||
// NamespaceScoped is false for persistentvolumes.
|
||||
func (persistentvolumeStrategy) NamespaceScoped() bool {
|
||||
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) {
|
||||
pv := obj.(*api.PersistentVolume)
|
||||
pv.Status = api.PersistentVolumeStatus{}
|
||||
}
|
||||
|
||||
// Validate validates a new persistentvolume.
|
||||
func (persistentvolumeStrategy) Validate(ctx api.Context, obj runtime.Object) fielderrors.ValidationErrorList {
|
||||
persistentvolume := obj.(*api.PersistentVolume)
|
||||
return validation.ValidatePersistentVolume(persistentvolume)
|
||||
}
|
||||
|
||||
// AllowCreateOnUpdate is false for persistentvolumes.
|
||||
func (persistentvolumeStrategy) AllowCreateOnUpdate() bool {
|
||||
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 {
|
||||
persistentvolumeStrategy
|
||||
}
|
||||
|
||||
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) {
|
||||
newPv := obj.(*api.PersistentVolume)
|
||||
oldPv := obj.(*api.PersistentVolume)
|
||||
|
|
|
@ -56,7 +56,7 @@ func NewStorage(h tools.EtcdHelper) *REST {
|
|||
}
|
||||
|
||||
store.CreateStrategy = persistentvolumeclaim.Strategy
|
||||
store.UpdateStrategy = persistentvolumeclaim.StatusStrategy
|
||||
store.UpdateStrategy = persistentvolumeclaim.Strategy
|
||||
store.ReturnDeletedObject = true
|
||||
|
||||
return &REST{store}
|
||||
|
|
|
@ -38,49 +38,34 @@ type persistentvolumeclaimStrategy struct {
|
|||
// objects via the REST API.
|
||||
var Strategy = persistentvolumeclaimStrategy{api.Scheme, api.SimpleNameGenerator}
|
||||
|
||||
// NamespaceScoped is true for persistentvolumeclaims.
|
||||
func (persistentvolumeclaimStrategy) NamespaceScoped() bool {
|
||||
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) {
|
||||
pv := obj.(*api.PersistentVolumeClaim)
|
||||
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) {
|
||||
newPvc := obj.(*api.PersistentVolumeClaim)
|
||||
oldPvc := obj.(*api.PersistentVolumeClaim)
|
||||
newPvc.Status = oldPvc.Status
|
||||
}
|
||||
|
||||
// Validate validates a new persistentvolumeclaim.
|
||||
func (persistentvolumeclaimStrategy) Validate(ctx api.Context, obj runtime.Object) fielderrors.ValidationErrorList {
|
||||
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))
|
||||
func (persistentvolumeclaimStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||||
return validation.ValidatePersistentVolumeClaimUpdate(obj.(*api.PersistentVolumeClaim), old.(*api.PersistentVolumeClaim))
|
||||
}
|
||||
|
||||
// MatchPersistentVolumeClaim returns a generic matcher for a given label and field selector.
|
||||
|
|
Loading…
Reference in New Issue