-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enables remote custom analyzers (#906)
* feat: enables remote custom analyzers Signed-off-by: Alex Jones <[email protected]> * chore: fixed test that was broken Signed-off-by: Alex Jones <[email protected]> * chore: hiding custom analysis behind a flag Signed-off-by: Alex Jones <[email protected]> * chore: resolved govet issue Signed-off-by: Alex Jones <[email protected]> * chore: updated Signed-off-by: Alex Jones <[email protected]> * chore: updated Signed-off-by: Alex Jones <[email protected]> * chore: updated deps Signed-off-by: Alex Jones <[email protected]> * chore: updated deps Signed-off-by: Alex Jones <[email protected]> --------- Signed-off-by: Alex Jones <[email protected]>
- Loading branch information
1 parent
070aa7f
commit c8c9dbf
Showing
5 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package custom | ||
|
||
import ( | ||
rpc "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go/schema/v1/schemav1grpc" | ||
schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1" | ||
"context" | ||
"fmt" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/common" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
) | ||
|
||
type Client struct { | ||
c *grpc.ClientConn | ||
analyzerClient rpc.AnalyzerServiceClient | ||
} | ||
|
||
func NewClient(c Connection) (*Client, error) { | ||
|
||
conn, err := grpc.Dial(fmt.Sprintf("%s:%s", c.Url, c.Port), grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
client := rpc.NewAnalyzerServiceClient(conn) | ||
return &Client{ | ||
c: conn, | ||
analyzerClient: client, | ||
}, nil | ||
} | ||
|
||
func (cli *Client) Run() (common.Result, error) { | ||
var result common.Result | ||
req := &schemav1.AnalyzerRunRequest{} | ||
res, err := cli.analyzerClient.Run(context.Background(), req) | ||
if err != nil { | ||
return result, err | ||
} | ||
if res.Result != nil { | ||
|
||
// We should refactor this, because Error and Failure do not map 1:1 from K8sGPT/schema | ||
var errorsFound []common.Failure | ||
for _, e := range res.Result.Error { | ||
errorsFound = append(errorsFound, common.Failure{ | ||
Text: e.Text, | ||
// TODO: Support sensitive data | ||
}) | ||
} | ||
|
||
result.Name = res.Result.Name | ||
result.Kind = res.Result.Kind | ||
result.Details = res.Result.Details | ||
result.ParentObject = res.Result.ParentObject | ||
result.Error = errorsFound | ||
} | ||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package custom | ||
|
||
type Connection struct { | ||
Url string `json:"url"` | ||
Port string `json:"port"` | ||
} | ||
type CustomAnalyzer struct { | ||
Name string `json:"name"` | ||
Connection Connection `json:"connection"` | ||
} |