diff --git a/cloud/apikey_test.go b/cloud/apikey_test.go index 89cbaea..562f650 100644 --- a/cloud/apikey_test.go +++ b/cloud/apikey_test.go @@ -131,6 +131,7 @@ resource "streamnative_pulsar_cluster" "test-api-key-pulsar-cluster" { custom = { "allowAutoTopicCreation" = "true" "bookkeeper.journalSyncData" = "false" + "managedLedgerOffloadAutoTriggerSizeThresholdBytes" = "0" } } } diff --git a/cloud/data_source_pulsar_cluster.go b/cloud/data_source_pulsar_cluster.go index 536052c..e53bb6f 100644 --- a/cloud/data_source_pulsar_cluster.go +++ b/cloud/data_source_pulsar_cluster.go @@ -62,6 +62,11 @@ func dataSourcePulsarCluster() *schema.Resource { Description: descriptions["location"], Computed: true, }, + "release_channel": { + Type: schema.TypeString, + Description: descriptions["release_channel"], + Computed: true, + }, "bookie_replicas": { Type: schema.TypeInt, Description: descriptions["bookie_replicas"], @@ -238,6 +243,10 @@ func dataSourcePulsarClusterRead(ctx context.Context, d *schema.ResourceData, me _ = d.Set("pulsar_version", brokerImage[1]) bookkeeperImage := strings.Split(pulsarCluster.Spec.BookKeeper.Image, ":") _ = d.Set("bookkeeper_version", bookkeeperImage[1]) + releaseChannel := pulsarCluster.Spec.ReleaseChannel + if releaseChannel != "" { + _ = d.Set("release_channel", releaseChannel) + } d.SetId(fmt.Sprintf("%s/%s", pulsarCluster.Namespace, pulsarCluster.Name)) return nil } diff --git a/cloud/provider.go b/cloud/provider.go index 34e839a..013187c 100644 --- a/cloud/provider.go +++ b/cloud/provider.go @@ -62,6 +62,7 @@ func init() { "instance_name": "The pulsar instance name", "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", diff --git a/cloud/pulsar_cluster_test.go b/cloud/pulsar_cluster_test.go index dc28a13..8d9f6e6 100644 --- a/cloud/pulsar_cluster_test.go +++ b/cloud/pulsar_cluster_test.go @@ -43,7 +43,7 @@ func TestPulsarCluster(t *testing.T) { "sndev", clusterGeneratedName, "terraform-test-pulsar-instance", - "us-central1"), + "us-central1", "rapid"), Check: resource.ComposeTestCheckFunc( testCheckPulsarClusterExists("streamnative_pulsar_cluster.test-pulsar-cluster"), ), @@ -114,7 +114,7 @@ func testCheckPulsarClusterExists(name string) resource.TestCheckFunc { } } -func testResourceDataSourcePulsarCluster(organization, name, instanceName, location string) string { +func testResourceDataSourcePulsarCluster(organization, name, instanceName, location, releaseChannel string) string { return fmt.Sprintf(` provider "streamnative" { } @@ -123,6 +123,7 @@ resource "streamnative_pulsar_cluster" "test-pulsar-cluster" { name = "%s" instance_name = "%s" location = "%s" + release_channel = "%s" config { websocket_enabled = true function_enabled = false @@ -138,6 +139,7 @@ resource "streamnative_pulsar_cluster" "test-pulsar-cluster" { custom = { "allowAutoTopicCreation" = "true" "bookkeeper.journalSyncData" = "false" + "managedLedgerOffloadAutoTriggerSizeThresholdBytes" = "0" } } } @@ -146,5 +148,5 @@ data "streamnative_pulsar_cluster" "test-pulsar-cluster" { organization = streamnative_pulsar_cluster.test-pulsar-cluster.organization name = streamnative_pulsar_cluster.test-pulsar-cluster.name } -`, organization, name, instanceName, location) +`, organization, name, instanceName, location, releaseChannel) } diff --git a/cloud/resource_pulsar_cluster.go b/cloud/resource_pulsar_cluster.go index 5958cf8..969d794 100644 --- a/cloud/resource_pulsar_cluster.go +++ b/cloud/resource_pulsar_cluster.go @@ -84,6 +84,13 @@ func resourcePulsarCluster() *schema.Resource { Description: descriptions["location"], ValidateFunc: validateNotBlank, }, + "release_channel": { + Type: schema.TypeString, + Optional: true, + Default: "rapid", + Description: descriptions["release_channel"], + ValidateFunc: validateReleaseChannel, + }, "bookie_replicas": { Type: schema.TypeInt, Optional: true, @@ -232,6 +239,7 @@ func resourcePulsarClusterCreate(ctx context.Context, d *schema.ResourceData, me name := d.Get("name").(string) instanceName := d.Get("instance_name").(string) location := d.Get("location").(string) + 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) @@ -272,8 +280,9 @@ func resourcePulsarClusterCreate(ctx context.Context, d *schema.ResourceData, me Namespace: namespace, }, Spec: cloudv1alpha1.PulsarClusterSpec{ - InstanceName: instanceName, - Location: location, + InstanceName: instanceName, + Location: location, + ReleaseChannel: releaseChannel, BookKeeper: &cloudv1alpha1.BookKeeper{ Replicas: &bookieReplicas, Resources: &cloudv1alpha1.BookkeeperNodeResource{ @@ -375,6 +384,10 @@ func resourcePulsarClusterRead(ctx context.Context, d *schema.ResourceData, meta _ = d.Set("pulsar_version", brokerImage[1]) bookkeeperImage := strings.Split(pulsarCluster.Spec.BookKeeper.Image, ":") _ = d.Set("bookkeeper_version", bookkeeperImage[1]) + releaseChannel := pulsarCluster.Spec.ReleaseChannel + if releaseChannel != "" { + _ = d.Set("release_channel", releaseChannel) + } d.SetId(fmt.Sprintf("%s/%s", pulsarCluster.Namespace, pulsarCluster.Name)) return nil } @@ -396,6 +409,10 @@ func resourcePulsarClusterUpdate(ctx context.Context, d *schema.ResourceData, me return diag.FromErr(fmt.Errorf("ERROR_UPDATE_PULSAR_CLUSTER: " + "The pulsar cluster location does not support updates")) } + if d.HasChange("release_channel") { + return diag.FromErr(fmt.Errorf("ERROR_UPDATE_PULSAR_CLUSTER: " + + "The pulsar cluster release channel does not support updates")) + } namespace := d.Get("organization").(string) name := d.Get("name").(string) clientSet, err := getClientSet(getFactoryFromMeta(meta)) diff --git a/cloud/validate_helpers.go b/cloud/validate_helpers.go index bebe05d..f008526 100644 --- a/cloud/validate_helpers.go +++ b/cloud/validate_helpers.go @@ -28,6 +28,14 @@ func validateNotBlank(val interface{}, key string) (warns []string, errs []error return } +func validateReleaseChannel(val interface{}, key string) (warns []string, errs []error) { + v := val.(string) + if v != "lts" && v != "rapid" { + errs = append(errs, fmt.Errorf("%q must be tls or rapid", key)) + } + return +} + func validateBookieReplicas(val interface{}, key string) (warns []string, errs []error) { v := val.(int) if v < 3 || v > 15 { diff --git a/docs/resources/pulsar_cluster.md b/docs/resources/pulsar_cluster.md index 946d347..5b9ac65 100644 --- a/docs/resources/pulsar_cluster.md +++ b/docs/resources/pulsar_cluster.md @@ -28,6 +28,7 @@ description: |- - `broker_replicas` (Number) The number of broker replicas - `compute_unit` (Number) compute unit, 1 compute unit is 2 cpu and 8gb memory - `config` (Block List) (see [below for nested schema](#nestedblock--config)) +- `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 ### Read-Only diff --git a/examples/pulsarclusters/main.tf b/examples/pulsarclusters/main.tf index 784daad..354a70b 100644 --- a/examples/pulsarclusters/main.tf +++ b/examples/pulsarclusters/main.tf @@ -19,7 +19,7 @@ terraform { required_providers { streamnative = { version = "0.1.0" - source = "streamnative/streamnative" + source = "streamnative/streamnative" } } } @@ -30,18 +30,19 @@ provider "streamnative" { } resource "streamnative_pulsar_cluster" "test-cluster-1" { - organization = "sndev" - name = "test-cluster-1" - instance_name = "test-instance" - location = "us-central1" + organization = "sndev" + name = "test-cluster-1" + instance_name = "test-instance" + location = "us-central1" + release_channel = "rapid" bookie_replicas = 3 broker_replicas = 2 - compute_unit = 0.3 - storage_unit = 0.3 + compute_unit = 0.3 + storage_unit = 0.3 config { - websocket_enabled = true - function_enabled = false + websocket_enabled = true + function_enabled = false transaction_enabled = false protocols { mqtt = { @@ -55,15 +56,15 @@ resource "streamnative_pulsar_cluster" "test-cluster-1" { categories = ["Management", "Describe", "Produce", "Consume"] } custom = { - allowAutoTopicCreation = "true" + allowAutoTopicCreation = "true" } } } data "streamnative_pulsar_cluster" "test-cluster-1" { - depends_on = [streamnative_pulsar_cluster.test-cluster-1] + depends_on = [streamnative_pulsar_cluster.test-cluster-1] organization = streamnative_pulsar_cluster.test-cluster-1.organization - name = streamnative_pulsar_cluster.test-cluster-1.name + name = streamnative_pulsar_cluster.test-cluster-1.name } output "pulsar_cluster" { diff --git a/go.mod b/go.mod index 9315703..1479bfe 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/lestrrat-go/jwx/v2 v2.0.21 github.com/mitchellh/go-homedir v1.1.0 github.com/pkg/errors v0.9.1 - github.com/streamnative/cloud-api-server v1.17.1-0.20240201114855-a7d3a65094e8 + github.com/streamnative/cloud-api-server v1.25.3 github.com/streamnative/cloud-cli v0.14.3-0.20240202094224-5eec608e4680 github.com/xhit/go-str2duration/v2 v2.1.0 k8s.io/apimachinery v0.28.4 @@ -160,7 +160,7 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/api v0.28.4 // indirect - k8s.io/apiserver v0.23.17 // indirect + k8s.io/apiserver v0.24.0 // indirect k8s.io/component-base v0.28.4 // indirect k8s.io/klog v1.0.0 // indirect k8s.io/klog/v2 v2.100.1 // indirect diff --git a/go.sum b/go.sum index 76a7777..98b0532 100644 --- a/go.sum +++ b/go.sum @@ -521,6 +521,8 @@ github.com/streamnative/apiserver-builder-alpha v0.0.0-20230717175906-0f92408874 github.com/streamnative/apiserver-builder-alpha v0.0.0-20230717175906-0f9240887463/go.mod h1:W1q2VCPvT9GjMUsFX4JYmdXfSAYsrmLVLALfutt5LsE= github.com/streamnative/cloud-api-server v1.17.1-0.20240201114855-a7d3a65094e8 h1:xBeOFWaVodZLoF0G9suB+XcV1wts3bWAyQII0bjCwSk= github.com/streamnative/cloud-api-server v1.17.1-0.20240201114855-a7d3a65094e8/go.mod h1:rnneB8IS0MtXXwi/HAXxBojs2qQj8w2taq48WCrYhv8= +github.com/streamnative/cloud-api-server v1.25.3 h1:Dvr7H7tyOKCKGwj5JmO7KGN2TVlu9KrsF/Ih3zBce1c= +github.com/streamnative/cloud-api-server v1.25.3/go.mod h1:GX9siEefhX5wq6u3ay3lh8taVVvM7TTTGnXuJrWksWw= github.com/streamnative/cloud-cli v0.14.3-0.20240202094224-5eec608e4680 h1:PRqjyTsfwTCAd3SGDjgPT4Nmbczeegdm/ApyDGr14PA= github.com/streamnative/cloud-cli v0.14.3-0.20240202094224-5eec608e4680/go.mod h1:48XuDAuu3upsbndxqN+grxz9yPSklZk9ycxKB235dGs= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=