Search in sources :

Example 6 with Labels

use of io.strimzi.operator.common.model.Labels in project strimzi by strimzi.

the class ClusterOperatorConfig method fromMap.

/**
 * Loads configuration parameters from a related map and custom KafkaVersion.Lookup instance.
 * This is used for testing.
 *
 * @param map   map from which loading configuration parameters
 * @param lookup KafkaVersion.Lookup instance with the supported Kafka version information
 * @return  Cluster Operator configuration instance
 */
public static ClusterOperatorConfig fromMap(Map<String, String> map, KafkaVersion.Lookup lookup) {
    Set<String> namespaces = parseNamespaceList(map.get(STRIMZI_NAMESPACE));
    long reconciliationInterval = parseReconciliationInterval(map.get(STRIMZI_FULL_RECONCILIATION_INTERVAL_MS));
    long operationTimeout = parseTimeout(map.get(STRIMZI_OPERATION_TIMEOUT_MS), DEFAULT_OPERATION_TIMEOUT_MS);
    long connectBuildTimeout = parseTimeout(map.get(STRIMZI_CONNECT_BUILD_TIMEOUT_MS), DEFAULT_CONNECT_BUILD_TIMEOUT_MS);
    boolean createClusterRoles = parseBoolean(map.get(STRIMZI_CREATE_CLUSTER_ROLES), DEFAULT_CREATE_CLUSTER_ROLES);
    boolean networkPolicyGeneration = parseBoolean(map.get(STRIMZI_NETWORK_POLICY_GENERATION), DEFAULT_NETWORK_POLICY_GENERATION);
    ImagePullPolicy imagePullPolicy = parseImagePullPolicy(map.get(STRIMZI_IMAGE_PULL_POLICY));
    List<LocalObjectReference> imagePullSecrets = parseImagePullSecrets(map.get(STRIMZI_IMAGE_PULL_SECRETS));
    String operatorNamespace = map.get(STRIMZI_OPERATOR_NAMESPACE);
    Labels operatorNamespaceLabels = parseLabels(map, STRIMZI_OPERATOR_NAMESPACE_LABELS);
    Labels customResourceSelector = parseLabels(map, STRIMZI_CUSTOM_RESOURCE_SELECTOR);
    String featureGates = map.getOrDefault(STRIMZI_FEATURE_GATES, "");
    int operationsThreadPoolSize = parseInt(map.get(STRIMZI_OPERATIONS_THREAD_POOL_SIZE), DEFAULT_OPERATIONS_THREAD_POOL_SIZE);
    int zkAdminSessionTimeout = parseInt(map.get(STRIMZI_ZOOKEEPER_ADMIN_SESSION_TIMEOUT_MS), DEFAULT_ZOOKEEPER_ADMIN_SESSION_TIMEOUT_MS);
    int dnsCacheTtlSec = parseInt(map.get(STRIMZI_DNS_CACHE_TTL), DEFAULT_DNS_CACHE_TTL);
    boolean podSetReconciliationOnly = parseBoolean(map.get(STRIMZI_POD_SET_RECONCILIATION_ONLY), DEFAULT_POD_SET_RECONCILIATION_ONLY);
    int podSetControllerWorkQueueSize = parseInt(map.get(STRIMZI_POD_SET_CONTROLLER_WORK_QUEUE_SIZE), DEFAULT_POD_SET_CONTROLLER_WORK_QUEUE_SIZE);
    return new ClusterOperatorConfig(namespaces, reconciliationInterval, operationTimeout, connectBuildTimeout, createClusterRoles, networkPolicyGeneration, lookup, imagePullPolicy, imagePullSecrets, operatorNamespace, operatorNamespaceLabels, customResourceSelector, featureGates, operationsThreadPoolSize, zkAdminSessionTimeout, dnsCacheTtlSec, podSetReconciliationOnly, podSetControllerWorkQueueSize);
}
Also used : ImagePullPolicy(io.strimzi.operator.cluster.model.ImagePullPolicy) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) Labels(io.strimzi.operator.common.model.Labels)

Example 7 with Labels

use of io.strimzi.operator.common.model.Labels in project strimzi by strimzi.

the class ClusterOperatorConfig method parseLabels.

/**
 * Parse labels from String into the Labels format.
 *
 * @param vars              Map with configuration variables
 * @param configurationKey  Key containing the string with labels
 * @return                  Labels object with the Labels or null if no labels are configured
 */
