Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recompute non configurable defaults #778

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pkg/engine2/operational_eval/vertex_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,17 @@ func (v *propertyVertex) evaluateConstraints(sol solution_context.SolutionContex
return fmt.Errorf("could not get current value for %s: %w", v.Ref, err)
}

if currentValue == nil && setConstraint.Operator == "" && v.Template != nil && v.Template.DefaultValue != nil {
recompute := false
if v.Template != nil && v.Template.ConfigurationDisabled && v.Template.DefaultValue != nil && len(v.EdgeRules) == 0 {
// If the property is configured via edge rules, we don't want to recompute it
// as it will be set by the edge rules
recompute = true
}
setDefault := false
if currentValue == nil && v.Template != nil && v.Template.DefaultValue != nil {
setDefault = true
}
if setConstraint.Operator == "" && (setDefault || recompute) {
err = solution_context.ConfigureResource(
sol,
res,
Expand Down
12 changes: 6 additions & 6 deletions pkg/graph_addons/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ func walk[K comparable, T any](
f WalkGraphFunc[K],
deps map[K]map[K]graph.Edge[K],
) error {
visited := make(set.Set[K])
queued := make(set.Set[K])
var queue []K

queued.Add(start)
for d := range deps[start] {
queue = append(queue, d)
queued.Add(d)
}
visited.Add(start)

var err error
var current K
for len(queue) > 0 {
current, queue = queue[0], queue[1:]
visited.Add(current)

nerr := f(current, err)
if errors.Is(nerr, StopWalk) {
Expand All @@ -62,10 +62,10 @@ func walk[K comparable, T any](
err = nerr

for d := range deps[current] {
if visited.Contains(d) {
continue
if !queued.Contains(d) {
queue = append(queue, d)
queued.Add(d)
}
queue = append(queue, d)
}
}
return err
Expand Down
32 changes: 18 additions & 14 deletions pkg/knowledge_base2/property_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@ func (list *ListPropertyType) Parse(value any, ctx DynamicContext, data DynamicV
if !ok {
// before we fail, check to see if the entire value is a template
if strVal, ok := value.(string); ok {
var result []any
err := ctx.ExecuteDecode(strVal, data, &result)
return result, err
err := ctx.ExecuteDecode(strVal, data, &val)
if err != nil {
return nil, fmt.Errorf("invalid list value %v", value)
}
}
return nil, fmt.Errorf("invalid list value %v", value)
}

for _, v := range val {
Expand Down Expand Up @@ -331,11 +331,12 @@ func (s *SetPropertyType) Parse(value any, ctx DynamicContext, data DynamicValue
if !ok {
// before we fail, check to see if the entire value is a template
if strVal, ok := value.(string); ok {
var result []any
err := ctx.ExecuteDecode(strVal, data, &result)
return result, err
err := ctx.ExecuteDecode(strVal, data, &val)
if err != nil {
return nil, fmt.Errorf("invalid list value %v", value)
}
}
return nil, fmt.Errorf("invalid list value %v", value)

}

for _, v := range val {
Expand Down Expand Up @@ -370,12 +371,15 @@ func (m *MapPropertyType) Parse(value any, ctx DynamicContext, data DynamicValue
if !ok {
// before we fail, check to see if the entire value is a template
if strVal, ok := value.(string); ok {
err := ctx.ExecuteDecode(strVal, data, &result)
return result, err
}
mapVal, ok = value.(construct.Properties)
if !ok {
return nil, fmt.Errorf("invalid map value %v", value)
err := ctx.ExecuteDecode(strVal, data, &mapVal)
if err != nil {
return result, fmt.Errorf("invalid map value %v, decoding string err: %s", value, err)
}
} else {
mapVal, ok = value.(construct.Properties)
if !ok {
return nil, fmt.Errorf("invalid map value %v", value)
}
}
}
// If we are an object with sub properties then we know that we need to get the type of our sub properties to determine how we are parsed into a value
Expand Down
9 changes: 1 addition & 8 deletions pkg/templates/aws/edges/api_deployment-api_integration.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
source: aws:api_deployment
target: aws:api_integration
operational_rules:
- configuration_rules:
- resource: '{{ .Source }}'
configuration:
field: Triggers
value: |
{"{{ .Target.Name }}": "{{ .Target.Name }}"}
target: aws:api_integration
9 changes: 1 addition & 8 deletions pkg/templates/aws/edges/api_deployment-api_method.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
source: aws:api_deployment
target: aws:api_method
operational_rules:
- configuration_rules:
- resource: '{{ .Source }}'
configuration:
field: Triggers
value: |
{"{{ .Target.Name }}": "{{ .Target.Name }}"}
target: aws:api_method
13 changes: 13 additions & 0 deletions pkg/templates/aws/resources/api_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ properties:
- aws:rest_api
Triggers:
type: map(string,string)
configuration_disabled: true
default_value: |
{{ $api := fieldValue "RestApi" .Self }}
{{ $integrations := allDownstream "aws:api_integration" $api}}
{{ $methods := allDownstream "aws:api_method" $api }}
{
{{- range $index, $integration := $integrations }}
"integ/{{ $integration.Name }}": "{{ $integration.Name }}"{{ if or (ne $index (sub (len $integrations) 1)) (ne (len $methods) 0) }},{{ end}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wish there was a better way to do trailing comma...

{{- end }}
{{- range $index, $method := $methods }}
"method/{{ $method.Name }}": "{{ $method.Name }}"{{ if ne $index (sub (len $integrations) 1) }},{{ end}}
{{- end }}
}

classification:

Expand Down
2 changes: 2 additions & 0 deletions pkg/templates/aws/resources/api_integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ properties:
Resource:
type: resource(aws:api_resource)
operational_rule:
if: |
{{ ne (fieldValue "Route" .Self) "/" }}
steps:
- direction: upstream
resources:
Expand Down
2 changes: 2 additions & 0 deletions pkg/templates/aws/resources/api_method.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading