fix: do not allow nil Callbacks functions
If user specifies a nil callback, then error out rather than crashing at runtime due to a nil reference.
This commit is contained in:
		@@ -89,6 +89,12 @@ func NewLeaderElector(lec LeaderElectionConfig) (*LeaderElector, error) {
 | 
				
			|||||||
	if lec.RetryPeriod < 1 {
 | 
						if lec.RetryPeriod < 1 {
 | 
				
			||||||
		return nil, fmt.Errorf("retryPeriod must be greater than zero")
 | 
							return nil, fmt.Errorf("retryPeriod must be greater than zero")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if lec.Callbacks.OnStartedLeading == nil {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("OnStartedLeading callback must not be nil")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if lec.Callbacks.OnStoppedLeading == nil {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("OnStoppedLeading callback must not be nil")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if lec.Lock == nil {
 | 
						if lec.Lock == nil {
 | 
				
			||||||
		return nil, fmt.Errorf("Lock must not be nil.")
 | 
							return nil, fmt.Errorf("Lock must not be nil.")
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user