Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

balloons: add debug logging to selecting a balloon type #396

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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