From 9840d342a4b58e5915b5341bfeea09c8dda3f02d Mon Sep 17 00:00:00 2001 From: Jordan Singer Date: Tue, 21 Nov 2023 15:39:41 -0500 Subject: [PATCH] fix api gw dependencies --- pkg/engine2/operational_rule/operational_action.go | 5 +++-- pkg/engine2/operational_rule/operational_rule.go | 3 +++ pkg/engine2/operational_rule/operational_step.go | 2 +- pkg/engine2/operational_rule/resource_placer.go | 2 +- pkg/templates/aws/edges/api_deployment-rest_api.yaml | 2 ++ pkg/templates/aws/resources/api_integration.yaml | 2 ++ pkg/templates/aws/resources/api_method.yaml | 2 ++ 7 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/engine2/operational_rule/operational_action.go b/pkg/engine2/operational_rule/operational_action.go index 16b584743..05eb1cb2f 100644 --- a/pkg/engine2/operational_rule/operational_action.go +++ b/pkg/engine2/operational_rule/operational_action.go @@ -22,7 +22,7 @@ type ( ) func (action *operationalResourceAction) handleOperationalResourceAction(resource *construct.Resource) error { - if action.numNeeded <= 0 { + if action.numNeeded == 0 { return nil } @@ -34,7 +34,8 @@ func (action *operationalResourceAction) handleOperationalResourceAction(resourc return nil } - if action.numNeeded > 0 { + // we want the negative and positive case to trigger this so you can specify -1 as all available + if action.numNeeded != 0 { err := action.useAvailableResources(resource) if err != nil { return fmt.Errorf("error during operational resource action while using available resources: %w", err) diff --git a/pkg/engine2/operational_rule/operational_rule.go b/pkg/engine2/operational_rule/operational_rule.go index a8559b559..156956f52 100644 --- a/pkg/engine2/operational_rule/operational_rule.go +++ b/pkg/engine2/operational_rule/operational_rule.go @@ -22,6 +22,9 @@ type ( func (ctx OperationalRuleContext) HandleOperationalRule(rule knowledgebase.OperationalRule) error { + if ctx.Data.Edge != nil && ctx.Data.Edge.Source.String() == "aws:api_deployment:rest_api_0:api_deployment-0" { + fmt.Println("here") + } shouldRun, err := EvaluateIfCondition(rule, ctx.Solution, ctx.Data) if err != nil { return err diff --git a/pkg/engine2/operational_rule/operational_step.go b/pkg/engine2/operational_rule/operational_step.go index d2a0367c4..eee644410 100644 --- a/pkg/engine2/operational_rule/operational_step.go +++ b/pkg/engine2/operational_rule/operational_step.go @@ -51,7 +51,7 @@ func (ctx OperationalRuleContext) HandleOperationalStep(step knowledgebase.Opera } } - if len(ids) >= step.NumNeeded { + if len(ids) >= step.NumNeeded && step.NumNeeded > 0 { return nil } diff --git a/pkg/engine2/operational_rule/resource_placer.go b/pkg/engine2/operational_rule/resource_placer.go index 61189b850..b987e33a1 100644 --- a/pkg/engine2/operational_rule/resource_placer.go +++ b/pkg/engine2/operational_rule/resource_placer.go @@ -162,7 +162,7 @@ func (p ClosestPlacer) PlaceResources( return resourceDepths[availableResources[i].ID] < resourceDepths[availableResources[j].ID] }) num := *numNeeded - if num > len(availableResources) { + if num > len(availableResources) || num < 0 { num = len(availableResources) } for _, availableResource := range availableResources[:num] { diff --git a/pkg/templates/aws/edges/api_deployment-rest_api.yaml b/pkg/templates/aws/edges/api_deployment-rest_api.yaml index a1b9be95a..5a4cb3e88 100644 --- a/pkg/templates/aws/edges/api_deployment-rest_api.yaml +++ b/pkg/templates/aws/edges/api_deployment-rest_api.yaml @@ -7,9 +7,11 @@ operational_rules: direction: downstream resources: - '{{ allDownstream "aws:api_integration" .Target}}' + num_needed: -1 - if: '{{ hasDownstream "aws:api_method" .Target }}' steps: - resource: '{{ .Source }}' direction: downstream resources: - '{{ allDownstream "aws:api_method" .Target}}' + num_needed: -1 diff --git a/pkg/templates/aws/resources/api_integration.yaml b/pkg/templates/aws/resources/api_integration.yaml index 133b97a9d..7cee2f823 100644 --- a/pkg/templates/aws/resources/api_integration.yaml +++ b/pkg/templates/aws/resources/api_integration.yaml @@ -15,6 +15,8 @@ properties: Resource: type: resource(aws:api_resource) operational_rule: + if: | + {{ ne (fieldValue "Route" .Self) "/" }} steps: - direction: upstream resources: diff --git a/pkg/templates/aws/resources/api_method.yaml b/pkg/templates/aws/resources/api_method.yaml index 5af9fda16..1211cc456 100644 --- a/pkg/templates/aws/resources/api_method.yaml +++ b/pkg/templates/aws/resources/api_method.yaml @@ -15,6 +15,8 @@ properties: Resource: type: resource(aws:api_resource) operational_rule: + if: | + {{ ne (fieldValue "Route" (downstream "aws:api_integration" .Self)) "/" }} steps: - direction: upstream resources: