Skip to content

Commit d627846

Browse files
authored
Merge pull request #1383 from flanksource/fix-config-lookup
fix: config lookup for properties with test
2 parents b7b7a6f + f1a549f commit d627846

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

fixtures/topology/component-with-properties.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,15 @@ spec:
9696
name: value_lookup
9797
display:
9898
expr: '"value"'
99+
# Test property with config lookup
100+
- name: config-key
101+
configLookup:
102+
config:
103+
name: config-item
104+
tags:
105+
tag-1: a
106+
tag-2: b
107+
type: Config::Dummy
108+
display:
109+
javascript: |
110+
config.spec.container.version

pkg/topology/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func lookupConfig(ctx *ComponentContext, property *v1.Property) (*pkg.Property,
264264
}
265265

266266
templateEnv := map[string]any{
267-
"config": _config.Spec,
267+
"config": *_config.Spec,
268268
"tags": toMapStringAny(_config.Tags),
269269
}
270270
prop.Text, err = gomplate.RunTemplate(templateEnv, property.ConfigLookup.Display.Template.Gomplate())

pkg/topology/run_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import (
44
"os"
55

66
v1 "github.com/flanksource/canary-checker/api/v1"
7+
"github.com/flanksource/canary-checker/pkg/db"
8+
"github.com/flanksource/canary-checker/pkg/utils"
9+
"github.com/flanksource/duty/models"
10+
"github.com/flanksource/duty/types"
711
ginkgo "github.com/onsi/ginkgo/v2"
812
. "github.com/onsi/gomega"
913
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -42,16 +46,30 @@ var _ = ginkgo.Describe("Test topology run", ginkgo.Ordered, func() {
4246
ginkgo.Fail("Error converting yaml to v1.Topology:" + err.Error())
4347
}
4448

49+
ci := models.ConfigItem{
50+
Name: utils.Ptr("config-item"),
51+
Tags: &types.JSONStringMap{
52+
"tag-1": "a",
53+
"tag-2": "b",
54+
},
55+
Config: utils.Ptr(`{"spec": {"container": {"name": "hello", "version": "v3"}}}`),
56+
Type: utils.Ptr("Config::Dummy"),
57+
ConfigClass: "Dummy",
58+
}
59+
60+
err = db.Gorm.Create(&ci).Error
61+
Expect(err).To(BeNil())
62+
4563
rootComponent := Run(opts, t)
4664
Expect(len(rootComponent[0].Components)).To(Equal(3))
4765

4866
componentA := rootComponent[0].Components[0]
4967
componentB := rootComponent[0].Components[1]
5068
componentC := rootComponent[0].Components[2]
5169

52-
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"}]`))
53-
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"}]`))
54-
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"}]`))
70+
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"},{"name":"config-key","text":"v3"}]`))
71+
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"},{"name":"config-key","text":"v3"}]`))
72+
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"},{"name":"config-key","text":"v3"}]`))
5573
})
5674

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

0 commit comments

Comments
 (0)