Skip to content

Commit

Permalink
Reduce event spam by using command.Action() instead of command.String…
Browse files Browse the repository at this point in the history
…() (aws#461)
  • Loading branch information
jonathan-innis authored Aug 10, 2023
1 parent 8083be5 commit 20516d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/samber/lo v1.38.1
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.24.0
golang.org/x/text v0.11.0
golang.org/x/time v0.3.0
k8s.io/api v0.26.6
k8s.io/apiextensions-apiserver v0.26.6
Expand Down Expand Up @@ -84,7 +85,6 @@ require (
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/tools v0.9.3 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/api v0.124.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions pkg/controllers/deprovisioning/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (c *Controller) executeCommand(ctx context.Context, d Deprovisioner, comman
}

for _, candidate := range command.candidates {
c.recorder.Publish(deprovisioningevents.Terminating(candidate.Node, candidate.Machine, command.String())...)
c.recorder.Publish(deprovisioningevents.Terminating(candidate.Node, candidate.Machine, reason)...)

if err := c.kubeClient.Delete(ctx, candidate.Machine); err != nil {
if errors.IsNotFound(err) {
Expand Down Expand Up @@ -239,7 +239,7 @@ func (c *Controller) launchReplacementMachines(ctx context.Context, action Comma
workqueue.ParallelizeUntil(ctx, len(machineNames), len(machineNames), func(i int) {
// machine never became ready or the machines that we tried to launch got Insufficient Capacity or some
// other transient error
errs[i] = c.waitForReadiness(ctx, action, machineNames[i])
errs[i] = c.waitForReadiness(ctx, machineNames[i], reason)
})
if err = multierr.Combine(errs...); err != nil {
c.cluster.UnmarkForDeletion(candidateNodeNames...)
Expand All @@ -250,7 +250,7 @@ func (c *Controller) launchReplacementMachines(ctx context.Context, action Comma
}

// TODO @njtran: Allow to bypass this check for certain deprovisioners
func (c *Controller) waitForReadiness(ctx context.Context, action Command, name string) error {
func (c *Controller) waitForReadiness(ctx context.Context, name string, reason string) error {
// Wait for the machine to be initialized
var once sync.Once
pollStart := time.Now()
Expand All @@ -265,7 +265,7 @@ func (c *Controller) waitForReadiness(ctx context.Context, action Command, name
return fmt.Errorf("getting machine, %w", err)
}
once.Do(func() {
c.recorder.Publish(deprovisioningevents.Launching(machine, action.String()))
c.recorder.Publish(deprovisioningevents.Launching(machine, reason))
})
if !machine.StatusConditions().GetCondition(v1alpha5.MachineInitialized).IsTrue() {
// make the user aware of why deprovisioning is paused
Expand Down
8 changes: 5 additions & 3 deletions pkg/controllers/deprovisioning/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"fmt"
"time"

"golang.org/x/text/cases"
"golang.org/x/text/language"
v1 "k8s.io/api/core/v1"

"github.com/aws/karpenter-core/pkg/apis/v1alpha5"
Expand All @@ -29,7 +31,7 @@ func Launching(machine *v1alpha5.Machine, reason string) events.Event {
InvolvedObject: machine,
Type: v1.EventTypeNormal,
Reason: "DeprovisioningLaunching",
Message: fmt.Sprintf("Launching machine for %s", reason),
Message: fmt.Sprintf("Launching machine: %s", cases.Title(language.Und, cases.NoLower).String(reason)),
DedupeValues: []string{machine.Name, reason},
}
}
Expand Down Expand Up @@ -60,14 +62,14 @@ func Terminating(node *v1.Node, machine *v1alpha5.Machine, reason string) []even
InvolvedObject: node,
Type: v1.EventTypeNormal,
Reason: "DeprovisioningTerminating",
Message: fmt.Sprintf("Deprovisioning node via %s", reason),
Message: fmt.Sprintf("Deprovisioning node: %s", cases.Title(language.Und, cases.NoLower).String(reason)),
DedupeValues: []string{node.Name, reason},
},
{
InvolvedObject: machine,
Type: v1.EventTypeNormal,
Reason: "DeprovisioningTerminating",
Message: fmt.Sprintf("Deprovisioning machine via %s", reason),
Message: fmt.Sprintf("Deprovisioning machine: %s", cases.Title(language.Und, cases.NoLower).String(reason)),
DedupeValues: []string{machine.Name, reason},
},
}
Expand Down

0 comments on commit 20516d9

Please sign in to comment.