Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Prevent deletes in consumers and streams #89

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions controllers/jetstream/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ func deleteConsumer(ctx context.Context, c jsmClient, spec apis.ConsumerSpec) (e
}
}()

if spec.PreventDelete {
fmt.Printf("Consumer %q is configured to preventDelete on stream %q:\n", stream, consumer)
return nil
}

var apierr jsmapi.ApiError
cn, err := c.LoadConsumer(ctx, stream, consumer)
if errors.As(err, &apierr) && apierr.NotFoundError() {
Expand Down
5 changes: 5 additions & 0 deletions controllers/jetstream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ func deleteStream(ctx context.Context, c jsmClient, spec apis.StreamSpec) (err e
}
}()

if spec.PreventDelete {
fmt.Printf("Stream %q is configured to preventDelete:\n", name)
return nil
}

var apierr jsmapi.ApiError
str, err := c.LoadStream(ctx, name)
if errors.As(err, &apierr) && apierr.NotFoundError() {
Expand Down
8 changes: 8 additions & 0 deletions deploy/crds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ spec:
source:
type: string
description: Messages will be published from that subject to the destination subject.
preventDelete:
description: When true, the managed Stream will not be deleted when the resource is deleted
type: boolean
default: false
status:
type: object
properties:
Expand Down Expand Up @@ -551,6 +555,10 @@ spec:
description: Name of the account to which the Consumer belongs.
type: string
pattern: '^[^.*>]*$'
preventDelete:
description: When true, the managed Consumer will not be deleted when the resource is deleted
type: boolean
default: false
status:
type: object
properties:
Expand Down
1 change: 1 addition & 0 deletions pkg/jetstream/apis/jetstream/v1beta2/consumertypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ConsumerSpec struct {
DeliverPolicy string `json:"deliverPolicy"`
DeliverSubject string `json:"deliverSubject"`
Description string `json:"description"`
PreventDelete bool `json:"preventDelete"`
DurableName string `json:"durableName"`
FilterSubject string `json:"filterSubject"`
FlowControl bool `json:"flowControl"`
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 @@ -25,6 +25,7 @@ type StreamSpec struct {
Account string `json:"account"`
Creds string `json:"creds"`
Description string `json:"description"`
PreventDelete bool `json:"preventDelete"`
Discard string `json:"discard"`
DuplicateWindow string `json:"duplicateWindow"`
MaxAge string `json:"maxAge"`
Expand Down
21 changes: 21 additions & 0 deletions pkg/jetstream/apis/jetstream/v1beta2/zz_generated.deepcopy.go

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

14 changes: 7 additions & 7 deletions pkg/jetstream/generated/clientset/versioned/fake/register.go

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

14 changes: 7 additions & 7 deletions pkg/jetstream/generated/clientset/versioned/scheme/register.go

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