...
1
2
3
4 package flagutils
5
6 import (
7 "fmt"
8
9 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10 "sigs.k8s.io/cli-utils/pkg/inventory"
11 )
12
13 const (
14 InventoryPolicyFlag = "inventory-policy"
15 InventoryPolicyStrict = "strict"
16 InventoryPolicyAdopt = "adopt"
17 InventoryPolicyForceAdopt = "force-adopt"
18 )
19
20
21
22 func ConvertPropagationPolicy(propagationPolicy string) (metav1.DeletionPropagation, error) {
23 switch propagationPolicy {
24 case string(metav1.DeletePropagationForeground):
25 return metav1.DeletePropagationForeground, nil
26 case string(metav1.DeletePropagationBackground):
27 return metav1.DeletePropagationBackground, nil
28 case string(metav1.DeletePropagationOrphan):
29 return metav1.DeletePropagationOrphan, nil
30 default:
31 return metav1.DeletePropagationBackground, fmt.Errorf(
32 "prune propagation policy must be one of Background, Foreground, Orphan")
33 }
34 }
35
36 func ConvertInventoryPolicy(policy string) (inventory.Policy, error) {
37 switch policy {
38 case InventoryPolicyStrict:
39 return inventory.PolicyMustMatch, nil
40 case InventoryPolicyAdopt:
41 return inventory.PolicyAdoptIfNoInventory, nil
42 case InventoryPolicyForceAdopt:
43 return inventory.PolicyAdoptAll, nil
44 default:
45 return inventory.PolicyMustMatch, fmt.Errorf(
46 "inventory policy must be one of strict, adopt")
47 }
48 }
49
50
51
52 func PathFromArgs(args []string) string {
53 if len(args) == 0 {
54 return "-"
55 }
56 return args[0]
57 }
58
View as plain text