Skip to content

Commit 1464dd8

Browse files
feat: Prevent deletes in consumers and streams (#89)
* feat: Prevent deletes in consumers and streams Adding a `preventDelete` property for streams and consumers CRDS which when set to true 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. * update preventDelete descriptions Co-authored-by: Caleb Lloyd <[email protected]>
1 parent 84c2f02 commit 1464dd8

File tree

8 files changed

+55
-14
lines changed

8 files changed

+55
-14
lines changed

controllers/jetstream/consumer.go

+5
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ func deleteConsumer(ctx context.Context, c jsmClient, spec apis.ConsumerSpec) (e
387387
}
388388
}()
389389

390+
if spec.PreventDelete {
391+
fmt.Printf("Consumer %q is configured to preventDelete on stream %q:\n", stream, consumer)
392+
return nil
393+
}
394+
390395
var apierr jsmapi.ApiError
391396
cn, err := c.LoadConsumer(ctx, stream, consumer)
392397
if errors.As(err, &apierr) && apierr.NotFoundError() {

controllers/jetstream/stream.go

+5
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,11 @@ func deleteStream(ctx context.Context, c jsmClient, spec apis.StreamSpec) (err e
397397
}
398398
}()
399399

400+
if spec.PreventDelete {
401+
fmt.Printf("Stream %q is configured to preventDelete:\n", name)
402+
return nil
403+
}
404+
400405
var apierr jsmapi.ApiError
401406
str, err := c.LoadStream(ctx, name)
402407
if errors.As(err, &apierr) && apierr.NotFoundError() {

deploy/crds.yml

+8
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ spec:
189189
source:
190190
type: string
191191
description: Messages will be published from that subject to the destination subject.
192+
preventDelete:
193+
description: When true, the managed Stream will not be deleted when the resource is deleted
194+
type: boolean
195+
default: false
192196
status:
193197
type: object
194198
properties:
@@ -551,6 +555,10 @@ spec:
551555
description: Name of the account to which the Consumer belongs.
552556
type: string
553557
pattern: '^[^.*>]*$'
558+
preventDelete:
559+
description: When true, the managed Consumer will not be deleted when the resource is deleted
560+
type: boolean
561+
default: false
554562
status:
555563
type: object
556564
properties:

pkg/jetstream/apis/jetstream/v1beta2/consumertypes.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type ConsumerSpec struct {
3030
DeliverPolicy string `json:"deliverPolicy"`
3131
DeliverSubject string `json:"deliverSubject"`
3232
Description string `json:"description"`
33+
PreventDelete bool `json:"preventDelete"`
3334
DurableName string `json:"durableName"`
3435
FilterSubject string `json:"filterSubject"`
3536
FlowControl bool `json:"flowControl"`

pkg/jetstream/apis/jetstream/v1beta2/streamtypes.go

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type StreamSpec struct {
2525
Account string `json:"account"`
2626
Creds string `json:"creds"`
2727
Description string `json:"description"`
28+
PreventDelete bool `json:"preventDelete"`
2829
Discard string `json:"discard"`
2930
DuplicateWindow string `json:"duplicateWindow"`
3031
MaxAge string `json:"maxAge"`

pkg/jetstream/apis/jetstream/v1beta2/zz_generated.deepcopy.go

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/jetstream/generated/clientset/versioned/fake/register.go

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/jetstream/generated/clientset/versioned/scheme/register.go

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)