-
Notifications
You must be signed in to change notification settings - Fork 670
Fix nil pointer panic in npc/namespace.go #3833
Conversation
7b019ab
to
82209f2
Compare
What exactly gets set to nil? Where? It's probably a good idea to file the problem as an issue, with this PR referring to it, in case there are different ways to solve it. |
Oh, and thanks for the PR. |
Do I still need to open an issue and provide more info? |
My previous comment stands, yes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is really great. I have a couple of suggestions below.
Did you look into adding a test for this case?
npc/namespace.go
Outdated
@@ -3,7 +3,6 @@ package npc | |||
import ( | |||
"errors" | |||
"fmt" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please leave this gap between different classes of imports.
npc/namespace.go
Outdated
policies map[types.UID]interface{} // k8s NetworkPolicy objects by UID | ||
name string // k8s Namespace name | ||
nodeName string // my node name | ||
namespace *coreapi.Namespace // k8s Namespace object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the UID is the only other thing that we use from namespace
, so I suggest to copy that out and lose namespace
, so we don't have to worry about setting it to nil.
82209f2
to
0789670
Compare
e5e9a37
to
2ec3e1e
Compare
@@ -508,23 +511,25 @@ func (ns *ns) addNamespace(obj *coreapi.Namespace) error { | |||
} | |||
|
|||
func (ns *ns) updateNamespace(oldObj, newObj *coreapi.Namespace) error { | |||
ns.namespace = newObj | |||
ns.namespaceUID = newObj.ObjectMeta.UID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't change, can it?
Thanks for making all those changes - it's a bit more than I had thought (sorry!). |
Merge conflicts resolved at master...fix-nil-ns-pointer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM
Try to solve this issue #3836 .
The
*coreapi.Namespace
in structns
may be set tonil
in funcdeleteNamespace
before funcdeletePod
called,it will cause a pinic whendeletePod
use the namespace pointer.I use a new map to store the lables of namespace, when the pointer is set to nil, it can avoid panic and work well.