All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkiverse.operatorsdk.common.CustomResourceAugmentedClassInfo Maven / Gradle / Ivy

The newest version!
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 CustomResourceAugmentedClassInfo extends ReconciledResourceAugmentedClassInfo> {

    public static final String EXISTING_CRDS_KEY = "existing-crds-key";

    protected CustomResourceAugmentedClassInfo(ClassInfo classInfo, String associatedReconcilerName) {
        super(classInfo, Constants.CUSTOM_RESOURCE, 2, associatedReconcilerName);
    }

    @Override
    protected boolean doKeep(IndexView index, Logger log, Map context) {

        // only keep the information if the associated CRD hasn't already been generated
        final var fullName = fullResourceName();
        return Optional.ofNullable(context.get(EXISTING_CRDS_KEY))
                .map(value -> {
                    @SuppressWarnings("unchecked")
                    Set generated = (Set) value;
                    return !generated.contains(fullName);
                })
                .orElse(true);
    }

    @Override
    protected void doAugment(IndexView index, Logger log, Map context) {
        super.doAugment(index, log, context);

        // registering these classes is not necessary anymore since the kubernetes client extension takes care of it
        // however, we keep doing it here so that the name of these classes appear in the logs as has been the case since the first version of this extension
        final var specClassName = typeAt(0).name().toString();
        final var statusClassName = typeAt(1).name().toString();
        registerForReflection(specClassName);
        registerForReflection(statusClassName);
    }

    @Override
    protected boolean hasStatus(IndexView index) {
        final var statusClassName = typeAt(1).name().toString();
        return ClassUtils.isStatusNotVoid(statusClassName);
    }

    @Override
    public boolean isCR() {
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy