Search in sources :

Example 1 with CustomResource

use of io.fabric8.kubernetes.client.CustomResource in project syndesis-qe by syndesisio.

the class Syndesis method enableTestSupport.

private boolean enableTestSupport() {
    TestUtils.waitFor(() -> "AtLatestKnown".equalsIgnoreCase(getSubscription().getJSONObject("status").getString("state")), 2, 60 * 3, "CSV didn't get installed in time");
    JSONObject json = new JSONObject(OpenShiftUtils.getInstance().customResource(getCSVContext()).get(TestConfiguration.openShiftNamespace(), "fuse-online-operator.v7.9.0"));
    JSONObject operatorDeployment = json.getJSONObject("spec").getJSONObject("install").getJSONObject("spec").getJSONArray("deployments").getJSONObject(0);
    JSONArray envVars = operatorDeployment.getJSONObject("spec").getJSONObject("template").getJSONObject("spec").getJSONArray("containers").getJSONObject(0).getJSONArray("env");
    envVars.put(TestUtils.map("name", "TEST_SUPPORT", "value", "true"));
    try {
        OpenShiftUtils.getInstance().customResource(getCSVContext()).edit(TestConfiguration.openShiftNamespace(), "fuse-online-operator.v7.9.0", json.toMap());
        return true;
    } catch (Exception e) {
        log.error("Couldn't edit Syndesis CSV", e);
        return false;
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TimeoutException(java.util.concurrent.TimeoutException) JSONException(org.json.JSONException) WaiterException(cz.xtf.core.waiting.WaiterException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException)

Example 2 with CustomResource

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

the class DocGenerator method main.

public static void main(String[] args) throws IOException, ClassNotFoundException {
    Linker linker = null;
    File out = null;
    List<Class<? extends CustomResource>> classes = new ArrayList<>();
    outer: for (int i = 0; i < args.length; i++) {
        String arg = args[i];
        if (arg.startsWith("-")) {
            if ("--linker".equals(arg)) {
                String className = args[++i];
                Class<? extends Linker> linkerClass = classInherits(Class.forName(className), Linker.class);
                if (linkerClass != null) {
                    try {
                        linker = linkerClass.getConstructor(String.class).newInstance(args[++i]);
                    } catch (ReflectiveOperationException e) {
                        throw new RuntimeException("--linker option can't be handled", e);
                    }
                } else {
                    System.err.println(className + " is not a subclass of " + Linker.class.getName());
                }
            } else {
                throw new RuntimeException("Unsupported option " + arg);
            }
        } else {
            if (out == null) {
                out = new File(arg);
            } else {
                String className = arg;
                Class<? extends CustomResource> cls = classInherits(Class.forName(className), CustomResource.class);
                if (cls != null) {
                    classes.add(cls);
                } else {
                    System.err.println(className + " is not a subclass of " + CustomResource.class.getName());
                }
            }
        }
    }
    ApiVersion crApiVersion = ApiVersion.V1BETA2;
    try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(out), StandardCharsets.UTF_8)) {
        writer.append("// This file is auto-generated by ").append(DocGenerator.class.getName()).append(".").append(NL);
        writer.append("// To change this documentation you need to edit the Java sources.").append(NL);
        writer.append(NL);
        DocGenerator dg = new DocGenerator(crApiVersion, 3, classes, writer, linker);
        for (Class<? extends CustomResource> c : classes) {
            dg.generate(c);
        }
        if (dg.numErrors > 0) {
            System.err.println("There were " + dg.numErrors + " errors");
            System.exit(1);
        }
    }
}
Also used : ApiVersion(io.strimzi.api.annotations.ApiVersion) CustomResource(io.fabric8.kubernetes.client.CustomResource) ArrayList(java.util.ArrayList) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) DescriptionFile(io.strimzi.crdgenerator.annotations.DescriptionFile) File(java.io.File)

Example 3 with CustomResource

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

the class MockKube method build.

@SuppressWarnings("unchecked")
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
public KubernetesClient build() {
    if (mockClient != null) {
        return mockClient;
    }
    configMapMockBuilder = addMockBuilder("configmaps", new MockBuilder<>(ConfigMap.class, ConfigMapList.class, MockBuilder.castClass(Resource.class), cmDb));
    endpointMockBuilder = addMockBuilder("endpoints", new MockBuilder<>(Endpoints.class, EndpointsList.class, MockBuilder.castClass(Resource.class), endpointDb));
    serviceMockBuilder = addMockBuilder("services", new ServiceMockBuilder(svcDb, endpointDb));
    secretMockBuilder = addMockBuilder("secrets", new MockBuilder<>(Secret.class, SecretList.class, MockBuilder.castClass(Resource.class), secretDb));
    serviceAccountMockBuilder = addMockBuilder("serviceaccounts", new MockBuilder<>(ServiceAccount.class, ServiceAccountList.class, MockBuilder.castClass(Resource.class), serviceAccountDb));
    routeMockBuilder = addMockBuilder("routes", new MockBuilder<>(Route.class, RouteList.class, MockBuilder.castClass(Resource.class), routeDb));
    buildConfigMockBuilder = addMockBuilder("buildConfigs", new MockBuilder<>(BuildConfig.class, BuildConfigList.class, MockBuilder.castClass(Resource.class), buildConfigDb));
    podDisruptionBudgedMockBuilder = addMockBuilder("poddisruptionbudgets", new MockBuilder<>(PodDisruptionBudget.class, PodDisruptionBudgetList.class, MockBuilder.castClass(Resource.class), pdbDb));
    podDisruptionBudgedV1Beta1MockBuilder = addMockBuilder("poddisruptionbudgetsV1Beta1", new MockBuilder<>(io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudget.class, io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudgetList.class, MockBuilder.castClass(Resource.class), pdbDbV1Beta1));
    roleBindingMockBuilder = addMockBuilder("rolebindings", new MockBuilder<>(RoleBinding.class, RoleBindingList.class, MockBuilder.castClass(Resource.class), pdbRb));
    roleMockBuilder = addMockBuilder("roles", new MockBuilder<>(Role.class, RoleList.class, MockBuilder.castClass(Resource.class), roleDb));
    clusterRoleBindingMockBuilder = addMockBuilder("clusterrolebindings", new MockBuilder<>(ClusterRoleBinding.class, ClusterRoleBindingList.class, MockBuilder.castClass(Resource.class), pdbCrb));
    networkPolicyMockBuilder = addMockBuilder("networkpolicies", new MockBuilder<>(NetworkPolicy.class, NetworkPolicyList.class, MockBuilder.castClass(Resource.class), policyDb));
    ingressMockBuilder = addMockBuilder("ingresses", new MockBuilder<>(Ingress.class, IngressList.class, MockBuilder.castClass(Resource.class), ingressDb));
    ingressV1Beta1MockBuilder = addMockBuilder("ingresses", new MockBuilder<>(io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress.class, io.fabric8.kubernetes.api.model.networking.v1beta1.IngressList.class, MockBuilder.castClass(Resource.class), ingressV1Beta1Db));
    podMockBuilder = addMockBuilder("pods", new MockBuilder<>(Pod.class, PodList.class, MockBuilder.castClass(PodResource.class), podDb));
    MixedOperation<Pod, PodList, PodResource<Pod>> mockPods = podMockBuilder.build();
    persistentVolumeClaimMockBuilder = addMockBuilder("persistentvolumeclaims", new MockBuilder<>(PersistentVolumeClaim.class, PersistentVolumeClaimList.class, MockBuilder.castClass(Resource.class), pvcDb));
    MixedOperation<PersistentVolumeClaim, PersistentVolumeClaimList, Resource<PersistentVolumeClaim>> mockPersistentVolumeClaims = persistentVolumeClaimMockBuilder.build();
    deploymentMockBuilder = addMockBuilder("deployments", new DeploymentMockBuilder(depDb, mockPods));
    MixedOperation<StatefulSet, StatefulSetList, RollableScalableResource<StatefulSet>> mockSs = buildStatefulSets(podMockBuilder, mockPods, mockPersistentVolumeClaims);
    // Top level group
    mockClient = mock(KubernetesClient.class);
    configMapMockBuilder.build2(mockClient::configMaps);
    serviceMockBuilder.build2(mockClient::services);
    secretMockBuilder.build2(mockClient::secrets);
    serviceAccountMockBuilder.build2(mockClient::serviceAccounts);
    when(mockClient.pods()).thenReturn(mockPods);
    endpointMockBuilder.build2(mockClient::endpoints);
    when(mockClient.persistentVolumeClaims()).thenReturn(mockPersistentVolumeClaims);
    // API group
    AppsAPIGroupDSL api = mock(AppsAPIGroupDSL.class);
    when(mockClient.apps()).thenReturn(api);
    when(api.statefulSets()).thenReturn(mockSs);
    deploymentMockBuilder.build2(api::deployments);
    MixedOperation<CustomResourceDefinition, CustomResourceDefinitionList, Resource<CustomResourceDefinition>> mockCrds = mock(MixedOperation.class);
    // Custom Resources
    if (mockedCrds != null && !mockedCrds.isEmpty()) {
        NonNamespaceOperation<CustomResourceDefinition, CustomResourceDefinitionList, Resource<CustomResourceDefinition>> crds = mock(MixedOperation.class);
        for (MockedCrd<?, ?, ?> mockedCrd : this.mockedCrds) {
            CustomResourceDefinition crd = mockedCrd.crd;
            Resource crdResource = mock(Resource.class);
            when(crdResource.get()).thenReturn(crd);
            when(crds.withName(crd.getMetadata().getName())).thenReturn(crdResource);
            String key = crdKey(mockedCrd.crClass);
            CreateOrReplaceable crdMixedOp = crdMixedOps.get(key);
            if (crdMixedOp == null) {
                CustomResourceMockBuilder customResourceMockBuilder = addMockBuilder(crd.getSpec().getNames().getPlural(), new CustomResourceMockBuilder<>((MockedCrd) mockedCrd));
                crdMixedOp = (MixedOperation<CustomResource, ? extends KubernetesResource, Resource<CustomResource>>) customResourceMockBuilder.build();
                crdMixedOps.put(key, crdMixedOp);
            }
            when(mockCrds.withName(eq(crd.getMetadata().getName()))).thenReturn(crdResource);
        }
        ApiextensionsAPIGroupDSL mockApiEx = mock(ApiextensionsAPIGroupDSL.class);
        V1ApiextensionAPIGroupDSL mockv1 = mock(V1ApiextensionAPIGroupDSL.class);
        when(mockClient.apiextensions()).thenReturn(mockApiEx);
        when(mockApiEx.v1()).thenReturn(mockv1);
        when(mockv1.customResourceDefinitions()).thenReturn(mockCrds);
        mockCrs(mockClient);
    }
    // Network group
    NetworkAPIGroupDSL network = mock(NetworkAPIGroupDSL.class);
    V1NetworkAPIGroupDSL networkV1 = mock(V1NetworkAPIGroupDSL.class);
    V1beta1NetworkAPIGroupDSL networkV1beta1 = mock(V1beta1NetworkAPIGroupDSL.class);
    when(mockClient.network()).thenReturn(network);
    when(network.v1()).thenReturn(networkV1);
    when(network.v1beta1()).thenReturn(networkV1beta1);
    networkPolicyMockBuilder.build2(network::networkPolicies);
    ingressMockBuilder.build2(networkV1::ingresses);
    ingressV1Beta1MockBuilder.build2(networkV1beta1::ingresses);
    // Policy group
    PolicyAPIGroupDSL policy = mock(PolicyAPIGroupDSL.class);
    V1PolicyAPIGroupDSL v1policy = mock(V1PolicyAPIGroupDSL.class);
    when(mockClient.policy()).thenReturn(policy);
    when(policy.v1()).thenReturn(v1policy);
    V1beta1PolicyAPIGroupDSL v1beta1policy = mock(V1beta1PolicyAPIGroupDSL.class);
    when(mockClient.policy()).thenReturn(policy);
    when(policy.v1beta1()).thenReturn(v1beta1policy);
    podDisruptionBudgedMockBuilder.build2(mockClient.policy().v1()::podDisruptionBudget);
    podDisruptionBudgedV1Beta1MockBuilder.build2(mockClient.policy().v1beta1()::podDisruptionBudget);
    // RBAC group
    RbacAPIGroupDSL rbac = mock(RbacAPIGroupDSL.class);
    when(mockClient.rbac()).thenReturn(rbac);
    roleBindingMockBuilder.build2(mockClient.rbac()::roleBindings);
    roleMockBuilder.build2(mockClient.rbac()::roles);
    clusterRoleBindingMockBuilder.buildNns(mockClient.rbac()::clusterRoleBindings);
    // Openshift group
    OpenShiftClient mockOpenShiftClient = mock(OpenShiftClient.class);
    when(mockClient.adapt(OpenShiftClient.class)).thenReturn(mockOpenShiftClient);
    routeMockBuilder.build2(mockOpenShiftClient::routes);
    buildConfigMockBuilder.build2(mockOpenShiftClient::buildConfigs);
    if (mockedCrds != null && !mockedCrds.isEmpty()) {
        ApiextensionsAPIGroupDSL mockApiEx = mock(ApiextensionsAPIGroupDSL.class);
        V1ApiextensionAPIGroupDSL mockv1 = mock(V1ApiextensionAPIGroupDSL.class);
        when(mockOpenShiftClient.apiextensions()).thenReturn(mockApiEx);
        when(mockApiEx.v1()).thenReturn(mockv1);
        when(mockv1.customResourceDefinitions()).thenReturn(mockCrds);
        mockCrs(mockOpenShiftClient);
    }
    doAnswer(i -> {
        for (MockBuilder<?, ?, ?> a : mockBuilders.values()) {
            a.assertNoWatchers();
        }
        return null;
    }).when(mockClient).close();
    return mockClient;
}
Also used : PersistentVolumeClaimList(io.fabric8.kubernetes.api.model.PersistentVolumeClaimList) CreateOrReplaceable(io.fabric8.kubernetes.client.dsl.CreateOrReplaceable) StatefulSetList(io.fabric8.kubernetes.api.model.apps.StatefulSetList) Pod(io.fabric8.kubernetes.api.model.Pod) V1ApiextensionAPIGroupDSL(io.fabric8.kubernetes.client.V1ApiextensionAPIGroupDSL) Resource(io.fabric8.kubernetes.client.dsl.Resource) BuildConfigResource(io.fabric8.openshift.client.dsl.BuildConfigResource) CustomResource(io.fabric8.kubernetes.client.CustomResource) RollableScalableResource(io.fabric8.kubernetes.client.dsl.RollableScalableResource) PodResource(io.fabric8.kubernetes.client.dsl.PodResource) KubernetesResource(io.fabric8.kubernetes.api.model.KubernetesResource) CustomResourceDefinitionList(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionList) V1PolicyAPIGroupDSL(io.fabric8.kubernetes.client.dsl.V1PolicyAPIGroupDSL) V1NetworkAPIGroupDSL(io.fabric8.kubernetes.client.V1NetworkAPIGroupDSL) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) RbacAPIGroupDSL(io.fabric8.kubernetes.client.dsl.RbacAPIGroupDSL) PodResource(io.fabric8.kubernetes.client.dsl.PodResource) ApiextensionsAPIGroupDSL(io.fabric8.kubernetes.client.dsl.ApiextensionsAPIGroupDSL) V1beta1PolicyAPIGroupDSL(io.fabric8.kubernetes.client.dsl.V1beta1PolicyAPIGroupDSL) PolicyAPIGroupDSL(io.fabric8.kubernetes.client.dsl.PolicyAPIGroupDSL) V1PolicyAPIGroupDSL(io.fabric8.kubernetes.client.dsl.V1PolicyAPIGroupDSL) PodList(io.fabric8.kubernetes.api.model.PodList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) CustomResource(io.fabric8.kubernetes.client.CustomResource) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) NetworkAPIGroupDSL(io.fabric8.kubernetes.client.dsl.NetworkAPIGroupDSL) V1NetworkAPIGroupDSL(io.fabric8.kubernetes.client.V1NetworkAPIGroupDSL) V1beta1NetworkAPIGroupDSL(io.fabric8.kubernetes.client.V1beta1NetworkAPIGroupDSL) AppsAPIGroupDSL(io.fabric8.kubernetes.client.dsl.AppsAPIGroupDSL) V1beta1PolicyAPIGroupDSL(io.fabric8.kubernetes.client.dsl.V1beta1PolicyAPIGroupDSL) V1beta1NetworkAPIGroupDSL(io.fabric8.kubernetes.client.V1beta1NetworkAPIGroupDSL) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) RollableScalableResource(io.fabric8.kubernetes.client.dsl.RollableScalableResource) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 4 with CustomResource

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

the class OperatorMetricsTest method testDeleteCountsReconcile.

@Test
public void testDeleteCountsReconcile(VertxTestContext context) {
    MetricsProvider metrics = createCleanMetricsProvider();
    AbstractWatchableStatusedResourceOperator resourceOperator = new AbstractWatchableStatusedResourceOperator(vertx, null, "TestResource") {

        @Override
        protected MixedOperation operation() {
            return null;
        }

        @Override
        public HasMetadata get(String namespace, String name) {
            return null;
        }

        @Override
        public Future updateStatusAsync(Reconciliation reconciliation, HasMetadata resource) {
            return null;
        }
    };
    AbstractOperator operator = new AbstractOperator(vertx, "TestResource", resourceOperator, metrics, null) {

        @Override
        protected Future createOrUpdate(Reconciliation reconciliation, CustomResource resource) {
            return null;
        }

        @Override
        public Set<Condition> validate(Reconciliation reconciliation, CustomResource resource) {
            // Do nothing
            return emptySet();
        }

        @Override
        protected Future<Boolean> delete(Reconciliation reconciliation) {
            return Future.succeededFuture(Boolean.TRUE);
        }

        @Override
        protected Status createStatus() {
            return new Status() {
            };
        }
    };
    Checkpoint async = context.checkpoint();
    operator.reconcile(new Reconciliation("test", "TestResource", "my-namespace", "my-resource")).onComplete(context.succeeding(v -> context.verify(() -> {
        MeterRegistry registry = metrics.meterRegistry();
        Tag selectorTag = Tag.of("selector", "");
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").timer().count(), is(1L));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
        assertThrows(MeterNotFoundException.class, () -> {
            registry.get(AbstractOperator.METRICS_PREFIX + "resource.state").tag("kind", "TestResource").tag("name", "my-resource").tag("resource-namespace", "my-namespace").gauge();
        });
        async.flag();
    })));
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) Status(io.strimzi.api.kafka.model.status.Status) VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) AfterAll(org.junit.jupiter.api.AfterAll) HashSet(java.util.HashSet) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Status(io.strimzi.api.kafka.model.status.Status) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Version(io.fabric8.kubernetes.model.annotation.Version) Tag(io.micrometer.core.instrument.Tag) Collections.emptyMap(java.util.Collections.emptyMap) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) Collections.emptySet(java.util.Collections.emptySet) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Set(java.util.Set) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) VertxExtension(io.vertx.junit5.VertxExtension) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Spec(io.strimzi.api.kafka.model.Spec) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) NamespaceAndName(io.strimzi.operator.common.model.NamespaceAndName) Labels(io.strimzi.operator.common.model.Labels) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Group(io.fabric8.kubernetes.model.annotation.Group) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Condition(io.strimzi.api.kafka.model.status.Condition) Collections(java.util.Collections) CustomResource(io.fabric8.kubernetes.client.CustomResource) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) CustomResource(io.fabric8.kubernetes.client.CustomResource) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Checkpoint(io.vertx.junit5.Checkpoint) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Tag(io.micrometer.core.instrument.Tag) Test(org.junit.jupiter.api.Test)

