Add missing lifecycle versioning config parameters (#3565)
Add the following flags to mc ilm command: --expired-object-delete-marker --noncurrentversion-expiration-days --noncurrentversion-transition-days --noncurrentversion-transition-storage-class
This commit is contained in:
@@ -90,6 +90,22 @@ var ilmAddFlags = []cli.Flag{
|
||||
Name: "disable",
|
||||
Usage: "disable the rule",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "expired-object-delete-marker",
|
||||
Usage: "remove delete markers with no parallel versions",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "noncurrentversion-expiration-days",
|
||||
Usage: "the number of days to remove noncurrent versions",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "noncurrentversion-transition-days",
|
||||
Usage: "the number of days to transition noncurrent versions",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "noncurrentversion-transition-storage-class",
|
||||
Usage: "the transition storage class for noncurrent versions",
|
||||
},
|
||||
}
|
||||
|
||||
type ilmAddMessage struct {
|
||||
|
||||
+9
-33
@@ -57,40 +57,16 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
var ilmEditFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "id",
|
||||
Usage: "id of the rule to be modified",
|
||||
var ilmEditFlags = append(
|
||||
// Start by showing --id in edit command
|
||||
[]cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "id",
|
||||
Usage: "id of the rule to be modified",
|
||||
},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tags",
|
||||
Usage: "format '<key1>=<value1>&<key2>=<value2>&<key3>=<value3>', multiple values allowed for multiple key/value pairs",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "expiry-date",
|
||||
Usage: "format 'YYYY-MM-DD' the date of expiration",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "expiry-days",
|
||||
Usage: "the number of days to expiration",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "transition-date",
|
||||
Usage: "format 'YYYY-MM-DD' for the date to transition",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "transition-days",
|
||||
Usage: "the number of days to transition",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "storage-class",
|
||||
Usage: "storage class for transition (STANDARD_IA, ONEZONE_IA, GLACIER. Etc)",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "disable",
|
||||
Usage: "disable the rule",
|
||||
},
|
||||
}
|
||||
ilmAddFlags...,
|
||||
)
|
||||
|
||||
type ilmEditMessage struct {
|
||||
Status string `json:"status"`
|
||||
|
||||
+2
-2
@@ -23,10 +23,10 @@ import (
|
||||
)
|
||||
|
||||
var ilmSubcommands = []cli.Command{
|
||||
ilmLsCmd,
|
||||
ilmAddCmd,
|
||||
ilmRmCmd,
|
||||
ilmEditCmd,
|
||||
ilmLsCmd,
|
||||
ilmRmCmd,
|
||||
ilmExportCmd,
|
||||
ilmImportCmd,
|
||||
}
|
||||
|
||||
+28
-11
@@ -111,6 +111,11 @@ type LifecycleOptions struct {
|
||||
TransitionDate string
|
||||
TransitionDays string
|
||||
StorageClass string
|
||||
|
||||
ExpiredObjectDeleteMarker bool
|
||||
NoncurrentVersionExpirationDays int
|
||||
NoncurrentVersionTransitionDays int
|
||||
NoncurrentVersionTransitionStorageClass string
|
||||
}
|
||||
|
||||
// ToConfig create lifecycle.Configuration based on LifecycleOptions
|
||||
@@ -146,6 +151,13 @@ func (opts LifecycleOptions) ToConfig(config *lifecycle.Configuration) (*lifecyc
|
||||
}(),
|
||||
Expiration: expiry,
|
||||
Transition: transition,
|
||||
NoncurrentVersionExpiration: lifecycle.NoncurrentVersionExpiration{
|
||||
NoncurrentDays: lifecycle.ExpirationDays(opts.NoncurrentVersionExpirationDays),
|
||||
},
|
||||
NoncurrentVersionTransition: lifecycle.NoncurrentVersionTransition{
|
||||
NoncurrentDays: lifecycle.ExpirationDays(opts.NoncurrentVersionTransitionDays),
|
||||
StorageClass: opts.NoncurrentVersionTransitionStorageClass,
|
||||
},
|
||||
}
|
||||
|
||||
ruleFound := false
|
||||
@@ -185,20 +197,25 @@ func GetLifecycleOptions(ctx *cli.Context) LifecycleOptions {
|
||||
}
|
||||
scSet := ctx.IsSet("storage-class")
|
||||
sc := strings.ToUpper(ctx.String("storage-class"))
|
||||
noncurrentSC := strings.ToUpper(ctx.String("noncurrentversion-transition-storage-class"))
|
||||
// for MinIO transition storage-class is same as label defined on
|
||||
// `mc admin bucket remote add --service ilm --label` command
|
||||
return LifecycleOptions{
|
||||
ID: id,
|
||||
Prefix: prefix,
|
||||
Status: !ctx.Bool("disable"),
|
||||
IsTagsSet: ctx.IsSet("tags"),
|
||||
IsStorageClassSet: scSet,
|
||||
Tags: ctx.String("tags"),
|
||||
ExpiryDate: ctx.String("expiry-date"),
|
||||
ExpiryDays: ctx.String("expiry-days"),
|
||||
TransitionDate: ctx.String("transition-date"),
|
||||
TransitionDays: ctx.String("transition-days"),
|
||||
StorageClass: sc,
|
||||
ID: id,
|
||||
Prefix: prefix,
|
||||
Status: !ctx.Bool("disable"),
|
||||
IsTagsSet: ctx.IsSet("tags"),
|
||||
IsStorageClassSet: scSet,
|
||||
Tags: ctx.String("tags"),
|
||||
ExpiryDate: ctx.String("expiry-date"),
|
||||
ExpiryDays: ctx.String("expiry-days"),
|
||||
TransitionDate: ctx.String("transition-date"),
|
||||
TransitionDays: ctx.String("transition-days"),
|
||||
StorageClass: sc,
|
||||
ExpiredObjectDeleteMarker: ctx.Bool("expired-object-delete-marker"),
|
||||
NoncurrentVersionExpirationDays: ctx.Int("noncurrentversion-expiration-days"),
|
||||
NoncurrentVersionTransitionDays: ctx.Int("noncurrentversion-transition-days"),
|
||||
NoncurrentVersionTransitionStorageClass: noncurrentSC,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -93,8 +93,10 @@ func validateTranDays(rule lifecycle.Rule) error {
|
||||
func validateRuleAction(rule lifecycle.Rule) error {
|
||||
expirySet := !rule.Expiration.IsNull()
|
||||
transitionSet := !rule.Transition.IsNull()
|
||||
if !expirySet && !transitionSet {
|
||||
errMsg := "At least one action (Expiry or Transition) needs to be specified in a rule."
|
||||
noncurrentExpirySet := !rule.NoncurrentVersionExpiration.IsDaysNull()
|
||||
noncurrentTransitionSet := !rule.NoncurrentVersionTransition.IsDaysNull()
|
||||
if !expirySet && !transitionSet && !noncurrentExpirySet && !noncurrentTransitionSet {
|
||||
errMsg := "At least one action (Expiry, Transition, NoncurrentExpiry or NoncurrentTransition) needs to be specified in a rule."
|
||||
return errors.New(errMsg)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -14,7 +14,7 @@ require (
|
||||
github.com/mattn/go-runewidth v0.0.9 // indirect
|
||||
github.com/minio/cli v1.22.0
|
||||
github.com/minio/minio v0.0.0-20201231050455-36fc2f98ed12
|
||||
github.com/minio/minio-go/v7 v7.0.7-0.20201217170524-3baf9ea06f7c
|
||||
github.com/minio/minio-go/v7 v7.0.7-0.20210107174959-40d41266f363
|
||||
github.com/minio/sha256-simd v0.1.1
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/pkg/profile v1.3.0
|
||||
|
||||
@@ -368,6 +368,8 @@ github.com/minio/minio v0.0.0-20201231050455-36fc2f98ed12 h1:yTz1GCGRf70a+2HHNOG
|
||||
github.com/minio/minio v0.0.0-20201231050455-36fc2f98ed12/go.mod h1:Y2vPTyVMgM/hdmWY4z1FAh0tAiPVAMLz4eeQ5FNcJmk=
|
||||
github.com/minio/minio-go/v7 v7.0.7-0.20201217170524-3baf9ea06f7c h1:NgTbI1w/B+2Jcl+YKTULAAXqkwWqMZbkzmVdWNwzKnA=
|
||||
github.com/minio/minio-go/v7 v7.0.7-0.20201217170524-3baf9ea06f7c/go.mod h1:pEZBUa+L2m9oECoIA6IcSK8bv/qggtQVLovjeKK5jYc=
|
||||
github.com/minio/minio-go/v7 v7.0.7-0.20210107174959-40d41266f363 h1:dMvWRvc6iSuBjeMVOZ4NrebkoIIeG0RclfxpYCFhMso=
|
||||
github.com/minio/minio-go/v7 v7.0.7-0.20210107174959-40d41266f363/go.mod h1:pEZBUa+L2m9oECoIA6IcSK8bv/qggtQVLovjeKK5jYc=
|
||||
github.com/minio/selfupdate v0.3.1 h1:BWEFSNnrZVMUWXbXIgLDNDjbejkmpAmZvy/nCz1HlEs=
|
||||
github.com/minio/selfupdate v0.3.1/go.mod h1:b8ThJzzH7u2MkF6PcIra7KaXO9Khf6alWPvMSyTDCFM=
|
||||
github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=
|
||||
|
||||
Reference in New Issue
Block a user