Skip to content

Commit

Permalink
feat: create new release (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirien committed May 9, 2024
1 parent 2a67595 commit 587c5cf
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 162 deletions.
32 changes: 15 additions & 17 deletions examples/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ go 1.21

toolchain go1.21.5

require github.com/pulumi/pulumi/sdk/v3 v3.102.0
require github.com/pulumi/pulumi/sdk/v3 v3.115.0

require github.com/pinecone-io/pulumi-pinecone/sdk v0.0.0

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
Expand All @@ -30,11 +29,11 @@ require (
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.11.0 // indirect
github.com/go-git/go-git/v5 v5.12.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
Expand Down Expand Up @@ -64,9 +63,8 @@ require (
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
Expand All @@ -76,18 +74,18 @@ require (
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/zclconf/go-cty v1.13.2 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/grpc v1.57.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/frand v1.4.2 // indirect
Expand Down
125 changes: 40 additions & 85 deletions examples/go/go.sum

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions provider/pkg/pinecone/config/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package config

import (
"context"
"fmt"
p "github.com/pulumi/pulumi-go-provider"
goprovider "github.com/pulumi/pulumi-go-provider"
"github.com/pulumi/pulumi-go-provider/infer"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"os"
)

Expand All @@ -16,8 +16,8 @@ func (c *PineconeProviderConfig) Annotate(a infer.Annotator) {
a.Describe(&c.APIKey, "The API token for Pinecone.")
}

func (c *PineconeProviderConfig) Configure(ctx p.Context) error {
ctx.Logf(diag.Debug, "Configuring Pinecone provider")
func (c *PineconeProviderConfig) Configure(ctx context.Context) error {
goprovider.GetLogger(ctx).Debugf("Configuring Pinecone provider")
if c.APIKey == "" {
APIKey, exists := os.LookupEnv("PINECONE_API_KEY")
if exists {
Expand Down
24 changes: 12 additions & 12 deletions provider/pkg/pinecone/index/collection.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package index

import (
"context"
"fmt"
"net/http"

"github.com/pinecone-io/pulumi-pinecone/provider/pkg/pinecone/client"
"github.com/pinecone-io/pulumi-pinecone/provider/pkg/pinecone/config"
"github.com/pinecone-io/pulumi-pinecone/provider/pkg/pinecone/utils"
p "github.com/pulumi/pulumi-go-provider"
goprovider "github.com/pulumi/pulumi-go-provider"
"github.com/pulumi/pulumi-go-provider/infer"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
)

type PineconeCollection struct{}
Expand All @@ -24,11 +24,11 @@ func (pc *PineconeCollectionArgs) Annotate(a infer.Annotator) {
a.Describe(&pc.CollectionSource, "The name of the index to be used as the source for the collection.")
}

func (*PineconeCollection) Create(ctx p.Context, name string, args PineconeCollectionArgs, preview bool) (string, PineconeCollectionState, error) {
func (*PineconeCollection) Create(ctx context.Context, name string, args PineconeCollectionArgs, preview bool) (string, PineconeCollectionState, error) {
pineconeConfig := infer.GetConfig[config.PineconeProviderConfig](ctx)

if preview {
ctx.Logf(diag.Debug, "Creating Pinecone collection %s", args.CollectionName)
goprovider.GetLogger(ctx).Debugf("Creating Pinecone collection %s", args.CollectionName)
return "", PineconeCollectionState{
PineconeCollectionArgs: PineconeCollectionArgs{
CollectionName: args.CollectionName,
Expand All @@ -47,16 +47,16 @@ func (*PineconeCollection) Create(ctx p.Context, name string, args PineconeColle
if err != nil {
return "", PineconeCollectionState{}, fmt.Errorf("failed to create Pinecone client: %w", err)
}
ctx.Logf(diag.Debug, "Creating Pinecone collection %s", args.CollectionName)
goprovider.GetLogger(ctx).Debugf("Creating Pinecone collection %s", args.CollectionName)
resp, err := pineconeClient.CreateCollectionWithResponse(ctx, client.CreateCollectionJSONRequestBody{
Name: args.CollectionName,
Source: args.CollectionSource,
})
if err != nil {
ctx.Logf(diag.Debug, "Failed to create Pinecone collection %s with http status code %d", args.CollectionName, resp.StatusCode())
goprovider.GetLogger(ctx).Debugf("Failed to create Pinecone collection %s with http status code %d", args.CollectionName, resp.StatusCode())
return "", PineconeCollectionState{}, fmt.Errorf("failed to create Pinecone collection: %w", err)
}
ctx.Logf(diag.Debug, "Pinecone collection creaation responese: %s", string(resp.Body))
goprovider.GetLogger(ctx).Debugf("Pinecone collection creaation responese: %s", string(resp.Body))

ready := false
for !ready {
Expand All @@ -80,7 +80,7 @@ func (*PineconeCollection) Create(ctx p.Context, name string, args PineconeColle
}, nil
}

func (*PineconeCollection) Delete(ctx p.Context, id string, args PineconeCollectionArgs) error {
func (*PineconeCollection) Delete(ctx context.Context, id string, args PineconeCollectionArgs) error {
pineconeConfig := infer.GetConfig[config.PineconeProviderConfig](ctx)
httpClient := &http.Client{
Transport: &utils.CustomTransport{
Expand All @@ -94,14 +94,14 @@ func (*PineconeCollection) Delete(ctx p.Context, id string, args PineconeCollect
}
response, err := pineconeClient.DeleteCollectionWithResponse(ctx, args.CollectionName)
if err != nil {
ctx.Logf(diag.Error, "Failed to delete Pinecone collection: %s with http status code: %d", args.CollectionName, response.StatusCode())
goprovider.GetLogger(ctx).Errorf("Failed to delete Pinecone collection: %s with http status code: %d", args.CollectionName, response.StatusCode())
return fmt.Errorf("failed to delete Pinecone collection: %w", err)
}
ctx.Logf(diag.Debug, "Successfully deleted Pinecone collection: %s", args.CollectionName)
goprovider.GetLogger(ctx).Debugf("Successfully deleted Pinecone collection: %s", args.CollectionName)
return nil
}

func (*PineconeCollection) Read(ctx p.Context, id string, args PineconeCollectionArgs, state PineconeCollectionState) (canonicalID string, normalizedInputs PineconeCollectionArgs, normalizedState PineconeCollectionState, err error) {
func (*PineconeCollection) Read(ctx context.Context, id string, args PineconeCollectionArgs, state PineconeCollectionState) (canonicalID string, normalizedInputs PineconeCollectionArgs, normalizedState PineconeCollectionState, err error) {
pineconeConfig := infer.GetConfig[config.PineconeProviderConfig](ctx)
httpClient := &http.Client{
Transport: &utils.CustomTransport{
Expand All @@ -117,7 +117,7 @@ func (*PineconeCollection) Read(ctx p.Context, id string, args PineconeCollectio
resp, err := pineconeClient.DescribeCollectionWithResponse(ctx, args.CollectionName)
if err != nil {
if resp.JSON404 != nil {
ctx.Logf(diag.Debug, "Pinecone collection '%s' not found", args.CollectionName)
goprovider.GetLogger(ctx).Debugf("Pinecone collection '%s' not found", args.CollectionName)
return id, args, state, nil
}
return id, args, state, fmt.Errorf("error getting Pinecone collection details '%s': %w", args.CollectionName, err)
Expand Down
10 changes: 5 additions & 5 deletions provider/pkg/pinecone/index/getCollection.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package index

import (
"context"
"fmt"
goprovider "github.com/pulumi/pulumi-go-provider"
"net/http"

"github.com/pinecone-io/pulumi-pinecone/provider/pkg/pinecone/client"
"github.com/pinecone-io/pulumi-pinecone/provider/pkg/pinecone/config"
"github.com/pinecone-io/pulumi-pinecone/provider/pkg/pinecone/utils"
p "github.com/pulumi/pulumi-go-provider"
"github.com/pulumi/pulumi-go-provider/infer"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
)

type LookupPineconeCollection struct{}
Expand All @@ -18,7 +18,7 @@ func (g *LookupPineconeCollection) Annotate(a infer.Annotator) {
a.Describe(&g, "The result of a get operation on a Pinecone collection.")
}

func (*LookupPineconeCollection) Call(ctx p.Context, args LookupPineconeCollectionArgs) (LookupPineconeCollectionResult, error) {
func (*LookupPineconeCollection) Call(ctx context.Context, args LookupPineconeCollectionArgs) (LookupPineconeCollectionResult, error) {
pineconeConfig := infer.GetConfig[config.PineconeProviderConfig](ctx)
httpClient := &http.Client{
Transport: &utils.CustomTransport{
Expand All @@ -31,9 +31,9 @@ func (*LookupPineconeCollection) Call(ctx p.Context, args LookupPineconeCollecti
return LookupPineconeCollectionResult{}, err
}
resp, err := pineconeClient.DescribeCollectionWithResponse(ctx, args.CollectionName)
ctx.Logf(diag.Debug, "DescribeCollectionWithResponse: %v", resp.Status())
goprovider.GetLogger(ctx).Debugf("DescribeCollectionWithResponse: %v", resp.Status())
if err != nil {
ctx.Logf(diag.Error, "DescribeCollectionWithResponse: %v", resp.Status())
goprovider.GetLogger(ctx).Errorf("DescribeCollectionWithResponse: %v", resp.Status())
return LookupPineconeCollectionResult{}, err
}
if resp.StatusCode() != http.StatusOK {
Expand Down
10 changes: 5 additions & 5 deletions provider/pkg/pinecone/index/getIndex.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package index

import (
"context"
"fmt"
"github.com/pinecone-io/pulumi-pinecone/provider/pkg/pinecone/client"
"github.com/pinecone-io/pulumi-pinecone/provider/pkg/pinecone/config"
"github.com/pinecone-io/pulumi-pinecone/provider/pkg/pinecone/utils"
p "github.com/pulumi/pulumi-go-provider"
goprovider "github.com/pulumi/pulumi-go-provider"
"github.com/pulumi/pulumi-go-provider/infer"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"net/http"
)

type LookupPineconeIndex struct{}

func (*LookupPineconeIndex) Call(ctx p.Context, args LookupPineconeIndexArgs) (LookupPineconeIndexResult, error) {
func (*LookupPineconeIndex) Call(ctx context.Context, args LookupPineconeIndexArgs) (LookupPineconeIndexResult, error) {
pineconeConfig := infer.GetConfig[config.PineconeProviderConfig](ctx)
httpClient := &http.Client{
Transport: &utils.CustomTransport{
Expand All @@ -26,9 +26,9 @@ func (*LookupPineconeIndex) Call(ctx p.Context, args LookupPineconeIndexArgs) (L
return LookupPineconeIndexResult{}, err
}
resp, err := pineconeClient.DescribeIndexWithResponse(ctx, args.IndexName)
ctx.Logf(diag.Debug, "DescribeIndexWithResponse: %v", resp.Status())
goprovider.GetLogger(ctx).Debugf("DescribeIndexWithResponse: %v", resp.Status())
if err != nil {
ctx.Logf(diag.Error, "DescribeIndexWithResponse: %v", resp.Status())
goprovider.GetLogger(ctx).Errorf("DescribeIndexWithResponse: %v", resp.Status())
return LookupPineconeIndexResult{}, err
}
if resp.StatusCode() != http.StatusOK {
Expand Down
39 changes: 19 additions & 20 deletions provider/pkg/pinecone/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"github.com/pinecone-io/pulumi-pinecone/provider/pkg/pinecone/client"
"github.com/pinecone-io/pulumi-pinecone/provider/pkg/pinecone/config"
"github.com/pinecone-io/pulumi-pinecone/provider/pkg/pinecone/utils"
p "github.com/pulumi/pulumi-go-provider"
goprovider "github.com/pulumi/pulumi-go-provider"
"github.com/pulumi/pulumi-go-provider/infer"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"net/http"
)

Expand Down Expand Up @@ -40,7 +39,7 @@ type PineconePodSpec struct {
Shards PodSpecShards `pulumi:"shards,optional,omitempty"`
PodType PodSpecPodType `pulumi:"podType"`
Pods int `pulumi:"pods,optional,omitempty"`
MetaDataConfig MetaDataConfig `pulumi:"metaDataConfig,optional"`
MetaDataConfig *MetaDataConfig `pulumi:"metaDataConfig,optional"`
SourceCollection *string `pulumi:"sourceCollection,optional"`
}

Expand Down Expand Up @@ -139,7 +138,7 @@ func (pim *MetaDataConfig) Annotate(a infer.Annotator) {
" property to specify an array of metadata fields which should be indexed.")
}

func (*PineconeIndex) Create(ctx p.Context, name string, args PineconeIndexArgs, preview bool) (string, PineconeIndexState, error) {
func (*PineconeIndex) Create(ctx context.Context, name string, args PineconeIndexArgs, preview bool) (string, PineconeIndexState, error) {
pineconeConfig := infer.GetConfig[config.PineconeProviderConfig](ctx)
if err := utils.ValidateIndexName(args.IndexName); err != nil {
return "", PineconeIndexState{}, fmt.Errorf("invalid index name: %w", err)
Expand All @@ -149,10 +148,10 @@ func (*PineconeIndex) Create(ctx p.Context, name string, args PineconeIndexArgs,
if indexDimension == 0 {
indexDimension = utils.IndexDimensionDefault
}
ctx.Logf(diag.Debug, "Pinecone index dimension: %d", indexDimension)
goprovider.GetLogger(ctx).Debugf("Pinecone index dimension: %d", indexDimension)

if preview {
ctx.Logf(diag.Debug, "Previewing Pinecone index creation: %s", args.IndexName)
goprovider.GetLogger(ctx).Debugf("Previewing Pinecone index creation: %s", args.IndexName)
return args.IndexName, PineconeIndexState{
PineconeIndexArgs: PineconeIndexArgs{
IndexName: args.IndexName,
Expand All @@ -174,20 +173,20 @@ func (*PineconeIndex) Create(ctx p.Context, name string, args PineconeIndexArgs,
return "", PineconeIndexState{}, fmt.Errorf("failed to create Pinecone client: %w", err)
}

ctx.Logf(diag.Debug, "Creating Pinecone index: %s", args.IndexName)
goprovider.GetLogger(ctx).Debugf("Creating Pinecone index: %s", args.IndexName)

var spec client.CreateIndexRequest_Spec

if args.IndexSpec.Serverless != nil {
ctx.Logf(diag.Debug, "Creating Pinecone serverless index: %s", args.IndexName)
goprovider.GetLogger(ctx).Debugf("Creating Pinecone serverless index: %s", args.IndexName)
spec = client.CreateIndexRequest_Spec{
Serverless: &client.ServerlessSpec{
Cloud: client.ServerlessSpecCloud(args.IndexSpec.Serverless.Cloud),
Region: args.IndexSpec.Serverless.Region,
},
}
} else if args.IndexSpec.Pod != nil {
ctx.Logf(diag.Debug, "Creating Pinecone pod-based index: %s", args.IndexName)
goprovider.GetLogger(ctx).Debugf("Creating Pinecone pod-based index: %s", args.IndexName)
spec = client.CreateIndexRequest_Spec{
Pod: &client.PodSpec{
Environment: args.IndexSpec.Pod.Environment,
Expand All @@ -212,22 +211,22 @@ func (*PineconeIndex) Create(ctx p.Context, name string, args PineconeIndexArgs,
Spec: spec,
})
if err != nil {
ctx.Logf(diag.Error, "Failed to create Pinecone index: %s with http status code: %d", args.IndexName, response.StatusCode())
ctx.Logf(diag.Error, "Please run the Pulumi command with the `-d` flag to see the full error message")
goprovider.GetLogger(ctx).Errorf("Failed to create Pinecone index: %s with http status code: %d", args.IndexName, response.StatusCode())
goprovider.GetLogger(ctx).Errorf("Please run the Pulumi command with the `-d` flag to see the full error message")
return "", PineconeIndexState{}, fmt.Errorf("failed to create Pinecone index: %w", err)
}
ctx.Logf(diag.Debug, "Pinecone index creation response: %s", string(response.Body))
goprovider.GetLogger(ctx).Debugf("Pinecone index creation response: %s", string(response.Body))

ready := false
for !ready {
ctx.Logf(diag.Debug, "Waiting for Pinecone index: %s to be ready", args.IndexName)
goprovider.GetLogger(ctx).Debugf("Waiting for Pinecone index: %s to be ready", args.IndexName)
response, err := pineconeClient.DescribeIndexWithResponse(context.Background(), args.IndexName)
if err != nil {
ctx.Logf(diag.Error, "Failed to get Pinecone index: %s with http error code: %d", args.IndexName, response.StatusCode())
goprovider.GetLogger(ctx).Errorf("Failed to get Pinecone index: %s with http error code: %d", args.IndexName, response.StatusCode())
return "", PineconeIndexState{}, fmt.Errorf("failed to get Pinecone index: %w", err)
}
if response.StatusCode() != http.StatusOK {
ctx.Logf(diag.Error, "Failed to get Pinecone index: %s with http error code: %d", args.IndexName, response.StatusCode())
goprovider.GetLogger(ctx).Errorf("Failed to get Pinecone index: %s with http error code: %d", args.IndexName, response.StatusCode())
return "", PineconeIndexState{}, fmt.Errorf("failed to get Pinecone index: %s", args.IndexName)
}
if response.JSON200.Status.Ready {
Expand All @@ -254,7 +253,7 @@ func (*PineconeIndex) Create(ctx p.Context, name string, args PineconeIndexArgs,
}, nil
}

func (pi *PineconeIndex) Delete(ctx p.Context, id string, state PineconeIndexState) error {
func (pi *PineconeIndex) Delete(ctx context.Context, id string, state PineconeIndexState) error {
pineconeConfig := infer.GetConfig[config.PineconeProviderConfig](ctx)
httpClient := &http.Client{
Transport: &utils.CustomTransport{
Expand All @@ -269,14 +268,14 @@ func (pi *PineconeIndex) Delete(ctx p.Context, id string, state PineconeIndexSta

response, err := pineconeClient.DeleteIndexWithResponse(context.Background(), state.IndexName)
if err != nil {
ctx.Logf(diag.Error, "Failed to delete Pinecone index: %s with http error code: %d", state.IndexName, response.StatusCode())
goprovider.GetLogger(ctx).Errorf("Failed to delete Pinecone index: %s with http error code: %d", state.IndexName, response.StatusCode())
return fmt.Errorf("error deleting Pinecone index '%s': %w", state.IndexName, err)
}
ctx.Logf(diag.Debug, "Successfully deleted Pinecone index: %s", state.IndexName)
goprovider.GetLogger(ctx).Debugf("Successfully deleted Pinecone index: %s", state.IndexName)
return nil
}

func (pi *PineconeIndex) Read(ctx p.Context, id string, args PineconeIndexArgs, state PineconeIndexState) (canonicalID string, normalizedInputs PineconeIndexArgs, normalizedState PineconeIndexState, err error) {
func (pi *PineconeIndex) Read(ctx context.Context, id string, args PineconeIndexArgs, state PineconeIndexState) (canonicalID string, normalizedInputs PineconeIndexArgs, normalizedState PineconeIndexState, err error) {
pineconeConfig := infer.GetConfig[config.PineconeProviderConfig](ctx)
httpClient := &http.Client{
Transport: &utils.CustomTransport{
Expand All @@ -292,7 +291,7 @@ func (pi *PineconeIndex) Read(ctx p.Context, id string, args PineconeIndexArgs,
indexDetails, err := pineconeClient.DescribeIndexWithResponse(context.Background(), state.IndexName)
if err != nil {
if indexDetails.JSON404 != nil {
ctx.Logf(diag.Debug, "Pinecone index '%s' not found", state.IndexName)
goprovider.GetLogger(ctx).Debugf("Pinecone index '%s' not found", state.IndexName)
return id, args, state, nil
}
return id, args, state, fmt.Errorf("error getting Pinecone index details '%s': %w", state.IndexName, err)
Expand Down
Loading

0 comments on commit 587c5cf

Please sign in to comment.