Skip to content

[Bug] Chainsaw Panics with "invalid memory address" when running --no-cluster test #2383

@sheshananda

Description

@sheshananda

chainsaw version Version

v0.2.12

Description

Chainsaw panics with a runtime error: invalid memory address or nil pointer dereference when attempting to run tests in --no-cluster mode. This occurs specifically during the apply operation within a test step.

Steps to reproduce

  1. Chainsaw Version
    Version: 0.2.12
    Time: 2024-12-04T13:06:58Z
    Git commit ID: 6459cd8

    Steps to reproduce

    1. Create a ClusterPolicy named require-app-label (details below).
    2. Create a Chainsaw Test file (details below) that attempts to apply a resource that would be processed by this policy.
    3. Run the test: chainsaw test <path-to-test-file-or-dir> --no-cluster
cat require-app-label.yaml
	
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: require-app-label
spec:
  validationFailureAction: Enforce
  rules:
    - name: check-for-app-label
      match:
        resources:
          kinds:
            - Pod
      validate:
        message: "Every pod must have the 'app' label."
        pattern:
          metadata:
            labels:
              app: "?*"	
			  
			  
cat chainsaw-test.yaml

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: app-label
spec:
  steps:
  - name: step-01
    try:
    - apply:
        file: require-app-label.yaml	

Expected behavior

I expected Chainsaw to successfully evaluate the policy and resource in --no-cluster mode, either passing the test or providing a clear validation error/denial message without crashing.

Screenshots

Image

Logs

# chainsaw test . --no-cluster
Version: 0.2.11
Loading default configuration...
- Using test file: chainsaw-test
- TestDirs [.]
- SkipDelete false
- FailFast false
- Namespace ''
- FullName false
- IncludeTestRegex ''
- ExcludeTestRegex ''
- ApplyTimeout 5s
- AssertTimeout 30s
- CleanupTimeout 30s
- DeleteTimeout 15s
- ErrorTimeout 30s
- ExecTimeout 5s
- DeletionPropagationPolicy Background
- Template true
- NoCluster true
- PauseOnFailure false
Loading tests...
- app-label (.)
Loading values...
Running tests...
=== RUN   chainsaw
=== PAUSE chainsaw
=== CONT  chainsaw
=== RUN   chainsaw/app-label
=== PAUSE chainsaw/app-label
=== CONT  chainsaw/app-label
    | 16:35:29 | app-label | step-01   | TRY       | BEGIN |
    | 16:35:29 | app-label | step-01   | APPLY     | RUN   | kyverno.io/v1/ClusterPolicy @ require-app-label
