Skip to content

Conversation

@dobsonj
Copy link
Member

@dobsonj dobsonj commented Aug 13, 2025

ReadNetworkPolicyV1OrDie should use netCodecs instead of coreCodecs,
otherwise it panics because NetworkPolicy is not in the core scheme.

Example panic where I called this function from a new controller in openshift/local-storage-operator:

I0813 10:46:03.944908 2644555 reconcile.go:41] "Reconciling NetworkPolicies" namespace="openshift-local-storage" name=""
2025-08-13T10:46:03.945-0600    ERROR   runtime/runtime.go:142  Observed a panic        {"controller": "networkpolicy", "controllerGroup": "networking.k8s.io", "controllerKind": "NetworkPolicy", "NetworkPolicy": {"name":"","namespace":"openshift-local-storage"}, "namespace": "openshift-local-storage", "name": "", "reconcileID": "93797f73-f3ff-48e8-a860-34b0dbbec9f0", "panic": "no kind \"NetworkPolicy\" is registered for version \"networking.k8s.io/v1\" in scheme \"github.com/openshift/library-go/pkg/operator/resource/resourceread/core.go:10\"", "panicGoValue": "&runtime.notRegisteredErr{schemeName:\"github.com/openshift/library-go/pkg/operator/resource/resourceread/core.go:10\", gvk:schema.GroupVersionKind{Group:\"networking.k8s.io\", Version:\"v1\", Kind:\"NetworkPolicy\"}, target:runtime.GroupVersioner(nil), t:reflect.Type(nil)}", "stacktrace": "goroutine 427 [running]:\nk8s.io/apimachinery/pkg/util/runtime.logPanic({0x2a92c48, 0xc0009fb560}, {0x2262320, 0xc000c8ef00})\n\t/home/jon/workspace/local-storage-operator/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go:132 +0xbc\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Reconcile.func1()\n\t/home/jon/workspace/local-storage-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:108 +0x112\npanic({0x2262320?, 0xc000c8ef00?})\n\t/home/jon/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.4.linux-amd64/src/runtime/panic.go:792 +0x132\ngithub.com/openshift/library-go/pkg/operator/resource/resourceread.ReadNetworkPolicyV1OrDie({0xc000470f00, 0x263, 0x280})\n\t/home/jon/workspace/local-storage-operator/vendor/github.com/openshift/library-go/pkg/operator/resource/resourceread/networking.go:23 +0x11e\ngithub.com/openshift/local-storage-operator/pkg/controllers/networkpolicy.(*NetworkPolicyReconciler).Reconcile(0xc000464a50, {0x2a92c48, 0xc0009fb560}, {{{0xc00085e078?, 0x268a7cb?}, {0x0?, 0x100?}}})\n\t/home/jon/workspace/local-storage-operator/pkg/controllers/networkpolicy/reconcile.go:59 +0x295\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Reconcile(0xc0009fb4d0?, {0x2a92c48?, 0xc0009fb560?}, {{{0xc00085e078?, 0x0?}, {0x0?, 0x0?}}})\n\t/home/jon/workspace/local-storage-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:119 +0xbf\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).reconcileHandler(0x2abfec0, {0x2a92c80, 0xc0003b5860}, {{{0xc00085e078, 0x17}, {0x0, 0x0}}}, 0x0)\n\t/home/jon/workspace/local-storage-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:340 +0x3ad\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).processNextWorkItem(0x2abfec0, {0x2a92c80, 0xc0003b5860})\n\t/home/jon/workspace/local-storage-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:300 +0x21b\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Start.func2.1()\n\t/home/jon/workspace/local-storage-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:202 +0x85\ncreated by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Start.func2 in goroutine 111\n\t/home/jon/workspace/local-storage-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:198 +0x28f\n"}
k8s.io/apimachinery/pkg/util/runtime.logPanic
        /home/jon/workspace/local-storage-operator/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go:142
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Reconcile.func1
        /home/jon/workspace/local-storage-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:108
runtime.gopanic
        /home/jon/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.4.linux-amd64/src/runtime/panic.go:792
github.com/openshift/library-go/pkg/operator/resource/resourceread.ReadNetworkPolicyV1OrDie
        /home/jon/workspace/local-storage-operator/vendor/github.com/openshift/library-go/pkg/operator/resource/resourceread/networking.go:23
github.com/openshift/local-storage-operator/pkg/controllers/networkpolicy.(*NetworkPolicyReconciler).Reconcile
        /home/jon/workspace/local-storage-operator/pkg/controllers/networkpolicy/reconcile.go:59

The panic message is the important bit:
"no kind \"NetworkPolicy\" is registered for version \"networking.k8s.io/v1\" in scheme \"github.com/openshift/library-go/pkg/operator/resource/resourceread/core.go:10\""

Using netCodecs instead of coreCodecs fixes this issue and allows ReadNetworkPolicyV1OrDie to return successfully.

/cc @tmshort @jsafrane

ReadNetworkPolicyV1OrDie should use netCodecs instead of coreCodecs,
otherwise it panics because NetworkPolicy is not in the core scheme.
@openshift-ci openshift-ci bot requested review from jsafrane and tmshort August 13, 2025 17:16
@dobsonj
Copy link
Member Author

dobsonj commented Aug 13, 2025

/assign @jsafrane
congrats, you are the last approver remaining :)

@jsafrane
Copy link
Contributor

/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 28, 2025
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 28, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dobsonj, jsafrane

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 28, 2025
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 28, 2025

@dobsonj: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@openshift-merge-bot openshift-merge-bot bot merged commit 3ee684a into openshift:master Aug 28, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants