github.com/cilium/cilium@v1.16.2/pkg/k8s/resource/error.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package resource 5 6 type ErrorAction string 7 8 var ( 9 // ErrorActionRetry instructs to retry the processing. The key is requeued after 10 // rate limiting. 11 ErrorActionRetry ErrorAction = "retry" 12 13 // ErrorActionIgnore instructs to ignore the error. 14 ErrorActionIgnore ErrorAction = "ignore" 15 16 // ErrorActionStop instructs to stop the processing for this subscriber. 17 ErrorActionStop ErrorAction = "stop" 18 ) 19 20 // ErrorHandler is a function that takes the key of the failing object (zero key if event 21 // was sync), the number of times the key has been retried and the error that occurred. 22 // The function returns the action that should be taken. 23 type ErrorHandler func(key Key, numRetries int, err error) ErrorAction 24 25 // AlwaysRetry is an error handler that always retries the error. 26 func AlwaysRetry(Key, int, error) ErrorAction { 27 return ErrorActionRetry 28 } 29 30 // RetryUpTo is an error handler that retries a key up to specified number of 31 // times before stopping. 32 func RetryUpTo(n int) ErrorHandler { 33 return func(key Key, numRetries int, err error) ErrorAction { 34 if numRetries >= n { 35 return ErrorActionStop 36 } 37 return ErrorActionRetry 38 } 39 }