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(crd-generator): Add CRD-Generator CLI #6337

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

Conversation

baloo42
Copy link
Contributor

@baloo42 baloo42 commented Sep 7, 2024

Description

Fixes #5958
Relates to #5950

Add CRD-Generator CLI application (using api-v2).

Usage:

crd-gen [-hVv] [--force-index] [--force-scan] [--implicit-preserve-unknown-fields] [--no-parallel]
        [-o=<outputDirectory>] [-cp=<classpathElement>]... [--exclude-package=<package>]...
        [--include-package=<package>]... <source>...

Description:

Fabric8 CRD-Generator
Generate Custom Resource Definitions (CRD) for Kubernetes from Java classes.

Parameters:
      <source>...     A directory or JAR file to scan for Custom Resource classes, or a full qualified Custom Resource
                        class name.

Options:
  -o, --output-dir=<outputDirectory>
                      The output directory where the CRDs are emitted.
                        Default: .
      -cp, --classpath=<classpathElement>
                      Additional classpath element, e.g. a dependency packaged as JAR file or a directory of class
                        files.
      --force-index   Create Jandex index even if the directory or JAR file contains an existing index.
      --force-scan    Scan directories and JAR files even if Custom Resource classes are given.
      --no-parallel   Disable parallel generation of CRDs.
      --implicit-preserve-unknown-fields
                      `x-kubernetes-preserve-unknown-fields: true` will be added on objects which contain an any-setter
                        or any-getter.
      --include-package=<package>
                      Filter Custom Resource classes after scanning by package inclusions.
      --exclude-package=<package>
                      Filter Custom Resource classes after scanning by package exclusions.
  -v                  Verbose mode. Helpful for troubleshooting.
                      Multiple -v options increase the verbosity.
  -h, --help          Show this help message and exit.
  -V, --version       Print version information and exit.

Exit Codes:
   0   Successful execution
   1   Unexpected error
   2   Invalid input
  70   Custom Resource class loading failed
  80   No Custom Resource classes retained after filtering

Examples:
  Generate CRDs for Custom Resource classes in a directory:
    crd-gen target/classes/
  Generate CRDs for Custom Resource classes in a JAR file:
    crd-gen my-jar-with-custom-resources.jar
  Generate CRD by using a single class only:
    crd-gen -cp target/classes/ com.example.MyCustomResource

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report

Copy link
Member

@manusa manusa left a comment

Choose a reason for hiding this comment

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

This seems fine to me,
@metacosm @andreaTP, @shawkins any additional comments?

Copy link
Contributor Author

@baloo42 baloo42 left a comment

Choose a reason for hiding this comment

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

@manusa Thanks for looking into this.

I added some comments where I'm not sure if it's done right.

pom.xml Outdated Show resolved Hide resolved
crd-generator/cli/pom.xml Show resolved Hide resolved
@baloo42 baloo42 force-pushed the iss_5958 branch 3 times, most recently from 8af230d to feeb169 Compare October 6, 2024 14:56
class CRDGeneratorExecutionExceptionHandler implements CommandLine.IExecutionExceptionHandler {

private static final Logger log = LoggerFactory.getLogger(CRDGeneratorExecutionExceptionHandler.class);

private final CRDGeneratorCLI crdGeneratorCLI;
private final Supplier<String> diagTextSupplier;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick: maybe record the result of calling the supplier instead of calling the supplier repeatedly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The diag text is not yet available when the constructor of CRDGeneratorExecutionExceptionHandler is called. So I have to fetch it somehow later if an error occurs from the CLI class. To prevent a circular reference it's a supplier, so technically cheating 😏. But anyways I think it will be called at most only once: each if statement has a return statement.

Copy link

sonarcloud bot commented Oct 24, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CRD-Generator v2: CLI Application
4 participants