Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
More logs for BOSH add-ons
Browse files Browse the repository at this point in the history
  • Loading branch information
viovanov authored and rohitsakala committed Oct 1, 2019
1 parent 40ae643 commit 09095a7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/bosh/converter/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (r *ResolverImpl) WithOpsManifest(ctx context.Context, instance *bdv1.BOSHD
}

// Apply addons
err = manifest.ApplyAddons()
err = manifest.ApplyAddons(ctx)
if err != nil {
return nil, varSecrets, errors.Wrapf(err, "failed to apply addons")
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func (r *ResolverImpl) WithOpsManifestDetailed(ctx context.Context, instance *bd
}

// Apply addons
err = manifest.ApplyAddons()
err = manifest.ApplyAddons(ctx)
if err != nil {
return nil, varSecrets, errors.Wrapf(err, "failed to apply addons")
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/bosh/manifest/addon_placement.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package manifest

import (
"context"
"fmt"

"github.com/pkg/errors"

"code.cloudfoundry.org/cf-operator/pkg/kube/util/ctxlog"
)

type matcher func(*InstanceGroup, *AddOnPlacementRules) (bool, error)
Expand Down Expand Up @@ -73,17 +76,19 @@ func (m *Manifest) instanceGroupMatch(instanceGroup *InstanceGroup, rules *AddOn
}

// addOnPlacementMatch returns true if any placement rule of the addon matches the instance group
func (m *Manifest) addOnPlacementMatch(instanceGroup *InstanceGroup, rules *AddOnPlacementRules) (bool, error) {
func (m *Manifest) addOnPlacementMatch(ctx context.Context, placementType string, instanceGroup *InstanceGroup, rules *AddOnPlacementRules) (bool, error) {
// This check is special, not a matcher. Lifecycle always needs to match
if (instanceGroup.LifeCycle == IGTypeErrand ||
instanceGroup.LifeCycle == IGTypeAutoErrand) &&
(rules == nil || rules.Lifecycle != IGTypeErrand) {
ctxlog.Debugf(ctx, "Instance group '%s' is an errand, but the %s placement rules don't match an errand", instanceGroup.Name, placementType)
return false, nil
}

if (instanceGroup.LifeCycle == IGTypeService ||
instanceGroup.LifeCycle == IGTypeDefault) &&
(rules != nil && rules.Lifecycle != IGTypeDefault && rules.Lifecycle != IGTypeService) {
ctxlog.Debugf(ctx, "Instance group '%s' is a BOSH service, but the %s placement rules don't match a BOSH service", instanceGroup.Name, placementType)
return false, nil
}

Expand All @@ -104,5 +109,9 @@ func (m *Manifest) addOnPlacementMatch(instanceGroup *InstanceGroup, rules *AddO
matchResult = matchResult || matched
}

if !matchResult {
ctxlog.Debugf(ctx, "Instance group '%s' did not match the %s placement rules", instanceGroup.Name, placementType)
}

return matchResult, nil
}
10 changes: 7 additions & 3 deletions pkg/bosh/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package manifest

import (
"bytes"
"context"
"crypto"
"crypto/sha1"
"encoding/hex"
Expand All @@ -18,6 +19,7 @@ import (
"sigs.k8s.io/yaml"

esv1 "code.cloudfoundry.org/cf-operator/pkg/kube/apis/extendedsecret/v1alpha1"
"code.cloudfoundry.org/cf-operator/pkg/kube/util/ctxlog"
)

const (
Expand Down Expand Up @@ -456,19 +458,20 @@ func (m *Manifest) ImplicitVariables() ([]string, error) {
}

// ApplyAddons goes through all defined addons and adds jobs to matched instance groups
func (m *Manifest) ApplyAddons() error {
func (m *Manifest) ApplyAddons(ctx context.Context) error {
for _, addon := range m.AddOns {
for _, ig := range m.InstanceGroups {
include, err := m.addOnPlacementMatch(ig, addon.Include)
include, err := m.addOnPlacementMatch(ctx, "inclusion", ig, addon.Include)
if err != nil {
return errors.Wrap(err, "failed to process include placement matches")
}
exclude, err := m.addOnPlacementMatch(ig, addon.Exclude)
exclude, err := m.addOnPlacementMatch(ctx, "exclusion", ig, addon.Exclude)
if err != nil {
return errors.Wrap(err, "failed to process exclude placement matches")
}

if exclude || !include {
ctxlog.Debugf(ctx, "Addon '%s' doesn't match instance group '%s'", addon.Name, ig.Name)
continue
}

Expand All @@ -481,6 +484,7 @@ func (m *Manifest) ApplyAddons() error {

addedJob.Properties.Quarks.IsAddon = true

ctxlog.Debugf(ctx, "Applying addon job '%s/%s' to instance group '%s'", addon.Name, addonJob.Name, ig.Name)
ig.Jobs = append(ig.Jobs, addedJob)
}
}
Expand Down

0 comments on commit 09095a7

Please sign in to comment.