generated from quarkiverse/quarkiverse-template
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow CRD generation of all detected CRs (#399)
Fixes #90
- Loading branch information
Showing
18 changed files
with
474 additions
and
133 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
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
50 changes: 50 additions & 0 deletions
50
common-deployment/src/main/java/io/quarkiverse/operatorsdk/common/HasMetadataUtils.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,50 @@ | ||
package io.quarkiverse.operatorsdk.common; | ||
|
||
import static io.quarkiverse.operatorsdk.common.ConfigurationUtils.annotationValueOrDefault; | ||
|
||
import java.util.Locale; | ||
|
||
import org.jboss.jandex.AnnotationValue; | ||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.DotName; | ||
|
||
import io.fabric8.kubernetes.api.Pluralize; | ||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.fabric8.kubernetes.model.annotation.Group; | ||
import io.fabric8.kubernetes.model.annotation.Kind; | ||
import io.fabric8.kubernetes.model.annotation.Plural; | ||
import io.fabric8.kubernetes.model.annotation.Singular; | ||
|
||
public class HasMetadataUtils { | ||
|
||
private static final DotName GROUP = DotName.createSimple(Group.class.getName()); | ||
private static final DotName PLURAL = DotName.createSimple(Plural.class.getName()); | ||
private static final DotName SINGULAR = DotName.createSimple(Singular.class.getName()); | ||
private static final DotName KIND = DotName.createSimple(Kind.class.getName()); | ||
|
||
public static String getFullResourceName(ClassInfo resourceCI) { | ||
return HasMetadata.getFullResourceName(getPlural(resourceCI), getGroup(resourceCI)); | ||
} | ||
|
||
public static String getPlural(ClassInfo resourceCI) { | ||
return annotationValueOrDefault(resourceCI.classAnnotation(PLURAL), | ||
"value", | ||
value -> value.asString().toLowerCase(Locale.ROOT), | ||
() -> Pluralize.toPlural(getSingular(resourceCI))); | ||
} | ||
|
||
public static String getGroup(ClassInfo resourceCI) { | ||
return annotationValueOrDefault(resourceCI.classAnnotation(GROUP), "value", | ||
AnnotationValue::asString, () -> null); | ||
} | ||
|
||
public static String getSingular(ClassInfo resourceCI) { | ||
return annotationValueOrDefault(resourceCI.classAnnotation(SINGULAR), "value", | ||
AnnotationValue::asString, () -> getKind(resourceCI).toLowerCase(Locale.ROOT)); | ||
} | ||
|
||
public static String getKind(ClassInfo resourceCI) { | ||
return annotationValueOrDefault(resourceCI.classAnnotation(KIND), | ||
"value", AnnotationValue::asString, resourceCI::simpleName); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...on-deployment/src/main/java/io/quarkiverse/operatorsdk/common/LoadableResourceHolder.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,9 @@ | ||
package io.quarkiverse.operatorsdk.common; | ||
|
||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
|
||
public interface LoadableResourceHolder<T extends HasMetadata> { | ||
String getAssociatedResourceTypeName(); | ||
|
||
Class<T> loadAssociatedClass(); | ||
} |
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
48 changes: 48 additions & 0 deletions
48
.../src/main/java/io/quarkiverse/operatorsdk/common/ResourceTargetingAugmentedClassInfo.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,48 @@ | ||
package io.quarkiverse.operatorsdk.common; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.IndexView; | ||
import org.jboss.logging.Logger; | ||
|
||
import io.fabric8.kubernetes.client.CustomResource; | ||
|
||
public class ResourceTargetingAugmentedClassInfo extends SelectiveAugmentedClassInfo | ||
implements LoadableResourceHolder<CustomResource<?, ?>> { | ||
private final LoadableResourceHolder<CustomResource<?, ?>> holder; | ||
private final String reconcilerName; | ||
public static final String EXISTING_CRDS_KEY = "existing-crds-key"; | ||
|
||
protected ResourceTargetingAugmentedClassInfo(ClassInfo classInfo, String associatedReconcilerName) { | ||
super(classInfo, Constants.CUSTOM_RESOURCE, 2); | ||
this.reconcilerName = associatedReconcilerName; | ||
this.holder = new SimpleLoadableResourceHolder<>(classInfo); | ||
} | ||
|
||
@Override | ||
protected boolean augmentIfKept(IndexView index, Logger log, Map<String, Object> context) { | ||
// only keep the information if the associated CRD hasn't already been generated | ||
return Optional.ofNullable(context.get(EXISTING_CRDS_KEY)) | ||
.map(value -> { | ||
@SuppressWarnings("unchecked") | ||
Set<String> generated = (Set<String>) value; | ||
return !generated.contains(getAssociatedResourceTypeName()); | ||
}) | ||
.orElse(true); | ||
} | ||
|
||
public String getAssociatedResourceTypeName() { | ||
return holder.getAssociatedResourceTypeName(); | ||
} | ||
|
||
public Optional<String> getAssociatedReconcilerName() { | ||
return Optional.ofNullable(reconcilerName); | ||
} | ||
|
||
public Class<CustomResource<?, ?>> loadAssociatedClass() { | ||
return holder.loadAssociatedClass(); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...loyment/src/main/java/io/quarkiverse/operatorsdk/common/SimpleLoadableResourceHolder.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,37 @@ | ||
package io.quarkiverse.operatorsdk.common; | ||
|
||
import static io.quarkiverse.operatorsdk.common.ClassLoadingUtils.loadClass; | ||
|
||
import org.jboss.jandex.ClassInfo; | ||
|
||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
|
||
public class SimpleLoadableResourceHolder<T extends HasMetadata> implements LoadableResourceHolder<T> { | ||
|
||
private Class<T> clazz; | ||
private final String resourceTypeName; | ||
private final String resourceClassName; | ||
private final ClassInfo resourceCI; | ||
|
||
public SimpleLoadableResourceHolder(ClassInfo resourceCI) { | ||
this.resourceTypeName = HasMetadataUtils.getFullResourceName(resourceCI); | ||
this.resourceClassName = resourceCI.name().toString(); | ||
this.resourceCI = resourceCI; | ||
} | ||
|
||
public String getAssociatedResourceTypeName() { | ||
return resourceTypeName; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public Class<T> loadAssociatedClass() { | ||
if (clazz == null) { | ||
clazz = (Class<T>) loadClass(resourceClassName, HasMetadata.class); | ||
} | ||
return clazz; | ||
} | ||
|
||
public ClassInfo getResourceCI() { | ||
return resourceCI; | ||
} | ||
} |
Oops, something went wrong.