Search in sources :

Example 31 with CustomResource

use of io.fabric8.kubernetes.client.CustomResource in project strimzi-kafka-operator by strimzi.

the class CrdGenerator method main.

public static void main(String[] args) throws IOException, ClassNotFoundException {
    CommandOptions opts = new CommandOptions(args);
    CrdGenerator generator = new CrdGenerator(opts.targetKubeVersions, opts.crdApiVersion, opts.yaml ? YAML_MAPPER.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true) : JSON_MATTER, opts.labels, new DefaultReporter(), opts.apiVersions, opts.storageVersion, null, opts.conversionStrategy, opts.describeVersions);
    for (Map.Entry<String, Class<? extends CustomResource>> entry : opts.classes.entrySet()) {
        File file = new File(entry.getKey());
        if (file.getParentFile().exists()) {
            if (!file.getParentFile().isDirectory()) {
                generator.err(file.getParentFile() + " is not a directory");
            }
        } else if (!file.getParentFile().mkdirs()) {
            generator.err(file.getParentFile() + " does not exist and could not be created");
        }
        try (Writer w = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
            generator.generate(entry.getValue(), w);
        }
    }
    if (generator.numErrors > 0) {
        System.err.println("There were " + generator.numErrors + " errors");
        System.exit(1);
    } else {
        System.exit(0);
    }
}
Also used : CustomResource(io.fabric8.kubernetes.client.CustomResource) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Collections.emptyMap(java.util.Collections.emptyMap) TreeMap(java.util.TreeMap) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 32 with CustomResource

use of io.fabric8.kubernetes.client.CustomResource in project strimzi-kafka-operator by strimzi.

the class MockKube method mockCrs.

@SuppressWarnings({ "unchecked", "deprecation" })
public void mockCrs(KubernetesClient mockClient) {
    when(mockClient.customResources(any(CustomResourceDefinitionContext.class), any(Class.class), any(Class.class))).thenAnswer(invocation -> {
        Class<CustomResource> crClass = invocation.getArgument(1);
        String key = crdKey(crClass);
        CreateOrReplaceable createOrReplaceable = crdMixedOps.get(key);
        if (createOrReplaceable == null) {
            throw new RuntimeException("Unknown CRD " + key);
        }
        return createOrReplaceable;
    });
    when(mockClient.customResources(any(Class.class), any(Class.class))).thenAnswer(invocation -> {
        Class<CustomResource> crClass = invocation.getArgument(0);
        String key = crdKey(crClass);
        CreateOrReplaceable createOrReplaceable = crdMixedOps.get(key);
        if (createOrReplaceable == null) {
            throw new RuntimeException("Unknown CRD " + key);
        }
        return createOrReplaceable;
    });
    when(mockClient.resources(any(Class.class), any(Class.class))).thenAnswer(invocation -> {
        Class<CustomResource> crClass = invocation.getArgument(0);
        String key = crdKey(crClass);
        CreateOrReplaceable createOrReplaceable = crdMixedOps.get(key);
        if (createOrReplaceable == null) {
            throw new RuntimeException("Unknown CRD " + key);
        }
        return createOrReplaceable;
    });
}
Also used : CustomResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext) CustomResource(io.fabric8.kubernetes.client.CustomResource) CreateOrReplaceable(io.fabric8.kubernetes.client.dsl.CreateOrReplaceable)

Aggregations

CustomResource (io.fabric8.kubernetes.client.CustomResource)22 Collections.emptyMap (java.util.Collections.emptyMap)16 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)15 Condition (io.strimzi.api.kafka.model.status.Condition)14 HashSet (java.util.HashSet)14 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)13 Group (io.fabric8.kubernetes.model.annotation.Group)12 Version (io.fabric8.kubernetes.model.annotation.Version)12 Spec (io.strimzi.api.kafka.model.Spec)12 Status (io.strimzi.api.kafka.model.status.Status)12 Labels (io.strimzi.operator.common.model.Labels)12 AbstractWatchableStatusedResourceOperator (io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator)12 Future (io.vertx.core.Future)12 Promise (io.vertx.core.Promise)12 Vertx (io.vertx.core.Vertx)12 Collections (java.util.Collections)12 Set (java.util.Set)12 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)10 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)10 Tag (io.micrometer.core.instrument.Tag)10