bug: ClusterCatalog and ClusterExtension analyzers panic on objects without an image or catalog source
Expected Behavior
The ClusterCatalog and ClusterExtension analyzers should report on any valid object without crashing, and should not write anything to stdout outside the normal analysis output.
Current Behavior
Both analyzers panic with a nil pointer dereference on objects that are perfectly valid.
Each one opens its loop with a leftover debug Printf that dereferences a pointer field without checking it first:
// pkg/analyzer/clustercatalog.go
fmt.Printf("ClusterCatalog: %s | Source: %s\n", catalog.Name, catalog.Spec.Source.Image.Ref)
// pkg/analyzer/clusterextension.go
fmt.Printf("ClusterExtension: %s | Source: %s\n", extension.Name, extension.Spec.Source.Catalog.PackageName)Spec.Source.Image is *ImageSource and Spec.Source.Catalog is *CatalogFilter (pkg/common/types.go). A ClusterCatalog whose source carries no image, or a ClusterExtension with no catalog source, makes either line panic.
Analyzers run in goroutines, so the panic takes the whole k8sgpt process down rather than just that analyzer.
ValidateClusterCatalog has the same problem twice more:
if !isValidImageRef(catalog.Spec.Source.Image.Ref) { // Image may be nil
...
if catalog.Status.ResolvedSource != nil {
if catalog.Status.ResolvedSource.Image.Ref == "" { // Image may be nilThe second one checks ResolvedSource for nil but then dereferences ResolvedSource.Image, which is also a pointer.
Worth noting that ValidateClusterExtension does guard its pointer (extension.Spec.Source.Catalog != nil). The validation logic is careful; it is the debug lines that are not.
Separately, those two Printf calls write to stdout for every item, ahead of the real output. That corrupts --output json for anyone parsing it.
Steps to Reproduce
With OLM v1 installed and the analyzer enabled:
k8sgpt filters add ClusterCatalog
k8sgpt analyze --filter ClusterCatalogagainst a cluster holding a ClusterCatalog whose spec.source has no image. The process panics at clustercatalog.go:63.
The same reproduces in a unit test with the fake dynamic client:
"spec": map[string]interface{}{
"source": map[string]interface{}{"type": "Unknown"},
},panic: runtime error: invalid memory address or nil pointer dereference
ClusterCatalogAnalyzer.Analyze
pkg/analyzer/clustercatalog.go:63Three cases panic in total:
| Site | Field |
|---|---|
clustercatalog.go:63 |
Spec.Source.Image |
clustercatalog.go:137 |
Status.ResolvedSource.Image |
clusterextension.go:62 |
Spec.Source.Catalog |
Environment
- k8sgpt version: built from
mainat9456068 - Kubernetes version: v1.34.0 (kind)
- AI Backend/Provider: none, reproduces without
--explain - OS/Platform: Windows 11
Additional Context
Both analyzers are opt-in rather than core, so this only affects people who have enabled them against an OLM v1 cluster. That narrows the blast radius, but the failure mode is a crash of the whole process rather than a bad result.
I have a fix with regression tests for all three sites and will open a PR referencing this issue.
Source: k8sgpt-ai/k8sgpt