Merge pull request #355 from nokia/respect_finalizers
Support foreground cascading deletion
This commit is contained in:
commit
bce61005a1
|
@ -31,6 +31,21 @@ const (
|
|||
DeletionDelete DeletionPolicy = "Delete"
|
||||
)
|
||||
|
||||
// A CompositeDeletePolicy determines how the composite resource should be deleted
|
||||
// when the corresponding claim is deleted.
|
||||
// +kubebuilder:validation:Enum=Background;Foreground
|
||||
type CompositeDeletePolicy string
|
||||
|
||||
const (
|
||||
// CompositeDeleteBackground means the composite resource will be deleted using
|
||||
// the Background Propagation Policy when the claim is deleted.
|
||||
CompositeDeleteBackground CompositeDeletePolicy = "Background"
|
||||
|
||||
// CompositeDeleteForeground means the composite resource will be deleted using
|
||||
// the Foreground Propagation Policy when the claim is deleted.
|
||||
CompositeDeleteForeground CompositeDeletePolicy = "Foreground"
|
||||
)
|
||||
|
||||
// An UpdatePolicy determines how something should be updated - either
|
||||
// automatically (without human intervention) or manually.
|
||||
// +kubebuilder:validation:Enum=Automatic;Manual
|
||||
|
|
|
@ -118,9 +118,10 @@ func AsOwner(r *xpv1.TypedReference) metav1.OwnerReference {
|
|||
// AsController converts the supplied object reference to a controller
|
||||
// reference. You may also consider using metav1.NewControllerRef.
|
||||
func AsController(r *xpv1.TypedReference) metav1.OwnerReference {
|
||||
c := true
|
||||
t := true
|
||||
ref := AsOwner(r)
|
||||
ref.Controller = &c
|
||||
ref.Controller = &t
|
||||
ref.BlockOwnerDeletion = &t
|
||||
return ref
|
||||
}
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ func TestAsOwner(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAsController(t *testing.T) {
|
||||
controller := true
|
||||
flag := true
|
||||
|
||||
tests := map[string]struct {
|
||||
r *xpv1.TypedReference
|
||||
|
@ -176,11 +176,12 @@ func TestAsController(t *testing.T) {
|
|||
UID: uid,
|
||||
},
|
||||
want: metav1.OwnerReference{
|
||||
APIVersion: groupVersion,
|
||||
Kind: kind,
|
||||
Name: name,
|
||||
UID: uid,
|
||||
Controller: &controller,
|
||||
APIVersion: groupVersion,
|
||||
Kind: kind,
|
||||
Name: name,
|
||||
UID: uid,
|
||||
Controller: &flag,
|
||||
BlockOwnerDeletion: &flag,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -204,6 +204,19 @@ func (m *CompositionUpdater) GetCompositionUpdatePolicy() *xpv1.UpdatePolicy {
|
|||
return m.Policy
|
||||
}
|
||||
|
||||
// CompositeResourceDeleter is a mock that implements CompositeResourceDeleter interface.
|
||||
type CompositeResourceDeleter struct{ Policy *xpv1.CompositeDeletePolicy }
|
||||
|
||||
// SetCompositeDeletePolicy sets the CompositeDeletePolicy.
|
||||
func (m *CompositeResourceDeleter) SetCompositeDeletePolicy(p *xpv1.CompositeDeletePolicy) {
|
||||
m.Policy = p
|
||||
}
|
||||
|
||||
// GetCompositeDeletePolicy gets the CompositeDeletePolicy.
|
||||
func (m *CompositeResourceDeleter) GetCompositeDeletePolicy() *xpv1.CompositeDeletePolicy {
|
||||
return m.Policy
|
||||
}
|
||||
|
||||
// CompositeResourceReferencer is a mock that implements CompositeResourceReferencer interface.
|
||||
type CompositeResourceReferencer struct{ Ref *corev1.ObjectReference }
|
||||
|
||||
|
@ -374,6 +387,7 @@ type CompositeClaim struct {
|
|||
CompositionSelector
|
||||
CompositionReferencer
|
||||
CompositionRevisionReferencer
|
||||
CompositeResourceDeleter
|
||||
CompositionUpdater
|
||||
CompositeResourceReferencer
|
||||
LocalConnectionSecretWriterTo
|
||||
|
|
|
@ -130,6 +130,13 @@ type CompositionUpdater interface {
|
|||
GetCompositionUpdatePolicy() *xpv1.UpdatePolicy
|
||||
}
|
||||
|
||||
// A CompositeResourceDeleter creates a composite, and controls the policy
|
||||
// used to delete the composite.
|
||||
type CompositeResourceDeleter interface {
|
||||
SetCompositeDeletePolicy(policy *xpv1.CompositeDeletePolicy)
|
||||
GetCompositeDeletePolicy() *xpv1.CompositeDeletePolicy
|
||||
}
|
||||
|
||||
// A ComposedResourcesReferencer may reference the resources it composes.
|
||||
type ComposedResourcesReferencer interface {
|
||||
SetResourceReferences([]corev1.ObjectReference)
|
||||
|
@ -248,6 +255,7 @@ type CompositeClaim interface {
|
|||
CompositionReferencer
|
||||
CompositionUpdater
|
||||
CompositionRevisionReferencer
|
||||
CompositeResourceDeleter
|
||||
CompositeResourceReferencer
|
||||
LocalConnectionSecretWriterTo
|
||||
ConnectionDetailsPublisherTo
|
||||
|
|
|
@ -87,11 +87,12 @@ func TestLocalConnectionSecretFor(t *testing.T) {
|
|||
Namespace: namespace,
|
||||
Name: secretName,
|
||||
OwnerReferences: []metav1.OwnerReference{{
|
||||
APIVersion: MockOwnerGVK.GroupVersion().String(),
|
||||
Kind: MockOwnerGVK.Kind,
|
||||
Name: name,
|
||||
UID: uid,
|
||||
Controller: &controller,
|
||||
APIVersion: MockOwnerGVK.GroupVersion().String(),
|
||||
Kind: MockOwnerGVK.Kind,
|
||||
Name: name,
|
||||
UID: uid,
|
||||
Controller: &controller,
|
||||
BlockOwnerDeletion: &controller,
|
||||
}},
|
||||
},
|
||||
Type: SecretTypeConnection,
|
||||
|
@ -140,11 +141,12 @@ func TestConnectionSecretFor(t *testing.T) {
|
|||
Namespace: namespace,
|
||||
Name: secretName,
|
||||
OwnerReferences: []metav1.OwnerReference{{
|
||||
APIVersion: MockOwnerGVK.GroupVersion().String(),
|
||||
Kind: MockOwnerGVK.Kind,
|
||||
Name: name,
|
||||
UID: uid,
|
||||
Controller: &controller,
|
||||
APIVersion: MockOwnerGVK.GroupVersion().String(),
|
||||
Kind: MockOwnerGVK.Kind,
|
||||
Name: name,
|
||||
UID: uid,
|
||||
Controller: &controller,
|
||||
BlockOwnerDeletion: &controller,
|
||||
}},
|
||||
},
|
||||
Type: SecretTypeConnection,
|
||||
|
|
|
@ -122,6 +122,21 @@ func (c *Unstructured) GetCompositionUpdatePolicy() *xpv1.UpdatePolicy {
|
|||
return &out
|
||||
}
|
||||
|
||||
// SetCompositeDeletePolicy of this resource claim.
|
||||
func (c *Unstructured) SetCompositeDeletePolicy(p *xpv1.CompositeDeletePolicy) {
|
||||
_ = fieldpath.Pave(c.Object).SetValue("spec.compositeDeletePolicy", p)
|
||||
}
|
||||
|
||||
// GetCompositeDeletePolicy of this resource claim.
|
||||
func (c *Unstructured) GetCompositeDeletePolicy() *xpv1.CompositeDeletePolicy {
|
||||
p, err := fieldpath.Pave(c.Object).GetString("spec.compositeDeletePolicy")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
out := xpv1.CompositeDeletePolicy(p)
|
||||
return &out
|
||||
}
|
||||
|
||||
// GetResourceReference of this composite resource claim.
|
||||
func (c *Unstructured) GetResourceReference() *corev1.ObjectReference {
|
||||
out := &corev1.ObjectReference{}
|
||||
|
|
|
@ -216,6 +216,31 @@ func TestCompositionUpdatePolicy(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCompositeDeletePolicy(t *testing.T) {
|
||||
p := xpv1.CompositeDeleteBackground
|
||||
cases := map[string]struct {
|
||||
u *Unstructured
|
||||
set *xpv1.CompositeDeletePolicy
|
||||
want *xpv1.CompositeDeletePolicy
|
||||
}{
|
||||
"NewRef": {
|
||||
u: New(),
|
||||
set: &p,
|
||||
want: &p,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
tc.u.SetCompositeDeletePolicy(tc.set)
|
||||
got := tc.u.GetCompositeDeletePolicy()
|
||||
if diff := cmp.Diff(tc.want, got); diff != "" {
|
||||
t.Errorf("\nu.GetCompositeDeletePolicy(): -want, +got:\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceReference(t *testing.T) {
|
||||
ref := &corev1.ObjectReference{Namespace: "ns", Name: "cool"}
|
||||
cases := map[string]struct {
|
||||
|
|
Loading…
Reference in New Issue