Skip to content

Commit 06b64a5

Browse files
authored
Update instance type for pulsarinstance (#79)
1 parent fc194e6 commit 06b64a5

File tree

13 files changed

+317
-60
lines changed

13 files changed

+317
-60
lines changed

cloud/apikey_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestApiKey(t *testing.T) {
4242
apiKeyGeneratedName,
4343
"shared-gcp",
4444
"streamnative",
45-
"us-central1", "lts"),
45+
"us-central1", "rapid"),
4646
Check: resource.ComposeTestCheckFunc(
4747
testCheckApiKeyExists("streamnative_apikey.test-terraform-api-key"),
4848
),
@@ -121,6 +121,7 @@ resource "streamnative_pulsar_instance" "test-api-key-pulsar-instance" {
121121
availability_mode = "zonal"
122122
pool_name = "%s"
123123
pool_namespace = "%s"
124+
type = "dedicated"
124125
}
125126
resource "streamnative_pulsar_cluster" "test-api-key-pulsar-cluster" {
126127
organization = "%s"
@@ -129,7 +130,7 @@ resource "streamnative_pulsar_cluster" "test-api-key-pulsar-cluster" {
129130
location = "%s"
130131
release_channel = "%s"
131132
config {
132-
websocket_enabled = true
133+
websocket_enabled = false
133134
function_enabled = false
134135
transaction_enabled = false
135136
protocols {
@@ -141,7 +142,6 @@ resource "streamnative_pulsar_cluster" "test-api-key-pulsar-cluster" {
141142
}
142143
}
143144
custom = {
144-
"allowAutoTopicCreation" = "true"
145145
"bookkeeper.journalSyncData" = "false"
146146
"managedLedgerOffloadAutoTriggerSizeThresholdBytes" = "0"
147147
}

cloud/data_source_pulsar_cluster.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,14 @@ func dataSourcePulsarClusterRead(ctx context.Context, d *schema.ResourceData, me
341341
}
342342
if pulsarInstance.Spec.Type != cloudv1alpha1.PulsarInstanceTypeServerless && !pulsarCluster.IsUsingUrsaEngine() {
343343
bookkeeperImage := strings.Split(pulsarCluster.Spec.BookKeeper.Image, ":")
344-
_ = d.Set("bookkeeper_version", bookkeeperImage[1])
344+
if len(bookkeeperImage) > 1 {
345+
_ = d.Set("bookkeeper_version", bookkeeperImage[1])
346+
}
345347
}
346348
brokerImage := strings.Split(pulsarCluster.Spec.Broker.Image, ":")
347-
_ = d.Set("pulsar_version", brokerImage[1])
349+
if len(brokerImage) > 1 {
350+
_ = d.Set("pulsar_version", brokerImage[1])
351+
}
348352
_ = d.Set("type", pulsarInstance.Spec.Type)
349353
releaseChannel := pulsarCluster.Spec.ReleaseChannel
350354
if releaseChannel != "" {

cloud/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func init() {
7575
"pool_member_type": "Type of infrastructure pool member, one of aws, gcloud and azure",
7676
"pool_member_location": "The location of the infrastructure pool member",
7777
"instance_name": "The pulsar instance name",
78-
"instance_type": "The streamnative cloud instance type, supporting 'serverless' and 'standard'",
78+
"instance_type": "The streamnative cloud instance type, supporting 'serverless', 'dedicated', 'byoc' and 'byoc-pro'",
7979
"instance_engine": "The streamnative cloud instance engine, supporting 'ursa' and 'classic', default 'classic'",
8080
"location": "The location of the pulsar cluster, " +
8181
"supported location https://docs.streamnative.io/docs/cluster#cluster-location",

cloud/pulsar_cluster_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestPulsarCluster(t *testing.T) {
4444
clusterGeneratedName,
4545
"shared-gcp",
4646
"streamnative",
47-
"us-central1", "lts"),
47+
"us-central1", "rapid"),
4848
Check: resource.ComposeTestCheckFunc(
4949
testCheckPulsarClusterExists("streamnative_pulsar_cluster.test-pulsar-cluster"),
5050
),
@@ -125,6 +125,7 @@ resource "streamnative_pulsar_instance" "test-pulsar-instance" {
125125
availability_mode = "zonal"
126126
pool_name = "%s"
127127
pool_namespace = "%s"
128+
type = "dedicated"
128129
}
129130
resource "streamnative_pulsar_cluster" "test-pulsar-cluster" {
130131
organization = "%s"
@@ -133,7 +134,7 @@ resource "streamnative_pulsar_cluster" "test-pulsar-cluster" {
133134
location = "%s"
134135
release_channel = "%s"
135136
config {
136-
websocket_enabled = true
137+
websocket_enabled = false
137138
function_enabled = false
138139
transaction_enabled = false
139140
protocols {
@@ -145,7 +146,6 @@ resource "streamnative_pulsar_cluster" "test-pulsar-cluster" {
145146
}
146147
}
147148
custom = {
148-
"allowAutoTopicCreation" = "true"
149149
"bookkeeper.journalSyncData" = "false"
150150
"managedLedgerOffloadAutoTriggerSizeThresholdBytes" = "0"
151151
}

cloud/resource_pulsar_cluster.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,6 @@ func resourcePulsarClusterCreate(ctx context.Context, d *schema.ResourceData, me
346346
if err != nil {
347347
return diag.FromErr(fmt.Errorf("ERROR_GET_PULSAR_INSTANCE_ON_CREATE_PULSAR_CLUSTER: %w", err))
348348
}
349-
if pulsarInstance.Spec.Plan == string(cloudv1alpha1.PulsarInstanceTypeFree) {
350-
return diag.FromErr(fmt.Errorf(
351-
"ERROR_CREATE_PULSAR_CLUSTER: "+
352-
"creating a cluster under instance of type '%s' is no longer allowed",
353-
cloudv1alpha1.PulsarInstanceTypeFree))
354-
}
355349
ursaEngine, ok := pulsarInstance.Annotations[UrsaEngineAnnotation]
356350
ursaEnabled := ok && ursaEngine == UrsaEngineValue
357351
bookieCPU := resource.NewMilliQuantity(int64(storageUnit*2*1000), resource.DecimalSI)
@@ -596,10 +590,14 @@ func resourcePulsarClusterRead(ctx context.Context, d *schema.ResourceData, meta
596590
}
597591
if pulsarInstance.Spec.Type != cloudv1alpha1.PulsarInstanceTypeServerless && !pulsarCluster.IsUsingUrsaEngine() {
598592
bookkeeperImage := strings.Split(pulsarCluster.Spec.BookKeeper.Image, ":")
599-
_ = d.Set("bookkeeper_version", bookkeeperImage[1])
593+
if len(bookkeeperImage) > 1 {
594+
_ = d.Set("bookkeeper_version", bookkeeperImage[1])
595+
}
600596
}
601597
brokerImage := strings.Split(pulsarCluster.Spec.Broker.Image, ":")
602-
_ = d.Set("pulsar_version", brokerImage[1])
598+
if len(brokerImage) > 1 {
599+
_ = d.Set("pulsar_version", brokerImage[1])
600+
}
603601
releaseChannel := pulsarCluster.Spec.ReleaseChannel
604602
if releaseChannel != "" {
605603
_ = d.Set("release_channel", releaseChannel)

cloud/resource_pulsar_instance.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,22 @@ func resourcePulsarInstanceCreate(ctx context.Context, d *schema.ResourceData, m
134134
Namespace: poolNamespace,
135135
Name: poolName,
136136
}
137-
var t cloudv1alpha1.PulsarInstanceType
137+
poolOption, err := clientSet.CloudV1alpha1().
138+
PoolOptions(namespace).
139+
Get(ctx, fmt.Sprintf("%s-%s", poolNamespace, poolName), metav1.GetOptions{})
140+
if err != nil {
141+
return diag.FromErr(fmt.Errorf("ERROR_GET_POOL_OPTION: %w", err))
142+
}
138143
if instanceType == "" {
139-
t = cloudv1alpha1.PulsarInstanceTypeStandard
140-
} else {
141-
t = cloudv1alpha1.PulsarInstanceType(instanceType)
144+
if poolOption.Spec.DeploymentType == cloudv1alpha1.PoolDeploymentTypeHosted {
145+
instanceType = "serverless"
146+
}
147+
if poolOption.Spec.DeploymentType == cloudv1alpha1.PoolDeploymentTypeManaged {
148+
instanceType = "byoc"
149+
}
150+
if poolOption.Spec.DeploymentType == cloudv1alpha1.PoolDeploymentTypeManagedPro {
151+
instanceType = "byoc-pro"
152+
}
142153
}
143154
pulsarInstance := &cloudv1alpha1.PulsarInstance{
144155
TypeMeta: metav1.TypeMeta{
@@ -151,7 +162,7 @@ func resourcePulsarInstanceCreate(ctx context.Context, d *schema.ResourceData, m
151162
},
152163
Spec: cloudv1alpha1.PulsarInstanceSpec{
153164
AvailabilityMode: cloudv1alpha1.InstanceAvailabilityMode(availabilityMode),
154-
Type: t,
165+
Type: cloudv1alpha1.PulsarInstanceType(instanceType),
155166
PoolRef: poolRef,
156167
},
157168
}

cloud/validate_helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func validateEngine(val interface{}, key string) (warns []string, errs []error)
4040

4141
func validateInstanceType(val interface{}, key string) (warns []string, errs []error) {
4242
v := val.(string)
43-
if v != "serverless" && v != "standard" {
44-
errs = append(errs, fmt.Errorf("%q must be serverless or standard", key))
43+
if v != "serverless" && v != "standard" && v != "dedicated" && v != "byoc" && v != "byoc-pro" {
44+
errs = append(errs, fmt.Errorf("%q must be serverless, dedicated, byoc and byoc-pro", key))
4545
}
4646
return
4747
}

docs/data-sources/pulsar_cluster.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ description: |-
4242
- `ready` (String) Pulsar cluster is ready, it will be set to 'True' after the cluster is ready
4343
- `release_channel` (String) The release channel of the pulsar cluster subscribe to, it must to be lts or rapid, default rapid
4444
- `storage_unit` (Number) storage unit, 1 storage unit is 2 cpu and 8gb memory
45-
- `type` (String) The streamnative cloud instance type, supporting 'serverless' and 'standard'
45+
- `type` (String) The streamnative cloud instance type, supporting 'serverless', 'dedicated', 'byoc' and 'byoc-pro'
4646
- `websocket_service_url` (String) If you want to connect to the pulsar cluster using the websocket protocol, use this websocket service url.
4747
- `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
4848

docs/resources/pulsar_cluster.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ description: |-
4848
- `pulsar_tls_service_urls` (List of String) The service url of the pulsar cluster, use it to produce and consume message. There'll be multiple service urls if the cluster attached with multiple gateways
4949
- `pulsar_version` (String) The version of the pulsar cluster
5050
- `ready` (String) Pulsar cluster is ready, it will be set to 'True' after the cluster is ready
51-
- `type` (String) The streamnative cloud instance type, supporting 'serverless' and 'standard'
51+
- `type` (String) The streamnative cloud instance type, supporting 'serverless', 'dedicated', 'byoc' and 'byoc-pro'
5252
- `websocket_service_url` (String) If you want to connect to the pulsar cluster using the websocket protocol, use this websocket service url.
5353
- `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
5454

docs/resources/pulsar_instance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ description: |-
2626
### Optional
2727

2828
- `engine` (String) The streamnative cloud instance engine, supporting 'ursa' and 'classic', default 'classic'
29-
- `type` (String) The streamnative cloud instance type, supporting 'serverless' and 'standard'
29+
- `type` (String) The streamnative cloud instance type, supporting 'serverless', 'dedicated', 'byoc' and 'byoc-pro'
3030

3131
### Read-Only
3232

0 commit comments

Comments
 (0)