mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 02:11:09 +00:00
Fix controller policy and improve logging of related errors
Improve error logging from timed workers which are used for pod eviction Co-authored-by: Aldo Culquicondor <1299064+alculquicondor@users.noreply.github.com>
This commit is contained in:
parent
91a9ce28ac
commit
bb561e0324
@ -52,11 +52,17 @@ type TimedWorker struct {
|
|||||||
// createWorker creates a TimedWorker that will execute `f` not earlier than `fireAt`.
|
// createWorker creates a TimedWorker that will execute `f` not earlier than `fireAt`.
|
||||||
func createWorker(ctx context.Context, args *WorkArgs, createdAt time.Time, fireAt time.Time, f func(ctx context.Context, args *WorkArgs) error, clock clock.WithDelayedExecution) *TimedWorker {
|
func createWorker(ctx context.Context, args *WorkArgs, createdAt time.Time, fireAt time.Time, f func(ctx context.Context, args *WorkArgs) error, clock clock.WithDelayedExecution) *TimedWorker {
|
||||||
delay := fireAt.Sub(createdAt)
|
delay := fireAt.Sub(createdAt)
|
||||||
|
fWithErrorLogging := func() {
|
||||||
|
err := f(ctx, args)
|
||||||
|
if err != nil {
|
||||||
|
klog.Errorf("NodeLifecycle: timed worker failed with error: %q", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
if delay <= 0 {
|
if delay <= 0 {
|
||||||
go f(ctx, args)
|
go fWithErrorLogging()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
timer := clock.AfterFunc(delay, func() { f(ctx, args) })
|
timer := clock.AfterFunc(delay, fWithErrorLogging)
|
||||||
return &TimedWorker{
|
return &TimedWorker{
|
||||||
WorkItem: args,
|
WorkItem: args,
|
||||||
CreatedAt: createdAt,
|
CreatedAt: createdAt,
|
||||||
|
@ -255,6 +255,7 @@ func buildControllerRoles() ([]rbacv1.ClusterRole, []rbacv1.ClusterRoleBinding)
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(features.PodDisruptionConditions) {
|
if utilfeature.DefaultFeatureGate.Enabled(features.PodDisruptionConditions) {
|
||||||
|
role.Rules = append(role.Rules, rbacv1helpers.NewRule("get").Groups(legacyGroup).Resources("pods").RuleOrDie())
|
||||||
role.Rules = append(role.Rules, rbacv1helpers.NewRule("patch").Groups(legacyGroup).Resources("pods/status").RuleOrDie())
|
role.Rules = append(role.Rules, rbacv1helpers.NewRule("patch").Groups(legacyGroup).Resources("pods/status").RuleOrDie())
|
||||||
}
|
}
|
||||||
return role
|
return role
|
||||||
|
Loading…
Reference in New Issue
Block a user