Skip to content

Commit 30554fd

Browse files
committed
address comments
1 parent 1367715 commit 30554fd

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

pkg/inventory/policy.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const (
3232
// The prune operation can go through when
3333
// - 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.
3635
InventoryPolicyMustMatch InventoryPolicy = iota
3736

3837
// AdoptIfNoInventory: This policy enforces that resources being applied
@@ -60,7 +59,7 @@ const (
6059
// live object has an unmatched owning-inventory annotation.
6160
//
6261
// The prune operation can go through when
63-
// - The owning-inventory annotation in the live object match with that
62+
// - The owning-inventory annotation in the live object match or doesn't match with that
6463
// in the package.
6564
// - The live object doesn't have the owning-inventory annotation.
6665
AdoptAll
@@ -122,11 +121,11 @@ func CanPrune(inv InventoryInfo, obj *unstructured.Unstructured, policy Inventor
122121
matchStatus := inventoryIDMatch(inv, obj)
123122
switch matchStatus {
124123
case Empty:
125-
return true
124+
return policy == AdoptIfNoInventory || policy == AdoptAll
126125
case Match:
127126
return true
128127
case NoMatch:
129-
return false
128+
return policy == AdoptAll
130129
}
131130
return false
132131
}

pkg/inventory/policy_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func TestCanPrune(t *testing.T) {
197197
obj: testObjectWithAnnotation("", ""),
198198
inv: &fakeInventoryInfo{id: "random-id"},
199199
policy: InventoryPolicyMustMatch,
200-
canPrune: true,
200+
canPrune: false,
201201
},
202202
{
203203
name: "matched with InventoryPolicyMustMatch",
@@ -239,7 +239,7 @@ func TestCanPrune(t *testing.T) {
239239
obj: testObjectWithAnnotation(owningInventoryKey, "unmatched"),
240240
inv: &fakeInventoryInfo{id: "random-id"},
241241
policy: AdoptAll,
242-
canPrune: false,
242+
canPrune: true,
243243
},
244244
}
245245
for _, tc := range testcases {

0 commit comments

Comments
 (0)