Skip to content

Commit

Permalink
Add compression
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
  • Loading branch information
Jarema committed Sep 22, 2023
1 parent abee178 commit 93217ee
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
15 changes: 15 additions & 0 deletions controllers/jetstream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

jsm "github.com/nats-io/jsm.go"
"github.com/nats-io/jsm.go/api"
jsmapi "github.com/nats-io/jsm.go/api"
apis "github.com/nats-io/nack/pkg/jetstream/apis/jetstream/v1beta2"
typed "github.com/nats-io/nack/pkg/jetstream/generated/clientset/versioned/typed/jetstream/v1beta2"
Expand Down Expand Up @@ -337,6 +338,13 @@ func createStream(ctx context.Context, c jsmClient, spec apis.StreamSpec) (err e
opts = append(opts, jsm.DiscardNew())
}

switch spec.Compression {
case "s2":
opts = append(opts, jsm.Compression(api.S2Compression))
case "none":
opts = append(opts, jsm.Compression(api.NoCompression))
}

if spec.NoAck {
opts = append(opts, jsm.NoAck())
}
Expand Down Expand Up @@ -492,6 +500,13 @@ func updateStream(ctx context.Context, c jsmClient, spec apis.StreamSpec) (err e
config.Sources[i] = jss
}

switch spec.Compression {
case "s2":
config.Compression = api.S2Compression
case "none":
config.Compression = api.NoCompression
}

return js.UpdateConfiguration(config)
}

Expand Down
7 changes: 7 additions & 0 deletions deploy/crds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ spec:
description: Sequence number from which the Stream will start.
type: number
default: 0
compression:
description: Stream specific compression.
type: string
enum:
- s2
- none
default: ''
preventDelete:
description: When true, the managed Stream will not be deleted when the resource is deleted
type: boolean
Expand Down
1 change: 1 addition & 0 deletions pkg/jetstream/apis/jetstream/v1beta2/streamtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type StreamSpec struct {
Replicas int `json:"replicas"`
Republish *RePublish `json:"republish"`
FirstSequence uint64 `json:"firstSequence"`
Compression string `json:"compression"`
Retention string `json:"retention"`
Servers []string `json:"servers"`
Sources []*StreamSource `json:"sources"`
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 93217ee

Please sign in to comment.