mirror of https://github.com/fluxcd/cli-utils.git
Merge pull request #320 from Liujingfang1/preprocess
move inventory-policy flags and values to package level constants
This commit is contained in:
commit
27cfaa6752
|
|
@ -56,9 +56,9 @@ func GetApplyRunner(provider provider.Provider, loader manifestreader.ManifestLo
|
||||||
"Background", "Propagation policy for pruning")
|
"Background", "Propagation policy for pruning")
|
||||||
cmd.Flags().DurationVar(&r.pruneTimeout, "prune-timeout", time.Duration(0),
|
cmd.Flags().DurationVar(&r.pruneTimeout, "prune-timeout", time.Duration(0),
|
||||||
"Timeout threshold for waiting for all pruned resources to be deleted")
|
"Timeout threshold for waiting for all pruned resources to be deleted")
|
||||||
cmd.Flags().StringVar(&r.inventoryPolicy, "inventory-policy", "strict",
|
cmd.Flags().StringVar(&r.inventoryPolicy, flagutils.InventoryPolicyFlag, flagutils.InventoryPolicyStrict,
|
||||||
"It determines the behavior when the resources don't belong to current inventory. Available options "+
|
"It determines the behavior when the resources don't belong to current inventory. Available options "+
|
||||||
"\"strict\" and \"adopt\".")
|
fmt.Sprintf("%q and %q.", flagutils.InventoryPolicyStrict, flagutils.InventoryPolicyAdopt))
|
||||||
|
|
||||||
r.Command = cmd
|
r.Command = cmd
|
||||||
return r
|
return r
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,9 @@ func GetDestroyRunner(provider provider.Provider, loader manifestreader.Manifest
|
||||||
|
|
||||||
cmd.Flags().StringVar(&r.output, "output", printers.DefaultPrinter(),
|
cmd.Flags().StringVar(&r.output, "output", printers.DefaultPrinter(),
|
||||||
fmt.Sprintf("Output format, must be one of %s", strings.Join(printers.SupportedPrinters(), ",")))
|
fmt.Sprintf("Output format, must be one of %s", strings.Join(printers.SupportedPrinters(), ",")))
|
||||||
cmd.Flags().StringVar(&r.inventoryPolicy, "inventory-policy", "strict",
|
cmd.Flags().StringVar(&r.inventoryPolicy, flagutils.InventoryPolicyFlag, flagutils.InventoryPolicyStrict,
|
||||||
"It determines the behavior when the resources don't belong to current inventory. Available options "+
|
"It determines the behavior when the resources don't belong to current inventory. Available options "+
|
||||||
"\"strict\" and \"adopt\".")
|
fmt.Sprintf("%q and %q.", flagutils.InventoryPolicyStrict, flagutils.InventoryPolicyAdopt))
|
||||||
|
|
||||||
r.Command = cmd
|
r.Command = cmd
|
||||||
return r
|
return r
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,17 @@ import (
|
||||||
"sigs.k8s.io/cli-utils/pkg/inventory"
|
"sigs.k8s.io/cli-utils/pkg/inventory"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
InventoryPolicyFlag = "inventory-policy"
|
||||||
|
InventoryPolicyStrict = "strict"
|
||||||
|
InventoryPolicyAdopt = "adopt"
|
||||||
|
)
|
||||||
|
|
||||||
func ConvertInventoryPolicy(policy string) (inventory.InventoryPolicy, error) {
|
func ConvertInventoryPolicy(policy string) (inventory.InventoryPolicy, error) {
|
||||||
switch policy {
|
switch policy {
|
||||||
case "strict":
|
case InventoryPolicyStrict:
|
||||||
return inventory.InventoryPolicyMustMatch, nil
|
return inventory.InventoryPolicyMustMatch, nil
|
||||||
case "adopt":
|
case InventoryPolicyAdopt:
|
||||||
return inventory.AdoptIfNoInventory, nil
|
return inventory.AdoptIfNoInventory, nil
|
||||||
default:
|
default:
|
||||||
return inventory.InventoryPolicyMustMatch, fmt.Errorf(
|
return inventory.InventoryPolicyMustMatch, fmt.Errorf(
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,9 @@ func GetPreviewRunner(provider provider.Provider, loader manifestreader.Manifest
|
||||||
cmd.Flags().BoolVar(&previewDestroy, "destroy", previewDestroy, "If true, preview of destroy operations will be displayed.")
|
cmd.Flags().BoolVar(&previewDestroy, "destroy", previewDestroy, "If true, preview of destroy operations will be displayed.")
|
||||||
cmd.Flags().StringVar(&r.output, "output", printers.DefaultPrinter(),
|
cmd.Flags().StringVar(&r.output, "output", printers.DefaultPrinter(),
|
||||||
fmt.Sprintf("Output format, must be one of %s", strings.Join(printers.SupportedPrinters(), ",")))
|
fmt.Sprintf("Output format, must be one of %s", strings.Join(printers.SupportedPrinters(), ",")))
|
||||||
cmd.Flags().StringVar(&r.inventoryPolicy, "inventory-policy", "strict",
|
cmd.Flags().StringVar(&r.inventoryPolicy, flagutils.InventoryPolicyFlag, flagutils.InventoryPolicyStrict,
|
||||||
"It determines the behavior when the resources don't belong to current inventory. Available options "+
|
"It determines the behavior when the resources don't belong to current inventory. Available options "+
|
||||||
"\"strict\" and \"adopt\".")
|
fmt.Sprintf("%q and %q.", flagutils.InventoryPolicyStrict, flagutils.InventoryPolicyAdopt))
|
||||||
|
|
||||||
r.Command = cmd
|
r.Command = cmd
|
||||||
return r
|
return r
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue