Skip to content

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

feat: relations #303

wants to merge 7 commits into from

Conversation

vertex451
Copy link
Member

@vertex451 vertex451 commented Aug 7, 2025

Resolves #254

Testing

Tested 15.08 at 44afd8b commit in local-setup

Demo

Screenshot 2025-08-07 at 16 52 27 and CRD: Screenshot 2025-08-08 at 16 47 08

@github-actions github-actions bot removed the feature label Aug 14, 2025
@vertex451 vertex451 marked this pull request as ready for review August 14, 2025 12:03
@vertex451 vertex451 requested a review from a team as a code owner August 14, 2025 12:03
On-behalf-of: @SAP a.shcherbatiuk@sap.com
Signed-off-by: Artem Shcherbatiuk <vertex451@gmail.com>
On-behalf-of: @SAP a.shcherbatiuk@sap.com
Signed-off-by: Artem Shcherbatiuk <vertex451@gmail.com>
On-behalf-of: @SAP a.shcherbatiuk@sap.com
Signed-off-by: Artem Shcherbatiuk <vertex451@gmail.com>
On-behalf-of: @SAP a.shcherbatiuk@sap.com
Signed-off-by: Artem Shcherbatiuk <vertex451@gmail.com>
@vertex451 vertex451 self-assigned this Aug 15, 2025
@vertex451 vertex451 added this to the 2025.Q3 milestone Aug 15, 2025
Copy link

@pteich pteich left a 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.

key.Namespace = ref.namespace
}

if err := rr.service.runtimeClient.Get(ctx, key, obj); err == nil {
Copy link

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improved error handling

log: log,
groupNames: make(map[string]string),
runtimeClient: runtimeClient,
}

// Initialize the relation resolver
s.relationResolver = NewRelationResolver(s)
Copy link

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.

Copy link
Member Author

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.

}

// Initialize the relation enhancer after gateway is created
g.relationEnhancer = NewRelationEnhancer(g)
Copy link

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.

Copy link
Member Author

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.

Comment on lines 262 to 291
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
}
Copy link

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:

Suggested change
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
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much cleaner approach, thanks!

On-behalf-of: @SAP a.shcherbatiuk@sap.com
Signed-off-by: Artem Shcherbatiuk <vertex451@gmail.com>
On-behalf-of: @SAP a.shcherbatiuk@sap.com
Signed-off-by: Artem Shcherbatiuk <vertex451@gmail.com>
On-behalf-of: @SAP a.shcherbatiuk@sap.com
Signed-off-by: Artem Shcherbatiuk <vertex451@gmail.com>
@vertex451 vertex451 requested a review from pteich August 15, 2025 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Resource relations in schema generation
2 participants