Skip to content

Commit 1f723ec

Browse files
committed
Improve logging and reasons
Several changes: - deadline exceeded: Feedback was that it was too general (looked like http error) - disruption type message is clearer (display allowed types as well) - log all rejections: before we logged only the "budget" rejections, now all rejections are logged.
1 parent cf87246 commit 1f723ec

File tree

5 files changed

+10
-33
lines changed

5 files changed

+10
-33
lines changed

cmd/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535

3636
nodedisruptionv1alpha1 "github.com/criteo/node-disruption-controller/api/v1alpha1"
3737
"github.com/criteo/node-disruption-controller/internal/controller"
38-
"github.com/criteo/node-disruption-controller/pkg/utils"
3938
//+kubebuilder:scaffold:imports
4039
)
4140

@@ -101,7 +100,7 @@ func main() {
101100
os.Exit(1)
102101
}
103102

104-
nodeDisruptionTypes := utils.FilterEmptyString(strings.Split(nodeDisruptionTypesRaw, ","))
103+
nodeDisruptionTypes := strings.FieldsFunc(nodeDisruptionTypesRaw, func(c rune) bool { return c == ',' })
105104

106105
if err = (&controller.NodeDisruptionReconciler{
107106
Client: mgr.GetClient(),

internal/controller/nodedisruption_controller.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ func (ndr *SingleNodeDisruptionReconciler) getRetryDate() metav1.Time {
222222
// tryTransitionToGranted attempt to transition to the granted state but can result in either pending or rejected
223223
func (ndr *SingleNodeDisruptionReconciler) tryTransitionToGranted(ctx context.Context) (err error) {
224224
nextRetryDate := ndr.getRetryDate()
225+
logger := log.FromContext(ctx)
225226

226227
var state nodedisruptionv1alpha1.NodeDisruptionState
227228

@@ -245,6 +246,11 @@ func (ndr *SingleNodeDisruptionReconciler) tryTransitionToGranted(ctx context.Co
245246
if !nextRetryDate.IsZero() {
246247
state = nodedisruptionv1alpha1.Pending
247248
} else {
249+
for _, status := range statuses {
250+
if !status.Ok {
251+
logger.Info("Disruption rejected", "status", status)
252+
}
253+
}
248254
state = nodedisruptionv1alpha1.Rejected
249255
}
250256
}
@@ -314,7 +320,7 @@ func (ndr *SingleNodeDisruptionReconciler) ValidateWithInternalConstraints(ctx c
314320
if ndr.NodeDisruption.Spec.Retry.IsAfterDeadline() {
315321
status := nodedisruptionv1alpha1.DisruptedBudgetStatus{
316322
Reference: ndr.getNodeDisruptionReference(),
317-
Reason: "Deadline exceeded",
323+
Reason: fmt.Sprintf("Failed to grant maintenance before deadline (deadline: %s)", ndr.NodeDisruption.Spec.Retry.Deadline),
318324
Ok: false,
319325
}
320326
// Conserve the statuses of the previous iteration to conserve the reason of rejection
@@ -338,7 +344,7 @@ func (ndr *SingleNodeDisruptionReconciler) ValidateWithInternalConstraints(ctx c
338344
if len(ndr.Config.NodeDisruptionTypes) != 0 && !slices.Contains(ndr.Config.NodeDisruptionTypes, ndr.NodeDisruption.Spec.Type) {
339345
status := nodedisruptionv1alpha1.DisruptedBudgetStatus{
340346
Reference: ndr.getNodeDisruptionReference(),
341-
Reason: "Type provided of node disruption is not managed",
347+
Reason: fmt.Sprintf("Type of node disruption provided is not allowed (supported: %s) (see --node-disruption-types on the controller)", ndr.Config.NodeDisruptionTypes),
342348
Ok: false,
343349
}
344350
return true, []nodedisruptionv1alpha1.DisruptedBudgetStatus{status}, nil
@@ -350,7 +356,6 @@ func (ndr *SingleNodeDisruptionReconciler) ValidateWithInternalConstraints(ctx c
350356
// ValidateBudgetConstraints check that the Node Disruption is valid against the budgets defined in the cluster
351357
func (ndr *SingleNodeDisruptionReconciler) ValidateWithBudgetConstraints(ctx context.Context, budgets []Budget) (anyFailed bool, statuses []nodedisruptionv1alpha1.DisruptedBudgetStatus) {
352358
disruptedNodes := resolver.NewNodeSetFromStringList(ndr.NodeDisruption.Status.DisruptedNodes)
353-
logger := log.FromContext(ctx)
354359
anyFailed = false
355360

356361
impactedBudgets := []Budget{}
@@ -368,7 +373,6 @@ func (ndr *SingleNodeDisruptionReconciler) ValidateWithBudgetConstraints(ctx con
368373
Ok: false,
369374
}
370375
statuses = append(statuses, status)
371-
logger.Info("Disruption rejected because: ", "status", status)
372376
DisruptionBudgetRejectedTotal.WithLabelValues(ref.Namespace, ref.Name, ref.Kind).Inc()
373377
break
374378
}
@@ -390,7 +394,6 @@ func (ndr *SingleNodeDisruptionReconciler) ValidateWithBudgetConstraints(ctx con
390394
Ok: false,
391395
}
392396
statuses = append(statuses, status)
393-
logger.Info("Disruption rejected because: ", "status", status)
394397
DisruptionBudgetRejectedTotal.WithLabelValues(ref.Namespace, ref.Name, ref.Kind).Inc()
395398
break
396399
}

internal/controller/nodedisruption_controller_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ var _ = Describe("NodeDisruption controller", func() {
562562
Name: "test-nodedisruption",
563563
Kind: "NodeDisruption",
564564
},
565-
Reason: "Deadline exceeded",
565+
Reason: fmt.Sprintf("Failed to grant maintenance before deadline (deadline: %s)", disruption.Spec.Retry.Deadline),
566566
Ok: false,
567567
}}
568568
Expect(disruption.Status.DisruptedDisruptionBudgets).Should(Equal(expectedStatus))

pkg/utils/utils.go

-10
This file was deleted.

pkg/utils/utils_test.go

-15
This file was deleted.

0 commit comments

Comments
 (0)