Skip to content

Commit 0b9f4ca

Browse files
authored
feat: add compute_unit_per_broker and storage_unit_per_bookie (#93)
### Motivation The compute_unit and storage_unit are actually "per broker" or "per bookie" rather than "total". so rename to avoid confuse. ### Modifications - Add `compute_unit_per_broker` and `storage_unit_per_bookie` - Deprecate `compute_unit` and `storage_unit` - Update docs #### Verifications Will show following warnings: ``` ╷ │ Warning: Argument is deprecated │ │ with streamnative_pulsar_cluster.test, │ on main.tf line 23, in resource "streamnative_pulsar_cluster" "test": │ 23: compute_unit = 0.3 │ │ Deprecated. Please use compute_unit_per_broker instead. │ │ (and 3 more similar warnings elsewhere) Full warnings terraform validate -json | jq -r '[ del( .diagnostics[] | select( .detail | startswith( "Experimental features" ) ) ) | .diagnostics[] | { Detail:.detail, Address:.address, Filename:.range.filename, Line:.range.start.line } ] | ( .[0] | keys_unsorted | ( . , map( length*"-" ) ) ), .[] | map(.) | @TSV' | column -ts $'\t' Detail Address Filename Line ------ ------- -------- ---- Deprecated. Please use compute_unit_per_broker instead. streamnative_pulsar_cluster.test main.tf 23 Deprecated. Please use storage_unit_per_bookie instead. streamnative_pulsar_cluster.test main.tf 24 ``` --------- Signed-off-by: Max Xu <[email protected]>
1 parent e73396c commit 0b9f4ca

File tree

9 files changed

+101
-44
lines changed

9 files changed

+101
-44
lines changed

cloud/data_source_pulsar_cluster.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ package cloud
1717
import (
1818
"context"
1919
"fmt"
20-
cloudv1alpha1 "github.com/streamnative/cloud-api-server/pkg/apis/cloud/v1alpha1"
21-
apierrors "k8s.io/apimachinery/pkg/api/errors"
2220
"strings"
2321

2422
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
2523
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
24+
cloudv1alpha1 "github.com/streamnative/cloud-api-server/pkg/apis/cloud/v1alpha1"
25+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
)
2828

@@ -86,13 +86,25 @@ func dataSourcePulsarCluster() *schema.Resource {
8686
Computed: true,
8787
},
8888
"compute_unit": {
89+
Deprecated: "Deprecated. Please use compute_unit_per_broker instead.",
90+
Type: schema.TypeFloat,
91+
Description: descriptions["compute_unit_per_broker"],
92+
Computed: true,
93+
},
94+
"compute_unit_per_broker": {
8995
Type: schema.TypeFloat,
90-
Description: descriptions["compute_unit"],
96+
Description: descriptions["compute_unit_per_broker"],
9197
Computed: true,
9298
},
9399
"storage_unit": {
100+
Deprecated: "Deprecated. Please use storage_unit_per_bookie instead.",
101+
Type: schema.TypeFloat,
102+
Description: descriptions["storage_unit_per_bookie"],
103+
Computed: true,
104+
},
105+
"storage_unit_per_broker": {
94106
Type: schema.TypeFloat,
95-
Description: descriptions["storage_unit"],
107+
Description: descriptions["storage_unit_per_bookie"],
96108
Computed: true,
97109
},
98110
"config": {

cloud/provider.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,16 @@ import (
2626
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
2727
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2828
"github.com/mitchellh/go-homedir"
29-
"k8s.io/cli-runtime/pkg/genericclioptions"
30-
"k8s.io/client-go/rest"
31-
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
32-
cmdutil "k8s.io/kubectl/pkg/cmd/util"
33-
"k8s.io/utils/clock"
34-
3529
"github.com/streamnative/cloud-cli/pkg/auth"
3630
"github.com/streamnative/cloud-cli/pkg/auth/store"
3731
"github.com/streamnative/cloud-cli/pkg/cmd"
3832
"github.com/streamnative/cloud-cli/pkg/config"
3933
"github.com/streamnative/cloud-cli/pkg/plugin"
34+
"k8s.io/cli-runtime/pkg/genericclioptions"
35+
"k8s.io/client-go/rest"
36+
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
37+
cmdutil "k8s.io/kubectl/pkg/cmd/util"
38+
"k8s.io/utils/clock"
4039
)
4140

4241
const (
@@ -79,18 +78,18 @@ func init() {
7978
"instance_engine": "The streamnative cloud instance engine, supporting 'ursa' and 'classic', default 'classic'",
8079
"location": "The location of the pulsar cluster, " +
8180
"supported location https://docs.streamnative.io/docs/cluster#cluster-location",
82-
"release_channel": "The release channel of the pulsar cluster subscribe to, it must to be lts or rapid, default rapid",
83-
"bookie_replicas": "The number of bookie replicas",
84-
"broker_replicas": "The number of broker replicas",
85-
"compute_unit": "compute unit, 1 compute unit is 2 cpu and 8gb memory",
86-
"storage_unit": "storage unit, 1 storage unit is 2 cpu and 8gb memory",
87-
"cluster_ready": "Pulsar cluster is ready, it will be set to 'True' after the cluster is ready",
88-
"instance_ready": "Pulsar instance is ready, it will be set to 'True' after the instance is ready",
89-
"websocket_enabled": "Whether the websocket is enabled",
90-
"function_enabled": "Whether the function is enabled",
91-
"transaction_enabled": "Whether the transaction is enabled",
92-
"kafka": "Controls the kafka protocol config of pulsar cluster",
93-
"mqtt": "Controls the mqtt protocol config of pulsar cluster",
81+
"release_channel": "The release channel of the pulsar cluster subscribe to, it must to be lts or rapid, default rapid",
82+
"bookie_replicas": "The number of bookie replicas",
83+
"broker_replicas": "The number of broker replicas",
84+
"compute_unit_per_broker": "compute unit per broker, 1 compute unit is 2 cpu and 8gb memory",
85+
"storage_unit_per_bookie": "storage unit per bookie, 1 storage unit is 2 cpu and 8gb memory",
86+
"cluster_ready": "Pulsar cluster is ready, it will be set to 'True' after the cluster is ready",
87+
"instance_ready": "Pulsar instance is ready, it will be set to 'True' after the instance is ready",
88+
"websocket_enabled": "Whether the websocket is enabled",
89+
"function_enabled": "Whether the function is enabled",
90+
"transaction_enabled": "Whether the transaction is enabled",
91+
"kafka": "Controls the kafka protocol config of pulsar cluster",
92+
"mqtt": "Controls the mqtt protocol config of pulsar cluster",
9493
"categories": "Controls the audit log categories config of pulsar cluster, supported categories: " +
9594
"\"Management\", \"Describe\", \"Produce\", \"Consume\"",
9695
"lakehouse_type": "The type of the lakehouse",

cloud/resource_pulsar_cluster.go

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@ package cloud
1717
import (
1818
"context"
1919
"fmt"
20-
"github.com/hashicorp/terraform-plugin-log/tflog"
21-
"k8s.io/apimachinery/pkg/api/errors"
2220
"strings"
2321
"time"
2422

25-
apierrors "k8s.io/apimachinery/pkg/api/errors"
26-
23+
"github.com/hashicorp/terraform-plugin-log/tflog"
2724
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
2825
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
2926
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
27+
cloudv1alpha1 "github.com/streamnative/cloud-api-server/pkg/apis/cloud/v1alpha1"
28+
"k8s.io/apimachinery/pkg/api/errors"
29+
apierrors "k8s.io/apimachinery/pkg/api/errors"
3030
"k8s.io/apimachinery/pkg/api/resource"
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32-
33-
cloudv1alpha1 "github.com/streamnative/cloud-api-server/pkg/apis/cloud/v1alpha1"
3432
)
3533

3634
func resourcePulsarCluster() *schema.Resource {
@@ -131,20 +129,42 @@ func resourcePulsarCluster() *schema.Resource {
131129
},
132130
},
133131
"compute_unit": {
132+
Deprecated: "Deprecated. Please use compute_unit_per_broker instead.",
133+
Type: schema.TypeFloat,
134+
Optional: true,
135+
Default: 0.5,
136+
Description: descriptions["compute_unit_per_broker"],
137+
ValidateFunc: validateCUSU,
138+
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
139+
return d.Get("type") == string(cloudv1alpha1.PulsarInstanceTypeServerless)
140+
},
141+
},
142+
"compute_unit_per_broker": {
134143
Type: schema.TypeFloat,
135144
Optional: true,
136145
Default: 0.5,
137-
Description: descriptions["compute_unit"],
146+
Description: descriptions["compute_unit_per_broker"],
138147
ValidateFunc: validateCUSU,
139148
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
140149
return d.Get("type") == string(cloudv1alpha1.PulsarInstanceTypeServerless)
141150
},
142151
},
143152
"storage_unit": {
153+
Deprecated: "Deprecated. Please use storage_unit_per_bookie instead.",
144154
Type: schema.TypeFloat,
145155
Optional: true,
146156
Default: 0.5,
147-
Description: descriptions["storage_unit"],
157+
Description: descriptions["storage_unit_per_bookie"],
158+
ValidateFunc: validateCUSU,
159+
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
160+
return d.Get("type") == string(cloudv1alpha1.PulsarInstanceTypeServerless)
161+
},
162+
},
163+
"storage_unit_per_bookie": {
164+
Type: schema.TypeFloat,
165+
Optional: true,
166+
Default: 0.5,
167+
Description: descriptions["storage_unit_per_bookie"],
148168
ValidateFunc: validateCUSU,
149169
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
150170
return d.Get("type") == string(cloudv1alpha1.PulsarInstanceTypeServerless)
@@ -345,8 +365,8 @@ func resourcePulsarClusterCreate(ctx context.Context, d *schema.ResourceData, me
345365
releaseChannel := d.Get("release_channel").(string)
346366
bookieReplicas := int32(d.Get("bookie_replicas").(int))
347367
brokerReplicas := int32(d.Get("broker_replicas").(int))
348-
computeUnit := d.Get("compute_unit").(float64)
349-
storageUnit := d.Get("storage_unit").(float64)
368+
computeUnit := getComputeUnit(d)
369+
storageUnit := getStorageUnit(d)
350370
clientSet, err := getClientSet(getFactoryFromMeta(meta))
351371
if err != nil {
352372
return diag.FromErr(fmt.Errorf("ERROR_INIT_CLIENT_ON_CREATE_PULSAR_CLUSTER: %w", err))
@@ -672,15 +692,15 @@ func resourcePulsarClusterUpdate(ctx context.Context, d *schema.ResourceData, me
672692
bookieReplicas := int32(d.Get("broker_replicas").(int))
673693
pulsarCluster.Spec.Broker.Replicas = &bookieReplicas
674694
}
675-
if d.HasChange("compute_unit") {
676-
computeUnit := d.Get("compute_unit").(float64)
695+
if d.HasChange("compute_unit") || d.HasChange("compute_unit_per_broker") {
696+
computeUnit := getComputeUnit(d)
677697
pulsarCluster.Spec.Broker.Resources.Cpu = resource.NewMilliQuantity(
678698
int64(computeUnit*2*1000), resource.DecimalSI)
679699
pulsarCluster.Spec.Broker.Resources.Memory = resource.NewQuantity(
680700
int64(computeUnit*8*1024*1024*1024), resource.DecimalSI)
681701
}
682-
if d.HasChange("storage_unit") {
683-
storageUnit := d.Get("storage_unit").(float64)
702+
if d.HasChange("storage_unit") || d.HasChange("storage_unit_per_bookie") {
703+
storageUnit := getStorageUnit(d)
684704
pulsarCluster.Spec.BookKeeper.Resources.Cpu = resource.NewMilliQuantity(
685705
int64(storageUnit*2*1000), resource.DecimalSI)
686706
pulsarCluster.Spec.BookKeeper.Resources.Memory = resource.NewQuantity(
@@ -694,7 +714,9 @@ func resourcePulsarClusterUpdate(ctx context.Context, d *schema.ResourceData, me
694714
if d.HasChange("bookie_replicas") ||
695715
d.HasChange("broker_replicas") ||
696716
d.HasChange("compute_unit") ||
697-
d.HasChange("storage_unit") || changed || displayNameChanged {
717+
d.HasChange("storage_unit") ||
718+
d.HasChange("compute_unit_per_broker") ||
719+
d.HasChange("storage_unit_per_bookie") || changed || displayNameChanged {
698720
_, err = clientSet.CloudV1alpha1().PulsarClusters(namespace).Update(ctx, pulsarCluster, metav1.UpdateOptions{
699721
FieldManager: "terraform-update",
700722
})
@@ -907,3 +929,19 @@ func getPulsarClusterChanged(ctx context.Context, pulsarCluster *cloudv1alpha1.P
907929
})
908930
return changed
909931
}
932+
933+
func getComputeUnit(d *schema.ResourceData) float64 {
934+
computeUnit := d.Get("compute_unit").(float64)
935+
if newComputeUnit, exist := d.GetOk("compute_unit_per_broker"); exist {
936+
computeUnit = newComputeUnit.(float64)
937+
}
938+
return computeUnit
939+
}
940+
941+
func getStorageUnit(d *schema.ResourceData) float64 {
942+
storageUnit := d.Get("storage_unit").(float64)
943+
if newStorageUnit, exist := d.GetOk("storage_unit"); exist {
944+
storageUnit = newStorageUnit.(float64)
945+
}
946+
return storageUnit
947+
}

docs/data-sources/cloud_environment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ description: |-
2727
- `id` (String) The ID of this resource.
2828
- `network` (List of Object) (see [below for nested schema](#nestedatt--network))
2929
- `private_service_ids` (List of String) The private service ids are ids are service names of PrivateLink in AWS, the ids of Private Service Attachment in GCP, and the aliases of PrivateLinkService in Azure.
30-
- `region` (String) The region of the cloud environment
30+
- `region` (String) The region of the cloud environment, for Azure, it should be the resource group name
3131

3232
<a id="nestedatt--default_gateway"></a>
3333
### Nested Schema for `default_gateway`

docs/data-sources/pulsar_cluster.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ description: |-
2525
- `bookie_replicas` (Number) The number of bookie replicas
2626
- `bookkeeper_version` (String) The version of the bookkeeper cluster
2727
- `broker_replicas` (Number) The number of broker replicas
28-
- `compute_unit` (Number) compute unit, 1 compute unit is 2 cpu and 8gb memory
28+
- `compute_unit` (Number, Deprecated) compute unit per broker, 1 compute unit is 2 cpu and 8gb memory
29+
- `compute_unit_per_broker` (Number) compute unit per broker, 1 compute unit is 2 cpu and 8gb memory
2930
- `config` (List of Object) (see [below for nested schema](#nestedatt--config))
3031
- `http_tls_service_url` (String) The service url of the pulsar cluster, use it to management the pulsar cluster.
3132
- `http_tls_service_urls` (List of String) The service url of the pulsar cluster, use it to management the pulsar cluster. There'll be multiple service urls if the cluster attached with multiple gateways
@@ -41,7 +42,8 @@ description: |-
4142
- `pulsar_version` (String) The version of the pulsar cluster
4243
- `ready` (String) Pulsar cluster is ready, it will be set to 'True' after the cluster is ready
4344
- `release_channel` (String) The release channel of the pulsar cluster subscribe to, it must to be lts or rapid, default rapid
44-
- `storage_unit` (Number) storage unit, 1 storage unit is 2 cpu and 8gb memory
45+
- `storage_unit` (Number, Deprecated) storage unit per bookie, 1 storage unit is 2 cpu and 8gb memory
46+
- `storage_unit_per_broker` (Number) storage unit per bookie, 1 storage unit is 2 cpu and 8gb memory
4547
- `type` (String) The streamnative cloud instance type, supporting 'serverless', 'dedicated', 'byoc' and 'byoc-pro'
4648
- `websocket_service_url` (String) If you want to connect to the pulsar cluster using the websocket protocol, use this websocket service url.
4749
- `websocket_service_urls` (List of String) If you want to connect to the pulsar cluster using the websocket protocol, use this websocket service url. There'll be multiple service urls if the cluster attached with multiple gateways

docs/data-sources/rolebinding.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ description: |-
2222

2323
### Read-Only
2424

25+
- `cel` (String) The CEL(Common Expression Langauge) for conditional role binding
2526
- `cluster_role_name` (String) The predefined role name
2627
- `id` (String) The ID of this resource.
2728
- `ready` (Boolean) The RoleBinding is ready, it will be set to 'True' after the cluster is ready
2829
- `service_account_names` (List of String) The list of service accounts that are role binding names
30+
- `user_names` (List of String) The list of users that are role binding names

docs/resources/cloud_environment.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ description: |-
1919

2020
- `cloud_connection_name` (String) Name of the cloud connection
2121
- `environment_type` (String) Type of the cloud environment, either: dev, test, staging, production, acc, qa or poc
22-
- `network` (Block List, Min: 1) (see [below for nested schema](#nestedblock--network))
22+
- `network` (Block List, Min: 1, Max: 1) (see [below for nested schema](#nestedblock--network))
2323
- `organization` (String) The organization name
24-
- `region` (String) The region of the cloud environment
24+
- `region` (String) The region of the cloud environment, for Azure, it should be the resource group name
2525

2626
### Optional
2727

docs/resources/pulsar_cluster.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ description: |-
2424

2525
- `bookie_replicas` (Number) The number of bookie replicas
2626
- `broker_replicas` (Number) The number of broker replicas
27-
- `compute_unit` (Number) compute unit, 1 compute unit is 2 cpu and 8gb memory
27+
- `compute_unit` (Number, Deprecated) compute unit per broker, 1 compute unit is 2 cpu and 8gb memory
28+
- `compute_unit_per_broker` (Number) compute unit per broker, 1 compute unit is 2 cpu and 8gb memory
2829
- `config` (Block List) (see [below for nested schema](#nestedblock--config))
2930
- `display_name` (String) The pulsar cluster display name
3031
- `endpoint_access` (Block List) (see [below for nested schema](#nestedblock--endpoint_access))
3132
- `location` (String) The location of the pulsar cluster, supported location https://docs.streamnative.io/docs/cluster#cluster-location
3233
- `name` (String) The pulsar cluster name
3334
- `pool_member_name` (String) The infrastructure pool member name
3435
- `release_channel` (String) The release channel of the pulsar cluster subscribe to, it must to be lts or rapid, default rapid
35-
- `storage_unit` (Number) storage unit, 1 storage unit is 2 cpu and 8gb memory
36+
- `storage_unit` (Number, Deprecated) storage unit per bookie, 1 storage unit is 2 cpu and 8gb memory
37+
- `storage_unit_per_bookie` (Number) storage unit per bookie, 1 storage unit is 2 cpu and 8gb memory
3638

3739
### Read-Only
3840

docs/resources/rolebinding.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ description: |-
2222

2323
### Optional
2424

25+
- `cel` (String) The CEL(Common Expression Langauge) for conditional role binding
2526
- `cluster_role_name` (String) The predefined role name
2627
- `service_account_names` (List of String) The list of service accounts that are role binding names
28+
- `user_names` (List of String) The list of users that are role binding names
2729

2830
### Read-Only
2931

0 commit comments

Comments
 (0)