Skip to content

Commit

Permalink
Merge pull request #21 from tensorchord/fix-image
Browse files Browse the repository at this point in the history
support vectorchord image
  • Loading branch information
xieydd authored Nov 28, 2024
2 parents 6a67127 + c9cff81 commit 747e986
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/resources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ Cluster resource. This resource allows you to create a new PGVecto.rs cluster.
- `cluster_name` (String) The name of the cluster to be created. It is a string of no more than 32 characters.
- `cluster_provider` (String) The cloud provider of the cluster instance. At present, only aws is supported.
- `database_name` (String) The name of the database.
- `image` (String) The image of the cluster instance. You can specify the tag of the image, please select limited tags in https://hub.docker.com/repository/docker/modelzai/pgvecto-rs/tags
- `image` (String) The image of the cluster instance. You can specify the tag of the image, please select limited tags in https://cloud.pgvecto.rs/api/v1/images
- `plan` (String) The plan tier of the PGVecto.rs Cloud service. Available options are Starter and Enterprise.
- `region` (String) The region of the cluster instance.Available options are us-east-1,eu-west-1
- `server_resource` (String) The server resource of the cluster instance. Available aws-t3-xlarge-4c-16g, aws-m7i-large-2c-8g, aws-r7i-large-2c-16g,aws-r7i-xlarge-4c-32g
- `server_resource` (String) The server resource of the cluster instance. Available aws-t3-xlarge-4c-16g, aws-m7i-large-2c-8g, aws-r7i-large-2c-16g,aws-r7i-xlarge-4c-32g,aws-i4i-xlarge-4c-32g

### Optional

Expand Down
17 changes: 11 additions & 6 deletions pgvecto.rs/provider/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func (r *ClusterResource) Metadata(ctx context.Context, req resource.MetadataReq
type imageValidator struct{}

func (v imageValidator) Description(ctx context.Context) string {
return "Validate image choose from https://hub.docker.com/repository/docker/modelzai/pgvecto-rs/tags"
return "Validate image"
}

func (v imageValidator) MarkdownDescription(ctx context.Context) string {
return "Validate image choose from https://hub.docker.com/repository/docker/modelzai/pgvecto-rs/tags"
return "Validate image"
}

func (v imageValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) {
Expand All @@ -66,7 +66,7 @@ func (v imageValidator) ValidateString(ctx context.Context, req validator.String
if resp.Diagnostics.HasError() {
return
}
pattern := `^\d+-v\d+\.\d+\.\d+-[a-zA-Z]+$`
pattern := `^\d+-v\d+\.\d+\.\d+(?:-[a-zA-Z]+(?:-[a-zA-Z]+)?)?$`
re := regexp.MustCompile(pattern)
match := re.MatchString(tag.ValueString())
if !match {
Expand Down Expand Up @@ -104,11 +104,11 @@ func (r *ClusterResource) Schema(ctx context.Context, req resource.SchemaRequest
Required: true,
},
"server_resource": schema.StringAttribute{
MarkdownDescription: "The server resource of the cluster instance. Available aws-t3-xlarge-4c-16g, aws-m7i-large-2c-8g, aws-r7i-large-2c-16g,aws-r7i-xlarge-4c-32g",
MarkdownDescription: "The server resource of the cluster instance. Available aws-t3-xlarge-4c-16g, aws-m7i-large-2c-8g, aws-r7i-large-2c-16g,aws-r7i-xlarge-4c-32g,aws-i4i-xlarge-4c-32g",
Required: true,
},
"image": schema.StringAttribute{
MarkdownDescription: "The image of the cluster instance. You can specify the tag of the image, please select limited tags in https://hub.docker.com/repository/docker/modelzai/pgvecto-rs/tags",
MarkdownDescription: "The image of the cluster instance. You can specify the tag of the image, please select limited tags in https://cloud.pgvecto.rs/api/v1/images",
Required: true,
Validators: []validator.String{
imageValidator{},
Expand Down Expand Up @@ -259,6 +259,11 @@ func (r *ClusterResource) Create(ctx context.Context, req resource.CreateRequest
var response *client.CNPGCluster
var err error

image := fmt.Sprintf("modelzai/pgvecto-rs:%s", data.Image.ValueString())
if !strings.Contains(image, "exts") {
image = fmt.Sprintf("modelzai/vchord-cnpg:%s", data.Image.ValueString())
}

spec := client.CNPGClusterSpec{
Name: data.ClusterName.ValueString(),
Plan: client.CNPGClusterPlan(data.Plan.ValueString()),
Expand All @@ -268,7 +273,7 @@ func (r *ClusterResource) Create(ctx context.Context, req resource.CreateRequest
Region: data.Region.ValueString(),
},
PostgreSQLConfig: client.PostgreSQLConfig{
Image: fmt.Sprintf("modelzai/pgvecto-rs:%s", data.Image.ValueString()),
Image: image,
PGDataDiskSize: data.PGDataDiskSize.ValueString(),
VectorConfig: client.VectorConfig{
DatabaseName: data.DatabaseName.ValueString(),
Expand Down
8 changes: 4 additions & 4 deletions pgvecto.rs/provider/cluster_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ resource "pgvecto-rs-cloud_cluster" "enterprise_plan_cluster" {
cluster_name = %q
account_id = "5c3cb62b-d00b-4dda-85e6-2c0452d50138"
plan = "Enterprise"
image = "16-v0.4.0-extensions"
image = "16-v0.4.0-extensions-exts"
server_resource = "aws-m7i-large-2c-8g"
region = "us-east-1"
cluster_provider = "aws"
Expand All @@ -135,7 +135,7 @@ resource "pgvecto-rs-cloud_cluster" "enterprise_plan_cluster" {
cluster_name = %q
account_id = "5c3cb62b-d00b-4dda-85e6-2c0452d50138"
plan = "Enterprise"
image = "16-v0.4.0-extensions"
image = "16-v0.4.0-extensions-exts"
server_resource = "aws-m7i-large-2c-8g"
region = "us-east-1"
cluster_provider = "aws"
Expand All @@ -152,7 +152,7 @@ resource "pgvecto-rs-cloud_cluster" "enterprise_plan_cluster_restore_backup" {
cluster_name = %q
account_id = "5c3cb62b-d00b-4dda-85e6-2c0452d50138"
plan = "Enterprise"
image = "16-v0.4.0-extensions"
image = "16-v0.4.0-extensions-exts"
server_resource = "aws-m7i-large-2c-8g"
region = "us-east-1"
cluster_provider = "aws"
Expand All @@ -171,7 +171,7 @@ resource "pgvecto-rs-cloud_cluster" "enterprise_plan_cluster_pitr" {
cluster_name = %q
account_id = "5c3cb62b-d00b-4dda-85e6-2c0452d50138"
plan = "Enterprise"
image = "16-v0.4.0-extensions"
image = "16-v0.4.0-extensions-exts"
server_resource = "aws-m7i-large-2c-8g"
region = "us-east-1"
cluster_provider = "aws"
Expand Down

0 comments on commit 747e986

Please sign in to comment.