bug: webhook analyzers never populate KubernetesDoc (wrong API group and field paths)
Expected Behavior
With --with-doc, failures reported by the MutatingWebhookConfiguration and ValidatingWebhookConfiguration analyzers should carry the relevant Kubernetes API documentation in KubernetesDoc, as other analyzers do.
Current Behavior
KubernetesDoc is always empty for both webhook analyzers, so --with-doc silently adds nothing for these kinds.
Two separate mistakes combine to cause it, in pkg/analyzer/mutating_webhook.go and pkg/analyzer/validating_webhook.go:
1. Wrong API group. Both declare:
apiDoc := kubernetes.K8sApiReference{
Kind: kind,
ApiVersion: schema.GroupVersion{
Group: "apps",
Version: "v1",
},
...
}MutatingWebhookConfiguration and ValidatingWebhookConfiguration are in admissionregistration.k8s.io/v1, not apps/v1.
GetApiDocV2 resolves a definition by suffix-matching "<group[0]>.<version>.<Kind>" (pkg/kubernetes/apireference.go):
group := strings.Split(k.ApiVersion.Group, ".")
...
if strings.HasSuffix(prop.GetName(), fmt.Sprintf("%s.%s.%s", group[0], k.ApiVersion.Version, k.Kind)) {So it searches for a definition ending in apps.v1.MutatingWebhookConfiguration, while the API server serves io.k8s.api.admissionregistration.v1.MutatingWebhookConfiguration. No match, startPoint stays "", and recursePath returns "".
2. Wrong field paths. Both analyzers look up spec.webhook.clientConfig.service and spec.webhook. MutatingWebhookConfiguration has no spec field — its schema is metadata plus a webhooks list, with the service reference at webhooks[].clientConfig.service.
Because of this second point, correcting the group alone is not sufficient: the path walk would still return "".
Steps to Reproduce
- Create a webhook configuration pointing at a service that does not exist:
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: demo
webhooks:
- name: demo.example.com
admissionReviewVersions: ["v1"]
sideEffects: None
clientConfig:
service:
name: missing-svc
namespace: default
rules: []- Run the analyzer with docs enabled:
k8sgpt analyze --filter MutatingWebhookConfiguration --with-doc- The failure is reported, but its
KubernetesDocis empty. Every other analyzer with a correct group and path populates it.
The same applies to ValidatingWebhookConfiguration.
Environment
- k8sgpt version: built from
mainatb4e7fdc - Kubernetes version: v1.34.0 (kind)
- AI Backend/Provider: none — analyzer-side only, reproduces without
--explain - OS/Platform: Windows 11
Additional Context
I audited every analyzer that declares a GroupVersion. These two are the only incorrect ones. Note that ingress.go and netpol.go declare networking rather than networking.k8s.io, but that is harmless: GetApiDocV2 splits on . and uses group[0], so both resolve identically.
I have a fix with regression tests ready and will open a PR referencing this issue.
Source: k8sgpt-ai/k8sgpt