Compare commits

...

25 Commits

Author SHA1 Message Date
Alex Jones
35c8deee8b Merge pull request #23 from k8sgpt-ai/feature/optimisation-caching
feat: adding performance optimisation through local caching
2023-03-22 11:53:12 +00:00
Alex Jones
05d2aef48a Merge pull request #19 from k8sgpt-ai/chore/pr_template
chore: add pull request template
2023-03-22 11:24:47 +00:00
AlexsJones
e4f138dc00 adding performance optimisation through local caching
Signed-off-by: AlexsJones <alexsimonjones@gmail.com>
2023-03-22 11:19:26 +00:00
Alex Jones
917380435f Merge pull request #21 from k8sgpt-ai/chore/copy-readme
chore: updated copy
2023-03-22 10:40:58 +00:00
AlexsJones
5d956e209f updated copy
Signed-off-by: AlexsJones <alexsimonjones@gmail.com>
2023-03-22 10:40:38 +00:00
Alex Jones
f62a944941 Merge pull request #20 from k8sgpt-ai/chore/readme-copy
chore:updated readme
2023-03-22 10:27:09 +00:00
AlexsJones
935c4d2c15 updated readme copy
Signed-off-by: AlexsJones <alexsimonjones@gmail.com>
2023-03-22 10:26:30 +00:00
Thomas Schuetz
a6d5132b8c chore: add pull request template
Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>
2023-03-22 10:58:17 +01:00
Alex Jones
b68895a7f1 Merge pull request #8 from k8sgpt-ai/renovate/github.com-sashabaranov-go-openai-1.x
fix(deps): update module github.com/sashabaranov/go-openai to v1.5.5
2023-03-22 09:40:31 +00:00
Alex Jones
3bd226fc3d Merge pull request #7 from k8sgpt-ai/renovate/pin-dependencies
chore(deps): pin dependencies
2023-03-22 09:40:09 +00:00
Alex Jones
0c8cbbbf1d Merge pull request #6 from k8sgpt-ai/doc/add_slack_info
doc: add slack information
2023-03-22 09:39:44 +00:00
Alex Jones
d08831278e Merge pull request #17 from k8sgpt-ai/chore/tidying
chore: tidying up packages
2023-03-22 09:39:21 +00:00
AlexsJones
9409998884 merged main
Signed-off-by: AlexsJones <alexsimonjones@gmail.com>
2023-03-22 09:38:45 +00:00
renovate[bot]
105fe44680 fix(deps): update module github.com/sashabaranov/go-openai to v1.5.5 2023-03-22 07:26:55 +00:00
renovate[bot]
7fea7d14a5 chore(deps): pin dependencies 2023-03-22 07:26:36 +00:00
Thomas Schuetz
7c0bdab60e doc: add slack information
Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>
2023-03-22 08:19:07 +01:00
Alex Jones
6d8b2fe39d Merge pull request #4 from k8sgpt-ai/chore/renaming
chore: change module repository references
2023-03-22 06:52:51 +00:00
Alex Jones
6934e9c5fa Merge pull request #5 from k8sgpt-ai/chore/renovate
chore: add initial renovate config
2023-03-22 06:52:27 +00:00
Thomas Schuetz
e37dbc7909 chore: add initial renovate config
Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>
2023-03-22 07:44:38 +01:00
Thomas Schuetz
a307c132b3 chore: change module repo
Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>
2023-03-22 07:40:21 +01:00
Alex Jones
54d8d1cea1 Update README.md 2023-03-21 22:05:34 +00:00
Alex Jones
dce276e509 Rename CONTRIBUTING to CONTRIBUTING.md 2023-03-21 22:05:01 +00:00
Alex Jones
7532fd26c2 Create CONTRIBUTING 2023-03-21 22:04:45 +00:00
Alex Jones
6733680a94 Update LICENSE 2023-03-21 22:01:53 +00:00
AlexsJones
8be2ba763e updated workflows
Signed-off-by: AlexsJones <alexsimonjones@gmail.com>
2023-03-21 21:47:20 +00:00
15 changed files with 146 additions and 61 deletions

21
.github/pull_request_template.md vendored Normal file
View File

@@ -0,0 +1,21 @@
<!--
Thanks for creating this pull request 🤗
Please make sure that the pull request is limited to one type (docs, feature, etc.) and keep it as small as possible. You can open multiple prs instead of opening a huge one.
-->
<!-- If this pull request closes an issue, please mention the issue number below -->
Closes # <!-- Issue # here -->
## 📑 Description
<!-- Add a brief description of the pr -->
## ✅ Checks
<!-- Make sure your pr passes the CI checks and do check the following fields as needed - -->
- [ ] My pull request adheres to the code style of this project
- [ ] My code requires changes to the documentation
- [ ] I have updated the documentation as required
- [ ] All the tests have passed
## Additional Information
<!-- Any additional information like breaking changes, dependencies added, screenshots, comparisons between new and old behavior, etc. -->

