mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Improve logging on kube-proxy exit
This commit is contained in:
		@@ -57,7 +57,7 @@ func (n *NodePodCIDRHandler) OnNodeAdd(node *v1.Node) {
 | 
				
			|||||||
	if !reflect.DeepEqual(n.podCIDRs, podCIDRs) {
 | 
						if !reflect.DeepEqual(n.podCIDRs, podCIDRs) {
 | 
				
			||||||
		klog.ErrorS(nil, "Using NodeCIDR LocalDetector mode, current PodCIDRs are different than previous PodCIDRs, restarting",
 | 
							klog.ErrorS(nil, "Using NodeCIDR LocalDetector mode, current PodCIDRs are different than previous PodCIDRs, restarting",
 | 
				
			||||||
			"node", klog.KObj(node), "newPodCIDRs", podCIDRs, "oldPodCIDRs", n.podCIDRs)
 | 
								"node", klog.KObj(node), "newPodCIDRs", podCIDRs, "oldPodCIDRs", n.podCIDRs)
 | 
				
			||||||
		panic("Current Node PodCIDRs are different than previous PodCIDRs, restarting")
 | 
							klog.FlushAndExit(klog.ExitFlushTimeout, 1)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -75,7 +75,7 @@ func (n *NodePodCIDRHandler) OnNodeUpdate(_, node *v1.Node) {
 | 
				
			|||||||
	if !reflect.DeepEqual(n.podCIDRs, podCIDRs) {
 | 
						if !reflect.DeepEqual(n.podCIDRs, podCIDRs) {
 | 
				
			||||||
		klog.ErrorS(nil, "Using NodeCIDR LocalDetector mode, current PodCIDRs are different than previous PodCIDRs, restarting",
 | 
							klog.ErrorS(nil, "Using NodeCIDR LocalDetector mode, current PodCIDRs are different than previous PodCIDRs, restarting",
 | 
				
			||||||
			"node", klog.KObj(node), "newPodCIDRs", podCIDRs, "oldPODCIDRs", n.podCIDRs)
 | 
								"node", klog.KObj(node), "newPodCIDRs", podCIDRs, "oldPODCIDRs", n.podCIDRs)
 | 
				
			||||||
		panic("Current Node PodCIDRs are different than previous PodCIDRs, restarting")
 | 
							klog.FlushAndExit(klog.ExitFlushTimeout, 1)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,13 +17,21 @@ limitations under the License.
 | 
				
			|||||||
package proxy
 | 
					package proxy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	v1 "k8s.io/api/core/v1"
 | 
						v1 "k8s.io/api/core/v1"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
 | 
						"k8s.io/klog/v2"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestNodePodCIDRHandlerAdd(t *testing.T) {
 | 
					func TestNodePodCIDRHandlerAdd(t *testing.T) {
 | 
				
			||||||
 | 
						oldKlogOsExit := klog.OsExit
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							klog.OsExit = oldKlogOsExit
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
						klog.OsExit = customExit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		name            string
 | 
							name            string
 | 
				
			||||||
		oldNodePodCIDRs []string
 | 
							oldNodePodCIDRs []string
 | 
				
			||||||
@@ -71,12 +79,19 @@ func TestNodePodCIDRHandlerAdd(t *testing.T) {
 | 
				
			|||||||
					t.Errorf("The code did panic")
 | 
										t.Errorf("The code did panic")
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}()
 | 
								}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			n.OnNodeAdd(node)
 | 
								n.OnNodeAdd(node)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestNodePodCIDRHandlerUpdate(t *testing.T) {
 | 
					func TestNodePodCIDRHandlerUpdate(t *testing.T) {
 | 
				
			||||||
 | 
						oldKlogOsExit := klog.OsExit
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							klog.OsExit = oldKlogOsExit
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
						klog.OsExit = customExit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		name            string
 | 
							name            string
 | 
				
			||||||
		oldNodePodCIDRs []string
 | 
							oldNodePodCIDRs []string
 | 
				
			||||||
@@ -125,7 +140,12 @@ func TestNodePodCIDRHandlerUpdate(t *testing.T) {
 | 
				
			|||||||
					t.Errorf("The code did panic")
 | 
										t.Errorf("The code did panic")
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}()
 | 
								}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			n.OnNodeUpdate(oldNode, node)
 | 
								n.OnNodeUpdate(oldNode, node)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func customExit(exitCode int) {
 | 
				
			||||||
 | 
						panic(strconv.Itoa(exitCode))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user