Skip to content

Commit

Permalink
chore: refactored cache input to lower
Browse files Browse the repository at this point in the history
Signed-off-by: AlexsJones <[email protected]>
  • Loading branch information
AlexsJones committed Nov 28, 2024
1 parent 5ed75bc commit f633232
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
3 changes: 2 additions & 1 deletion cmd/cache/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cache
import (
"fmt"
"os"
"strings"

"github.com/fatih/color"
"github.com/k8sgpt-ai/k8sgpt/pkg/cache"
Expand Down Expand Up @@ -51,7 +52,7 @@ var addCmd = &cobra.Command{
}
fmt.Println(color.YellowString("Adding remote based cache"))
cacheType := args[0]
remoteCache, err := cache.NewCacheProvider(cacheType, bucketName, region, endpoint, storageAccount, containerName, projectId, insecure)
remoteCache, err := cache.NewCacheProvider(strings.ToLower(cacheType), bucketName, region, endpoint, storageAccount, containerName, projectId, insecure)
if err != nil {
color.Red("Error: %v", err)
os.Exit(1)
Expand Down
35 changes: 6 additions & 29 deletions pkg/cache/interplex_based.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (
schemav1 "buf.build/gen/go/interplex-ai/schemas/protocolbuffers/go/protobuf/schema/v1"
"context"
"errors"
"fmt"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
)

var _ ICache = (*InterplexCache)(nil)
Expand All @@ -24,27 +22,6 @@ type InterplexCacheConfiguration struct {
}

type InterplexClient struct {
conn *grpc.ClientConn
}

func (c *InterplexClient) Close() error {
return c.conn.Close()
}

func NewClient(address string) (*InterplexClient, error) {
// Connect to the K8sGPT server and create a new client
conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
return nil, fmt.Errorf("failed to create context: %v", err)
}
// Wait until the connection is ready
state := conn.GetState()
if state != connectivity.Ready {
return nil, fmt.Errorf("failed to connect, current state: %v", state)
}
client := &InterplexClient{conn: conn}

return client, nil
}

func (c *InterplexCache) Configure(cacheInfo CacheProvider) error {
Expand All @@ -58,12 +35,12 @@ func (c *InterplexCache) Configure(cacheInfo CacheProvider) error {

func (c *InterplexCache) Store(key string, data string) error {

client, err := NewClient(c.configuration.ConnectionString)
conn, err := grpc.NewClient(c.configuration.ConnectionString, grpc.WithInsecure(), grpc.WithBlock())

Check failure on line 38 in pkg/cache/interplex_based.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci] reported by reviewdog 🐶 SA1019: grpc.WithInsecure is deprecated: use WithTransportCredentials and insecure.NewCredentials() instead. Will be supported throughout 1.x. (staticcheck) Raw Output: pkg/cache/interplex_based.go:38:64: SA1019: grpc.WithInsecure is deprecated: use WithTransportCredentials and insecure.NewCredentials() instead. Will be supported throughout 1.x. (staticcheck) conn, err := grpc.NewClient(c.configuration.ConnectionString, grpc.WithInsecure(), grpc.WithBlock()) ^
defer conn.Close()

Check failure on line 39 in pkg/cache/interplex_based.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci] reported by reviewdog 🐶 SA5001: should check error returned from grpc.NewClient() before deferring conn.Close() (staticcheck) Raw Output: pkg/cache/interplex_based.go:39:2: SA5001: should check error returned from grpc.NewClient() before deferring conn.Close() (staticcheck) defer conn.Close() ^
if err != nil {
return err
}
c.client = *client
serviceClient := rpc.NewCacheServiceClient(c.client.conn)
serviceClient := rpc.NewCacheServiceClient(conn)
c.cacheServiceClient = serviceClient
req := schemav1.SetRequest{
Key: key,
Expand All @@ -77,12 +54,12 @@ func (c *InterplexCache) Store(key string, data string) error {
}

func (c *InterplexCache) Load(key string) (string, error) {
client, err := NewClient(c.configuration.ConnectionString)
conn, err := grpc.NewClient(c.configuration.ConnectionString, grpc.WithInsecure(), grpc.WithBlock())

Check failure on line 57 in pkg/cache/interplex_based.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci] reported by reviewdog 🐶 SA1019: grpc.WithInsecure is deprecated: use WithTransportCredentials and insecure.NewCredentials() instead. Will be supported throughout 1.x. (staticcheck) Raw Output: pkg/cache/interplex_based.go:57:64: SA1019: grpc.WithInsecure is deprecated: use WithTransportCredentials and insecure.NewCredentials() instead. Will be supported throughout 1.x. (staticcheck) conn, err := grpc.NewClient(c.configuration.ConnectionString, grpc.WithInsecure(), grpc.WithBlock()) ^
defer conn.Close()

Check failure on line 58 in pkg/cache/interplex_based.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci] reported by reviewdog 🐶 SA5001: should check error returned from grpc.NewClient() before deferring conn.Close() (staticcheck) Raw Output: pkg/cache/interplex_based.go:58:2: SA5001: should check error returned from grpc.NewClient() before deferring conn.Close() (staticcheck) defer conn.Close() ^
if err != nil {
return "", err
}
c.client = *client
serviceClient := rpc.NewCacheServiceClient(c.client.conn)
serviceClient := rpc.NewCacheServiceClient(conn)
c.cacheServiceClient = serviceClient
req := schemav1.GetRequest{
Key: key,
Expand Down

0 comments on commit f633232

Please sign in to comment.