Default to deleting, not retaining, external resources.
Signed-off-by: Nic Cope <negz@rk0n.org>
This commit is contained in:
parent
72cd5521e6
commit
8e173f4a75
|
@ -202,8 +202,9 @@ type ResourceSpec struct {
|
||||||
ProviderReference Reference `json:"providerRef"`
|
ProviderReference Reference `json:"providerRef"`
|
||||||
|
|
||||||
// DeletionPolicy specifies what will happen to the underlying external
|
// DeletionPolicy specifies what will happen to the underlying external
|
||||||
// when this managed resource is deleted. The "Orphan" policy is used when
|
// when this managed resource is deleted - either "Delete" or "Orphan" the
|
||||||
// no policy is specified.
|
// external resource. The "Delete" policy is the default when no policy is
|
||||||
|
// specified.
|
||||||
//
|
//
|
||||||
// +optional
|
// +optional
|
||||||
// +kubebuilder:validation:Enum=Orphan;Delete
|
// +kubebuilder:validation:Enum=Orphan;Delete
|
||||||
|
@ -217,7 +218,7 @@ type ResourceSpec struct {
|
||||||
// when its managed resource is deleted. The "Retain" policy causes the
|
// when its managed resource is deleted. The "Retain" policy causes the
|
||||||
// managed resource to be retained, in binding phase "Released", when its
|
// managed resource to be retained, in binding phase "Released", when its
|
||||||
// resource claim is deleted, and in turn causes the external resource to be
|
// resource claim is deleted, and in turn causes the external resource to be
|
||||||
// retained when its managed resource is deleted. The "Retain" policy is
|
// retained when its managed resource is deleted. The "Delete" policy is
|
||||||
// used when no policy is specified.
|
// used when no policy is specified.
|
||||||
//
|
//
|
||||||
// Deprecated. DeletionPolicy takes precedence when both are set.
|
// Deprecated. DeletionPolicy takes precedence when both are set.
|
||||||
|
@ -257,8 +258,7 @@ type ClassSpecTemplate struct {
|
||||||
// policy causes the managed resource to be retained, in binding phase
|
// policy causes the managed resource to be retained, in binding phase
|
||||||
// "Released", when its resource claim is deleted, and in turn causes the
|
// "Released", when its resource claim is deleted, and in turn causes the
|
||||||
// external resource to be retained when its managed resource is deleted.
|
// external resource to be retained when its managed resource is deleted.
|
||||||
// The "Retain" policy is used when no policy is specified, however the
|
// The "Delete" policy is used when no policy is specified.
|
||||||
// "Delete" policy is set at dynamic provisioning time if no policy is set.
|
|
||||||
// +optional
|
// +optional
|
||||||
// +kubebuilder:validation:Enum=Retain;Delete
|
// +kubebuilder:validation:Enum=Retain;Delete
|
||||||
ReclaimPolicy ReclaimPolicy `json:"reclaimPolicy,omitempty"`
|
ReclaimPolicy ReclaimPolicy `json:"reclaimPolicy,omitempty"`
|
||||||
|
|
|
@ -700,11 +700,18 @@ func (r *Reconciler) Reconcile(req reconcile.Request) (reconcile.Result, error)
|
||||||
// should be inlined when claims (and thus reclaim policies) are removed.
|
// should be inlined when claims (and thus reclaim policies) are removed.
|
||||||
func shouldDelete(mg resource.Managed) bool {
|
func shouldDelete(mg resource.Managed) bool {
|
||||||
switch {
|
switch {
|
||||||
case mg.GetDeletionPolicy() == v1alpha1.DeletionDelete:
|
// The deletion policy should take precedence over the reclaim policy.
|
||||||
return true
|
|
||||||
case mg.GetDeletionPolicy() == v1alpha1.DeletionOrphan:
|
case mg.GetDeletionPolicy() == v1alpha1.DeletionOrphan:
|
||||||
return false
|
return false
|
||||||
|
case mg.GetDeletionPolicy() == v1alpha1.DeletionDelete:
|
||||||
|
return true
|
||||||
|
|
||||||
|
case mg.GetReclaimPolicy() == v1alpha1.ReclaimRetain:
|
||||||
|
return false
|
||||||
|
case mg.GetReclaimPolicy() == v1alpha1.ReclaimDelete:
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return mg.GetReclaimPolicy() == v1alpha1.ReclaimDelete
|
// If no policy is set, we default to deleting the resource.
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -797,11 +797,11 @@ func TestShouldDelete(t *testing.T) {
|
||||||
want: false,
|
want: false,
|
||||||
},
|
},
|
||||||
"NoPolicy": {
|
"NoPolicy": {
|
||||||
reason: "Resources should not be deleted when no deletion or reclaim policy is specified.",
|
reason: "Resources should be deleted when no deletion or reclaim policy is specified.",
|
||||||
mg: &fake.Managed{
|
mg: &fake.Managed{
|
||||||
Reclaimer: fake.Reclaimer{},
|
Reclaimer: fake.Reclaimer{},
|
||||||
},
|
},
|
||||||
want: false,
|
want: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue