add inventory policy

This commit is contained in:
Jingfang Liu 2020-11-19 14:59:15 -08:00
parent b023543ed6
commit bff0ab8ace
3 changed files with 64 additions and 0 deletions

View File

@ -275,6 +275,9 @@ type Options struct {
// to be fully deleted after pruning, and if so, how long we should
// wait.
PruneTimeout time.Duration
// InventoryPolicy defines the inventory policy of apply.
InventoryPolicy inventory.InventoryPolicy
}
// setDefaults set the options to the default values if they

View File

@ -76,6 +76,9 @@ type Options struct {
DryRunStrategy common.DryRunStrategy
PropagationPolicy metav1.DeletionPropagation
// InventoryPolicy defines the inventory policy of prune.
InventoryPolicy inventory.InventoryPolicy
}
// Prune deletes the set of resources which were previously applied

58
pkg/inventory/policy.go Normal file
View File

@ -0,0 +1,58 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package inventory
// InventoryPolicy defines if an inventory object can take over
// objects that belong to another inventory object or don't
// belong to any inventory object.
// This is done by determining if the apply/prune operation
// can go through for a resource based on the comparison
// the inventory-d annotation value in the package and that
// in the live object.
type InventoryPolicy int
const (
// InvnetoryPolicyMustMatch: This policy enforces that the resources being applied can not
// have any overlap with objects in other inventories or objects that already exist
// in the cluster but don't belong to an inventory.
//
// The apply operation can go through when
// - A new resources in the package doesn't exist in the cluster
// - An existing resource in the package doesn't exist in the cluster
// - An existing resource exist in the cluster. The inventory-id annotation in the live object
// matches with that in the package.
//
// The prune operation can go through when
// - The inventory-id annotation in the live object match with that
// in the package.
InventoryPolicyMustMatch InventoryPolicy = iota
// AdoptIfNoInventory: This policy enforces that resources being applied
// can not have any overlap with objects in other inventories, but are
// permitted to take ownership of objects that don't belong to any inventories.
//
// The apply operation can go through when
// - New resource in the package doesn't exist in the cluster
// - If a new resource exist in the cluster, its inventory-id annotation is empty
// - Existing resource in the package doesn't exist in the cluster
// - If existing resource exist in the cluster, its inventory-id annotation in the live object
// is empty
// - An existing resource exist in the cluster. The inventory-id annotation in the live object
// matches with that in the package.
//
// The prune operation can go through when
// - The inventory-id annotation in the live object match with that
// in the package.
AdoptIfNoInventory
// AdoptAll: This policy will let the current inventory take ownership of any objects.
//
// The apply operation can go through for any resource in the package even if the
// live object has an unmatched inventory-id annotation.
//
// The prune operation can go through when
// - The inventory-id annotation in the live object match with that
// in the package.
AdoptAll
)