Skip to content

Commit a9a6066

Browse files
Support DeletionProtection, index configure command, and bump go-pinecone from v0.5.0 -> v1.1.0 (#16)
## Problem Currently the CLI relies on `v0.5.0` of the `go-pinecone` SDK. We've since released `v1.1.0` of `go-pinecone` and would like to bump the dependency within the CLI. `v1.0.0` added `DeletionProtection` for indexes, which wasn't supported in either `index create-pod`, `index create-serverless`, or any of the other index operations. Additionally, while working on this I noticed we don't currently support an `index configure` command. ## Solution - Bump the `go-pinecone` dependency from `v0.5.0` -> `v1.1.0`. There were no major API changes that needed to be accounted for in the CLI because of this update. - Add `deletion_protection` as an optional argument for both `index create-pod` and `index create-serverless` commands. - Print `DeletionProtection` as a part of the `PrintDescribeIndexTable` presenter. - Add new `/command/index/configure.go` command to allow configuring indexes through the CLI. Use the command in `/command/index/cmd.go`. - Fix errors being swallowed when calling `index delete` command. ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [X] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [ ] None of the above: (explain here) ## Test Plan CLI functionality should remain largely unchanged. You can pull this branch down and install `goreleaser` to build and test locally: ``` # build CLI locally goreleaser build --single-target --snapshot --clean # login or set-api-key manually ./dist/pinecone_darwin_arm64/pinecone login ./dist/pinecone_darwin_arm64/pinecone config set-api-key "YOUR_API_KEY" # work with indexes ./dist/pinecone_darwin_arm64/pinecone index list ./dist/pinecone_darwin_arm64/pinecone index create-pod -n "test-cli-create-pod" -d 3 -m "cosine" -e "us-east-1-aws" -t "p1.x1" --deletion_protection "enabled" ./dist/pinecone_darwin_arm64/pinecone index configure -n "test-cli-create_pod" -p "disabled" ./dist/pinecone_darwin_arm64/pinecone index describe --name test-cli-create-pod ``` --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1208161607942737
1 parent 81f7555 commit a9a6066

File tree

8 files changed

+156
-71
lines changed

8 files changed

+156
-71
lines changed

go.mod

+14-13
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ require (
99
github.com/charmbracelet/lipgloss v0.10.0
1010
github.com/fatih/color v1.16.0
1111
github.com/golang-jwt/jwt/v5 v5.2.1
12-
github.com/pinecone-io/go-pinecone v0.5.0
12+
github.com/pinecone-io/go-pinecone v1.1.0
1313
github.com/rs/zerolog v1.32.0
1414
github.com/spf13/cobra v1.8.0
1515
github.com/spf13/viper v1.18.2
16-
golang.org/x/oauth2 v0.19.0
16+
golang.org/x/oauth2 v0.21.0
1717
)
1818

1919
require (
2020
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
2121
github.com/atotto/clipboard v0.1.4 // indirect
2222
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
2323
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
24+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2425
github.com/fsnotify/fsnotify v1.7.0 // indirect
25-
github.com/golang/protobuf v1.5.3 // indirect
2626
github.com/google/uuid v1.6.0 // indirect
2727
github.com/hashicorp/hcl v1.0.0 // indirect
2828
github.com/inconshreveable/mousetrap v1.1.0 // indirect
@@ -39,6 +39,7 @@ require (
3939
github.com/muesli/termenv v0.15.2 // indirect
4040
github.com/oapi-codegen/runtime v1.1.1 // indirect
4141
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
42+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
4243
github.com/rivo/uniseg v0.4.7 // indirect
4344
github.com/sagikazarmark/locafero v0.4.0 // indirect
4445
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
@@ -47,20 +48,20 @@ require (
4748
github.com/spf13/afero v1.11.0 // indirect
4849
github.com/spf13/cast v1.6.0 // indirect
4950
github.com/spf13/pflag v1.0.5 // indirect
51+
github.com/stretchr/testify v1.9.0 // indirect
5052
github.com/subosito/gotenv v1.6.0 // indirect
5153
go.uber.org/atomic v1.9.0 // indirect
5254
go.uber.org/multierr v1.9.0 // indirect
5355
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
54-
golang.org/x/net v0.21.0 // indirect
55-
golang.org/x/sync v0.6.0 // indirect
56-
golang.org/x/sys v0.19.0 // indirect
57-
golang.org/x/term v0.17.0 // indirect
58-
golang.org/x/text v0.14.0 // indirect
59-
google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c // indirect
60-
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c // indirect
61-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
62-
google.golang.org/grpc v1.62.0 // indirect
63-
google.golang.org/protobuf v1.32.0 // indirect
56+
golang.org/x/net v0.29.0 // indirect
57+
golang.org/x/sync v0.8.0 // indirect
58+
golang.org/x/sys v0.25.0 // indirect
59+
golang.org/x/term v0.24.0 // indirect
60+
golang.org/x/text v0.18.0 // indirect
61+
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
62+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
63+
google.golang.org/grpc v1.66.1 // indirect
64+
google.golang.org/protobuf v1.34.2 // indirect
6465
gopkg.in/ini.v1 v1.67.0 // indirect
6566
gopkg.in/yaml.v3 v3.0.1 // indirect
6667
)

go.sum

+24-32
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyT
3131
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
3232
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
3333
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
34-
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
35-
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
36-
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
37-
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
3834
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
3935
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
4036
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@@ -79,8 +75,8 @@ github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmt
7975
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
8076
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
8177
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
82-
github.com/pinecone-io/go-pinecone v0.5.0 h1:Vw4Wbn/yYEx9XSjPqGMU0sVnxitub11FhJk4gWc+EvQ=
83-
github.com/pinecone-io/go-pinecone v0.5.0/go.mod h1:KwWSueZFx9zccC+thBk13+LDiOgii8cff9bliUI4tQs=
78+
github.com/pinecone-io/go-pinecone v1.1.0 h1:IUGfb1x2dtN7oN+p8ssQMf1M2S3BgQ26h54mdmibKG4=
79+
github.com/pinecone-io/go-pinecone v1.1.0/go.mod h1:KfJhn4yThX293+fbtrZLnxe2PJYo8557Py062W4FYKk=
8480
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
8581
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8682
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
@@ -120,8 +116,9 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
120116
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
121117
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
122118
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
123-
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
124119
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
120+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
121+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
125122
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
126123
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
127124
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
@@ -130,35 +127,30 @@ go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
130127
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
131128
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
132129
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
133-
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
134-
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
135-
golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg=
136-
golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8=
137-
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
138-
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
130+
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
131+
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
132+
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
133+
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
134+
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
135+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
139136
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
140137
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
141138
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
142139
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
143-
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
144-
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
145-
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
146-
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
147-
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
148-
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
149-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
150-
google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c h1:Zmyn5CV/jxzKnF+3d+xzbomACPwLQqVpLTpyXN5uTaQ=
151-
google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo=
152-
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c h1:9g7erC9qu44ks7UK4gDNlnk4kOxZG707xKm4jVniy6o=
153-
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8=
154-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c h1:NUsgEN92SQQqzfA+YtqYNqYmB3DMMYLlIwUZAQFVFbo=
155-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
156-
google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk=
157-
google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
158-
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
159-
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
160-
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
161-
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
140+
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
141+
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
142+
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
143+
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
144+
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
145+
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
146+
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 h1:hjSy6tcFQZ171igDaN5QHOw2n6vx40juYbC/x67CEhc=
147+
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:qpvKtACPCQhAdu3PyQgV4l3LMXZEtft7y8QcarRsp9I=
148+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ=
149+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
150+
google.golang.org/grpc v1.66.1 h1:hO5qAXR19+/Z44hmvIM4dQFMSYX9XcWsByfoxutBpAM=
151+
google.golang.org/grpc v1.66.1/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
152+
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
153+
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
162154
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
163155
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
164156
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

internal/pkg/cli/command/index/cmd.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func NewIndexCmd() *cobra.Command {
2323
cmd.AddCommand(NewListCmd())
2424
cmd.AddCommand(NewCreateServerlessCmd())
2525
cmd.AddCommand(NewCreatePodCmd())
26+
cmd.AddCommand(NewConfigureIndexCmd())
2627
cmd.AddCommand(NewDeleteCmd())
2728

2829
return cmd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package index
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/pinecone-io/cli/internal/pkg/utils/exit"
8+
"github.com/pinecone-io/cli/internal/pkg/utils/msg"
9+
"github.com/pinecone-io/cli/internal/pkg/utils/pcio"
10+
"github.com/pinecone-io/cli/internal/pkg/utils/presenters"
11+
"github.com/pinecone-io/cli/internal/pkg/utils/sdk"
12+
"github.com/pinecone-io/cli/internal/pkg/utils/style"
13+
"github.com/pinecone-io/cli/internal/pkg/utils/text"
14+
"github.com/pinecone-io/go-pinecone/pinecone"
15+
"github.com/spf13/cobra"
16+
)
17+
18+
type configureIndexOptions struct {
19+
name string
20+
podType string
21+
replicas int32
22+
deletionProtection string
23+
24+
json bool
25+
}
26+
27+
func NewConfigureIndexCmd() *cobra.Command {
28+
options := configureIndexOptions{}
29+
30+
cmd := &cobra.Command{
31+
Use: "configure",
32+
Short: "Configure an existing index with the specified configuration",
33+
Example: "",
34+
Run: func(cmd *cobra.Command, args []string) {
35+
runConfigureIndexCmd(cmd, options)
36+
},
37+
}
38+
39+
// Required flags
40+
cmd.Flags().StringVarP(&options.name, "name", "n", "", "name of index to configure")
41+
42+
// Optional flags
43+
cmd.Flags().StringVarP(&options.podType, "pod_type", "t", "", "type of pod to use, can only upgrade when configuring")
44+
cmd.Flags().Int32VarP(&options.replicas, "replicas", "r", 0, "replicas of the index to configure")
45+
cmd.Flags().StringVarP(&options.deletionProtection, "deletion_protection", "p", "", "enable or disable deletion protection for the index")
46+
47+
return cmd
48+
}
49+
50+
func runConfigureIndexCmd(cmd *cobra.Command, options configureIndexOptions) {
51+
ctx := context.Background()
52+
pc := sdk.NewPineconeClient()
53+
54+
idx, err := pc.ConfigureIndex(ctx, options.name, pinecone.ConfigureIndexParams{
55+
PodType: options.podType,
56+
Replicas: options.replicas,
57+
DeletionProtection: pinecone.DeletionProtection(options.deletionProtection),
58+
})
59+
if err != nil {
60+
msg.FailMsg("Failed to configure index %s: %+v\n", style.Emphasis(options.name), err)
61+
exit.Error(err)
62+
}
63+
if options.json {
64+
text.PrettyPrintJSON(idx)
65+
return
66+
}
67+
68+
describeCommand := pcio.Sprintf("pinecone index describe --name %s", idx.Name)
69+
msg.SuccessMsg("Index %s configured successfully. Run %s to check status. \n\n", style.Emphasis(idx.Name), style.Code(describeCommand))
70+
fmt.Printf("Index model on configure return: %+v\n", idx.Spec.Pod)
71+
presenters.PrintDescribeIndexTable(idx)
72+
}

internal/pkg/cli/command/index/create_pod.go

+18-15
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ import (
1515
)
1616

1717
type createPodOptions struct {
18-
name string
19-
dimension int32
20-
metric string
21-
environment string
22-
podType string
23-
shards int32
24-
replicas int32
25-
sourceCollection string
18+
name string
19+
dimension int32
20+
metric string
21+
environment string
22+
podType string
23+
shards int32
24+
replicas int32
25+
sourceCollection string
26+
deletionProtection string
2627
// metadataConfig *PodSpecMetadataConfig
2728

2829
json bool
@@ -56,6 +57,7 @@ func NewCreatePodCmd() *cobra.Command {
5657
cmd.Flags().Int32VarP(&options.shards, "shards", "s", 1, "shards of the index to create")
5758
cmd.Flags().Int32VarP(&options.replicas, "replicas", "r", 1, "replicas of the index to create")
5859
cmd.Flags().StringVarP(&options.sourceCollection, "source_collection", "c", "", "When creating a pod index using data from a collection, the name of the source collection")
60+
cmd.Flags().StringVarP(&options.deletionProtection, "deletion_protection", "p", "", "Whether to enable deletion protection for the index")
5961
cmd.MarkFlagRequired("sourceCollection")
6062

6163
return cmd
@@ -66,13 +68,14 @@ func runCreatePodCmd(cmd *cobra.Command, options createPodOptions) {
6668
pc := sdk.NewPineconeClient()
6769

6870
createRequest := &pinecone.CreatePodIndexRequest{
69-
Name: options.name,
70-
Metric: pinecone.IndexMetric(options.metric),
71-
Dimension: options.dimension,
72-
Environment: options.environment,
73-
PodType: options.podType,
74-
Shards: options.shards,
75-
Replicas: options.replicas,
71+
Name: options.name,
72+
Metric: pinecone.IndexMetric(options.metric),
73+
Dimension: options.dimension,
74+
Environment: options.environment,
75+
PodType: options.podType,
76+
Shards: options.shards,
77+
Replicas: options.replicas,
78+
DeletionProtection: pinecone.DeletionProtection(options.deletionProtection),
7679
}
7780

7881
idx, err := pc.CreatePodIndex(ctx, createRequest)

internal/pkg/cli/command/index/create_serverless.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package index
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/pinecone-io/cli/internal/pkg/utils/exit"
78
"github.com/pinecone-io/cli/internal/pkg/utils/msg"
@@ -15,12 +16,14 @@ import (
1516
)
1617

1718
type createServerlessOptions struct {
18-
name string
19-
dimension int32
20-
metric string
21-
cloud string
22-
region string
23-
json bool
19+
name string
20+
dimension int32
21+
metric string
22+
cloud string
23+
region string
24+
deletionProtection string
25+
26+
json bool
2427
}
2528

2629
func NewCreateServerlessCmd() *cobra.Command {
@@ -46,6 +49,7 @@ func NewCreateServerlessCmd() *cobra.Command {
4649

4750
// Optional flags
4851
cmd.Flags().StringVarP(&options.metric, "metric", "m", "cosine", "metric to use. One of: cosine, euclidean, dotproduct")
52+
cmd.Flags().StringVarP(&options.deletionProtection, "deletion_protection", "p", "", "Whether to enable deletion protection for the index")
4953
cmd.Flags().BoolVar(&options.json, "json", false, "output as JSON")
5054

5155
return cmd
@@ -54,13 +58,15 @@ func NewCreateServerlessCmd() *cobra.Command {
5458
func runCreateServerlessCmd(cmd *cobra.Command, options createServerlessOptions) {
5559
ctx := context.Background()
5660
pc := sdk.NewPineconeClient()
61+
fmt.Printf("Creating serverless index with deletion protection maybe enabled: %v\n", options.deletionProtection)
5762

5863
createRequest := &pinecone.CreateServerlessIndexRequest{
59-
Name: options.name,
60-
Metric: pinecone.IndexMetric(options.metric),
61-
Dimension: options.dimension,
62-
Cloud: pinecone.Cloud(options.cloud),
63-
Region: options.region,
64+
Name: options.name,
65+
Metric: pinecone.IndexMetric(options.metric),
66+
Dimension: options.dimension,
67+
Cloud: pinecone.Cloud(options.cloud),
68+
Region: options.region,
69+
DeletionProtection: pinecone.DeletionProtection(options.deletionProtection),
6470
}
6571

6672
idx, err := pc.CreateServerlessIndex(ctx, createRequest)

internal/pkg/cli/command/index/delete.go

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ func NewDeleteCmd() *cobra.Command {
2929
if err != nil {
3030
if strings.Contains(err.Error(), "not found") {
3131
msg.FailMsg("The index %s does not exist\n", style.Emphasis(options.name))
32+
} else {
33+
msg.FailMsg("Failed to delete index %s: %s\n", style.Emphasis(options.name), err)
3234
}
3335
exit.Error(err)
3436
}

internal/pkg/utils/presenters/index_description.go

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ func ColorizeState(state pinecone.IndexStatusState) string {
2323
}
2424
}
2525

26+
func ColorizeDeletionProtection(deletionProtection pinecone.DeletionProtection) string {
27+
if deletionProtection == pinecone.DeletionProtectionEnabled {
28+
return style.StatusGreen("enabled")
29+
}
30+
return style.StatusRed("disabled")
31+
}
32+
2633
func PrintDescribeIndexTable(idx *pinecone.Index) {
2734
writer := NewTabWriter()
2835
log.Debug().Str("name", idx.Name).Msg("Printing index description")
@@ -34,6 +41,7 @@ func PrintDescribeIndexTable(idx *pinecone.Index) {
3441
pcio.Fprintf(writer, "Name\t%s\n", idx.Name)
3542
pcio.Fprintf(writer, "Dimension\t%d\n", idx.Dimension)
3643
pcio.Fprintf(writer, "Metric\t%s\n", string(idx.Metric))
44+
pcio.Fprintf(writer, "Deletion Protection\t%s\n", ColorizeDeletionProtection(idx.DeletionProtection))
3745
pcio.Fprintf(writer, "\t\n")
3846
pcio.Fprintf(writer, "State\t%s\n", ColorizeState(idx.Status.State))
3947
pcio.Fprintf(writer, "Ready\t%s\n", ColorizeBool(idx.Status.Ready))

0 commit comments

Comments
 (0)