Skip to content

Commit

Permalink
fix namespace replication_clusters drift (#140)
Browse files Browse the repository at this point in the history
* add test case to validation

* add test case

* revert first

* change replication_clusters to set type

* update code

* fix ci

* fix ci

* fix lint ci

* fix lint check
  • Loading branch information
freeznet authored Feb 5, 2025
1 parent 1f270cb commit 088e94c
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 10 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.21
id: go
Expand All @@ -43,9 +43,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

-
name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21

- name: Run GoReleaser (check)
uses: goreleaser/goreleaser-action@v3
uses: goreleaser/goreleaser-action@v6
with:
args: check
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ builds:
goarch: '386'
binary: '{{ .ProjectName }}_v{{ .Version }}'
archives:
- format: zip
- formats: [ 'zip' ]
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
checksum:
extra_files:
Expand Down
10 changes: 5 additions & 5 deletions pulsar/resource_pulsar_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func resourcePulsarNamespace() *schema.Resource {
ValidateFunc: validateGtEq0,
},
"replication_clusters": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Computed: true,
MinItems: 1,
Expand Down Expand Up @@ -388,10 +388,11 @@ func resourcePulsarNamespaceRead(ctx context.Context, d *schema.ResourceData, me
if err != nil {
return diag.FromErr(fmt.Errorf("ERROR_READ_NAMESPACE: GetMaxProducersPerTopic: %w", err))
} else {
replClusters := make([]interface{}, len(replClustersRaw))
replClustersInterface := make([]interface{}, len(replClustersRaw))
for i, cl := range replClustersRaw {
replClusters[i] = cl
replClustersInterface[i] = cl
}
replClusters := schema.NewSet(schema.HashString, replClustersInterface)
namespaceConfig["replication_clusters"] = replClusters
}

Expand Down Expand Up @@ -817,8 +818,7 @@ func unmarshalNamespaceConfigList(v []interface{}) *types.NamespaceConfig {

for _, ns := range v {
data := ns.(map[string]interface{})
rplClusters := data["replication_clusters"].([]interface{})

rplClusters := data["replication_clusters"].(*schema.Set).List()
nsConfig.ReplicationClusters = handleHCLArrayV2(rplClusters)
nsConfig.MaxProducersPerTopic = data["max_producers_per_topic"].(int)
nsConfig.MaxConsumersPerTopic = data["max_consumers_per_topic"].(int)
Expand Down
128 changes: 128 additions & 0 deletions pulsar/resource_pulsar_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func TestNamespace(t *testing.T) {
testPulsarNamespaceExists(resourceName),
),
},
{
Config: testPulsarNamespace(testWebServiceURL, cName, tName, nsName),
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
},
})
}
Expand Down Expand Up @@ -435,6 +440,40 @@ func TestNamespaceWithUndefinedOptionalsDrift(t *testing.T) {
})
}

func TestNamespaceReplicationClustersDrift(t *testing.T) {

resourceName := "pulsar_namespace.test"
cName := acctest.RandString(10)
tName := acctest.RandString(10)
nsName := acctest.RandString(10)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
IDRefreshName: resourceName,
CheckDestroy: testPulsarNamespaceDestroy,
Steps: []resource.TestStep{
{
Config: testPulsarNamespaceWithMultipleReplicationClusters(testWebServiceURL, cName, tName, nsName),
Check: resource.ComposeTestCheckFunc(
testPulsarNamespaceExists(resourceName),
),
},
{
Config: testPulsarNamespaceWithMultipleReplicationClusters(testWebServiceURL, cName, tName, nsName),
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
{
Config: testPulsarNamespace(testWebServiceURL, cName, tName, nsName),
Check: resource.ComposeTestCheckFunc(
testPulsarNamespaceExists(resourceName),
),
},
},
})
}

func createNamespace(t *testing.T, id string) {
client, err := sharedClient(testWebServiceURL)
if err != nil {
Expand Down Expand Up @@ -753,3 +792,92 @@ resource "pulsar_namespace" "test" {
}
`, wsURL, cluster, tenant, ns, topicAutoCreation)
}

func testPulsarNamespaceWithMultipleReplicationClusters(wsURL, cluster, tenant, ns string) string {
return fmt.Sprintf(`
provider "pulsar" {
web_service_url = "%s"
}
resource "pulsar_cluster" "test_cluster" {
cluster = "%s"
cluster_data {
web_service_url = "http://localhost:8080"
broker_service_url = "http://localhost:6050"
peer_clusters = ["standalone"]
}
}
resource "pulsar_tenant" "test_tenant" {
tenant = "%s"
allowed_clusters = [pulsar_cluster.test_cluster.cluster, "standalone"]
}
resource "pulsar_namespace" "test" {
tenant = pulsar_tenant.test_tenant.tenant
namespace = "%s"
enable_deduplication = true
namespace_config {
anti_affinity = "anti-aff"
max_consumers_per_subscription = "50"
max_consumers_per_topic = "50"
max_producers_per_topic = "50"
message_ttl_seconds = "86400"
replication_clusters = [pulsar_cluster.test_cluster.cluster]
is_allow_auto_update_schema = false
offload_threshold_size_in_mb = "100"
}
dispatch_rate {
dispatch_msg_throttling_rate = 50
rate_period_seconds = 50
dispatch_byte_throttling_rate = 2048
}
subscription_dispatch_rate {
dispatch_msg_throttling_rate = 50
rate_period_seconds = 50
dispatch_byte_throttling_rate = 2048
}
retention_policies {
retention_minutes = "1600"
retention_size_in_mb = "10000"
}
persistence_policies {
bookkeeper_ensemble = 2
bookkeeper_write_quorum = 2
bookkeeper_ack_quorum = 2
managed_ledger_max_mark_delete_rate = 0.0
}
backlog_quota {
limit_bytes = "10000000000"
limit_seconds = "-1"
policy = "producer_request_hold"
type = "destination_storage"
}
permission_grant {
role = "some-role-1"
actions = ["produce", "consume", "functions"]
}
permission_grant {
role = "some-role-2"
actions = ["produce", "consume"]
}
topic_auto_creation {
enable = true
type = "partitioned"
partitions = 3
}
}
`, wsURL, cluster, tenant, ns)
}

0 comments on commit 088e94c

Please sign in to comment.