Skip to content

Commit

Permalink
feat: Prevent deletes in consumers and streams
Browse files Browse the repository at this point in the history
Adding a `preventDelete` property for streams and consumers CRDS which
when set to false nack should be able to delete it, otherwise it should
just ignore that stream or consumer.

The use case for this is in a multi-cloud context when we have deploy
deployed in different clouds it becomes troublesome. For example, nack
on GKE might check that a stream CRD is missing and proceeds to delete
it, however that CRD exists in AWS and AKS and it should not be deleted
because its going to impact other applications.
  • Loading branch information
danielcibrao-form3 committed Oct 26, 2022
1 parent 84c2f02 commit 33a94a9
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 14 deletions.
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: Indicates if a Stream can be deleted or not
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: Indicates if a Consumer can be deleted or not
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.

0 comments on commit 33a94a9

Please sign in to comment.