Skip to content

Commit

Permalink
Revert refactor to filtering that broke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karlkfi committed Sep 17, 2021
1 parent eb774d6 commit da1775d
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions pkg/apply/task/apply_task.go
Expand Up @@ -115,18 +115,28 @@ func (a *ApplyTask) Start(taskContext *taskrunner.TaskContext) {
}

// Check filters to see if we're prevented from applying.
filtered, err := a.filter(obj)
if err != nil {
if klog.V(5).Enabled() {
klog.Errorf("error filtering: %w", err)
var filtered bool
var filterErr error
for _, filter := range a.Filters {
klog.V(6).Infof("apply filter %s: %s", filter.Name(), id)
var reason string
filtered, reason, filterErr = filter.Filter(obj)
if filterErr != nil {
if klog.V(5).Enabled() {
klog.Errorf("error during %s, (%s): %s", filter.Name(), id, filterErr)
}
taskContext.EventChannel() <- createApplyFailedEvent(id, filterErr)
taskContext.CaptureResourceFailure(id)
break
}
if filtered {
klog.V(4).Infof("apply filtered by %s because (%s): %s", filter.Name(), reason, id)
taskContext.EventChannel() <- createApplyEvent(id, event.Unchanged, obj)
taskContext.CaptureResourceFailure(id)
break
}
taskContext.EventChannel() <- createApplyFailedEvent(id, err)
taskContext.CaptureResourceFailure(id)
continue
}
if filtered {
taskContext.EventChannel() <- createApplyEvent(id, event.Unchanged, obj)
taskContext.CaptureResourceFailure(id)
if filtered || filterErr != nil {
continue
}

Expand Down Expand Up @@ -220,25 +230,6 @@ func (a *ApplyTask) sendTaskResult(taskContext *taskrunner.TaskContext) {
// ClearTimeout is not supported by the ApplyTask.
func (a *ApplyTask) ClearTimeout() {}

// filter loops through the filter list and executes them on the object.
// Returns true if the object should be filtered (not applied).
func (a *ApplyTask) filter(obj *unstructured.Unstructured) (bool, error) {
id := object.UnstructuredToObjMetaOrDie(obj)
for _, filter := range a.Filters {
klog.V(6).Infof("apply filter %s: %s", filter.Name(), id)
var reason string
filtered, reason, err := filter.Filter(obj)
if err != nil {
return true, fmt.Errorf("failed to filter %q with %q: %w", id, filter.Name(), err)
}
if filtered {
klog.V(4).Infof("apply filtered by %s because (%s): %s", filter.Name(), reason, id)
return true, nil
}
}
return false, nil
}

// mutate loops through the mutator list and executes them on the object.
func (a *ApplyTask) mutate(ctx context.Context, obj *unstructured.Unstructured) error {
id := object.UnstructuredToObjMetaOrDie(obj)
Expand Down

0 comments on commit da1775d

Please sign in to comment.