Merge pull request #320 from Liujingfang1/preprocess

move inventory-policy flags and values to package level constants
This commit is contained in:
Kubernetes Prow Robot 2021-01-27 11:27:08 -08:00 committed by GitHub
commit 27cfaa6752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 8 deletions

View File

@ -56,9 +56,9 @@ func GetApplyRunner(provider provider.Provider, loader manifestreader.ManifestLo
"Background", "Propagation policy for pruning")
cmd.Flags().DurationVar(&r.pruneTimeout, "prune-timeout", time.Duration(0),
"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 "+
"\"strict\" and \"adopt\".")
fmt.Sprintf("%q and %q.", flagutils.InventoryPolicyStrict, flagutils.InventoryPolicyAdopt))
r.Command = cmd
return r

View File

@ -37,9 +37,9 @@ func GetDestroyRunner(provider provider.Provider, loader manifestreader.Manifest
cmd.Flags().StringVar(&r.output, "output", printers.DefaultPrinter(),
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 "+
"\"strict\" and \"adopt\".")
fmt.Sprintf("%q and %q.", flagutils.InventoryPolicyStrict, flagutils.InventoryPolicyAdopt))
r.Command = cmd
return r

View File

@ -9,11 +9,17 @@ import (
"sigs.k8s.io/cli-utils/pkg/inventory"
)
const (
InventoryPolicyFlag = "inventory-policy"
InventoryPolicyStrict = "strict"
InventoryPolicyAdopt = "adopt"
)
func ConvertInventoryPolicy(policy string) (inventory.InventoryPolicy, error) {
switch policy {
case "strict":
case InventoryPolicyStrict:
return inventory.InventoryPolicyMustMatch, nil
case "adopt":
case InventoryPolicyAdopt:
return inventory.AdoptIfNoInventory, nil
default:
return inventory.InventoryPolicyMustMatch, fmt.Errorf(

View File

@ -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().StringVar(&r.output, "output", printers.DefaultPrinter(),
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 "+
"\"strict\" and \"adopt\".")
fmt.Sprintf("%q and %q.", flagutils.InventoryPolicyStrict, flagutils.InventoryPolicyAdopt))
r.Command = cmd
return r