Skip to content

Commit

Permalink
Improve name for unspecified targets
Browse files Browse the repository at this point in the history
  • Loading branch information
iwahbe committed Oct 25, 2022
1 parent 224b3d6 commit 4a5f016
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
10 changes: 6 additions & 4 deletions pkg/resource/deploy/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ type UrnTargets struct {
//
// Each element is considered a glob if it contains any '*' and an URN otherwise. No other
// URN validation is performed.
//
// If len(urnOrGlobs) == 0, an unconstrained set will be created.
func NewUrnTargets(urnOrGlobs []string) UrnTargets {
literals, globs := []resource.URN{}, map[string]*regexp.Regexp{}
for _, urn := range urnOrGlobs {
Expand All @@ -114,8 +116,8 @@ func NewUrnTargetsFromUrns(urns []resource.URN) UrnTargets {
return UrnTargets{urns, nil}
}

// Return if the instance was explicitly created, or if it was default initialized.
func (t UrnTargets) IsInitialized() bool {
// Return if the target set constrains the set of acceptable URNs.
func (t UrnTargets) IsConstrained() bool {
return len(t.literals) > 0 || len(t.globs) > 0
}

Expand Down Expand Up @@ -145,7 +147,7 @@ func (t UrnTargets) getMatcher(glob string) *regexp.Regexp {
//
// If method receiver is not initialized, `true` is always returned.
func (t UrnTargets) Contains(urn resource.URN) bool {
if !t.IsInitialized() {
if !t.IsConstrained() {
return true
}
for _, literal := range t.literals {
Expand All @@ -171,7 +173,7 @@ func (t UrnTargets) Literals() []resource.URN {

// Adds a literal iff t is already initialized.
func (t *UrnTargets) addLiteral(urn resource.URN) {
if t.IsInitialized() {
if t.IsConstrained() {
t.literals = append(t.literals, urn)
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/resource/deploy/deployment_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type deploymentExecutor struct {
// are generated for any target that cannot be found. The target must either have existed in the stack
// prior to running the operation, or it must be the urn for a resource that was created.
func (ex *deploymentExecutor) checkTargets(targets UrnTargets, op display.StepOp) result.Result {
if !targets.IsInitialized() {
if !targets.IsConstrained() {
return nil
}

Expand Down Expand Up @@ -173,7 +173,7 @@ func (ex *deploymentExecutor) Execute(callerCtx context.Context, opts Options, p
return nil, res
}

if (updateTargetsOpt.IsInitialized() || replaceTargetsOpt.IsInitialized()) && destroyTargetsOpt.IsInitialized() {
if (updateTargetsOpt.IsConstrained() || replaceTargetsOpt.IsConstrained()) && destroyTargetsOpt.IsConstrained() {
contract.Failf("Should not be possible to have both .DestroyTargets and .UpdateTargets or .ReplaceTargets")
}

Expand Down Expand Up @@ -369,9 +369,9 @@ func (ex *deploymentExecutor) performDeletes(
// delete. However, if the user provided -target's we will only actually delete the specific
// resources that are in the set explicitly asked for.
var targetsOpt UrnTargets
if updateTargetsOpt.IsInitialized() {
if updateTargetsOpt.IsConstrained() {
targetsOpt = updateTargetsOpt
} else if destroyTargetsOpt.IsInitialized() {
} else if destroyTargetsOpt.IsConstrained() {
targetsOpt = destroyTargetsOpt
}

Expand Down Expand Up @@ -399,7 +399,7 @@ func (ex *deploymentExecutor) performDeletes(

// After executing targeted deletes, we may now have resources that depend on the resource that
// were deleted. Go through and clean things up accordingly for them.
if targetsOpt.IsInitialized() {
if targetsOpt.IsConstrained() {
resourceToStep := make(map[*resource.State]Step)
for _, step := range deleteSteps {
resourceToStep[ex.deployment.olds[step.URN()]] = step
Expand Down
6 changes: 3 additions & 3 deletions pkg/resource/deploy/step_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type stepGenerator struct {
}

func (sg *stepGenerator) isTargetedUpdate() bool {
return sg.updateTargetsOpt.IsInitialized() || sg.replaceTargetsOpt.IsInitialized()
return sg.updateTargetsOpt.IsConstrained() || sg.replaceTargetsOpt.IsConstrained()
}

// isTargetedForUpdate returns if `res` is targeted for update. The function accommodates
Expand Down Expand Up @@ -106,7 +106,7 @@ func (sg *stepGenerator) isTargetedForUpdate(res *resource.State) bool {
}

func (sg *stepGenerator) isTargetedReplace(urn resource.URN) bool {
return sg.replaceTargetsOpt.IsInitialized() && sg.replaceTargetsOpt.Contains(urn)
return sg.replaceTargetsOpt.IsConstrained() && sg.replaceTargetsOpt.Contains(urn)
}

func (sg *stepGenerator) Errored() bool {
Expand Down Expand Up @@ -1179,7 +1179,7 @@ func (sg *stepGenerator) getTargetDependents(targetsOpt UrnTargets) map[resource
func (sg *stepGenerator) determineAllowedResourcesToDeleteFromTargets(
targetsOpt UrnTargets) (map[resource.URN]bool, result.Result) {

if !targetsOpt.IsInitialized() {
if !targetsOpt.IsConstrained() {
// no specific targets, so we won't filter down anything
return nil, nil
}
Expand Down

0 comments on commit 4a5f016

Please sign in to comment.