Skip to content

Commit 1367715

Browse files
committed
allow pruning object without owning-inventory annotation
1 parent b9ff655 commit 1367715

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

pkg/inventory/policy.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
// belong to any inventory object.
1515
// This is done by determining if the apply/prune operation
1616
// can go through for a resource based on the comparison
17-
// the inventory-d annotation value in the package and that
18-
// in the live object.
17+
// the inventory-id value in the package and the owning-inventory
18+
// annotation in the live object.
1919
type InventoryPolicy int
2020

2121
const (
@@ -26,12 +26,13 @@ const (
2626
// The apply operation can go through when
2727
// - A new resources in the package doesn't exist in the cluster
2828
// - An existing resource in the package doesn't exist in the cluster
29-
// - An existing resource exist in the cluster. The inventory-id annotation in the live object
29+
// - An existing resource exist in the cluster. The owning-inventory annotation in the live object
3030
// matches with that in the package.
3131
//
3232
// The prune operation can go through when
33-
// - The inventory-id annotation in the live object match with that
33+
// - The owning-inventory annotation in the live object match with that
3434
// in the package.
35+
// - The live object doesn't have the owning-inventory annotation.
3536
InventoryPolicyMustMatch InventoryPolicy = iota
3637

3738
// AdoptIfNoInventory: This policy enforces that resources being applied
@@ -40,26 +41,28 @@ const (
4041
//
4142
// The apply operation can go through when
4243
// - New resource in the package doesn't exist in the cluster
43-
// - If a new resource exist in the cluster, its inventory-id annotation is empty
44+
// - If a new resource exist in the cluster, its owning-inventory annotation is empty
4445
// - Existing resource in the package doesn't exist in the cluster
45-
// - If existing resource exist in the cluster, its inventory-id annotation in the live object
46+
// - If existing resource exist in the cluster, its owning-inventory annotation in the live object
4647
// is empty
47-
// - An existing resource exist in the cluster. The inventory-id annotation in the live object
48+
// - An existing resource exist in the cluster. The owning-inventory annotation in the live object
4849
// matches with that in the package.
4950
//
5051
// The prune operation can go through when
51-
// - The inventory-id annotation in the live object match with that
52+
// - The owning-inventory annotation in the live object match with that
5253
// in the package.
54+
// - The live object doesn't have the owning-inventory annotation.
5355
AdoptIfNoInventory
5456

5557
// AdoptAll: This policy will let the current inventory take ownership of any objects.
5658
//
5759
// The apply operation can go through for any resource in the package even if the
58-
// live object has an unmatched inventory-id annotation.
60+
// live object has an unmatched owning-inventory annotation.
5961
//
6062
// The prune operation can go through when
61-
// - The inventory-id annotation in the live object match with that
63+
// - The owning-inventory annotation in the live object match with that
6264
// in the package.
65+
// - The live object doesn't have the owning-inventory annotation.
6366
AdoptAll
6467
)
6568

@@ -119,7 +122,7 @@ func CanPrune(inv InventoryInfo, obj *unstructured.Unstructured, policy Inventor
119122
matchStatus := inventoryIDMatch(inv, obj)
120123
switch matchStatus {
121124
case Empty:
122-
return false
125+
return true
123126
case Match:
124127
return true
125128
case NoMatch:

pkg/inventory/policy_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,21 +183,21 @@ func TestCanPrune(t *testing.T) {
183183
obj: testObjectWithAnnotation("", ""),
184184
inv: &fakeInventoryInfo{id: "random-id"},
185185
policy: AdoptIfNoInventory,
186-
canPrune: false,
186+
canPrune: true,
187187
},
188188
{
189189
name: "empty with AdoptAll",
190190
obj: testObjectWithAnnotation("", ""),
191191
inv: &fakeInventoryInfo{id: "random-id"},
192192
policy: AdoptAll,
193-
canPrune: false,
193+
canPrune: true,
194194
},
195195
{
196196
name: "empty with InventoryPolicyMustMatch",
197197
obj: testObjectWithAnnotation("", ""),
198198
inv: &fakeInventoryInfo{id: "random-id"},
199199
policy: InventoryPolicyMustMatch,
200-
canPrune: false,
200+
canPrune: true,
201201
},
202202
{
203203
name: "matched with InventoryPolicyMustMatch",

0 commit comments

Comments
 (0)