Skip to content

Commit

Permalink
feat: AI playbook actions
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Dec 31, 2024
1 parent ddb0d5e commit 8cf0c6f
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 4 deletions.
25 changes: 25 additions & 0 deletions charts/playbooks-kubernetes/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/

.bin/
6 changes: 5 additions & 1 deletion charts/playbooks-kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ Flanksource Mission Control Playbooks that interact directly with the Kubernetes
| delete.types[5] | string | `"Kubernetes::CronJob"` | |
| delete.types[6] | string | `"Kubernetes::DaemonSet"` | |
| delete.types[7] | string | `"Kubernetes::ConfigMap"` | |
| playbooks.ai.connection | string | `""` | |
| playbooks.ai.diagnose.cluster | string | `""` | |
| playbooks.ai.diagnose.systemPrompt | string | `""` | |
| playbooks.ai.enabled | bool | `false` | |
| playbooks.cleanupFailedPods | bool | `true` | |
| playbooks.createDeployment | bool | `true` | |
| playbooks.delete | bool | `true` | |
| playbooks.deployHelmChart | bool | `true` | |
| playbooks.enabled | bool | `true` | |
| playbooks.enabled | bool | `false` | |
| playbooks.ignoreChanges | bool | `true` | |
| playbooks.logs | bool | `true` | |
| playbooks.podSnapshot | bool | `false` | |
Expand Down
58 changes: 58 additions & 0 deletions charts/playbooks-kubernetes/templates/diagnose-kubernetes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/flanksource/duty/main/schema/openapi/playbook.schema.json

{{- if .Values.playbooks.ai.enabled }}
---
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: diagnose-any-kubernetes-resource
spec:
description: Use AI to diagnose unhealthy kubernetes resources
configs:
- tagSelector: 'cluster={{.Values.playbooks.ai.diagnose.cluster}}'
healths:
- unhealthy
- warning
# TODO: Limit this selector to kubernetes types
parameters:
- name: prompt
label: Prompt
default: Find out why $(.config.name) is unhealthy
properties:
multiline: 'true'
actions:
- name: query
ai:
connection: '{{.Values.playbooks.ai.connection}}'
systemPrompt: |-
{{- if .Values.playbooks.ai.diagnose.systemPrompt }}
{{- .Values.playbooks.ai.diagnose.systemPrompt | nindent 10 }}
{{- else }}
**Role:** Seasoned Kubernetes engineer and Diagnostic Expert
**Objective:** Assist users in diagnosing issues with unhealthy Kubernetes resources by analyzing provided manifests and related resources.
**Instructions:**
1. **Resource Analysis:** Examine the manifest of the unhealthy resource thoroughly.
2. **Contextual Investigation:** Consider additional related resources provided (e.g., pods, replica sets, namespaces) to gain a comprehensive understanding of the issue.
3. **Diagnostic Steps:** Clearly outline the steps taken during the investigation, focusing on precision and brevity.
4. **One-Time Diagnosis:** Aim to diagnose the issue in a single response without requiring follow-up questions.
**Output:** Provide a concise diagnosis and potential solutions based on the analysis.
{{- end }}
prompt: '$(.params.prompt)'
changes:
since: 2d
analysis:
since: 2d
relationships:
- depth: 5
direction: outgoing
changes:
since: 24h
- depth: 5
direction: incoming
changes:
since: 24h
{{- end}}
55 changes: 53 additions & 2 deletions charts/playbooks-kubernetes/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,57 @@
},
"playbooks": {
"additionalProperties": false,
"description": "yaml-language-server: $schema=values.schema.json",
"properties": {
"ai": {
"additionalProperties": false,
"properties": {
"connection": {
"default": "",
"description": "LLM connection: one of ollama, openai or anthropic",
"required": [],
"title": "connection",
"type": "string"
},
"diagnose": {
"additionalProperties": false,
"properties": {
"cluster": {
"default": "",
"description": "name of the cluster",
"required": [],
"title": "cluster",
"type": "string"
},
"systemPrompt": {
"default": "",
"description": "Optional system prompt for the LLM. If not provided, a default prompt will be used.",
"required": [],
"title": "systemPrompt",
"type": "string"
}
},
"required": [
"cluster"
],
"title": "diagnose",
"type": "object"
},
"enabled": {
"default": false,
"required": [],
"title": "enabled",
"type": "boolean"
}
},
"required": [
"enabled",
"connection",
"diagnose"
],
"title": "ai",
"type": "object"
},
"cleanupFailedPods": {
"default": true,
"required": [],
Expand All @@ -88,7 +138,7 @@
"type": "boolean"
},
"enabled": {
"default": true,
"default": false,
"description": "If this is set to false, no playbooks will be created",
"required": [],
"title": "enabled",
Expand Down Expand Up @@ -156,7 +206,8 @@
"scale",
"updateImage",
"updateResources",
"deployHelmChart"
"deployHelmChart",
"ai"
],
"title": "playbooks",
"type": "object"
Expand Down
26 changes: 25 additions & 1 deletion charts/playbooks-kubernetes/values.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# yaml-language-server: $schema=values.schema.json
playbooks:
# If this is set to false, no playbooks will be created
enabled: true
enabled: false
createDeployment: true
logs: true
delete: true
Expand All @@ -14,6 +14,30 @@ playbooks:
updateImage: true
updateResources: true
deployHelmChart: true
ai:
enabled: false

# @schema
# type: string
# required: true
# @schema
# LLM connection: one of ollama, openai or anthropic
connection: ""

diagnose:
# @schema
# type: string
# required: true
# @schema
# name of the cluster
cluster: ""

# @schema
# type: string
# required: false
# @schema
# Optional system prompt for the LLM. If not provided, a default prompt will be used.
systemPrompt: ""

delete:
types:
Expand Down

0 comments on commit 8cf0c6f

Please sign in to comment.