Skip to content

Commit

Permalink
Merge pull request #558 from karlkfi/karl-fix-dep-filter
Browse files Browse the repository at this point in the history
fix: Make DependencyFilter handle DryRun
  • Loading branch information
k8s-ci-robot authored Mar 2, 2022
2 parents 5c6134a + 0f7f95b commit 326b8a2
Show file tree
Hide file tree
Showing 6 changed files with 426 additions and 46 deletions.
10 changes: 6 additions & 4 deletions pkg/apply/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ func (a *Applier) Run(ctx context.Context, invInfo inventory.Info, objects objec
InvPolicy: options.InventoryPolicy,
},
filter.DependencyFilter{
TaskContext: taskContext,
Strategy: actuation.ActuationStrategyApply,
TaskContext: taskContext,
ActuationStrategy: actuation.ActuationStrategyApply,
DryRunStrategy: options.DryRunStrategy,
},
}
// Build list of prune validation filters.
Expand All @@ -156,8 +157,9 @@ func (a *Applier) Run(ctx context.Context, invInfo inventory.Info, objects objec
LocalNamespaces: localNamespaces(invInfo, object.UnstructuredSetToObjMetadataSet(objects)),
},
filter.DependencyFilter{
TaskContext: taskContext,
Strategy: actuation.ActuationStrategyDelete,
TaskContext: taskContext,
ActuationStrategy: actuation.ActuationStrategyDelete,
DryRunStrategy: options.DryRunStrategy,
},
}
// Build list of apply mutators.
Expand Down
5 changes: 3 additions & 2 deletions pkg/apply/destroyer.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ func (d *Destroyer) Run(ctx context.Context, invInfo inventory.Info, options Des
InvPolicy: options.InventoryPolicy,
},
filter.DependencyFilter{
TaskContext: taskContext,
Strategy: actuation.ActuationStrategyDelete,
TaskContext: taskContext,
ActuationStrategy: actuation.ActuationStrategyDelete,
DryRunStrategy: options.DryRunStrategy,
},
}
taskBuilder := &solver.TaskQueueBuilder{
Expand Down
28 changes: 18 additions & 10 deletions pkg/apply/filter/dependency-filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/cli-utils/pkg/apis/actuation"
"sigs.k8s.io/cli-utils/pkg/apply/taskrunner"
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/cli-utils/pkg/object"
)

Expand All @@ -24,8 +25,9 @@ const (
// DependencyFilter implements ValidationFilter interface to determine if an
// object can be applied or deleted based on the status of it's dependencies.
type DependencyFilter struct {
TaskContext *taskrunner.TaskContext
Strategy actuation.ActuationStrategy
TaskContext *taskrunner.TaskContext
ActuationStrategy actuation.ActuationStrategy
DryRunStrategy common.DryRunStrategy
}

const DependencyFilterName = "DependencyFilter"
Expand All @@ -40,7 +42,7 @@ func (dnrf DependencyFilter) Name() string {
func (dnrf DependencyFilter) Filter(obj *unstructured.Unstructured) (bool, string, error) {
id := object.UnstructuredToObjMetadata(obj)

switch dnrf.Strategy {
switch dnrf.ActuationStrategy {
case actuation.ActuationStrategyApply:
// For apply, check dependencies (outgoing)
for _, depID := range dnrf.TaskContext.Graph().Dependencies(id) {
Expand All @@ -64,7 +66,7 @@ func (dnrf DependencyFilter) Filter(obj *unstructured.Unstructured) (bool, strin
}
}
default:
panic(fmt.Sprintf("invalid filter strategy: %q", dnrf.Strategy))
panic(fmt.Sprintf("invalid filter strategy: %q", dnrf.ActuationStrategy))
}
return false, "", nil
}
Expand All @@ -91,9 +93,9 @@ func (dnrf DependencyFilter) filterByRelationStatus(id object.ObjMetadata, relat

// Dependencies must have the same actuation strategy.
// If there is a mismatch, skip both.
if status.Strategy != dnrf.Strategy {
if status.Strategy != dnrf.ActuationStrategy {
return true, fmt.Sprintf("%s skipped because %s is scheduled for %s: %q",
strings.ToLower(dnrf.Strategy.String()),
strings.ToLower(dnrf.ActuationStrategy.String()),
strings.ToLower(relationship.String()),
strings.ToLower(status.Strategy.String()),
id), nil
Expand All @@ -103,7 +105,7 @@ func (dnrf DependencyFilter) filterByRelationStatus(id object.ObjMetadata, relat
case actuation.ActuationPending:
// If actuation is still pending, dependency sorting is probably broken.
return false, "", fmt.Errorf("premature %s: %s %s actuation %s: %q",
strings.ToLower(dnrf.Strategy.String()),
strings.ToLower(dnrf.ActuationStrategy.String()),
strings.ToLower(relationship.String()),
strings.ToLower(status.Strategy.String()),
strings.ToLower(status.Actuation.String()),
Expand All @@ -112,7 +114,7 @@ func (dnrf DependencyFilter) filterByRelationStatus(id object.ObjMetadata, relat
// Skip!
return true, fmt.Sprintf("%s %s actuation %s: %q",
strings.ToLower(relationship.String()),
strings.ToLower(dnrf.Strategy.String()),
strings.ToLower(dnrf.ActuationStrategy.String()),
strings.ToLower(status.Actuation.String()),
id), nil
case actuation.ActuationSucceeded:
Expand All @@ -124,11 +126,17 @@ func (dnrf DependencyFilter) filterByRelationStatus(id object.ObjMetadata, relat
id)
}

// DryRun skips WaitTasks, so reconcile status can be ignored
if dnrf.DryRunStrategy.ClientOrServerDryRun() {
// Don't skip!
return false, "", nil
}

switch status.Reconcile {
case actuation.ReconcilePending:
// If reconcile is still pending, dependency sorting is probably broken.
return false, "", fmt.Errorf("premature %s: %s %s reconcile %s: %q",
strings.ToLower(dnrf.Strategy.String()),
strings.ToLower(dnrf.ActuationStrategy.String()),
strings.ToLower(relationship.String()),
strings.ToLower(status.Strategy.String()),
strings.ToLower(status.Reconcile.String()),
Expand All @@ -137,7 +145,7 @@ func (dnrf DependencyFilter) filterByRelationStatus(id object.ObjMetadata, relat
// Skip!
return true, fmt.Sprintf("%s %s reconcile %s: %q",
strings.ToLower(relationship.String()),
strings.ToLower(dnrf.Strategy.String()),
strings.ToLower(dnrf.ActuationStrategy.String()),
strings.ToLower(status.Reconcile.String()),
id), nil
case actuation.ReconcileSucceeded:
Expand Down
Loading

0 comments on commit 326b8a2

Please sign in to comment.