Skip to content

Commit

Permalink
feat: add compute_unit_per_broker and storage_unit_per_bookie
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsxu committed Dec 19, 2024
1 parent e73396c commit 6ba12cf
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 34 deletions.
14 changes: 11 additions & 3 deletions cloud/data_source_pulsar_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ package cloud
import (
"context"
"fmt"
"strings"

cloudv1alpha1 "github.com/streamnative/cloud-api-server/pkg/apis/cloud/v1alpha1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -86,13 +87,20 @@ func dataSourcePulsarCluster() *schema.Resource {
Computed: true,
},
"compute_unit": {
Deprecated: "Deprecated. Please use compute_unit_per_broker instead.",
Type: schema.TypeFloat,
Description: descriptions["compute_unit_per_broker"],
Computed: true,
},
"compute_unit_per_broker": {
Type: schema.TypeFloat,
Description: descriptions["compute_unit"],
Description: descriptions["compute_unit_per_broker"],
Computed: true,
},
"storage_unit": {
Deprecated: "Deprecated. Please use storage_unit_per_bookie instead.",
Type: schema.TypeFloat,
Description: descriptions["storage_unit"],
Description: descriptions["storage_unit_per_bookie"],
Computed: true,
},
"config": {
Expand Down
24 changes: 12 additions & 12 deletions cloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ func init() {
"instance_engine": "The streamnative cloud instance engine, supporting 'ursa' and 'classic', default 'classic'",
"location": "The location of the pulsar cluster, " +
"supported location https://docs.streamnative.io/docs/cluster#cluster-location",
"release_channel": "The release channel of the pulsar cluster subscribe to, it must to be lts or rapid, default rapid",
"bookie_replicas": "The number of bookie replicas",
"broker_replicas": "The number of broker replicas",
"compute_unit": "compute unit, 1 compute unit is 2 cpu and 8gb memory",
"storage_unit": "storage unit, 1 storage unit is 2 cpu and 8gb memory",
"cluster_ready": "Pulsar cluster is ready, it will be set to 'True' after the cluster is ready",
"instance_ready": "Pulsar instance is ready, it will be set to 'True' after the instance is ready",
"websocket_enabled": "Whether the websocket is enabled",
"function_enabled": "Whether the function is enabled",
"transaction_enabled": "Whether the transaction is enabled",
"kafka": "Controls the kafka protocol config of pulsar cluster",
"mqtt": "Controls the mqtt protocol config of pulsar cluster",
"release_channel": "The release channel of the pulsar cluster subscribe to, it must to be lts or rapid, default rapid",
"bookie_replicas": "The number of bookie replicas",
"broker_replicas": "The number of broker replicas",
"compute_unit_per_broker": "compute unit per broker, 1 compute unit is 2 cpu and 8gb memory",
"storage_unit_per_bookie": "storage unit per bookie, 1 storage unit is 2 cpu and 8gb memory",
"cluster_ready": "Pulsar cluster is ready, it will be set to 'True' after the cluster is ready",
"instance_ready": "Pulsar instance is ready, it will be set to 'True' after the instance is ready",
"websocket_enabled": "Whether the websocket is enabled",
"function_enabled": "Whether the function is enabled",
"transaction_enabled": "Whether the transaction is enabled",
"kafka": "Controls the kafka protocol config of pulsar cluster",
"mqtt": "Controls the mqtt protocol config of pulsar cluster",
"categories": "Controls the audit log categories config of pulsar cluster, supported categories: " +
"\"Management\", \"Describe\", \"Produce\", \"Consume\"",
"lakehouse_type": "The type of the lakehouse",
Expand Down
47 changes: 35 additions & 12 deletions cloud/resource_pulsar_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ package cloud
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-log/tflog"
"k8s.io/apimachinery/pkg/api/errors"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-log/tflog"
"k8s.io/apimachinery/pkg/api/errors"

apierrors "k8s.io/apimachinery/pkg/api/errors"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -131,20 +132,42 @@ func resourcePulsarCluster() *schema.Resource {
},
},
"compute_unit": {
Deprecated: "Deprecated. Please use compute_unit_per_broker instead.",
Type: schema.TypeFloat,
Optional: true,
Default: 0.5,
Description: descriptions["compute_unit"],
Description: descriptions["compute_unit_per_broker"],
ValidateFunc: validateCUSU,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return d.Get("type") == string(cloudv1alpha1.PulsarInstanceTypeServerless)
},
},
"compute_unit_per_broker": {
Type: schema.TypeFloat,
Optional: true,
Default: 0.5,
Description: descriptions["compute_unit_per_broker"],
ValidateFunc: validateCUSU,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return d.Get("type") == string(cloudv1alpha1.PulsarInstanceTypeServerless)
},
},
"storage_unit": {
Deprecated: "Deprecated. Please use storage_unit_per_bookie instead.",
Type: schema.TypeFloat,
Optional: true,
Default: 0.5,
Description: descriptions["storage_unit_per_bookie"],
ValidateFunc: validateCUSU,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return d.Get("type") == string(cloudv1alpha1.PulsarInstanceTypeServerless)
},
},
"storage_unit_per_bookie": {
Type: schema.TypeFloat,
Optional: true,
Default: 0.5,
Description: descriptions["storage_unit"],
Description: descriptions["storage_unit_per_bookie"],
ValidateFunc: validateCUSU,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return d.Get("type") == string(cloudv1alpha1.PulsarInstanceTypeServerless)
Expand Down Expand Up @@ -345,8 +368,8 @@ func resourcePulsarClusterCreate(ctx context.Context, d *schema.ResourceData, me
releaseChannel := d.Get("release_channel").(string)
bookieReplicas := int32(d.Get("bookie_replicas").(int))
brokerReplicas := int32(d.Get("broker_replicas").(int))
computeUnit := d.Get("compute_unit").(float64)
storageUnit := d.Get("storage_unit").(float64)
computeUnit := d.Get("compute_unit_per_broker").(float64)
storageUnit := d.Get("storage_unit_per_bookie").(float64)
clientSet, err := getClientSet(getFactoryFromMeta(meta))
if err != nil {
return diag.FromErr(fmt.Errorf("ERROR_INIT_CLIENT_ON_CREATE_PULSAR_CLUSTER: %w", err))
Expand Down Expand Up @@ -672,15 +695,15 @@ func resourcePulsarClusterUpdate(ctx context.Context, d *schema.ResourceData, me
bookieReplicas := int32(d.Get("broker_replicas").(int))
pulsarCluster.Spec.Broker.Replicas = &bookieReplicas
}
if d.HasChange("compute_unit") {
computeUnit := d.Get("compute_unit").(float64)
if d.HasChange("compute_unit_per_broker") {
computeUnit := d.Get("compute_unit_per_broker").(float64)
pulsarCluster.Spec.Broker.Resources.Cpu = resource.NewMilliQuantity(
int64(computeUnit*2*1000), resource.DecimalSI)
pulsarCluster.Spec.Broker.Resources.Memory = resource.NewQuantity(
int64(computeUnit*8*1024*1024*1024), resource.DecimalSI)
}
if d.HasChange("storage_unit") {
storageUnit := d.Get("storage_unit").(float64)
if d.HasChange("storage_unit_per_bookie") {
storageUnit := d.Get("storage_unit_per_bookie").(float64)
pulsarCluster.Spec.BookKeeper.Resources.Cpu = resource.NewMilliQuantity(
int64(storageUnit*2*1000), resource.DecimalSI)
pulsarCluster.Spec.BookKeeper.Resources.Memory = resource.NewQuantity(
Expand All @@ -693,8 +716,8 @@ func resourcePulsarClusterUpdate(ctx context.Context, d *schema.ResourceData, me
}
if d.HasChange("bookie_replicas") ||
d.HasChange("broker_replicas") ||
d.HasChange("compute_unit") ||
d.HasChange("storage_unit") || changed || displayNameChanged {
d.HasChange("compute_unit_per_broker") ||
d.HasChange("storage_unit_per_bookie") || changed || displayNameChanged {
_, err = clientSet.CloudV1alpha1().PulsarClusters(namespace).Update(ctx, pulsarCluster, metav1.UpdateOptions{
FieldManager: "terraform-update",
})
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/cloud_environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ description: |-
- `id` (String) The ID of this resource.
- `network` (List of Object) (see [below for nested schema](#nestedatt--network))
- `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.
- `region` (String) The region of the cloud environment
- `region` (String) The region of the cloud environment, for Azure, it should be the resource group name

<a id="nestedatt--default_gateway"></a>
### Nested Schema for `default_gateway`
Expand Down
5 changes: 3 additions & 2 deletions docs/data-sources/pulsar_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ description: |-
- `bookie_replicas` (Number) The number of bookie replicas
- `bookkeeper_version` (String) The version of the bookkeeper cluster
- `broker_replicas` (Number) The number of broker replicas
- `compute_unit` (Number) compute unit, 1 compute unit is 2 cpu and 8gb memory
- `compute_unit` (Number, Deprecated) compute unit per broker, 1 compute unit is 2 cpu and 8gb memory
- `compute_unit_per_broker` (Number) compute unit per broker, 1 compute unit is 2 cpu and 8gb memory
- `config` (List of Object) (see [below for nested schema](#nestedatt--config))
- `http_tls_service_url` (String) The service url of the pulsar cluster, use it to management the pulsar cluster.
- `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
Expand All @@ -41,7 +42,7 @@ description: |-
- `pulsar_version` (String) The version of the pulsar cluster
- `ready` (String) Pulsar cluster is ready, it will be set to 'True' after the cluster is ready
- `release_channel` (String) The release channel of the pulsar cluster subscribe to, it must to be lts or rapid, default rapid
- `storage_unit` (Number) storage unit, 1 storage unit is 2 cpu and 8gb memory
- `storage_unit` (Number, Deprecated) storage unit per bookie, 1 storage unit is 2 cpu and 8gb memory
- `type` (String) The streamnative cloud instance type, supporting 'serverless', 'dedicated', 'byoc' and 'byoc-pro'
- `websocket_service_url` (String) If you want to connect to the pulsar cluster using the websocket protocol, use this websocket service url.
- `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
Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/rolebinding.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ description: |-

### Read-Only

- `cel` (String) The CEL(Common Expression Langauge) for conditional role binding
- `cluster_role_name` (String) The predefined role name
- `id` (String) The ID of this resource.
- `ready` (Boolean) The RoleBinding is ready, it will be set to 'True' after the cluster is ready
- `service_account_names` (List of String) The list of service accounts that are role binding names
- `user_names` (List of String) The list of users that are role binding names
4 changes: 2 additions & 2 deletions docs/resources/cloud_environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ description: |-

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

### Optional

Expand Down
6 changes: 4 additions & 2 deletions docs/resources/pulsar_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ description: |-

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

### Read-Only

Expand Down
2 changes: 2 additions & 0 deletions docs/resources/rolebinding.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ description: |-

### Optional

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

### Read-Only

Expand Down

0 comments on commit 6ba12cf

Please sign in to comment.