E0523 16:35:29.663531   28763 panic.go:262] "Observed a panic" panic="runtime error: invalid memory address or nil pointer dereference" panicGoValue="\"invalid memory address or nil pointer dereference\"" stacktrace=<
        goroutine 11 [running]:
        k8s.io/apimachinery/pkg/util/runtime.logPanic({0x6d24790, 0x81b54e0}, {0x2187d80, 0x812f1d0})
                k8s.io/[email protected]/pkg/util/runtime/runtime.go:107 +0xbc
        k8s.io/apimachinery/pkg/util/runtime.handleCrash({0x6d24790, 0x81b54e0}, {0x2187d80, 0x812f1d0}, {0x81b54e0, 0x0, 0x43af05?})
                k8s.io/[email protected]/pkg/util/runtime/runtime.go:82 +0x5e
        k8s.io/apimachinery/pkg/util/runtime.HandleCrash({0x0, 0x0, 0xc000fe2700?})
                k8s.io/[email protected]/pkg/util/runtime/runtime.go:59 +0x108
        panic({0x2187d80?, 0x812f1d0?})
                runtime/panic.go:785 +0x132
        github.com/kyverno/chainsaw/pkg/engine/operations/apply.(*operation).tryApplyResource(0xc000566b40, {0x6d24870, 0xc000a0fd50}, {0x6d09cc8, 0xc00133c2a0}, {0xc00133cc00})
                github.com/kyverno/chainsaw/pkg/engine/operations/apply/operation.go:103 +0x166
        github.com/kyverno/chainsaw/pkg/engine/operations/apply.(*operation).execute.func1({0x6d24870?, 0xc000a0fd50?})
                github.com/kyverno/chainsaw/pkg/engine/operations/apply/operation.go:87 +0x4c
        k8s.io/apimachinery/pkg/util/wait.loopConditionUntilContext.func2(0xc000112bc0?, {0x6d24870?, 0xc000a0fd50?})
                k8s.io/[email protected]/pkg/util/wait/loop.go:87 +0x52
        k8s.io/apimachinery/pkg/util/wait.loopConditionUntilContext({0x6d24870, 0xc000a0fd50}, {0x6d13b20, 0xc0004c8120}, 0x0, 0x0, 0xc000112c90)
                k8s.io/[email protected]/pkg/util/wait/loop.go:88 +0x237
        k8s.io/apimachinery/pkg/util/wait.PollUntilContextCancel({0x6d24870, 0xc000a0fd50}, 0x207ed00?, 0x0, 0xc000112c90)
                k8s.io/[email protected]/pkg/util/wait/poll.go:33 +0x56
        github.com/kyverno/chainsaw/pkg/engine/operations/apply.(*operation).execute(0xc000a7eb90?, {0x6d24870?, 0xc000a0fd50?}, {0x6d09cc8?, 0xc00133c2a0?}, {0x6d24870?})
                github.com/kyverno/chainsaw/pkg/engine/operations/apply/operation.go:86 +0x8c
        github.com/kyverno/chainsaw/pkg/engine/operations/apply.(*operation).Exec(0xc000566b40, {0x6d24870, 0xc000a0fd50}, {0x6d09cc8?, 0xc00133c2a0?})
                github.com/kyverno/chainsaw/pkg/engine/operations/apply/operation.go:80 +0x39d
        github.com/kyverno/chainsaw/pkg/runner/processors.operation.execute({{0x1, 0x1}, {0x24eda2b, 0x5}, 0xc000a7eb40}, {0x6d247c8, 0xc000e68090}, {0xc001354780, 0xc000ac4de0, {0x6d09cc8, ...}, ...}, ...)
                github.com/kyverno/chainsaw/pkg/runner/processors/operation.go:54 +0x3ba
        github.com/kyverno/chainsaw/pkg/runner/processors.(*stepProcessor).Run(0xc00087a840, {0x6d247c8, 0xc000e68090}, {0x0, 0x0}, {0xc001354780, 0xc000ac4de0, {0x6d09cc8, 0xc000e680c0}, {{0x6d09388, ...}, ...}, ...})
                github.com/kyverno/chainsaw/pkg/runner/processors/step.go:230 +0x103c
        github.com/kyverno/chainsaw/pkg/runner/processors.(*testProcessor).Run(0xc0007db800, {0x6d247c8, 0xc00149ede0}, {0x0, 0x0}, {0xc001354780, 0xc000ac4de0, {0x6d09cc8, 0xc00149ee10}, {{0x6d09388, ...}, ...}, ...})
                github.com/kyverno/chainsaw/pkg/runner/processors/test.go:188 +0xcde
        github.com/kyverno/chainsaw/pkg/runner/processors.(*testsProcessor).Run.func2(0xc00118a000)
                github.com/kyverno/chainsaw/pkg/runner/processors/tests.go:145 +0x714
        testing.tRunner(0xc00118a000, 0xc000a0e9a0)
                testing/testing.go:1690 +0xf4
        created by testing.(*T).Run in goroutine 10
                testing/testing.go:1743 +0x390
 >
    | 16:35:29 | app-label | step-01   | APPLY     | DONE  | kyverno.io/v1/ClusterPolicy @ require-app-label
    | 16:35:29 | app-label | step-01   | TRY       | END   |
--- FAIL: chainsaw (0.07s)
    --- FAIL: chainsaw/app-label (0.06s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x1f34d06]

goroutine 11 [running]:
testing.tRunner.func1.2({0x2187d80, 0x812f1d0})
        testing/testing.go:1632 +0x230
testing.tRunner.func1()
        testing/testing.go:1635 +0x35e
panic({0x2187d80?, 0x812f1d0?})
        runtime/panic.go:785 +0x132
k8s.io/apimachinery/pkg/util/runtime.handleCrash({0x6d24790, 0x81b54e0}, {0x2187d80, 0x812f1d0}, {0x81b54e0, 0x0, 0x43af05?})
        k8s.io/[email protected]/pkg/util/runtime/runtime.go:89 +0xee
