generated from quarkiverse/quarkiverse-template
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make it possible to revert to using the v1 CRD generator
Note that this should only be used if a blocking issue is found with the v2 generator because the v1 version won't be supported moving forward. Signed-off-by: Chris Laprun <claprun@redhat.com>
- Loading branch information
Showing
6 changed files
with
130 additions
and
20 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
14 changes: 14 additions & 0 deletions
14
core/deployment/src/main/java/io/quarkiverse/operatorsdk/deployment/CRDGenerator.java
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,14 @@ | ||
package io.quarkiverse.operatorsdk.deployment; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import io.fabric8.kubernetes.client.CustomResource; | ||
import io.quarkiverse.operatorsdk.runtime.CRDInfos; | ||
|
||
interface CRDGenerator { | ||
void generate(List<String> crdSpecVersions, File outputDir, Set<String> generated, CRDInfos converted); | ||
|
||
void scheduleForGeneration(Class<? extends CustomResource<?, ?>> crClass); | ||
} |
46 changes: 46 additions & 0 deletions
46
core/deployment/src/main/java/io/quarkiverse/operatorsdk/deployment/CRDGeneratorV1.java
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,46 @@ | ||
package io.quarkiverse.operatorsdk.deployment; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.fabric8.crd.generator.CustomResourceInfo; | ||
import io.fabric8.kubernetes.client.CustomResource; | ||
import io.quarkiverse.operatorsdk.runtime.CRDInfo; | ||
import io.quarkiverse.operatorsdk.runtime.CRDInfos; | ||
|
||
class CRDGeneratorV1 implements CRDGenerator { | ||
private static final Logger log = Logger.getLogger(CRDGeneratorV1.class.getName()); | ||
private final io.fabric8.crd.generator.CRDGenerator generator; | ||
|
||
public CRDGeneratorV1(boolean parallelGeneration) { | ||
this.generator = new io.fabric8.crd.generator.CRDGenerator().withParallelGenerationEnabled(parallelGeneration); | ||
} | ||
|
||
@Override | ||
public void generate(List<String> crdSpecVersions, File outputDir, Set<String> generated, CRDInfos converted) { | ||
final var info = generator.forCRDVersions(crdSpecVersions).inOutputDir(outputDir).detailedGenerate(); | ||
final var crdDetailsPerNameAndVersion = info.getCRDDetailsPerNameAndVersion(); | ||
|
||
crdDetailsPerNameAndVersion.forEach((crdName, initialVersionToCRDInfoMap) -> { | ||
log.infov("Generated {0} CRD:", crdName); | ||
generated.add(crdName); | ||
|
||
initialVersionToCRDInfoMap | ||
.forEach((crdSpecVersion, crdInfo) -> { | ||
final var filePath = crdInfo.getFilePath(); | ||
log.infov(" - {0} -> {1}", crdSpecVersion, filePath); | ||
converted.addCRDInfo(new CRDInfo(crdName, | ||
crdSpecVersion, filePath, crdInfo.getDependentClassNames())); | ||
}); | ||
}); | ||
} | ||
|
||
@Override | ||
public void scheduleForGeneration(Class<? extends CustomResource<?, ?>> crClass) { | ||
final var info = CustomResourceInfo.fromClass(crClass); | ||
generator.customResources(info); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
core/deployment/src/main/java/io/quarkiverse/operatorsdk/deployment/CRDGeneratorV2.java
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,46 @@ | ||
package io.quarkiverse.operatorsdk.deployment; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.fabric8.crdv2.generator.CustomResourceInfo; | ||
import io.fabric8.kubernetes.client.CustomResource; | ||
import io.quarkiverse.operatorsdk.runtime.CRDInfo; | ||
import io.quarkiverse.operatorsdk.runtime.CRDInfos; | ||
|
||
class CRDGeneratorV2 implements CRDGenerator { | ||
private static final Logger log = Logger.getLogger(CRDGeneratorV2.class.getName()); | ||
private final io.fabric8.crdv2.generator.CRDGenerator generator; | ||
|
||
public CRDGeneratorV2(boolean parallelGeneration) { | ||
this.generator = new io.fabric8.crdv2.generator.CRDGenerator().withParallelGenerationEnabled(parallelGeneration); | ||
} | ||
|
||
@Override | ||
public void generate(List<String> crdSpecVersions, File outputDir, Set<String> generated, CRDInfos converted) { | ||
final var info = generator.forCRDVersions(crdSpecVersions).inOutputDir(outputDir).detailedGenerate(); | ||
final var crdDetailsPerNameAndVersion = info.getCRDDetailsPerNameAndVersion(); | ||
|
||
crdDetailsPerNameAndVersion.forEach((crdName, initialVersionToCRDInfoMap) -> { | ||
log.infov("Generated {0} CRD:", crdName); | ||
generated.add(crdName); | ||
|
||
initialVersionToCRDInfoMap | ||
.forEach((crdSpecVersion, crdInfo) -> { | ||
final var filePath = crdInfo.getFilePath(); | ||
log.infov(" - {0} -> {1}", crdSpecVersion, filePath); | ||
converted.addCRDInfo(new CRDInfo(crdName, | ||
crdSpecVersion, filePath, crdInfo.getDependentClassNames())); | ||
}); | ||
}); | ||
} | ||
|
||
@Override | ||
public void scheduleForGeneration(Class<? extends CustomResource<?, ?>> crClass) { | ||
final var info = CustomResourceInfo.fromClass(crClass); | ||
generator.customResources(info); | ||
} | ||
} |
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