Skip to content

[BUG] pdbminavailable check crashes on PDB with minAvailable and no selector #1041

@abyrne55

Description

@abyrne55

System info:
Using kube-linter CLI v0.7.6 on Fedora Linux 42, but also observed this behavior with a downstream consumer (Deployment Validation Operator)

Describe the bug
kube-linter panics with a "nil pointer dereference" when its pdbminavailable check encounters a PodDisruptionBudget that has spec.minAvailable defined but is missing the required spec.selector field.

To Reproduce

  1. Create a file named bad-pdb.yaml with the content below.
  2. Run kube-linter lint bad-pdb.yaml.

Sample YAML input

apiVersion: policy/v1
kind: PodDisruptionBudget
spec:
  minAvailable: 40%

Expected behavior
kube-linter should not panic. It should report a linting error because the PDB is invalid due to the missing spec.selector.

Additional context
Full stack trace from the panic:

panic: runtime error: invalid memory address or nil pointer dereference                                            
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x19e533d]
                                                                                                                   
goroutine 1 [running]:                                                                                             
golang.stackrox.io/kube-linter/pkg/templates/pdbminavailable.minAvailableCheck({0x220f368, 0xc0006338c0}, {{{0xc0004abc40, 0x34}, {0xc000540280, 0x49, 0x80}}, {0x224b1f8, 0xc0006bf340}})
        golang.stackrox.io/kube-linter/pkg/templates/pdbminavailable/template.go:81 +0x1bd                         
golang.stackrox.io/kube-linter/pkg/run.Run({0xc00032fd90, 0x1, 0x0?}, {0x220efa8, 0xc00067b020}, {0xc0001b8a00?, 0x1f?, 0x0?})
        golang.stackrox.io/kube-linter/pkg/run/run.go:63 +0x8a3                                                    
golang.stackrox.io/kube-linter/pkg/command/lint.Command.func1(0xc000167600?, {0xc00071b660, 0x1, 0x1eb2620?})      
        golang.stackrox.io/kube-linter/pkg/command/lint/command.go:129 +0x7b2                                      
github.com/spf13/cobra.(*Command).execute(0xc0006c0c08, {0xc00071b630, 0x1, 0x1})                                  
        github.com/spf13/[email protected]/command.go:1015 +0xb02                                                      
github.com/spf13/cobra.(*Command).ExecuteC(0xc0006c0308)                                                                                                                                                                              
        github.com/spf13/[email protected]/command.go:1148 +0x465                                                                                                                                                                         
github.com/spf13/cobra.(*Command).Execute(0x0?)                                                                                                                                                                                       
        github.com/spf13/[email protected]/command.go:1071 +0x13                                                                                                                                                                          
main.main()                                                                                                                                                                                                                           
        golang.stackrox.io/kube-linter/cmd/kube-linter/kube-linter.go:14 +0x18 

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions