Skip to content
Merged
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
5 changes: 4 additions & 1 deletion runtime/parser/parse_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ func parseMCPConnector(tmp *ConnectorYAML) ([]*runtimev1.SecurityRule, []string,
return rules, sec.Agents, nil
}

// analyzeTemplatedProperties returns a slice of map keys that have a value which contains templating tags.
// analyzeTemplatedProperties returns a sorted slice of map keys that have a value which contains templating tags.
// The keys are sorted because map iteration order is random,
// and the project parser treats a spec as changed (and re-reconciles everything downstream) if the order differs between parses.
func analyzeTemplatedProperties(m map[string]any) ([]string, error) {
var res []string
for k, v := range m {
Expand All @@ -205,6 +207,7 @@ func analyzeTemplatedProperties(m map[string]any) ([]string, error) {
res = append(res, k)
}
}
slices.Sort(res)
return res, nil
}

Expand Down
26 changes: 26 additions & 0 deletions runtime/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,32 @@ driver: duckdb
require.NotContains(t, m1Updated.Refs, ResourceName{Kind: ResourceKindConnector, Name: "duckdb"}, "model should not ref deleted connector")
}

func TestConnectorTemplatedPropertiesOrder(t *testing.T) {
// The project parser compares specs with proto.Equal to detect changes,
// so re-parsing an unchanged connector must return its templated properties in the same order.
ctx := context.Background()
repo := makeRepo(t, map[string]string{
`rill.yaml`: ``,
`connectors/clickhouse.yaml`: `
type: connector
driver: clickhouse
mode: readwrite
dsn: "{{ .env.dsn }}"
write_dsn: "{{ .env.write_dsn }}"
password: "{{ .env.password }}"
`,
})

// Parse several times since an unstable order only shows up on some runs
for range 20 {
p, err := Parse(ctx, repo, "", "", "duckdb", true)
require.NoError(t, err)
r := p.Resources[ResourceName{Kind: ResourceKindConnector, Name: "clickhouse"}]
require.NotNil(t, r)
require.Equal(t, []string{"dsn", "password", "write_dsn"}, r.ConnectorSpec.TemplatedProperties)
}
}

func BenchmarkReparse(b *testing.B) {
ctx := context.Background()
files := map[string]string{
Expand Down
Loading