Skip to content

Commit

Permalink
Merge pull request #1377 from flanksource/fix-prop-value-lookup
Browse files Browse the repository at this point in the history
fix: handle direct values in topology property lookups
  • Loading branch information
moshloop authored Oct 25, 2023
2 parents eadcdd5 + 7500c1b commit b9fa9dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions fixtures/topology/component-with-properties.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,11 @@ spec:
{'name': 'company', 'text': 'Acme'},
{'name': 'location', 'text': 'Mars'},
].toJSON()
# Test property as direct value
- name: key
lookup:
http:
- endpoint: https://httpbin.demo.aws.flanksource.com/status/200
name: value_lookup
display:
expr: '"value"'
7 changes: 7 additions & 0 deletions pkg/topology/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,13 @@ func lookupProperty(ctx *ComponentContext, property *v1.Property) ([]byte, error
return nil, fmt.Errorf("unknown property type %T", results)
}
data := []byte(dataStr)
// When the lookup returns just a value
// set the current property's text as that value
if !isComponentList(data) && !isPropertyList(data) {
prop := pkg.NewProperty(*property)
prop.Text = dataStr
return json.Marshal(pkg.Properties{prop})
}
return data, nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/topology/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ var _ = ginkgo.Describe("Test topology run", ginkgo.Ordered, func() {
componentB := rootComponent[0].Components[1]
componentC := rootComponent[0].Components[2]

Expect(string(componentA.Properties.AsJSON())).To(MatchJSON(`[{"name":"error_percentage","value":1,"min":0,"max":100},{"name":"owner","text":"team-a"},{"name":"company","text":"Acme"},{"name":"location","text":"Mars"}]`))
Expect(string(componentB.Properties.AsJSON())).To(MatchJSON(`[{"name":"error_percentage","value":10,"min":0,"max":100},{"name":"owner","text":"team-b"},{"name":"company","text":"Acme"},{"name":"location","text":"Mars"}]`))
Expect(string(componentC.Properties.AsJSON())).To(MatchJSON(`[{"name":"error_percentage","value":50,"min":0,"max":100},{"name":"owner","text":"team-b"},{"name":"company","text":"Acme"},{"name":"location","text":"Mars"}]`))
Expect(string(componentA.Properties.AsJSON())).To(MatchJSON(`[{"name":"error_percentage","value":1,"min":0,"max":100},{"name":"owner","text":"team-a"},{"name":"company","text":"Acme"},{"name":"location","text":"Mars"},{"name":"key","text":"value"}]`))
Expect(string(componentB.Properties.AsJSON())).To(MatchJSON(`[{"name":"error_percentage","value":10,"min":0,"max":100},{"name":"owner","text":"team-b"},{"name":"company","text":"Acme"},{"name":"location","text":"Mars"},{"name":"key","text":"value"}]`))
Expect(string(componentC.Properties.AsJSON())).To(MatchJSON(`[{"name":"error_percentage","value":50,"min":0,"max":100},{"name":"owner","text":"team-b"},{"name":"company","text":"Acme"},{"name":"location","text":"Mars"},{"name":"key","text":"value"}]`))
})

ginkgo.It("should create component with forEach functionality", func() {
Expand Down

0 comments on commit b9fa9dd

Please sign in to comment.