Skip to content
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

feat: print all resources #78

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

Conversation

mlavacca
Copy link
Member

@mlavacca mlavacca commented Oct 19, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

When reading the resources from a file, it is now possible to display all the resources, not only the Gateway API ones. Besides, the PROVIDER.md file has been properly formatted.

Which issue(s) this PR fixes:

Fixes #73

Does this PR introduce a user-facing change?:

By setting the flag `--all-resources`, it is now possible to print all the resources, not only the Gateway API ones. This flag is available only when reading the resources from a file.

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 19, 2023
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 19, 2023
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 20, 2023
@mlavacca mlavacca temporarily deployed to release October 20, 2023 10:46 — with GitHub Actions Inactive
@mlavacca mlavacca temporarily deployed to release October 20, 2023 10:49 — with GitHub Actions Inactive
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 20, 2023
@mlavacca mlavacca temporarily deployed to release October 20, 2023 13:46 — with GitHub Actions Inactive
@mlavacca mlavacca temporarily deployed to release October 20, 2023 13:49 — with GitHub Actions Inactive
@mlavacca mlavacca temporarily deployed to release October 20, 2023 14:28 — with GitHub Actions Inactive
@mlavacca mlavacca temporarily deployed to release October 20, 2023 14:30 — with GitHub Actions Inactive
@mlavacca mlavacca temporarily deployed to release October 20, 2023 14:31 — with GitHub Actions Inactive
@mlavacca mlavacca marked this pull request as ready for review October 20, 2023 14:35
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 20, 2023
@mlavacca mlavacca temporarily deployed to release October 20, 2023 15:14 — with GitHub Actions Inactive
Copy link
Member

@levikobi levikobi left a comment

Choose a reason for hiding this comment

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

Thank you @mlavacca!
I have some questions regarding a few things but overall it's seems like another great contribution to me.

PROVIDER.md Outdated Show resolved Hide resolved
PROVIDER.md Outdated Show resolved Hide resolved
cmd/print.go Outdated Show resolved Hide resolved
cmd/print.go Show resolved Hide resolved
cmd/print.go Outdated Show resolved Hide resolved
pkg/i2gw/provider.go Outdated Show resolved Hide resolved
pkg/i2gw/provider.go Outdated Show resolved Hide resolved
@mlavacca mlavacca temporarily deployed to release October 23, 2023 08:12 — with GitHub Actions Inactive
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 2, 2024
@mlavacca
Copy link
Member Author

mlavacca commented May 2, 2024

I've revamped this PR after a long time of inactivity. I drastically changed the initial approach after all the changes that have been merged. The PR is 95% complete, there is some documentation missing and some minor cleanup, but I'd like to have the idea validated before adding the last bits.

Please, folks, take another look :)

/cc @LiorLieberman @levikobi

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 3, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 6, 2024
cmd/print.go Show resolved Hide resolved
@@ -39,7 +38,7 @@ func (r *resourceReader) readResourcesFromCluster(ctx context.Context) (*storage
// read apisix related resources from cluster.
storage := newResourcesStorage()

ingresses, err := common.ReadIngressesFromCluster(ctx, r.conf.Client, ApisixIngressClass)
ingresses, err := i2gw.ReadIngressesFromCluster(ctx, r.conf.Client, ApisixIngressClass)
Copy link
Member

Choose a reason for hiding this comment

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

why ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I needed to move the resource-reader files to the i2gw package to avoid the import cycle as with this change we read resources not only from the provider packages but from i2gw as well, as we want to read resources that do not have to be converted.

Comment on lines +151 to +159
if _, ok := FilteredResources[o.GetObjectKind().GroupVersionKind().GroupKind()]; ok {
continue
Copy link
Member

Choose a reason for hiding this comment

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

Trying to think if there is a different way to do it. I less like the fact that every provider needs to register its resources and that we depends on it.. I have not thought on anything smart yet.
But.. we should have all the resources the provider cares about (which are the resources that we need to filter out from the file) in its storage.. Maybe we can leverage that?

Copy link
Member

Choose a reason for hiding this comment

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

I guess we can add a GetCRDs() method to the provider interface. We have access to all the providers in i2gw package, so we can do the registration in this package. Instead of having each one registering his own CRDs

Copy link
Member Author

Choose a reason for hiding this comment

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

I followed @levikobi's suggestion and added a GetCRDs method to the provider interface. Let me know if it looks better now. In that case, I'll add documentation about the new method for the providers to implement.

cmd/print.go Outdated Show resolved Hide resolved
cmd/print.go Show resolved Hide resolved
Comment on lines +151 to +159
if _, ok := FilteredResources[o.GetObjectKind().GroupVersionKind().GroupKind()]; ok {
continue
Copy link
Member

Choose a reason for hiding this comment

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

I guess we can add a GetCRDs() method to the provider interface. We have access to all the providers in i2gw package, so we can do the registration in this package. Instead of having each one registering his own CRDs

Copy link
Member

@levikobi levikobi left a comment

Choose a reason for hiding this comment

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

@mlavacca you moved some logic from common to i2gw, can you please explain why?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 30, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 5, 2024
@mlavacca
Copy link
Member Author

mlavacca commented Jun 5, 2024

@mlavacca you moved some logic from common to i2gw, can you please explain why?

I needed to move the resource-reader files to the i2gw package to avoid the import cycle as with this change we read resources not only from the provider packages but from i2gw as well, as we want to read resources that do not have to be converted.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 8, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 13, 2024
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 13, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Member

@LiorLieberman LiorLieberman left a comment

Choose a reason for hiding this comment

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

Thanks @mlavacca, left some comments.
the move of logic from common to i2gw a bit bothers me because the function moved are actually common functions. Maybe we can come up with different package structure that will still accommodate the changes you introduced?

@@ -30,7 +32,7 @@ import (
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)

func ToGatewayAPIResources(ctx context.Context, namespace string, inputFile string, providers []string, providerSpecificFlags map[string]map[string]string) ([]GatewayResources, error) {
func GetResources(ctx context.Context, namespace string, inputFile string, allresources bool, providers []string, providerSpecificFlags map[string]map[string]string) ([]client.Object, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we leave some version of the old name (ToGatewayAPIResources) and return []client.Object, []client.Object, error ? GetResources does not really reflect what the function is doing

Copy link
Member

Choose a reason for hiding this comment

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

or []GatewayResources, []client.Object, error

return append(gatewayResourcesToObjects(gatewayResources), genericResources...), nil
}

func gatewayResourcesToObjects(gatewayResources []GatewayResources) []client.Object {
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a small function comment, also mention the order it returns the resources

Comment on lines +148 to +152
for _, p := range providerByName {
for _, crd := range p.GetCRDs() {
FilteredResources[crd] = struct{}{}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

haven't thought much about it, but what are your thoughts on this approach VS every provider registers the resources he cares about in init().

I am not sure what I prefer, slight preference to what you currently have but wanted to discuss this

Comment on lines +78 to +80
func (p *Provider) GetCRDs() []schema.GroupKind {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

similar comment below on how we handle, provider == kong but ingress is gce. The implemented approach here would not print the gce ingress (although it hasn't been converted)

Comment on lines +31 to +33
ingressClassGK: {},
ingressGK: {},
}
Copy link
Member

Choose a reason for hiding this comment

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

re mentioning the comment about not differentiating between ingress of different providers when running with --all-resources

networkingv1beta1 "k8s.io/api/networking/v1beta1"
)

func GetIngressClass(ingress networkingv1.Ingress) string {
Copy link
Member

Choose a reason for hiding this comment

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

we already have similar function in common, why not using it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

print all resources when reading from files
5 participants