Skip to content

Commit

Permalink
balloons: add debug logging to selecting a balloon type
Browse files Browse the repository at this point in the history
Signed-off-by: Antti Kervinen <[email protected]>
  • Loading branch information
askervin authored and klihub committed Nov 5, 2024
1 parent a0d1476 commit 416f238
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/plugins/balloons/policy/balloons-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,21 @@ func (p *balloons) balloonDefByName(defName string) *BalloonDef {
}

func (p *balloons) chooseBalloonDef(c cache.Container) (*BalloonDef, error) {
log.Debugf("choosing balloon type for container %s...", c.PrettyName())
// Case 1: BalloonDef is defined by annotation.
if blnDefName, ok := c.GetEffectiveAnnotation(balloonKey); ok {
blnDef := p.balloonDefByName(blnDefName)
if blnDef == nil {
return nil, balloonsError("no balloon for annotation %q", blnDefName)
}
log.Debugf("- annotation %q found, using balloon type %q", balloonKey, blnDefName)
return blnDef, nil
}

for _, blnDef := range p.bpoptions.BalloonDefs {
// Case 2: BalloonDef is defined by a match expression.
for _, expr := range blnDef.MatchExpressions {
log.Debugf("- checking expression %s of balloon %q against container %s...",
log.Debugf("- checking expression %s of balloon type %q against container %s...",
expr.String(), blnDef.Name, c.PrettyName())
if expr.Evaluate(c) {
log.Debugf(" => matches")
Expand All @@ -424,10 +426,12 @@ func (p *balloons) chooseBalloonDef(c cache.Container) (*BalloonDef, error) {

// Case 3: BalloonDef is defined by the namespace.
if namespaceMatches(c.GetNamespace(), blnDef.Namespaces) {
log.Debugf("- namespace %q matches namespaces of balloon type %q", c.GetNamespace(), blnDef.Name)
return blnDef, nil
}
}

log.Debugf("- no match found, using default balloon type %q", defaultBalloonDefName)
// Case 4: Fallback to the default balloon.
return p.defaultBalloonDef, nil
}
Expand Down

0 comments on commit 416f238

Please sign in to comment.