Skip to content

Commit

Permalink
Support DeletionProtection, index configure command, and bump `go…
Browse files Browse the repository at this point in the history
…-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
  • Loading branch information
austin-denoble authored Sep 10, 2024
1 parent 81f7555 commit a9a6066
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 71 deletions.
27 changes: 14 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ require (
github.com/charmbracelet/lipgloss v0.10.0
github.com/fatih/color v1.16.0
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/pinecone-io/go-pinecone v0.5.0
github.com/pinecone-io/go-pinecone v1.1.0
github.com/rs/zerolog v1.32.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
golang.org/x/oauth2 v0.19.0
golang.org/x/oauth2 v0.21.0
)

require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -39,6 +39,7 @@ require (
github.com/muesli/termenv v0.15.2 // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand All @@ -47,20 +48,20 @@ require (
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.66.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
56 changes: 24 additions & 32 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyT
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
Expand Down Expand Up @@ -79,8 +75,8 @@ github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmt
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pinecone-io/go-pinecone v0.5.0 h1:Vw4Wbn/yYEx9XSjPqGMU0sVnxitub11FhJk4gWc+EvQ=
github.com/pinecone-io/go-pinecone v0.5.0/go.mod h1:KwWSueZFx9zccC+thBk13+LDiOgii8cff9bliUI4tQs=
github.com/pinecone-io/go-pinecone v1.1.0 h1:IUGfb1x2dtN7oN+p8ssQMf1M2S3BgQ26h54mdmibKG4=
github.com/pinecone-io/go-pinecone v1.1.0/go.mod h1:KfJhn4yThX293+fbtrZLnxe2PJYo8557Py062W4FYKk=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
Expand Down Expand Up @@ -120,8 +116,9 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
Expand All @@ -130,35 +127,30 @@ go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg=
golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c h1:Zmyn5CV/jxzKnF+3d+xzbomACPwLQqVpLTpyXN5uTaQ=
google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo=
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c h1:9g7erC9qu44ks7UK4gDNlnk4kOxZG707xKm4jVniy6o=
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c h1:NUsgEN92SQQqzfA+YtqYNqYmB3DMMYLlIwUZAQFVFbo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk=
google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 h1:hjSy6tcFQZ171igDaN5QHOw2n6vx40juYbC/x67CEhc=
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:qpvKtACPCQhAdu3PyQgV4l3LMXZEtft7y8QcarRsp9I=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.66.1 h1:hO5qAXR19+/Z44hmvIM4dQFMSYX9XcWsByfoxutBpAM=
google.golang.org/grpc v1.66.1/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/cli/command/index/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func NewIndexCmd() *cobra.Command {
cmd.AddCommand(NewListCmd())
cmd.AddCommand(NewCreateServerlessCmd())
cmd.AddCommand(NewCreatePodCmd())
cmd.AddCommand(NewConfigureIndexCmd())
cmd.AddCommand(NewDeleteCmd())

return cmd
Expand Down
72 changes: 72 additions & 0 deletions internal/pkg/cli/command/index/configure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package index

import (
"context"
"fmt"

"github.com/pinecone-io/cli/internal/pkg/utils/exit"
"github.com/pinecone-io/cli/internal/pkg/utils/msg"
"github.com/pinecone-io/cli/internal/pkg/utils/pcio"
"github.com/pinecone-io/cli/internal/pkg/utils/presenters"
"github.com/pinecone-io/cli/internal/pkg/utils/sdk"
"github.com/pinecone-io/cli/internal/pkg/utils/style"
"github.com/pinecone-io/cli/internal/pkg/utils/text"
"github.com/pinecone-io/go-pinecone/pinecone"
"github.com/spf13/cobra"
)

type configureIndexOptions struct {
name string
podType string
replicas int32
deletionProtection string

json bool
}

func NewConfigureIndexCmd() *cobra.Command {
options := configureIndexOptions{}

cmd := &cobra.Command{
Use: "configure",
Short: "Configure an existing index with the specified configuration",
Example: "",
Run: func(cmd *cobra.Command, args []string) {
runConfigureIndexCmd(cmd, options)
},
}

// Required flags
cmd.Flags().StringVarP(&options.name, "name", "n", "", "name of index to configure")

// Optional flags
cmd.Flags().StringVarP(&options.podType, "pod_type", "t", "", "type of pod to use, can only upgrade when configuring")
cmd.Flags().Int32VarP(&options.replicas, "replicas", "r", 0, "replicas of the index to configure")
cmd.Flags().StringVarP(&options.deletionProtection, "deletion_protection", "p", "", "enable or disable deletion protection for the index")

return cmd
}

func runConfigureIndexCmd(cmd *cobra.Command, options configureIndexOptions) {
ctx := context.Background()
pc := sdk.NewPineconeClient()

idx, err := pc.ConfigureIndex(ctx, options.name, pinecone.ConfigureIndexParams{
PodType: options.podType,
Replicas: options.replicas,
DeletionProtection: pinecone.DeletionProtection(options.deletionProtection),
})
if err != nil {
msg.FailMsg("Failed to configure index %s: %+v\n", style.Emphasis(options.name), err)
exit.Error(err)
}
if options.json {
text.PrettyPrintJSON(idx)
return
}

describeCommand := pcio.Sprintf("pinecone index describe --name %s", idx.Name)
msg.SuccessMsg("Index %s configured successfully. Run %s to check status. \n\n", style.Emphasis(idx.Name), style.Code(describeCommand))
fmt.Printf("Index model on configure return: %+v\n", idx.Spec.Pod)
presenters.PrintDescribeIndexTable(idx)
}
33 changes: 18 additions & 15 deletions internal/pkg/cli/command/index/create_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import (
)

type createPodOptions struct {
name string
dimension int32
metric string
environment string
podType string
shards int32
replicas int32
sourceCollection string
name string
dimension int32
metric string
environment string
podType string
shards int32
replicas int32
sourceCollection string
deletionProtection string
// metadataConfig *PodSpecMetadataConfig

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

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

createRequest := &pinecone.CreatePodIndexRequest{
Name: options.name,
Metric: pinecone.IndexMetric(options.metric),
Dimension: options.dimension,
Environment: options.environment,
PodType: options.podType,
Shards: options.shards,
Replicas: options.replicas,
Name: options.name,
Metric: pinecone.IndexMetric(options.metric),
Dimension: options.dimension,
Environment: options.environment,
PodType: options.podType,
Shards: options.shards,
Replicas: options.replicas,
DeletionProtection: pinecone.DeletionProtection(options.deletionProtection),
}

idx, err := pc.CreatePodIndex(ctx, createRequest)
Expand Down
28 changes: 17 additions & 11 deletions internal/pkg/cli/command/index/create_serverless.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package index

import (
"context"
"fmt"

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

type createServerlessOptions struct {
name string
dimension int32
metric string
cloud string
region string
json bool
name string
dimension int32
metric string
cloud string
region string
deletionProtection string

json bool
}

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

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

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

createRequest := &pinecone.CreateServerlessIndexRequest{
Name: options.name,
Metric: pinecone.IndexMetric(options.metric),
Dimension: options.dimension,
Cloud: pinecone.Cloud(options.cloud),
Region: options.region,
Name: options.name,
Metric: pinecone.IndexMetric(options.metric),
Dimension: options.dimension,
Cloud: pinecone.Cloud(options.cloud),
Region: options.region,
DeletionProtection: pinecone.DeletionProtection(options.deletionProtection),
}

idx, err := pc.CreateServerlessIndex(ctx, createRequest)
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/cli/command/index/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func NewDeleteCmd() *cobra.Command {
if err != nil {
if strings.Contains(err.Error(), "not found") {
msg.FailMsg("The index %s does not exist\n", style.Emphasis(options.name))
} else {
msg.FailMsg("Failed to delete index %s: %s\n", style.Emphasis(options.name), err)
}
exit.Error(err)
}
Expand Down
8 changes: 8 additions & 0 deletions internal/pkg/utils/presenters/index_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ func ColorizeState(state pinecone.IndexStatusState) string {
}
}

func ColorizeDeletionProtection(deletionProtection pinecone.DeletionProtection) string {
if deletionProtection == pinecone.DeletionProtectionEnabled {
return style.StatusGreen("enabled")
}
return style.StatusRed("disabled")
}

func PrintDescribeIndexTable(idx *pinecone.Index) {
writer := NewTabWriter()
log.Debug().Str("name", idx.Name).Msg("Printing index description")
Expand All @@ -34,6 +41,7 @@ func PrintDescribeIndexTable(idx *pinecone.Index) {
pcio.Fprintf(writer, "Name\t%s\n", idx.Name)
pcio.Fprintf(writer, "Dimension\t%d\n", idx.Dimension)
pcio.Fprintf(writer, "Metric\t%s\n", string(idx.Metric))
pcio.Fprintf(writer, "Deletion Protection\t%s\n", ColorizeDeletionProtection(idx.DeletionProtection))
pcio.Fprintf(writer, "\t\n")
pcio.Fprintf(writer, "State\t%s\n", ColorizeState(idx.Status.State))
pcio.Fprintf(writer, "Ready\t%s\n", ColorizeBool(idx.Status.Ready))
Expand Down

0 comments on commit a9a6066

Please sign in to comment.