private static Labels parseLabels(Map<String, String> vars, String configurationKey) {
    String labelsString = vars.get(configurationKey);
    Labels labels = null;
    if (labelsString != null) {
        try {
            labels = Labels.fromString(labelsString);
        } catch (Exception e) {
            throw new InvalidConfigurationException("Failed to parse labels from " + configurationKey, e);
        }
    }
    return labels;
}
Also used : Labels(io.strimzi.operator.common.model.Labels) InvalidConfigurationException(io.strimzi.operator.common.InvalidConfigurationException) NoImageException(io.strimzi.operator.cluster.model.NoImageException) UnsupportedVersionException(io.strimzi.operator.cluster.model.UnsupportedVersionException) InvalidConfigurationException(io.strimzi.operator.common.InvalidConfigurationException)

Example 8 with Labels

use of io.strimzi.operator.common.model.Labels in project strimzi by strimzi.

the class CaReconciler method rollingUpdateForNewCaKey.

/**
 * Perform a rolling update of the cluster so that CA certificates get added to their truststores, or expired CA
 * certificates get removed from their truststores. Note this is only necessary when the CA certificate has changed
 * due to a new CA key. It is not necessary when the CA certificate is replace while retaining the existing key.
 */
Future<Void> rollingUpdateForNewCaKey() {
    List<String> reason = new ArrayList<>(2);
    if (clusterCa.keyReplaced()) {
        reason.add("trust new cluster CA certificate signed by new key");
    }
    if (clientsCa.keyReplaced()) {
        reason.add("trust new clients CA certificate signed by new key");
    }
    if (!reason.isEmpty()) {
        Future<Void> zkRollFuture;
        Function<Pod, List<String>> rollPodAndLogReason = pod -> {
            LOGGER.debugCr(reconciliation, "Rolling Pod {} to {}", pod.getMetadata().getName(), reason);
            return reason;
        };
        if (clusterCa.keyReplaced()) {
            // ZooKeeper is rolled only for new Cluster CA key
            Labels zkSelectorLabels = Labels.EMPTY.withStrimziKind(reconciliation.kind()).withStrimziCluster(reconciliation.name()).withStrimziName(KafkaResources.zookeeperStatefulSetName(reconciliation.name()));
            zkRollFuture = new ZooKeeperRoller(podOperator, zookeeperLeaderFinder, operationTimeoutMs).maybeRollingUpdate(reconciliation, zkSelectorLabels, rollPodAndLogReason, clusterCa.caCertSecret(), oldCoSecret);
        } else {
            zkRollFuture = Future.succeededFuture();
        }
        return zkRollFuture.compose(i -> {
            if (featureGates.useStrimziPodSetsEnabled()) {
                return strimziPodSetOperator.getAsync(reconciliation.namespace(), KafkaResources.kafkaStatefulSetName(reconciliation.name())).compose(podSet -> {
                    if (podSet != null) {
                        return Future.succeededFuture(KafkaCluster.generatePodList(reconciliation.name(), podSet.getSpec().getPods().size()));
                    } else {
                        return Future.succeededFuture(List.<String>of());
                    }
                });
            } else {
                return stsOperator.getAsync(reconciliation.namespace(), KafkaResources.kafkaStatefulSetName(reconciliation.name())).compose(sts -> {
                    if (sts != null) {
                        return Future.succeededFuture(KafkaCluster.generatePodList(reconciliation.name(), sts.getSpec().getReplicas()));
                    } else {
                        return Future.succeededFuture(List.<String>of());
                    }
                });
            }
        }).compose(replicas -> new KafkaRoller(reconciliation, vertx, podOperator, 1_000, operationTimeoutMs, () -> new BackOff(250, 2, 10), replicas, clusterCa.caCertSecret(), oldCoSecret, adminClientProvider, brokerId -> null, null, null, false).rollingRestart(rollPodAndLogReason)).compose(i -> {
            if (clusterCa.keyReplaced()) {
                // EO, KE and CC need to be rolled only for new Cluster CA key.
                return rollDeploymentIfExists(KafkaResources.entityOperatorDeploymentName(reconciliation.name()), reason.toString()).compose(i2 -> rollDeploymentIfExists(KafkaExporterResources.deploymentName(reconciliation.name()), reason.toString())).compose(i2 -> rollDeploymentIfExists(CruiseControlResources.deploymentName(reconciliation.name()), reason.toString()));
            } else {
                return Future.succeededFuture();
            }
        });
    } else {
        return Future.succeededFuture();
    }
}
Also used : BackOff(io.strimzi.operator.common.BackOff) KafkaExporterResources(io.strimzi.api.kafka.model.KafkaExporterResources) StrimziPodSetOperator(io.strimzi.operator.common.operator.resource.StrimziPodSetOperator) Date(java.util.Date) CertManager(io.strimzi.certs.CertManager) Annotations(io.strimzi.operator.common.Annotations) OwnerReference(io.fabric8.kubernetes.api.model.OwnerReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) FeatureGates(io.strimzi.operator.cluster.FeatureGates) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) ClusterOperator(io.strimzi.operator.cluster.ClusterOperator) Ca(io.strimzi.operator.cluster.model.Ca) Map(java.util.Map) ZookeeperLeaderFinder(io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) KafkaRoller(io.strimzi.operator.cluster.operator.resource.KafkaRoller) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) AbstractModel(io.strimzi.operator.cluster.model.AbstractModel) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) ModelUtils(io.strimzi.operator.cluster.model.ModelUtils) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) CertificateAuthority(io.strimzi.api.kafka.model.CertificateAuthority) OwnerReferenceBuilder(io.fabric8.kubernetes.api.model.OwnerReferenceBuilder) InvalidResourceException(io.strimzi.operator.cluster.model.InvalidResourceException) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Pod(io.fabric8.kubernetes.api.model.Pod) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) ClientsCa(io.strimzi.operator.cluster.model.ClientsCa) ZooKeeperRoller(io.strimzi.operator.cluster.operator.resource.ZooKeeperRoller) Future(io.vertx.core.Future) CruiseControlResources(io.strimzi.api.kafka.model.CruiseControlResources) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) Util(io.strimzi.operator.common.Util) Labels(io.strimzi.operator.common.model.Labels) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Secret(io.fabric8.kubernetes.api.model.Secret) AdminClientProvider(io.strimzi.operator.common.AdminClientProvider) Kafka(io.strimzi.api.kafka.model.Kafka) ClusterCa(io.strimzi.operator.cluster.model.ClusterCa) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) Pod(io.fabric8.kubernetes.api.model.Pod) ArrayList(java.util.ArrayList) Labels(io.strimzi.operator.common.model.Labels) BackOff(io.strimzi.operator.common.BackOff) ZooKeeperRoller(io.strimzi.operator.cluster.operator.resource.ZooKeeperRoller) ArrayList(java.util.ArrayList) List(java.util.List) KafkaRoller(io.strimzi.operator.cluster.operator.resource.KafkaRoller)