Example 5 with CustomResource

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

the class OperatorMetricsTest method testPauseReconcile.

@Test
public void testPauseReconcile(VertxTestContext context) {
    MetricsProvider metrics = createCleanMetricsProvider();
    AbstractWatchableStatusedResourceOperator resourceOperator = resourceOperatorWithExistingPausedResource();
    AbstractOperator operator = new AbstractOperator(vertx, "TestResource", resourceOperator, metrics, null) {

        @Override
        protected Future createOrUpdate(Reconciliation reconciliation, CustomResource resource) {
            return Future.succeededFuture();
        }

        @Override
        public Set<Condition> validate(Reconciliation reconciliation, CustomResource resource) {
            return new HashSet<>();
        }

        @Override
        protected Future<Boolean> delete(Reconciliation reconciliation) {
            return null;
        }

        @Override
        protected Status createStatus() {
            return new Status() {
            };
        }
    };
    Checkpoint async = context.checkpoint();
    operator.reconcile(new Reconciliation("test", "TestResource", "my-namespace", "my-resource")).onComplete(context.succeeding(v -> context.verify(() -> {
        MeterRegistry registry = metrics.meterRegistry();
        Tag selectorTag = Tag.of("selector", "");
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.successful").tag("kind", "TestResource").counter().count(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resources.paused").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resources.paused").tag("kind", "TestResource").gauge().value(), is(1.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").meter().getId().getTags().get(2), is(selectorTag));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").timer().count(), is(1L));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "TestResource").timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
        assertThat(registry.get(AbstractOperator.METRICS_PREFIX + "resource.state").tag("kind", "TestResource").tag("name", "my-resource").tag("resource-namespace", "my-namespace").gauge().value(), is(1.0));
        async.flag();
    })));
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) Status(io.strimzi.api.kafka.model.status.Status) VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) AfterAll(org.junit.jupiter.api.AfterAll) HashSet(java.util.HashSet) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Status(io.strimzi.api.kafka.model.status.Status) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Version(io.fabric8.kubernetes.model.annotation.Version) Tag(io.micrometer.core.instrument.Tag) Collections.emptyMap(java.util.Collections.emptyMap) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) Collections.emptySet(java.util.Collections.emptySet) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Set(java.util.Set) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) VertxExtension(io.vertx.junit5.VertxExtension) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Spec(io.strimzi.api.kafka.model.Spec) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) NamespaceAndName(io.strimzi.operator.common.model.NamespaceAndName) Labels(io.strimzi.operator.common.model.Labels) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Group(io.fabric8.kubernetes.model.annotation.Group) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Condition(io.strimzi.api.kafka.model.status.Condition) Collections(java.util.Collections) CustomResource(io.fabric8.kubernetes.client.CustomResource) CustomResource(io.fabric8.kubernetes.client.CustomResource) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Checkpoint(io.vertx.junit5.Checkpoint) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) Tag(io.micrometer.core.instrument.Tag) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

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