Skip to content

Commit 9f5ea52

Browse files
authored
feat(namespace): add RemovePersistence methods to namespace admin (#1447)
1 parent 9785c01 commit 9f5ea52

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

pulsaradmin/pkg/admin/namespace.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ type Namespaces interface {
396396
// SetPersistenceWithContext sets the persistence configuration for all the topics on a namespace
397397
SetPersistenceWithContext(ctx context.Context, namespace string, persistence utils.PersistencePolicies) error
398398

399+
// RemovePersistence removes the persistence configuration for a namespace
400+
RemovePersistence(namespace string) error
401+
402+
// RemovePersistenceWithContext removes the persistence configuration for a namespace
403+
RemovePersistenceWithContext(ctx context.Context, namespace string) error
404+
399405
// GetPersistence returns the persistence configuration for a namespace.
400406
// Returns nil if the persistence policy is not configured at the namespace level.
401407
GetPersistence(namespace string) (*utils.PersistencePolicies, error)
@@ -1433,6 +1439,19 @@ func (n *namespaces) SetPersistenceWithContext(
14331439
return n.pulsar.Client.PostWithContext(ctx, endpoint, &persistence)
14341440
}
14351441

1442+
func (n *namespaces) RemovePersistence(namespace string) error {
1443+
return n.RemovePersistenceWithContext(context.Background(), namespace)
1444+
}
1445+
1446+
func (n *namespaces) RemovePersistenceWithContext(ctx context.Context, namespace string) error {
1447+
nsName, err := utils.GetNamespaceName(namespace)
1448+
if err != nil {
1449+
return err
1450+
}
1451+
endpoint := n.pulsar.endpoint(n.basePath, nsName.String(), "persistence")
1452+
return n.pulsar.Client.DeleteWithContext(ctx, endpoint)
1453+
}
1454+
14361455
func (n *namespaces) SetBookieAffinityGroup(namespace string, bookieAffinityGroup utils.BookieAffinityGroupData) error {
14371456
return n.SetBookieAffinityGroupWithContext(context.Background(), namespace, bookieAffinityGroup)
14381457
}

pulsaradmin/pkg/admin/namespace_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,4 +861,12 @@ func TestNamespaces_Persistence(t *testing.T) {
861861
assert.NotNil(t, persistence, "Expected non-nil when persistence is configured")
862862
assert.Equal(t, 1, persistence.BookkeeperEnsemble)
863863
assert.Equal(t, 1, persistence.BookkeeperWriteQuorum)
864+
865+
// Remove persistence policy - should return nil
866+
err = admin.Namespaces().RemovePersistence(namespaceName)
867+
assert.NoError(t, err)
868+
869+
persistence, err = admin.Namespaces().GetPersistence(namespaceName)
870+
assert.NoError(t, err)
871+
assert.Nil(t, persistence, "Expected nil after removing persistence configuration")
864872
}

0 commit comments

Comments
 (0)