Design: Action-Classification Stage for K8sGPT
Related PR: #1805
Context
K8sGPT currently sends raw Kubernetes failures to a generative LLM and gets back unstructured English text. In #1805 I introduced a second, deterministic classification step that takes the LLM's output and produces a strictly typed action decision. @AlexsJones asked me to open a design issue before we go further, so here's my thinking on the four areas he called out.
1. Category Taxonomy
Right now the prototype hardcodes four categories:
[]string{"RestartPod", "ScaleDeployment", "Ignore", "ReviewConfig"}That's fine for a proof of concept, but it obviously can't stay hardcoded.
What I'd propose: K8sGPT ships with a sensible set of defaults, but lets users fully customize the taxonomy through their k8sgpt.yaml:
systemOne:
actions:
- RestartPod
- ScaleDeployment
- DrainNode
- CordonNode
- NotifyOnCallIf no config is set, the defaults kick in. The merged list gets passed to ClassifyAction(ctx, prompt, categories) at runtime, so adding or removing actions never needs a code change — it's just a config update.
Who owns the defaults? The K8sGPT maintainers. New default actions go through a normal PR review with documentation for when each one applies. User-defined actions are the user's responsibility — K8sGPT just passes them through to whatever System One model is configured.
How does it grow? Since the category list is just a []string passed at runtime, adding new actions is never a breaking change. A contributor opens a PR, adds the action, documents it, and maintainers review and merge. Simple.
2. Output Shape
After the latest revision in #1805, the Result struct carries the full classification:
type Result struct {
Kind string `json:"kind"`
Name string `json:"name"`
Error []Failure `json:"error"`
Details string `json:"details"`
ParentObject string `json:"parentObject"`
SystemOneAction *ai.ActionClassification `json:"systemOneAction,omitempty"`
}Where ActionClassification looks like:
type ActionClassification struct {
Decision string `json:"decision"`
Confidence float32 `json:"confidence"`
SuggestedAction string `json:"suggested_action"`
}So the JSON output a user would see is something like:
{
"kind": "Pod",
"name": "nginx-abc123",
"details": "The pod is in CrashLoopBackOff...",
"systemOneAction": {
"decision": "RestartPod",
"confidence": 0.97,
"suggested_action": "CrashLoopBackOff count exceeded threshold"
}
}When no --action-backend is configured, the field just doesn't show up (omitempty). No breaking change for anyone already consuming K8sGPT's output.
A few things I'd like maintainer input on:
| Question | My thinking |
|---|---|
Should the field be called Decision or Action? |
Action reads more naturally, but Decision avoids confusion with the parent field name. Could go either way. |
float32 (0.0–1.0) or integer percentage (0–100) for confidence? |
Float feels more standard in ML pipelines, but happy to change if the team prefers percentages. |
Should systemOneAction be renamed to something more generic like classification? |
Open to it if systemOne feels too implementation-specific. |
3. Remediation Stance: Dry-Run, Not Auto-Fix
This is the one I've thought about the most. K8sGPT is a diagnostics tool; it should tell you what to do, not do it for you.
So rather than building toward an --auto-fix flag that executes actions against a live cluster, I think the right approach is a dry-run philosophy: the classification is always a recommendation. K8sGPT gives you a decision and a confidence score, and you decide what to do with it.
For CLI users: The classification shows up in the JSON output. You see the recommendation; you decide whether to act on it. K8sGPT never touches the cluster.
For ChatOps integrations: The Slack or Teams integration could read the systemOneAction field and render interactive buttons — something like [ Restart Pod ] or [ Ignore ]. A human clicks the button to approve or reject. The human is always in the loop.
For automation pipelines: Teams that want full automation can consume K8sGPT's structured JSON output and wire it into their own remediation pipelines (Argo Workflows, Tekton, whatever they use). They control the confidence threshold, the allowed actions, and the blast radius. K8sGPT provides the intelligence; they provide the execution.
The key principle here is that K8sGPT stays firmly in the "diagnose and recommend" lane. It gives consumers everything they need to build automation on top, but it never pulls the trigger itself.
4. Core vs Plugin
My recommendation: core for the plumbing, pluggable for the models.
What lives in core:
- The
ISystemOneinterface andActionClassificationstruct (pkg/ai/systemone.go) - The
--action-backendCLI flag (cmd/analyze/analyze.go) - The classification hook in
GetAIResults(pkg/analysis/analysis.go) - The
SystemOneActionfield onResult(pkg/common/types.go)
What's pluggable:
- The actual model backends. Just like
ollama,openai, andazureopenaiare all pluggable generative backends today, classification backends would follow the same pattern. Any model that implementsISystemOnecan be wired in. The PR currently ships a generic HTTP client (SystemOneClient), but tomorrow someone could add an Ollama-native or OpenAI structured-output version.
Why not a custom analyzer? Custom analyzers run before the LLM; they scan Kubernetes resources and produce Result objects. Classification runs after the LLM, consuming the generative output. It doesn't fit the analyzer lifecycle; it's a post-processing step, not a resource scanner.
Why not a standalone plugin? The classification adds a field to the core Result struct. If it lived outside core, every consumer of K8sGPT's JSON output would need to handle two different result schemas depending on whether the plugin was installed. Keeping it in core with omitempty means the field simply doesn't appear when no classification backend is configured clean backward compatibility.
Summary
| Area | Proposal |
|---|---|
| Taxonomy | Ship defaults in core, fully customizable via k8sgpt.yaml |
| Output | Full ActionClassification struct on Result (decision + confidence + suggested action) |
| Remediation | Dry-run philosophy — classify and recommend, never execute |
| Location | Core plumbing + pluggable model backends |
Happy to iterate further on #1805 once we've agreed on the shape.
Source: k8sgpt-ai/k8sgpt