Skip to content

Commit

Permalink
Merge pull request #527 from nats-io/JMS-FixTieredLimitsValidation
Browse files Browse the repository at this point in the history
[fix] Tiered limits validation from blocking legitimate updates
  • Loading branch information
codegangsta authored Dec 6, 2022
2 parents f8a66a9 + 51a204c commit 35db940
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
11 changes: 6 additions & 5 deletions cmd/editaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ type JetStreamLimitParams struct {
DiskMaxStreamBytes NumberParams
MaxBytesRequired bool
MaxAckPending NumberParams
hasJSSetParams bool
}

type EditAccountParams struct {
Expand Down Expand Up @@ -172,7 +173,7 @@ func (p *EditAccountParams) SetDefaults(ctx ActionCtx) error {
p.SignerParams.SetDefaults(nkeys.PrefixByteOperator, true, ctx)

hasDeleteTier := ctx.AnySet("rm-js-tier")
hasJsSetFlags := ctx.AnySet("js-tier", "js-mem-storage",
p.hasJSSetParams = ctx.AnySet("js-tier", "js-mem-storage",
"js-disk-storage",
"js-streams",
"js-consumer",
Expand All @@ -181,7 +182,7 @@ func (p *EditAccountParams) SetDefaults(ctx ActionCtx) error {
"js-max-bytes-required",
"js-max-ack-pending")

if hasDeleteTier && hasJsSetFlags {
if hasDeleteTier && p.hasJSSetParams {
return fmt.Errorf("rm-js-tier is exclusive of all other js options")
}

Expand Down Expand Up @@ -305,12 +306,12 @@ func (p *EditAccountParams) validJsLimitConfig() error {
if tiered > 0 && globalIsSet {
return fmt.Errorf("configuration cannot contain both global and tiered limits '%s' - please use the --rm-js-tier to remove undesired tier(s)", strings.Join(keys, ","))
}
// trying to add global to tiered
if tiered > 0 && p.Tier == 0 {
// trying to add global to tiered (only if js set params have been passed)
if tiered > 0 && p.Tier == 0 && p.hasJSSetParams {
return fmt.Errorf("cannot set a jetstream global limit when a configuration has tiered limits '%s'", strings.Join(keys, ","))
}
// trying to add tiered to global
if globalIsSet && p.Tier > 0 {
if globalIsSet && p.Tier > 0 && p.hasJSSetParams {
return errors.New("cannot set a jetstream tier limit when a configuration has a global limit")
}
return nil
Expand Down
18 changes: 18 additions & 0 deletions cmd/editaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,24 @@ func Test_TieredPreventsGlobal(t *testing.T) {
require.Equal(t, "cannot set a jetstream global limit when a configuration has tiered limits 'R2'", err.Error())
}

func Test_TieredDoesntPreventOtherClaims(t *testing.T) {
ts := NewTestStore(t, "edit account")
defer ts.Done(t)

ts.AddAccount(t, "A")
_, _, err := ExecuteCmd(createEditAccount(),
"--js-tier", "2", "--js-streams", "5", "--js-disk-storage", "10")
require.NoError(t, err)

ac, err := ts.Store.ReadAccountClaim("A")
require.NoError(t, err)
require.Equal(t, int64(5), ac.Limits.JetStreamTieredLimits["R2"].Streams)

_, _, err = ExecuteCmd(createEditAccount(),
"--sk", "generate")
require.NoError(t, err)
}

func Test_EditAccountSigningKeys(t *testing.T) {
ts := NewTestStore(t, "edit account")
defer ts.Done(t)
Expand Down

0 comments on commit 35db940

Please sign in to comment.