-
Notifications
You must be signed in to change notification settings - Fork 90
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
Add a transformer to remove API group imports for cross-resource references #331
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
08422ad
Add the transformer "resolver" to remove API group imports for cross-…
ulucinar eb38f3f
Do not transform already transformed files
ulucinar 2b1d5df
Set the default value of the transformer command-line option --patter…
ulucinar 3674eb5
Use a hard-coded AST while generating the reference source statements…
ulucinar bc7c179
Add new imports to the resolver files in stable order
ulucinar 1493017
Move main.TransformPackages to transformers.Resolver.TransformPackages
ulucinar 994c07a
Add failure tests for the resolver transformer
ulucinar bbac0a6
Add the --api-group-override command-line option to the resolver tran…
ulucinar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-FileCopyrightText: 2024 The Crossplane Authors <https://crossplane.io> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/crossplane/crossplane-runtime/pkg/logging" | ||
"github.com/spf13/afero" | ||
"gopkg.in/alecthomas/kingpin.v2" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
|
||
"github.com/crossplane/upjet/pkg/transformers" | ||
) | ||
|
||
func main() { | ||
var ( | ||
app = kingpin.New(filepath.Base(os.Args[0]), "Transformer for the generated resolvers by the crossplane-tools so that cross API-group imports are removed.").DefaultEnvars() | ||
apiGroupSuffix = app.Flag("apiGroupSuffix", "Resource API group suffix, such as aws.upbound.io. The resource API group names are suffixed with this to get the canonical API group name.").Short('g').Required().String() | ||
apiGroupOverride = app.Flag("apiGroupOverride", "API group overrides").Short('o').StringMap() | ||
apiResolverPackage = app.Flag("apiResolverPackage", "The package that contains the implementation for the GetManagedResource function, such as github.com/upbound/provider-aws/internal/apis.").Short('a').Required().String() | ||
pattern = app.Flag("pattern", "List patterns for the packages to process, such as ./...").Short('p').Default("./...").Strings() | ||
resolverFilePattern = app.Flag("resolver", "Name of the generated resolver files to process.").Short('r').Default("zz_generated.resolvers.go").String() | ||
ignorePackageLoadErrors = app.Flag("ignoreLoadErrors", "Ignore errors encountered while loading the packages.").Short('s').Bool() | ||
) | ||
kingpin.MustParse(app.Parse(os.Args[1:])) | ||
logger := logging.NewLogrLogger(zap.New().WithName("transformer-resolver")) | ||
r := transformers.NewResolver(afero.NewOsFs(), *apiGroupSuffix, *apiResolverPackage, *ignorePackageLoadErrors, logger, transformers.WithAPIGroupOverrides(*apiGroupOverride)) | ||
kingpin.FatalIfError(r.TransformPackages(*resolverFilePattern, *pattern...), "Failed to transform the resolver files in the specified packages.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What about making the default of this option to
true
?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 feel like the default should be the more strict mode of operation (failing on package loading errors). Though I think I see your point: The purpose of this transformer is to prevent/get rid of circular imports, and any provider benefiting from this transformer should have an import cycle caused by the cross-API group references, so in order to run this transformer, they will need to supply the
-s
option. But still, I'd like the decision to ignore any package loading errors to be on the side of the Crossplane provider repo maintainer who's using this transformer as part of their code generation pipelines. So keeping the default mode strict forces the repo maintainer to show explicit consent while incorporating the transformer.The package loading issues we expect are the import cycle errors caused by cross-resource references but what if the API folder has some unexpected (by the transformer) compile errors? I believe it's better to give the responsibility of suppressing package loading errors to the repo maintainer, although from a practical perspective, I agree setting the default of this option to
true
will not make much difference, if this is the reasoning behind the proposal.