Add select-alpha and extract to create policy

Signed-off-by: jonathan-innis <jonathan.innis.ji@gmail.com>
pull/860/head
jonathan-innis 4 years ago
parent 42011d028e
commit 3f0cb1637c
No known key found for this signature in database
GPG Key ID: 5046BA5825A72350

@ -39,9 +39,11 @@ the status of the object.`,
RunE: createImagePolicyRun} RunE: createImagePolicyRun}
type imagePolicyFlags struct { type imagePolicyFlags struct {
imageRef string imageRef string
semver string semver string
filterRegex string alpha string
filterRegex string
filterExtract string
} }
var imagePolicyArgs = imagePolicyFlags{} var imagePolicyArgs = imagePolicyFlags{}
@ -49,8 +51,10 @@ var imagePolicyArgs = imagePolicyFlags{}
func init() { func init() {
flags := createImagePolicyCmd.Flags() flags := createImagePolicyCmd.Flags()
flags.StringVar(&imagePolicyArgs.imageRef, "image-ref", "", "the name of an image repository object") flags.StringVar(&imagePolicyArgs.imageRef, "image-ref", "", "the name of an image repository object")
flags.StringVar(&imagePolicyArgs.semver, "semver", "", "a semver range to apply to tags; e.g., '1.x'") flags.StringVar(&imagePolicyArgs.semver, "select-semver", "", "a semver range to apply to tags; e.g., '1.x'")
flags.StringVar(&imagePolicyArgs.filterRegex, "filter-regex", "", " regular expression pattern used to filter the image tags") flags.StringVar(&imagePolicyArgs.alpha, "select-alpha", "", "use alphabetical sorting to select image; either \"asc\" meaning select the last, or \"desc\" meaning select the first")
flags.StringVar(&imagePolicyArgs.filterRegex, "filter-regex", "", "regular expression pattern used to filter the image tags")
flags.StringVar(&imagePolicyArgs.filterExtract, "filter-extract", "", "replacement pattern (using capture groups from --filter-regex) to use for sorting")
createImageCmd.AddCommand(createImagePolicyCmd) createImageCmd.AddCommand(createImagePolicyCmd)
} }
@ -94,14 +98,27 @@ func createImagePolicyRun(cmd *cobra.Command, args []string) error {
policy.Spec.Policy.SemVer = &imagev1.SemVerPolicy{ policy.Spec.Policy.SemVer = &imagev1.SemVerPolicy{
Range: imagePolicyArgs.semver, Range: imagePolicyArgs.semver,
} }
case imagePolicyArgs.alpha != "":
if imagePolicyArgs.alpha != "desc" && imagePolicyArgs.alpha != "asc" {
return fmt.Errorf("--select-alpha must be one of [\"asc\", \"desc\"]")
}
policy.Spec.Policy.Alphabetical = &imagev1.AlphabeticalPolicy{
Order: imagePolicyArgs.alpha,
}
default: default:
return fmt.Errorf("a policy must be provided with --semver") return fmt.Errorf("a policy must be provided with either --select-semver or --select-alpha")
} }
if imagePolicyArgs.filterRegex != "" { if imagePolicyArgs.filterRegex != "" {
policy.Spec.FilterTags = &imagev1.TagFilter{ policy.Spec.FilterTags = &imagev1.TagFilter{
Pattern: imagePolicyArgs.filterRegex, Pattern: imagePolicyArgs.filterRegex,
} }
if imagePolicyArgs.filterExtract != "" {
policy.Spec.FilterTags.Extract = imagePolicyArgs.filterExtract
}
} else if imagePolicyArgs.filterExtract != "" {
return fmt.Errorf("cannot specify --filter-extract without specifying --filter-regex")
} }
if createArgs.export { if createArgs.export {

Loading…
Cancel
Save