Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2773 from /issues/2772-check-type-on-delete
Browse files Browse the repository at this point in the history
Handle cache.DeleteFinalStateUnknown
  • Loading branch information
bboreham committed Feb 13, 2017
2 parents 50b1aa0 + defa5cc commit 39f471e
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions prog/weave-npc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ func root(cmd *cobra.Command, args []string) {
handleError(npc.AddNamespace(obj.(*coreapi.Namespace)))
},
DeleteFunc: func(obj interface{}) {
handleError(npc.DeleteNamespace(obj.(*coreapi.Namespace)))
switch obj := obj.(type) {
case *coreapi.Namespace:
handleError(npc.DeleteNamespace(obj))
case cache.DeletedFinalStateUnknown:
// We know this object has gone away, but its final state is no longer
// available from the API server. Instead we use the last copy of it
// that we have, which is good enough for our cleanup.
handleError(npc.DeleteNamespace(obj.Obj.(*coreapi.Namespace)))
}
},
UpdateFunc: func(old, new interface{}) {
handleError(npc.UpdateNamespace(old.(*coreapi.Namespace), new.(*coreapi.Namespace)))
Expand All @@ -139,7 +147,15 @@ func root(cmd *cobra.Command, args []string) {
handleError(npc.AddPod(obj.(*coreapi.Pod)))
},
DeleteFunc: func(obj interface{}) {
handleError(npc.DeletePod(obj.(*coreapi.Pod)))
switch obj := obj.(type) {
case *coreapi.Pod:
handleError(npc.DeletePod(obj))
case cache.DeletedFinalStateUnknown:
// We know this object has gone away, but its final state is no longer
// available from the API server. Instead we use the last copy of it
// that we have, which is good enough for our cleanup.
handleError(npc.DeletePod(obj.Obj.(*coreapi.Pod)))
}
},
UpdateFunc: func(old, new interface{}) {
handleError(npc.UpdatePod(old.(*coreapi.Pod), new.(*coreapi.Pod)))
Expand All @@ -151,7 +167,15 @@ func root(cmd *cobra.Command, args []string) {
handleError(npc.AddNetworkPolicy(obj.(*extnapi.NetworkPolicy)))
},
DeleteFunc: func(obj interface{}) {
handleError(npc.DeleteNetworkPolicy(obj.(*extnapi.NetworkPolicy)))
switch obj := obj.(type) {
case *extnapi.NetworkPolicy:
handleError(npc.DeleteNetworkPolicy(obj))
case cache.DeletedFinalStateUnknown:
// We know this object has gone away, but its final state is no longer
// available from the API server. Instead we use the last copy of it
// that we have, which is good enough for our cleanup.
handleError(npc.DeleteNetworkPolicy(obj.Obj.(*extnapi.NetworkPolicy)))
}
},
UpdateFunc: func(old, new interface{}) {
handleError(npc.UpdateNetworkPolicy(old.(*extnapi.NetworkPolicy), new.(*extnapi.NetworkPolicy)))
Expand Down

0 comments on commit 39f471e

Please sign in to comment.