Example 9 with Labels

use of io.strimzi.operator.common.model.Labels in project strimzi by strimzi.

the class KafkaConnectAssemblyOperatorTest method testReconcile.

@Test
public void testReconcile(VertxTestContext context) {
    // Must create all needed checkpoints before flagging any, to avoid premature test success
    Checkpoint asyncCreated = context.checkpoint(2);
    Checkpoint async = context.checkpoint();
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(true);
    var mockConnectOps = supplier.connectOperator;
    var mockConnectorOps = supplier.kafkaConnectorOperator;
    DeploymentOperator mockDcOps = supplier.deploymentOperations;
    SecretOperator mockSecretOps = supplier.secretOperations;
    PodDisruptionBudgetOperator mockPdbOps = supplier.podDisruptionBudgetOperator;
    NetworkPolicyOperator mockNetPolOps = supplier.networkPolicyOperator;
    when(mockConnectorOps.listAsync(any(), any(Optional.class))).thenReturn(Future.succeededFuture(List.of()));
    String kcNamespace = "test";
    KafkaConnect foo = ResourceUtils.createEmptyKafkaConnect(kcNamespace, "foo");
    KafkaConnect bar = ResourceUtils.createEmptyKafkaConnect(kcNamespace, "bar");
    when(mockConnectOps.listAsync(eq(kcNamespace), any(Optional.class))).thenReturn(Future.succeededFuture(asList(foo, bar)));
    // when requested ConfigMap for a specific Kafka Connect cluster
    when(mockConnectOps.get(eq(kcNamespace), eq("foo"))).thenReturn(foo);
    when(mockConnectOps.get(eq(kcNamespace), eq("bar"))).thenReturn(bar);
    // providing the list of ALL Deployments for all the Kafka Connect clusters
    Labels newLabels = Labels.forStrimziKind(KafkaConnect.RESOURCE_KIND);
    when(mockDcOps.list(eq(kcNamespace), eq(newLabels))).thenReturn(List.of(KafkaConnectCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, bar, VERSIONS).generateDeployment(Map.of(), true, null, null)));
    // providing the list Deployments for already "existing" Kafka Connect clusters
    Labels barLabels = Labels.forStrimziCluster("bar");
    when(mockDcOps.list(eq(kcNamespace), eq(barLabels))).thenReturn(List.of(KafkaConnectCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, bar, VERSIONS).generateDeployment(Map.of(), true, null, null)));
    when(mockDcOps.readiness(any(), anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
    when(mockDcOps.waitForObserved(any(), anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
    when(mockNetPolOps.reconcile(any(), eq(kcNamespace), eq(KafkaConnectResources.deploymentName(bar.getMetadata().getName())), any())).thenReturn(Future.succeededFuture(ReconcileResult.created(new NetworkPolicy())));
    when(mockSecretOps.reconcile(any(), eq(kcNamespace), any(), any())).thenReturn(Future.succeededFuture());
    when(mockPdbOps.reconcile(any(), eq(kcNamespace), any(), any())).thenReturn(Future.succeededFuture());
    Set<String> createdOrUpdated = new CopyOnWriteArraySet<>();
    KafkaConnectAssemblyOperator ops = new KafkaConnectAssemblyOperator(vertx, new PlatformFeaturesAvailability(true, kubernetesVersion), supplier, ResourceUtils.dummyClusterOperatorConfig(VERSIONS)) {

        @Override
        public Future<KafkaConnectStatus> createOrUpdate(Reconciliation reconciliation, KafkaConnect kafkaConnectAssembly) {
            createdOrUpdated.add(kafkaConnectAssembly.getMetadata().getName());
            asyncCreated.flag();
            return Future.succeededFuture();
        }
    };
    Promise<Void> reconciled = Promise.promise();
    // Now try to reconcile all the Kafka Connect clusters
    ops.reconcileAll("test", kcNamespace, ignored -> reconciled.complete());
    reconciled.future().onComplete(context.succeeding(v -> context.verify(() -> {
        assertThat(createdOrUpdated, is(Set.of("foo", "bar")));
        async.flag();
    })));
}
Also used : KafkaConnectStatus(io.strimzi.api.kafka.model.status.KafkaConnectStatus) CoreMatchers.is(org.hamcrest.CoreMatchers.is) KafkaConnectorList(io.strimzi.api.kafka.KafkaConnectorList) ConnectorPluginBuilder(io.strimzi.api.kafka.model.connect.ConnectorPluginBuilder) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Annotations(io.strimzi.operator.common.Annotations) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) ClusterRoleBindingOperator(io.strimzi.operator.common.operator.resource.ClusterRoleBindingOperator) Collections.singletonList(java.util.Collections.singletonList) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) KafkaConnectStatus(io.strimzi.api.kafka.model.status.KafkaConnectStatus) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) AbstractModel(io.strimzi.operator.cluster.model.AbstractModel) KafkaJmxOptionsBuilder(io.strimzi.api.kafka.model.KafkaJmxOptionsBuilder) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Collections.emptyList(java.util.Collections.emptyList) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) VertxExtension(io.vertx.junit5.VertxExtension) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) KafkaConnectCluster(io.strimzi.operator.cluster.model.KafkaConnectCluster) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) RackBuilder(io.strimzi.api.kafka.model.RackBuilder) Optional(java.util.Optional) Checkpoint(io.vertx.junit5.Checkpoint) PodDisruptionBudgetOperator(io.strimzi.operator.common.operator.resource.PodDisruptionBudgetOperator) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Mockito.mock(org.mockito.Mockito.mock) VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) NetworkPolicyOperator(io.strimzi.operator.common.operator.resource.NetworkPolicyOperator) HashMap(java.util.HashMap) ServiceOperator(io.strimzi.operator.common.operator.resource.ServiceOperator) ArgumentCaptor(org.mockito.ArgumentCaptor) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) BuildConfigOperator(io.strimzi.operator.common.operator.resource.BuildConfigOperator) TestUtils(io.strimzi.test.TestUtils) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) Service(io.fabric8.kubernetes.api.model.Service) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) KafkaJmxAuthenticationPasswordBuilder(io.strimzi.api.kafka.model.KafkaJmxAuthenticationPasswordBuilder) Promise(io.vertx.core.Promise) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) ConnectorPlugin(io.strimzi.api.kafka.model.connect.ConnectorPlugin) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Mockito.verify(org.mockito.Mockito.verify) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) Util(io.strimzi.operator.common.Util) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) NetworkPolicy(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Collections(java.util.Collections) KafkaConnectResources(io.strimzi.api.kafka.model.KafkaConnectResources) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Optional(java.util.Optional) NetworkPolicy(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy) PodDisruptionBudgetOperator(io.strimzi.operator.common.operator.resource.PodDisruptionBudgetOperator) Labels(io.strimzi.operator.common.model.Labels) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) NetworkPolicyOperator(io.strimzi.operator.common.operator.resource.NetworkPolicyOperator) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Reconciliation(io.strimzi.operator.common.Reconciliation) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Test(org.junit.jupiter.api.Test)

