-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(crd-generator): add CRD-Generator CLI (6337)
feat(crd-generator): Add CRD-Generator CLI --- Fix code smells --- Add changelog --- Fix SourceArgumentConverterTest for windows and use only canonical files to compare --- Reduce dependencies in crd-generator-collector --- Downgrade logback to 1.3.44 --- Fix code smell and avoid cycle in exception use --- Fix license headers --- Refactor CRDGeneratorCLI to use log4j --- Fix code smell --- Make debug text platform independent and flush error output stream in exception handler
- Loading branch information
Showing
24 changed files
with
1,368 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# CRD-Generator CLI | ||
|
||
Generate Custom Resource Definitions (CRD) for Kubernetes from Java classes. | ||
|
||
## Install | ||
|
||
The CRD-Generator CLI is available for download on Sonatype at the link: | ||
|
||
``` | ||
https://oss.sonatype.org/content/repositories/releases/io/fabric8/crd-generator-cli/<version>/crd-generator-cli-<version>.sh | ||
``` | ||
|
||
Download the latest version with the following commands: | ||
|
||
```bash | ||
export VERSION=$(wget -q -O - https://github.com/fabric8io/kubernetes-client/releases/latest --header "Accept: application/json" | jq -r '.tag_name' | cut -c 2-) | ||
wget -O crd-gen https://oss.sonatype.org/content/repositories/releases/io/fabric8/crd-generator-cli/$VERSION/crd-generator-cli-$VERSION.sh | ||
chmod a+x crd-gen | ||
./crd-gen --version | ||
``` | ||
|
||
Alternatively, if you already have [jbang](https://www.jbang.dev/) installed, you can run the CLI by using the following command: | ||
|
||
```bash | ||
jbang io.fabric8:crd-generator-cli:<version> | ||
``` | ||
|
||
## 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:** | ||
|
||
```bash | ||
crd-gen target/classes/ | ||
``` | ||
|
||
**Generate CRDs for Custom Resource classes in a JAR file:** | ||
|
||
```bash | ||
crd-gen my-jar-with-custom-resources.jar | ||
``` | ||
|
||
**Generate CRD by using a single class only:** | ||
|
||
```bash | ||
crd-gen -cp target/classes/ com.example.MyCustomResource | ||
``` | ||
|
||
**Generate CRD(s) by using multiple classes:** | ||
|
||
```bash | ||
crd-gen -cp target/classes/ com.example.v1.MyCustomResource com.example.v2.MyCustomResource | ||
``` |
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,144 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (C) 2015 Red Hat, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>crd-generator-parent</artifactId> | ||
<groupId>io.fabric8</groupId> | ||
<version>7.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>crd-generator-cli</artifactId> | ||
<name>Fabric8 :: CRD generator :: CLI</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>crd-generator-api-v2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>crd-generator-collector</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>info.picocli</groupId> | ||
<artifactId>picocli</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-slf4j2-impl</artifactId> | ||
<!-- required because parent pom declares default scope to test --> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core</artifactId> | ||
<!-- required because parent pom declares default scope to test --> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>info.picocli</groupId> | ||
<artifactId>picocli-codegen</artifactId> | ||
<version>${picocli.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
<compilerArgs> | ||
<arg>-Aproject=${project.groupId}/${project.artifactId}</arg> | ||
</compilerArgs> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>io.fabric8.crd.generator.cli.CRDGeneratorCLI</mainClass> | ||
</transformer> | ||
</transformers> | ||
<createDependencyReducedPom>false</createDependencyReducedPom> | ||
<filters> | ||
<filter> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>META-INF/*.SF</exclude> | ||
<exclude>META-INF/*.DSA</exclude> | ||
<exclude>META-INF/*.RSA</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<!-- now make the jar chmod +x style executable --> | ||
<plugin> | ||
<groupId>org.skife.maven</groupId> | ||
<artifactId>really-executable-jar-maven-plugin</artifactId> | ||
<configuration> | ||
<flags>-Xmx1G</flags> | ||
<programFile>crd-gen</programFile> | ||
<attachProgramFile>true</attachProgramFile> | ||
</configuration> | ||
|
||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>really-executable-jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Oops, something went wrong.