-
Notifications
You must be signed in to change notification settings - Fork 0
feat: relations #303
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
base: main
Are you sure you want to change the base?
feat: relations #303
Conversation
4928320
to
c4e3060
Compare
c4e3060
to
ed11c85
Compare
On-behalf-of: @SAP a.shcherbatiuk@sap.com Signed-off-by: Artem Shcherbatiuk <vertex451@gmail.com>
19ea7a5
to
ad375ed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments and suggestions.
gateway/resolver/relations.go
Outdated
key.Namespace = ref.namespace | ||
} | ||
|
||
if err := rr.service.runtimeClient.Get(ctx, key, obj); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please switch the logic and return something in case of an error and do a proper "happy path" return at the end of the function.
and maybe als return the error - why is there an error return value anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improved error handling
gateway/resolver/resolver.go
Outdated
log: log, | ||
groupNames: make(map[string]string), | ||
runtimeClient: runtimeClient, | ||
} | ||
|
||
// Initialize the relation resolver | ||
s.relationResolver = NewRelationResolver(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This circular dependency between the relation resolver and the service feels bad. Especially as the RelationResolver
is no external dependency that is passed to the New
function of the service. So it's not replaceable and has no further meaning besides adding unnecessary complexity and get an OOP feeling 😅.
I would add the functions it to the service itself and rename the CreateResolver
to RelationResolver
of the service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, no need to isolate it for now, moved methods under the service receiver.
gateway/schema/schema.go
Outdated
} | ||
|
||
// Initialize the relation enhancer after gateway is created | ||
g.relationEnhancer = NewRelationEnhancer(g) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same circular dependency as above. I don't really see a need to separate it in another struct. You don't have an possibility to add a different RelationEnhancer
so it makes no sense. I would move the methods to the Gateway
. You can however keep it in a separate file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are not going to believe - I seen those deps, but decided to go with them since it is in the same package.
But eventually you have the point - no need to move it under a different struct.
listener/pkg/apischema/builder.go
Outdated
for kindKey, infos := range b.kindRegistry { | ||
slices.SortFunc(infos, func(a, b ResourceInfo) int { | ||
if a.Group != b.Group { | ||
if a.Group < b.Group { | ||
return -1 | ||
} | ||
return 1 | ||
} | ||
if a.Version != b.Version { | ||
if a.Version < b.Version { | ||
return -1 | ||
} | ||
return 1 | ||
} | ||
if a.Kind != b.Kind { | ||
if a.Kind < b.Kind { | ||
return -1 | ||
} | ||
return 1 | ||
} | ||
if a.SchemaKey < b.SchemaKey { | ||
return -1 | ||
} | ||
if a.SchemaKey > b.SchemaKey { | ||
return 1 | ||
} | ||
return 0 | ||
}) | ||
b.kindRegistry[kindKey] = infos | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using strings.Compare
should be a better approach:
for kindKey, infos := range b.kindRegistry { | |
slices.SortFunc(infos, func(a, b ResourceInfo) int { | |
if a.Group != b.Group { | |
if a.Group < b.Group { | |
return -1 | |
} | |
return 1 | |
} | |
if a.Version != b.Version { | |
if a.Version < b.Version { | |
return -1 | |
} | |
return 1 | |
} | |
if a.Kind != b.Kind { | |
if a.Kind < b.Kind { | |
return -1 | |
} | |
return 1 | |
} | |
if a.SchemaKey < b.SchemaKey { | |
return -1 | |
} | |
if a.SchemaKey > b.SchemaKey { | |
return 1 | |
} | |
return 0 | |
}) | |
b.kindRegistry[kindKey] = infos | |
} | |
for kindKey, infos := range b.kindRegistry { | |
slices.SortFunc(infos, func(a, b ResourceInfo) int { | |
if cmp := strings.Compare(a.Group, b.Group); cmp != 0 { | |
return cmp | |
} | |
if cmp := strings.Compare(a.Version, b.Version); cmp != 0 { | |
return cmp | |
} | |
if cmp := strings.Compare(a.Kind, b.Kind); cmp != 0 { | |
return cmp | |
} | |
return strings.Compare(a.SchemaKey, b.SchemaKey) | |
}) | |
b.kindRegistry[kindKey] = infos | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much cleaner approach, thanks!
Resolves #254
Testing
Tested 15.08 at
44afd8b
commit in local-setupDemo