Example 10 with Labels

use of io.strimzi.operator.common.model.Labels in project strimzi by strimzi.

the class KafkaAssemblyOperatorNonParametrizedTest method testSelectorLabels.

@Test
public void testSelectorLabels(VertxTestContext context) {
    Kafka kafka = new KafkaBuilder().withNewMetadata().withName(NAME).withNamespace(NAMESPACE).endMetadata().withNewSpec().withNewKafka().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().endKafka().withNewZookeeper().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().endZookeeper().endSpec().build();
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the CRD Operator for Kafka resources
    CrdOperator mockKafkaOps = supplier.kafkaOperator;
    when(mockKafkaOps.getAsync(eq(NAMESPACE), eq(NAME))).thenReturn(Future.succeededFuture(kafka));
    when(mockKafkaOps.get(eq(NAMESPACE), eq(NAME))).thenReturn(kafka);
    when(mockKafkaOps.updateStatusAsync(any(), any(Kafka.class))).thenReturn(Future.succeededFuture());
    ClusterOperatorConfig config = new ClusterOperatorConfig(singleton("dummy"), 60_000, 120_000, 300_000, false, true, KafkaVersionTestUtils.getKafkaVersionLookup(), null, null, null, null, Labels.fromMap(Map.of("selectorLabel", "value")), "", 10, 10_000, 30, false, 1024);
    KafkaAssemblyOperator op = new KafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, KubernetesVersion.V1_19), certManager, passwordGenerator, supplier, config);
    Reconciliation reconciliation = new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME);
    Checkpoint async = context.checkpoint();
    op.reconcile(reconciliation).onComplete(context.succeeding(v -> context.verify(() -> {
        // The resource labels don't match the selector labels => the reconciliation should exit right on
        // beginning with success. It should not reconcile any resources other than getting the Kafka
        // resource it self.
        verifyNoInteractions(supplier.stsOperations, supplier.serviceOperations, supplier.secretOperations, supplier.configMapOperations, supplier.podOperations, supplier.podDisruptionBudgetOperator, supplier.deploymentOperations);
        async.flag();
    })));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ClusterRoleBindingOperator(io.strimzi.operator.common.operator.resource.ClusterRoleBindingOperator) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Collections.singleton(java.util.Collections.singleton) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) AbstractModel(io.strimzi.operator.cluster.model.AbstractModel) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Secret(io.fabric8.kubernetes.api.model.Secret) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) CoreMatchers.not(org.hamcrest.CoreMatchers.not) HashMap(java.util.HashMap) OwnerReference(io.fabric8.kubernetes.api.model.OwnerReference) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ArgumentCaptor(org.mockito.ArgumentCaptor) ClusterOperator(io.strimzi.operator.cluster.ClusterOperator) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) CertificateAuthority(io.strimzi.api.kafka.model.CertificateAuthority) OwnerReferenceBuilder(io.fabric8.kubernetes.api.model.OwnerReferenceBuilder) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Reconciliation(io.strimzi.operator.common.Reconciliation) Mockito(org.mockito.Mockito) Kafka(io.strimzi.api.kafka.model.Kafka) OpenSslCertManager(io.strimzi.certs.OpenSslCertManager) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

Labels (io.strimzi.operator.common.model.Labels)80 Map (java.util.Map)52 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)50 Secret (io.fabric8.kubernetes.api.model.Secret)44 List (java.util.List)44 CoreMatchers.is (org.hamcrest.CoreMatchers.is)44 Collections (java.util.Collections)42 TestUtils (io.strimzi.test.TestUtils)40 Kafka (io.strimzi.api.kafka.model.Kafka)38 Reconciliation (io.strimzi.operator.common.Reconciliation)38 HashMap (java.util.HashMap)38 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)36 Future (io.vertx.core.Future)36 Vertx (io.vertx.core.Vertx)36 KafkaResources (io.strimzi.api.kafka.model.KafkaResources)34 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)34 ArrayList (java.util.ArrayList)34 Optional (java.util.Optional)34 BeforeAll (org.junit.jupiter.api.BeforeAll)34 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)34