Skip to content

Commit

Permalink
add more safe guards for merging resources
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Feb 16, 2024
1 parent 3a5372f commit 9fef3bd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
4 changes: 3 additions & 1 deletion providers-sdk/v1/resources/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ func (s *Schema) Add(other ResourcesSchema) ResourcesSchema {
existing.Fields = map[string]*Field{}
}
for fk, fv := range v.Fields {
if fExisting, ok := existing.Fields[fk]; ok {
// If the field exists in the current resource, but is from a different provider,
// we store it as an "other"
if fExisting, ok := existing.Fields[fk]; ok && fv.Provider != fExisting.Provider {
fExisting.Others = append(fExisting.Others, fv)
} else {
existing.Fields[fk] = fv
Expand Down
6 changes: 0 additions & 6 deletions providers/extensible_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,4 @@ func TestExtensibleSchema(t *testing.T) {
_, finfo = s.LookupField("eternity", "v")
require.NotNil(t, info)
assert.Equal(t, "first", finfo.Provider)

// s.prioritizeIDs("first")

_, finfo = s.LookupField("eternity", "iii")
require.NotNil(t, info)
assert.Equal(t, "first", finfo.Provider)
}
21 changes: 17 additions & 4 deletions providers/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,23 @@ func (r *Runtime) lookupFieldProvider(resource string, field string) (*Connected
}

// Make sure we grab the field that matches the provider of this runtime (if possible).
for _, f := range fieldInfo.Others {
if f.Provider == r.Provider.Instance.ID {
fieldInfo = f
break
if fieldInfo.Provider != r.Provider.Instance.ID {
for _, rI := range resourceInfo.Others {
// Check if the same field exists in another provider's resource
for _, f := range rI.Fields {
if f.Provider == r.Provider.Instance.ID {
fieldInfo = f
break
}

// Check if the same field is extended by another provider
for _, otherF := range f.Others {
if otherF.Provider == r.Provider.Instance.ID {
fieldInfo = f
break
}
}
}
}
}

Expand Down

0 comments on commit 9fef3bd

Please sign in to comment.