Compare commits

...

25 Commits

Author SHA1 Message Date
Alex Jones
dc8535b70a fixing spelling on path
Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
2023-03-28 12:12:24 +01:00
Alex Jones
02f5f921e2 Merge pull request #104 from k8sgpt-ai/chore/readme-update
feat: updated readme
2023-03-28 12:05:05 +01:00
Alex Jones
e0141d1cf5 feat: updated readme
Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
2023-03-28 11:51:50 +01:00
Alex Jones
d48ff1a942 Merge pull request #98 from k8sgpt-ai/release-please--branches--main
chore(main): release 0.1.0
2023-03-28 11:05:13 +01:00
github-actions[bot]
14f076a095 chore(main): release 0.1.0 2023-03-28 09:59:57 +00:00
Thomas Schuetz
829ff566c0 chore: add codeowners file (#102)
Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>
2023-03-28 11:59:32 +02:00
Alex Jones
0ecf248c3f Merge pull request #100 from k8sgpt-ai/chore/codeowners
chore: add CODEOWNERS
2023-03-28 10:59:00 +01:00
Thomas Schuetz
c5c6162df1 chore: add CODEOWNERS
Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>
2023-03-28 11:52:46 +02:00
Alex Jones
a270f7c89f feat: enables overwriting of cache (#95) 2023-03-28 11:43:12 +02:00
Thomas Schuetz
ff0b67b5a9 Merge branch 'main' of github.com:k8sgpt-ai/k8sgpt 2023-03-28 11:41:46 +02:00
Thomas Schuetz
f9c7daf3dc chore: release 0.1.0
Release-As: 0.1.0
Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>
2023-03-28 11:40:27 +02:00
Roberth Strand
a49cec98c0 Merge pull request #97 from k8sgpt-ai/feat/93-british-and-american-english
feat: added british alias
2023-03-28 11:18:21 +02:00
Roberth Strand
39c0444fac feat: added british alias
Added an alias for analyze with the British English variant analyse.

Closes #93

Signed-off-by: Roberth Strand <me@robstr.dev>
2023-03-28 11:07:45 +02:00
github-actions[bot]
0a0c88719e chore(main): release 0.0.9 (#91)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-28 07:22:32 +02:00
Thomas Schuetz
202e8e2977 chore: small update
Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>
2023-03-28 07:21:07 +02:00
Alex Jones
254dbcc4e3 Merge pull request #88 from k8sgpt-ai/release-please--branches--main
chore(main): release 0.0.8
2023-03-27 21:09:06 +01:00
github-actions[bot]
9983205ed6 chore(main): release 0.0.8 2023-03-27 20:07:06 +00:00
Alex Jones
57cb563038 Merge pull request #89 from k8sgpt-ai/feat/language-support
feat: addition of simple language support & version
2023-03-27 21:06:40 +01:00
Alex Jones
f602fb59fc Merge branch 'main' into feat/language-support 2023-03-27 21:06:33 +01:00
AlexsJones
4bbe583a97 updated readme
Signed-off-by: AlexsJones <alexsimonjones@gmail.com>
2023-03-27 21:04:34 +01:00
Thomas Schuetz
1c653ecc51 feat: add generation of api-keys to cli (#87)
* feat: add generate option in cli and the documentation

Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>

* chore: release 0.1.0

Release-As: 0.1.0
Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>

* fix: apply suggestions from code review

Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>

---------

Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>
Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
2023-03-27 21:04:34 +01:00
AlexsJones
0c231d635e feat: version
Signed-off-by: AlexsJones <alexsimonjones@gmail.com>
2023-03-27 20:49:40 +01:00
AlexsJones
931f072e0a feat: version
Signed-off-by: AlexsJones <alexsimonjones@gmail.com>
2023-03-27 20:40:15 +01:00
AlexsJones
c3008c5e75 feat: addition of simple language support
Signed-off-by: AlexsJones <alexsimonjones@gmail.com>
2023-03-27 20:15:35 +01:00
Thomas Schuetz
bb2db5ca79 feat: add generation of api-keys to cli (#87)
* feat: add generate option in cli and the documentation

Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>

* chore: release 0.1.0

Release-As: 0.1.0
Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>

* fix: apply suggestions from code review

Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>

---------

Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>
Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
2023-03-27 21:00:28 +02:00
16 changed files with 198 additions and 32 deletions

12
.github/CODEOWNERS vendored Normal file
View File

@@ -0,0 +1,12 @@
# CODEOWNERS file indicates code owners for certain files
#
# Code owners will automatically be added as a reviewer for PRs that touch
# the owned files.
#
# Default owners for everything in the repo
#
# Unless a later match takes precedence, these owners will be requested for
# review when someone opens a pull request.
* @k8sgpt-ai/maintainers

View File

@@ -13,6 +13,8 @@ builds:
- linux
- windows
- darwin
ldflags:
- -s -w -X main.version={{.Version}}
archives:
- format: tar.gz

View File

@@ -1 +1 @@
{".":"0.0.7"}
{".":"0.1.0"}

View File

@@ -1,5 +1,38 @@
# Changelog
## [0.1.0](https://github.com/k8sgpt-ai/k8sgpt/compare/v0.0.9...v0.1.0) (2023-03-28)
### Features
* added british alias ([39c0444](https://github.com/k8sgpt-ai/k8sgpt/commit/39c0444fac9b46d0faa347b45df779b97019e5b6)), closes [#93](https://github.com/k8sgpt-ai/k8sgpt/issues/93)
* enables overwriting of cache ([#95](https://github.com/k8sgpt-ai/k8sgpt/issues/95)) ([a270f7c](https://github.com/k8sgpt-ai/k8sgpt/commit/a270f7c89fb8bec35984715c5e4d160a2307e678))
### Other
* add CODEOWNERS ([c5c6162](https://github.com/k8sgpt-ai/k8sgpt/commit/c5c6162df1f3701659e47bce6e9fc6e3c569e539))
* add codeowners file ([#102](https://github.com/k8sgpt-ai/k8sgpt/issues/102)) ([829ff56](https://github.com/k8sgpt-ai/k8sgpt/commit/829ff566c0a964250d3d8d45306d410e1b9d9d35))
* release 0.1.0 ([f9c7daf](https://github.com/k8sgpt-ai/k8sgpt/commit/f9c7daf3dcd06dcd9cea5603108b8a42ee273348))
## [0.0.9](https://github.com/k8sgpt-ai/k8sgpt/compare/v0.0.8...v0.0.9) (2023-03-28)
### Other
* small update ([202e8e2](https://github.com/k8sgpt-ai/k8sgpt/commit/202e8e2977422b2b4506a80dc9b76a392c5457eb))
## [0.0.8](https://github.com/k8sgpt-ai/k8sgpt/compare/v0.0.7...v0.0.8) (2023-03-27)
### Features
* add generation of api-keys to cli ([#87](https://github.com/k8sgpt-ai/k8sgpt/issues/87)) ([1c653ec](https://github.com/k8sgpt-ai/k8sgpt/commit/1c653ecc51b74a2f51ce7240ffaee0fe75f2e8dd))
* add generation of api-keys to cli ([#87](https://github.com/k8sgpt-ai/k8sgpt/issues/87)) ([bb2db5c](https://github.com/k8sgpt-ai/k8sgpt/commit/bb2db5ca7923e2049308d1674bb59ae8154e415c))
* addition of simple language support ([c3008c5](https://github.com/k8sgpt-ai/k8sgpt/commit/c3008c5e75acbb35d864135199ca9c034f59e35f))
* version ([0c231d6](https://github.com/k8sgpt-ai/k8sgpt/commit/0c231d635e7ad71609bb80abac5e0ade15ffb860))
* version ([931f072](https://github.com/k8sgpt-ai/k8sgpt/commit/931f072e0ab0cfd77f261b0b719cf0819f85b951))
## [0.0.7](https://github.com/k8sgpt-ai/k8sgpt/compare/v0.0.6...v0.0.7) (2023-03-27)

View File

@@ -3,18 +3,27 @@
<img alt="Text changing depending on mode. Light: 'So light!' Dark: 'So dark!'" src="./images/banner-black.png" width="600px;">
</picture>
_Install it now_
`k8sgpt` is a tool for scanning your kubernetes clusters, diagnosing and triaging issues in simple english.
It has SRE experience codified into it's analyzers and helps to pull out the most relevent information to enrich it with AI.
## Quick Start
```
brew tap k8sgpt-ai/k8sgpt
brew install k8sgpt
```
`k8sgpt` is a tool for scanning your kubernetes clusters, diagnosing and triaging issues in simple english.
_brew also enables upgrades with `brew upgrade k8sgpt`_
It has SRE experience codified into it's analyzers and helps to pull out the most relevent information to enrich it with AI.
<img src="images/landing.png" width=650px; />
* Currently the default AI provider is OpenAI, you will need to generate an API key from [OpenAI](https://openai.com)
* You can do this by running `k8sgpt generate` to open a browser link to generate it
* Run `k8sgpt auth` to set it in k8sgpt.
* Run `k8sgpt analyze` to run a scan.
* And use `k8sgpt analyze --explain` to get a more detailed explanation of the issues.
<img src="images/demo4.gif" width=650px; />
## Analyzers
@@ -31,8 +40,6 @@ K8sGPT uses analyzers to triage and diagnose issues in your cluster. It has a se
## Usage
```
Kubernetes debugging powered by AI
Usage:
k8sgpt [command]
@@ -40,13 +47,24 @@ Available Commands:
analyze This command will find problems within your Kubernetes cluster
auth Authenticate with your chosen backend
completion Generate the autocompletion script for the specified shell
generate Generate Key for your chosen backend (opens browser)
help Help about any command
version Print the version number of k8sgpt
Flags:
--config string config file (default is $HOME/.k8sgpt.git.yaml)
-h, --help help for k8sgpt
--kubeconfig string Path to a kubeconfig. Only required if out-of-cluster.
--master string The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.
-t, --toggle Help message for toggle
Use "k8sgpt [command] --help" for more information about a command.
```
_Run a scan with the default analyzers_
```
k8sgpt generate
k8sgpt auth
k8sgpt analyze --explain
```
@@ -78,7 +96,7 @@ K8sgpt is focused on triaging and diagnosing issues in your cluster. It is a too
### Configuration
`k8sgpt` stores config data in `~/.k8sgpt` the data is stored in plain text, including your OpenAI key.
`k8sgpt` stores config data in `~/.k8sgpt.yaml` the data is stored in plain text, including your OpenAI key.
### Contributing

View File

@@ -17,18 +17,21 @@ import (
)
var (
explain bool
backend string
output string
filters []string
explain bool
backend string
output string
filters []string
language string
nocache bool
)
// AnalyzeCmd represents the problems command
var AnalyzeCmd = &cobra.Command{
Use: "analyze",
Short: "This command will find problems within your Kubernetes cluster",
Use: "analyze",
Aliases: []string{"analyse"},
Short: "This command will find problems within your Kubernetes cluster",
Long: `This command will find problems within your Kubernetes cluster and
provide you with a list of issues that need to be resolved`,
provide you with a list of issues that need to be resolved`,
Run: func(cmd *cobra.Command, args []string) {
// get backend from file
@@ -53,7 +56,7 @@ var AnalyzeCmd = &cobra.Command{
switch backendType {
case "openai":
aiClient = &ai.OpenAIClient{}
if err := aiClient.Configure(token); err != nil {
if err := aiClient.Configure(token, language); err != nil {
color.Red("Error: %v", err)
os.Exit(1)
}
@@ -99,7 +102,7 @@ var AnalyzeCmd = &cobra.Command{
for _, analysis := range *analysisResults {
if explain {
parsedText, err := analyzer.ParseViaAI(ctx, aiClient, analysis.Error)
parsedText, err := analyzer.ParseViaAI(ctx, aiClient, analysis.Error, nocache)
if err != nil {
color.Red("Error: %v", err)
continue
@@ -133,6 +136,7 @@ var AnalyzeCmd = &cobra.Command{
func init() {
AnalyzeCmd.Flags().BoolVarP(&nocache, "no-cache", "n", false, "Do not use cached data")
// array of strings flag
AnalyzeCmd.Flags().StringSliceVarP(&filters, "filter", "f", []string{}, "Filter for these analzyers (e.g. Pod,PersistentVolumeClaim,Service,ReplicaSet)")
@@ -141,5 +145,6 @@ func init() {
AnalyzeCmd.Flags().StringVarP(&backend, "backend", "b", "openai", "Backend AI provider")
// output as json
AnalyzeCmd.Flags().StringVarP(&output, "output", "o", "text", "Output format (text, json)")
// add language options for output
AnalyzeCmd.Flags().StringVarP(&language, "language", "l", "english", "Languages to use for AI (e.g. 'English', 'Spanish', 'French', 'German', 'Italian', 'Portuguese', 'Dutch', 'Russian', 'Chinese', 'Japanese', 'Korean')")
}

62
cmd/generate/generate.go Normal file
View File

@@ -0,0 +1,62 @@
package generate
import (
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os/exec"
"runtime"
"time"
)
var (
backend string
)
// generateCmd represents the auth command
var GenerateCmd = &cobra.Command{
Use: "generate",
Short: "Generate Key for your chosen backend (opens browser)",
Long: `Opens your browser to generate a key for your chosen backend.`,
Run: func(cmd *cobra.Command, args []string) {
backendType := viper.GetString("backend_type")
if backendType == "" {
// Set the default backend
backend = "openai"
}
// override the default backend if a flag is provided
if backend != "" {
backendType = backend
}
fmt.Println("")
color.Green("Opening: https://beta.openai.com/account/api-keys to generate a key for %s", backendType)
color.Green("Please copy the generated key and run `k8sgpt auth` to add it to your config file")
fmt.Println("")
time.Sleep(5 * time.Second)
openbrowser("https://beta.openai.com/account/api-keys")
},
}
func init() {
// add flag for backend
GenerateCmd.Flags().StringVarP(&backend, "backend", "b", "openai", "Backend AI provider")
}
func openbrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
fmt.Println(err)
}
}

View File

@@ -1,6 +1,7 @@
package cmd
import (
"github.com/k8sgpt-ai/k8sgpt/cmd/generate"
"os"
"github.com/fatih/color"
@@ -15,6 +16,7 @@ var (
cfgFile string
masterURL string
kubeconfig string
version string
)
// rootCmd represents the base command when called without any subcommands
@@ -29,7 +31,8 @@ var rootCmd = &cobra.Command{
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
func Execute(v string) {
version = v
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
@@ -44,7 +47,8 @@ func init() {
// will be global for your application.
rootCmd.AddCommand(auth.AuthCmd)
rootCmd.AddCommand(analyze.AnalyzeCmd)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.k8sgpt.git.yaml)")
rootCmd.AddCommand(generate.GenerateCmd)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.k8sgpt.yaml)")
rootCmd.PersistentFlags().StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
rootCmd.PersistentFlags().StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
// Cobra also supports local flags, which will only run

19
cmd/version.go Normal file
View File

@@ -0,0 +1,19 @@
package cmd
import (
"github.com/spf13/cobra"
)
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of k8sgpt",
Long: `All software has versions. This is k8sgpt's`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Printf("k8sgpt version %s", version)
},
}
func init() {
rootCmd.AddCommand(versionCmd)
}

3
go.mod
View File

@@ -3,9 +3,9 @@ module github.com/k8sgpt-ai/k8sgpt
go 1.20
require (
github.com/briandowns/spinner v1.23.0
github.com/fatih/color v1.15.0
github.com/sashabaranov/go-openai v1.5.7
github.com/schollz/progressbar/v3 v3.13.1
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
golang.org/x/term v0.6.0
@@ -44,7 +44,6 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/schollz/progressbar/v3 v3.13.1 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect

2
go.sum
View File

@@ -38,8 +38,6 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/briandowns/spinner v1.23.0 h1:alDF2guRWqa/FOZZYWjlMIx2L6H0wyewPxo/CH4Pt2A=
github.com/briandowns/spinner v1.23.0/go.mod h1:rPG4gmXeN3wQV/TsAY4w8lPdIM6RX3yqeBQJSrbXjuE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=

BIN
images/demo4.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 KiB

View File

@@ -5,6 +5,8 @@ package main
import "github.com/k8sgpt-ai/k8sgpt/cmd"
var version = "dev"
func main() {
cmd.Execute()
cmd.Execute(version)
}

View File

@@ -3,19 +3,29 @@ package ai
import (
"context"
"errors"
"fmt"
"github.com/sashabaranov/go-openai"
)
const (
default_prompt = "Simplify the following Kubernetes error message and provide a solution in %s: %s"
prompt_a = "Read the following input %s and provide possible scenarios for remediation in %s"
prompt_b = "Considering the following input from the Kubernetes resource %s and the error message %s, provide possible scenarios for remediation in %s"
prompt_c = "Reading the following %s error message and it's accompanying log message %s, how would you simplify this message?"
)
type OpenAIClient struct {
client *openai.Client
client *openai.Client
language string
}
func (c *OpenAIClient) Configure(token string) error {
func (c *OpenAIClient) Configure(token string, language string) error {
client := openai.NewClient(token)
if client == nil {
return errors.New("error creating OpenAI client")
}
c.language = language
c.client = client
return nil
}
@@ -27,7 +37,7 @@ func (c *OpenAIClient) GetCompletion(ctx context.Context, prompt string) (string
Messages: []openai.ChatCompletionMessage{
{
Role: "user",
Content: "Simplify the following Kubernetes error message and provide a solution: " + prompt,
Content: fmt.Sprintf(default_prompt, c.language, prompt),
},
},
})

View File

@@ -3,6 +3,6 @@ package ai
import "context"
type IAI interface {
Configure(token string) error
Configure(token string, language string) error
GetCompletion(ctx context.Context, prompt string) (string, error)
}

View File

@@ -11,7 +11,8 @@ import (
"github.com/spf13/viper"
)
func RunAnalysis(ctx context.Context, client *kubernetes.Client, aiClient ai.IAI, explain bool, analysisResults *[]Analysis) error {
func RunAnalysis(ctx context.Context, client *kubernetes.Client,
aiClient ai.IAI, explain bool, analysisResults *[]Analysis) error {
err := AnalyzePod(ctx, client, aiClient, explain, analysisResults)
if err != nil {
@@ -35,13 +36,14 @@ func RunAnalysis(ctx context.Context, client *kubernetes.Client, aiClient ai.IAI
return nil
}
func ParseViaAI(ctx context.Context, aiClient ai.IAI, prompt []string) (string, error) {
func ParseViaAI(ctx context.Context, aiClient ai.IAI, prompt []string,
nocache bool) (string, error) {
// parse the text with the AI backend
inputKey := strings.Join(prompt, " ")
// Check for cached data
sEnc := base64.StdEncoding.EncodeToString([]byte(inputKey))
// find in viper cache
if viper.IsSet(sEnc) {
if viper.IsSet(sEnc) && !nocache {
// retrieve data from cache
response := viper.GetString(sEnc)
if response == "" {