k8s.io/apimachinery/pkg/util/runtime.HandleCrash({0x0, 0x0, 0xc000fe2700?})
        k8s.io/[email protected]/pkg/util/runtime/runtime.go:59 +0x108
panic({0x2187d80?, 0x812f1d0?})
        runtime/panic.go:785 +0x132
github.com/kyverno/chainsaw/pkg/engine/operations/apply.(*operation).tryApplyResource(0xc000566b40, {0x6d24870, 0xc000a0fd50}, {0x6d09cc8, 0xc00133c2a0}, {0xc00133cc00})
        github.com/kyverno/chainsaw/pkg/engine/operations/apply/operation.go:103 +0x166
github.com/kyverno/chainsaw/pkg/engine/operations/apply.(*operation).execute.func1({0x6d24870?, 0xc000a0fd50?})
        github.com/kyverno/chainsaw/pkg/engine/operations/apply/operation.go:87 +0x4c
k8s.io/apimachinery/pkg/util/wait.loopConditionUntilContext.func2(0xc000112bc0?, {0x6d24870?, 0xc000a0fd50?})
        k8s.io/[email protected]/pkg/util/wait/loop.go:87 +0x52
k8s.io/apimachinery/pkg/util/wait.loopConditionUntilContext({0x6d24870, 0xc000a0fd50}, {0x6d13b20, 0xc0004c8120}, 0x0, 0x0, 0xc000112c90)
        k8s.io/[email protected]/pkg/util/wait/loop.go:88 +0x237
k8s.io/apimachinery/pkg/util/wait.PollUntilContextCancel({0x6d24870, 0xc000a0fd50}, 0x207ed00?, 0x0, 0xc000112c90)
        k8s.io/[email protected]/pkg/util/wait/poll.go:33 +0x56
github.com/kyverno/chainsaw/pkg/engine/operations/apply.(*operation).execute(0xc000a7eb90?, {0x6d24870?, 0xc000a0fd50?}, {0x6d09cc8?, 0xc00133c2a0?}, {0x6d24870?})
        github.com/kyverno/chainsaw/pkg/engine/operations/apply/operation.go:86 +0x8c
github.com/kyverno/chainsaw/pkg/engine/operations/apply.(*operation).Exec(0xc000566b40, {0x6d24870, 0xc000a0fd50}, {0x6d09cc8?, 0xc00133c2a0?})
        github.com/kyverno/chainsaw/pkg/engine/operations/apply/operation.go:80 +0x39d
github.com/kyverno/chainsaw/pkg/runner/processors.operation.execute({{0x1, 0x1}, {0x24eda2b, 0x5}, 0xc000a7eb40}, {0x6d247c8, 0xc000e68090}, {0xc001354780, 0xc000ac4de0, {0x6d09cc8, ...}, ...}, ...)
        github.com/kyverno/chainsaw/pkg/runner/processors/operation.go:54 +0x3ba
github.com/kyverno/chainsaw/pkg/runner/processors.(*stepProcessor).Run(0xc00087a840, {0x6d247c8, 0xc000e68090}, {0x0, 0x0}, {0xc001354780, 0xc000ac4de0, {0x6d09cc8, 0xc000e680c0}, {{0x6d09388, ...}, ...}, ...})
        github.com/kyverno/chainsaw/pkg/runner/processors/step.go:230 +0x103c
github.com/kyverno/chainsaw/pkg/runner/processors.(*testProcessor).Run(0xc0007db800, {0x6d247c8, 0xc00149ede0}, {0x0, 0x0}, {0xc001354780, 0xc000ac4de0, {0x6d09cc8, 0xc00149ee10}, {{0x6d09388, ...}, ...}, ...})
        github.com/kyverno/chainsaw/pkg/runner/processors/test.go:188 +0xcde
github.com/kyverno/chainsaw/pkg/runner/processors.(*testsProcessor).Run.func2(0xc00118a000)
        github.com/kyverno/chainsaw/pkg/runner/processors/tests.go:145 +0x714
testing.tRunner(0xc00118a000, 0xc000a0e9a0)
        testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 10
        testing/testing.go:1743 +0x390

Slack discussion

No response

Troubleshooting

  • I have searched other issues in this repository and mine is not recorded.

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