forked from k8sgpt-ai/k8sgpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/235/use-xdg-config-home
Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
- Loading branch information
Showing
33 changed files
with
403 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.PHONY: docker-build | ||
IMG ?= ghcr.io/k8sgpt-ai/k8sgpt:latest | ||
|
||
deploy: | ||
ifndef SECRET | ||
$(error SECRET environment variable is not set) | ||
endif | ||
kubectl create ns k8sgpt || true | ||
kubectl create secret generic ai-backend-secret --from-literal=secret-key=$(SECRET) --namespace=k8sgpt || true | ||
kubectl apply -f container/manifests | ||
undeploy: | ||
kubectl delete secret ai-backend-secret --namespace=k8sgpt | ||
kubectl delete -f container/manifests | ||
kubectl delete ns k8sgpt | ||
docker-build: | ||
docker buildx build --build-arg=VERSION="$$(git describe --tags --abbrev=0)" --build-arg=COMMIT="$$(git rev-parse --short HEAD)" --build-arg DATE="$$(date +%FT%TZ)" --platform="linux/amd64,linux/arm64" -t ${IMG} -f container/Dockerfile . --push |
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,42 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: k8sgpt-deployment | ||
namespace: k8sgpt | ||
labels: | ||
app: k8sgpt | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: k8sgpt | ||
template: | ||
metadata: | ||
labels: | ||
app: k8sgpt | ||
spec: | ||
serviceAccountName: k8sgpt | ||
containers: | ||
- name: k8sgpt-container | ||
imagePullPolicy: Always | ||
image: ghcr.io/k8sgpt-ai/k8sgpt:v0.2.2 #x-release-please-version | ||
ports: | ||
- containerPort: 8080 | ||
args: ["serve"] | ||
resources: | ||
limits: | ||
cpu: "1" | ||
memory: "512Mi" | ||
requests: | ||
cpu: "0.5" | ||
memory: "256Mi" | ||
env: | ||
- name: K8SGPT_MODEL | ||
value: "gpt-3.5-turbo" | ||
- name: K8SGPT_BACKEND | ||
value: "openai" | ||
- name: K8SGPT_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: ai-backend-secret | ||
key: secret-key |
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,13 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: k8sgpt-cluster-role-all | ||
rules: | ||
- apiGroups: | ||
- '*' | ||
resources: | ||
- '*' | ||
verbs: | ||
- get | ||
- list | ||
- watch |
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,13 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: k8sgpt-rolebinding | ||
namespace: k8sgpt | ||
subjects: | ||
- kind: ServiceAccount | ||
name: k8sgpt | ||
namespace: k8sgpt | ||
roleRef: | ||
kind: ClusterRole | ||
name: k8sgpt-cluster-role-all | ||
apiGroup: rbac.authorization.k8s.io |
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,5 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: k8sgpt | ||
namespace: k8sgpt |
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,13 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: k8sgpt-service | ||
namespace: k8sgpt | ||
spec: | ||
selector: | ||
app: k8sgpt | ||
ports: | ||
- name: http | ||
port: 8080 | ||
targetPort: 8080 | ||
type: ClusterIP |
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,11 @@ | ||
. demo-magic.sh | ||
clear | ||
|
||
pe "k8sgpt filter list" | ||
pe "k8sgpt analyze --filter=Pod --explain -o json | jq ." | ||
pe "k8sgpt integration list" | ||
pe "k8sgpt integration activate trivy" | ||
pe "k8sgpt filter list" | ||
pe "k8sgpt analyze --filter=VulnerabilityReport" | ||
pe "./k8sgpt analyze --filter=Node --explain" | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,72 @@ | ||
package analysis | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/fatih/color" | ||
) | ||
|
||
var outputFormats = map[string]func(*Analysis) ([]byte, error){ | ||
"json": (*Analysis).jsonOutput, | ||
"text": (*Analysis).textOutput, | ||
} | ||
|
||
func getOutputFormats() []string { | ||
formats := make([]string, 0, len(outputFormats)) | ||
for format := range outputFormats { | ||
formats = append(formats, format) | ||
} | ||
return formats | ||
} | ||
|
||
func (a *Analysis) PrintOutput(format string) ([]byte, error) { | ||
outputFunc, ok := outputFormats[format] | ||
if !ok { | ||
return nil, fmt.Errorf("unsupported output format: %s. Available format %s", format, strings.Join(getOutputFormats(), ",")) | ||
} | ||
return outputFunc(a) | ||
} | ||
|
||
func (a *Analysis) jsonOutput() ([]byte, error) { | ||
var problems int | ||
var status AnalysisStatus | ||
for _, result := range a.Results { | ||
problems += len(result.Error) | ||
} | ||
if problems > 0 { | ||
status = StateProblemDetected | ||
} else { | ||
status = StateOK | ||
} | ||
|
||
result := JsonOutput{ | ||
Problems: problems, | ||
Results: a.Results, | ||
Status: status, | ||
} | ||
output, err := json.MarshalIndent(result, "", " ") | ||
if err != nil { | ||
return nil, fmt.Errorf("error marshalling json: %v", err) | ||
} | ||
return output, nil | ||
} | ||
|
||
func (a *Analysis) textOutput() ([]byte, error) { | ||
var output strings.Builder | ||
output.WriteString("\n") | ||
if len(a.Results) == 0 { | ||
output.WriteString(color.GreenString("No problems detected\n")) | ||
return []byte(output.String()), nil | ||
} | ||
for n, result := range a.Results { | ||
output.WriteString(fmt.Sprintf("%s %s(%s)\n", color.CyanString("%d", n), | ||
color.YellowString(result.Name), color.CyanString(result.ParentObject))) | ||
for _, err := range result.Error { | ||
output.WriteString(fmt.Sprintf("- %s %s\n", color.RedString("Error:"), color.RedString(err.Text))) | ||
} | ||
output.WriteString(color.GreenString(result.Details + "\n")) | ||
} | ||
return []byte(output.String()), 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
Oops, something went wrong.