Skip to content

Commit bff0ab8

Browse files
committed
add inventory policy
1 parent b023543 commit bff0ab8

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

pkg/apply/applier.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ type Options struct {
275275
// to be fully deleted after pruning, and if so, how long we should
276276
// wait.
277277
PruneTimeout time.Duration
278+
279+
// InventoryPolicy defines the inventory policy of apply.
280+
InventoryPolicy inventory.InventoryPolicy
278281
}
279282

280283
// setDefaults set the options to the default values if they

pkg/apply/prune/prune.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ type Options struct {
7676
DryRunStrategy common.DryRunStrategy
7777

7878
PropagationPolicy metav1.DeletionPropagation
79+
80+
// InventoryPolicy defines the inventory policy of prune.
81+
InventoryPolicy inventory.InventoryPolicy
7982
}
8083

8184
// Prune deletes the set of resources which were previously applied

pkg/inventory/policy.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2019 The Kubernetes Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package inventory
5+
6+
// InventoryPolicy defines if an inventory object can take over
7+
// objects that belong to another inventory object or don't
8+
// belong to any inventory object.
9+
// This is done by determining if the apply/prune operation
10+
// can go through for a resource based on the comparison
11+
// the inventory-d annotation value in the package and that
12+
// in the live object.
13+
type InventoryPolicy int
14+
15+
const (
16+
// InvnetoryPolicyMustMatch: This policy enforces that the resources being applied can not
17+
// have any overlap with objects in other inventories or objects that already exist
18+
// in the cluster but don't belong to an inventory.
19+
//
20+
// The apply operation can go through when
21+
// - A new resources in the package doesn't exist in the cluster
22+
// - An existing resource in the package doesn't exist in the cluster
23+
// - An existing resource exist in the cluster. The inventory-id annotation in the live object
24+
// matches with that in the package.
25+
//
26+
// The prune operation can go through when
27+
// - The inventory-id annotation in the live object match with that
28+
// in the package.
29+
InventoryPolicyMustMatch InventoryPolicy = iota
30+
31+
// AdoptIfNoInventory: This policy enforces that resources being applied
32+
// can not have any overlap with objects in other inventories, but are
33+
// permitted to take ownership of objects that don't belong to any inventories.
34+
//
35+
// The apply operation can go through when
36+
// - New resource in the package doesn't exist in the cluster
37+
// - If a new resource exist in the cluster, its inventory-id annotation is empty
38+
// - Existing resource in the package doesn't exist in the cluster
39+
// - If existing resource exist in the cluster, its inventory-id annotation in the live object
40+
// is empty
41+
// - An existing resource exist in the cluster. The inventory-id annotation in the live object
42+
// matches with that in the package.
43+
//
44+
// The prune operation can go through when
45+
// - The inventory-id annotation in the live object match with that
46+
// in the package.
47+
AdoptIfNoInventory
48+
49+
// AdoptAll: This policy will let the current inventory take ownership of any objects.
50+
//
51+
// The apply operation can go through for any resource in the package even if the
52+
// live object has an unmatched inventory-id annotation.
53+
//
54+
// The prune operation can go through when
55+
// - The inventory-id annotation in the live object match with that
56+
// in the package.
57+
AdoptAll
58+
)

0 commit comments

Comments
 (0)