View File

@@ -15,21 +15,21 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4
with:
go-version: '1.20'
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --snapshot
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

5
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,5 @@
# Contributing
## Requirements
- Golang `1.20`

21
LICENSE
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Alex Jones
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -6,51 +6,34 @@
AI Powered Kubernetes debugging for SRE, Platform and DevOps teams.
<br />
<img src="images/demo.gif" width=800px; />
<img src="images/demo2.gif" width=650px; />
## What is k8sgpt?
`k8sgpt` is a tool for scanning your kubernetes clusters, diagnosing and triaging issues in simple english.
It reduces the mystery of kubernetes and makes it easy to understand what is going on in your cluster.
It reduces the mystery of kubernetes and makes it easy to understand what is going on in your cluster.
## Usage
```
# Ensure KUBECONFIG env is set to an active Kubernetes cluster
k8sgpt auth key <Your OpenAI key>
k8sgpt find problems --explain
```
### What about kubectl-ai?
The the kubectl-ai [project](https://github.com/sozercan/kubectl-ai) uses AI to create manifests and apply them to the cluster. It is not what we are trying to do here, it is focusing on writing YAML manifests.
K8sgpt is focused on triaging and diagnosing issues in your cluster. It is a tool for SRE, Platform & DevOps engineers to help them understand what is going on in their cluster. Cutting through the noise of logs and multiple tools to find the root cause of an issue.
### Configuration
`k8sgpt` stores config data in `~/.k8sgpt` the data is stored in plain text, including your OpenAI key.
### Example
```
k8sgpt find problems --explain
default/deathstar-5b559d699b-d4jm7: Back-off pulling image "docker.io/cilium/starwaraaes"
The Kubernetes error message: Back-off pulling image "docker.io/cilium/starwaraaes" means that the Kubernetes cluster is having trouble pulling the specified container image from the Docker registry.
To solve this issue, you can try the following:
1. Check if the specified image exists in the Docker registry by running the following command:
`docker pull docker.io/cilium/starwaraaes`
2. If the image exists, try pulling the image manually on the node where the container is trying to run. This can be done by running the following command:
`docker pull docker.io/cilium/starwaraaes`
3. If the image is not found in the Docker registry, check if the image name and tag are correct.
4. If the issue persists, check the Docker engine logs for any error messages that might provide more context on the issue.
placed-application-demo/placed-application-demo-58469d688c-7wdps: 0/5 nodes are available: 5 node(s) were unschedulable. preemption: 0/5 nodes are available: 5 Preemption is not helpful for scheduling..
```
### Community
* Find us on [Slack](https://cloud-native.slack.com/channels/k8sgpt-ai)

View File

@@ -7,10 +7,10 @@ import (
"context"
"os"
"github.com/cloud-native-skunkworks/k8sgpt/pkg/analyzer"
"github.com/cloud-native-skunkworks/k8sgpt/pkg/client"
"github.com/cloud-native-skunkworks/k8sgpt/pkg/openai"
"github.com/fatih/color"
"github.com/k8sgpt-ai/k8sgpt/pkg/ai"
"github.com/k8sgpt-ai/k8sgpt/pkg/analyzer"
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
@@ -26,7 +26,7 @@ var problemsCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
// Initialise the openAI client
openAIClient, err := openai.NewClient()
openAIClient, err := ai.NewClient()
if err != nil {
color.Red("Error: %v", err)
os.Exit(1)
@@ -34,9 +34,12 @@ var problemsCmd = &cobra.Command{
ctx := context.Background()
// Get kubernetes client from viper
client := viper.Get("kubernetesClient").(*client.Client)
client := viper.Get("kubernetesClient").(*kubernetes.Client)
analyzer.RunAnalysis(ctx, client, openAIClient, explain)
if err := analyzer.RunAnalysis(ctx, client, openAIClient, explain); err != nil {
color.Red("Error: %v", err)
os.Exit(1)
}
},
}

View File

@@ -6,10 +6,10 @@ package cmd
import (
"os"
"github.com/cloud-native-skunkworks/k8sgpt/cmd/auth"
"github.com/cloud-native-skunkworks/k8sgpt/cmd/find"
"github.com/cloud-native-skunkworks/k8sgpt/pkg/client"
"github.com/fatih/color"
"github.com/k8sgpt-ai/k8sgpt/cmd/auth"
"github.com/k8sgpt-ai/k8sgpt/cmd/find"
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
@@ -56,7 +56,7 @@ func init() {
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
//Initialise the kubeconfig
kubernetesClient, err := client.NewClient(masterURL, kubeconfig)
kubernetesClient, err := kubernetes.NewClient(masterURL, kubeconfig)
if err != nil {
color.Red("Error initialising kubernetes client: %v", err)
}

4
go.mod
View File

@@ -1,11 +1,11 @@
module github.com/cloud-native-skunkworks/k8sgpt
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.4
github.com/sashabaranov/go-openai v1.5.5
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
golang.org/x/term v0.6.0

2
go.sum
View File

@@ -210,6 +210,8 @@ github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBO
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sashabaranov/go-openai v1.5.4 h1:I2K7JMIx/EC/mwT2fbypBzJ3OtwKNxaFg4jf3KOvXuc=
github.com/sashabaranov/go-openai v1.5.4/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
github.com/sashabaranov/go-openai v1.5.5 h1:VYdzEGVk4zV04ZNqNb1DT8w7JCzWM77h3h6pBH27B1k=
github.com/sashabaranov/go-openai v1.5.5/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
github.com/spf13/afero v1.9.3 h1:41FoI0fD7OR7mGcKE/aOiLkGreyf8ifIOQmJANWogMk=
github.com/spf13/afero v1.9.3/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y=
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=

BIN
images/demo2.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

View File

@@ -3,7 +3,7 @@ Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package main
import "github.com/cloud-native-skunkworks/k8sgpt/cmd"
import "github.com/k8sgpt-ai/k8sgpt/cmd"
func main() {
cmd.Execute()

View File

@@ -1,4 +1,4 @@
package openai
package ai
import (
"context"

View File

@@ -2,25 +2,25 @@ package analyzer
import (
"context"
"encoding/base64"
"fmt"
"os"
"strings"
"time"
"github.com/briandowns/spinner"
"github.com/cloud-native-skunkworks/k8sgpt/pkg/client"
ai "github.com/cloud-native-skunkworks/k8sgpt/pkg/openai"
"github.com/fatih/color"
"github.com/k8sgpt-ai/k8sgpt/pkg/ai"
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
"github.com/spf13/viper"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func RunAnalysis(ctx context.Context, client *client.Client, openAIClient *ai.Client, explain bool) {
func RunAnalysis(ctx context.Context, client *kubernetes.Client, aiClient *ai.Client, explain bool) error {
// search all namespaces for pods that are not running
list, err := client.GetClient().CoreV1().Pods("").List(ctx, metav1.ListOptions{})
if err != nil {
color.Red("Error: %v", err)
os.Exit(1)
return err
}
var brokenPods = map[string][]string{}
@@ -52,21 +52,53 @@ func RunAnalysis(ctx context.Context, client *client.Client, openAIClient *ai.Cl
}
}
for key, value := range brokenPods {
fmt.Printf("%s: %s\n", color.YellowString(key), color.RedString(value[0]))
count := 0
for key, value := range brokenPods {
fmt.Printf("%s: %s: %s\n", color.CyanString("%d", count), color.YellowString(key), color.RedString(value[0]))
count++
if explain {
s := spinner.New(spinner.CharSets[35], 100*time.Millisecond) // Build our new spinner
s.Start()
response, err := openAIClient.GetCompletion(ctx, strings.Join(value, " "))
s.Stop()
if err != nil {
color.Red("Error: %v", err)
return
inputValue := strings.Join(value, " ")
// Check for cached data
sEnc := base64.StdEncoding.EncodeToString([]byte(inputValue))
// find in viper cache
if viper.IsSet(sEnc) {
s.Stop()
// retrieve data from cache
response := viper.GetString(sEnc)
if response == "" {
color.Red("error retrieving cached data")
continue
}
output, err := base64.StdEncoding.DecodeString(response)
if err != nil {
color.Red("error decoding cached data: %v", err)
continue
}
color.Green(string(output))
continue
}
fmt.Printf("%s\n", color.GreenString(response))
response, err := aiClient.GetCompletion(ctx, inputValue)
s.Stop()
if err != nil {
color.Red("error getting completion: %v", err)
continue
}
if !viper.IsSet(sEnc) {
viper.Set(sEnc, base64.StdEncoding.EncodeToString([]byte(response)))
if err := viper.WriteConfig(); err != nil {
return err
}
}
}
}
return nil
}

View File

@@ -1,4 +1,4 @@
package client
package kubernetes
import (
"k8s.io/client-go/kubernetes"

18
renovate.json Normal file
View File

@@ -0,0 +1,18 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base",
"helpers:pinGitHubActionDigests"
],
"packageRules": [
{
"matchUpdateTypes": ["minor", "patch"],
"matchCurrentVersion": "!/^0/",
"automerge": true
},
{
"matchManagers": ["github-actions"],
"automerge": true
}
]
}