Search in sources :

Example 16 with Dummy

use of io.fabric8.kubernetes.examples.crds.Dummy in project fabric8 by jboss-fuse.

the class ServiceFactoryTest method testDiscoveryOnRestartCurator.

@Test
public void testDiscoveryOnRestartCurator() throws Exception {
    underTest = new ActiveMQServiceFactory();
    underTest.curator = curator;
    Properties props = new Properties();
    props.put("config", "amq.xml");
    props.put("broker-name", "amq");
    props.put("group", "amq");
    props.put("connectors", "openwire");
    props.put("openwire-port", "0");
    props.put("container.ip", "localhost");
    underTest.updated("b", props);
    final AtomicReference<CuratorFramework> curatorFrameworkAtomicReference = new AtomicReference<>(curator);
    OsgiFabricDiscoveryAgent osgiFabricDiscoveryAgent = new OsgiFabricDiscoveryAgent(new BundleContext() {

        @Override
        public String getProperty(String s) {
            return null;
        }

        @Override
        public Bundle getBundle() {
            return null;
        }

        @Override
        public Bundle installBundle(String s, InputStream inputStream) throws BundleException {
            return null;
        }

        @Override
        public Bundle installBundle(String s) throws BundleException {
            return null;
        }

        @Override
        public Bundle getBundle(long l) {
            return null;
        }

        @Override
        public Bundle[] getBundles() {
            return new Bundle[0];
        }

        @Override
        public void addServiceListener(ServiceListener serviceListener, String s) throws InvalidSyntaxException {
        }

        @Override
        public void addServiceListener(ServiceListener serviceListener) {
        }

        @Override
        public void removeServiceListener(ServiceListener serviceListener) {
        }

        @Override
        public void addBundleListener(BundleListener bundleListener) {
        }

        @Override
        public void removeBundleListener(BundleListener bundleListener) {
        }

        @Override
        public void addFrameworkListener(FrameworkListener frameworkListener) {
        }

        @Override
        public void removeFrameworkListener(FrameworkListener frameworkListener) {
        }

        @Override
        public ServiceRegistration<?> registerService(String[] strings, Object o, Dictionary<String, ?> dictionary) {
            return null;
        }

        @Override
        public ServiceRegistration<?> registerService(String s, Object o, Dictionary<String, ?> dictionary) {
            return null;
        }

        @Override
        public <S> ServiceRegistration<S> registerService(Class<S> aClass, S s, Dictionary<String, ?> dictionary) {
            return null;
        }

        @Override
        public ServiceReference<?>[] getServiceReferences(String s, String s1) throws InvalidSyntaxException {
            return new ServiceReference<?>[0];
        }

        @Override
        public ServiceReference<?>[] getAllServiceReferences(String s, String s1) throws InvalidSyntaxException {
            return new ServiceReference<?>[0];
        }

        @Override
        public ServiceReference<?> getServiceReference(String s) {
            return null;
        }

        @Override
        public <S> ServiceReference<S> getServiceReference(Class<S> aClass) {
            return null;
        }

        @Override
        public <S> Collection<ServiceReference<S>> getServiceReferences(Class<S> aClass, String s) throws InvalidSyntaxException {
            return null;
        }

        @Override
        public <S> S getService(ServiceReference<S> serviceReference) {
            return (S) curatorFrameworkAtomicReference.get();
        }

        @Override
        public boolean ungetService(ServiceReference<?> serviceReference) {
            return false;
        }

        @Override
        public File getDataFile(String s) {
            return null;
        }

        @Override
        public Filter createFilter(String s) throws InvalidSyntaxException {
            return null;
        }

        @Override
        public Bundle getBundle(String s) {
            return null;
        }
    });
    final LinkedBlockingQueue<DiscoveryEvent> discoveryEvents = new LinkedBlockingQueue<DiscoveryEvent>(10);
    osgiFabricDiscoveryAgent.setDiscoveryListener(new DiscoveryListener() {

        @Override
        public void onServiceAdd(DiscoveryEvent discoveryEvent) {
            discoveryEvents.offer(discoveryEvent);
        }

        @Override
        public void onServiceRemove(DiscoveryEvent discoveryEvent) {
        }
    });
    // will call into dummy bundle and get curator
    osgiFabricDiscoveryAgent.addingService(null);
    osgiFabricDiscoveryAgent.setGroupName("amq");
    osgiFabricDiscoveryAgent.start();
    DiscoveryEvent event = discoveryEvents.poll(5, TimeUnit.SECONDS);
    LOG.info("event: " + event);
    assertNotNull("got added service", event);
    underTest.deleted("b");
    // swap curator ref
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).sessionTimeoutMs(15000).retryPolicy(new RetryNTimes(5000, 1000));
    curator = builder.build();
    LOG.debug("Starting new curator " + curator);
    curator.start();
    curatorFrameworkAtomicReference.get().close();
    curatorFrameworkAtomicReference.set(curator);
    // will call into dummy bundle and get new curator ref
    osgiFabricDiscoveryAgent.addingService(null);
    // start broker again
    underTest.curator = curator;
    underTest.updated("b", props);
    event = discoveryEvents.poll(5, TimeUnit.SECONDS);
    LOG.info("new event: " + event);
    assertNotNull("got newly added service", event);
    underTest.deleted("b");
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) DiscoveryEvent(org.apache.activemq.command.DiscoveryEvent) Properties(java.util.Properties) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryNTimes(org.apache.curator.retry.RetryNTimes) InputStream(java.io.InputStream) AtomicReference(java.util.concurrent.atomic.AtomicReference) OsgiFabricDiscoveryAgent(io.fabric8.mq.fabric.discovery.OsgiFabricDiscoveryAgent) Collection(java.util.Collection) File(java.io.File) DiscoveryListener(org.apache.activemq.transport.discovery.DiscoveryListener) Test(org.junit.Test)

Example 17 with Dummy

use of io.fabric8.kubernetes.examples.crds.Dummy in project fabric8 by jboss-fuse.

the class DevOpsConnectors method createDevOpsConnector.

/**
 * Returns a DevOpsConnector for the given project repository
 */
public static DevOpsConnector createDevOpsConnector(ProjectRepository project) {
    DevOpsConnector connector = new DevOpsConnector();
    connector.setGitUrl(project.getGitUrl());
    String repoName = project.getRepoName();
    connector.setRepoName(repoName);
    String username = project.getUser();
    connector.setUsername(username);
    String buildName = ProjectRepositories.createBuildName(username, repoName);
    if (project.isGitHubProject()) {
        // lets default the issue tracker
        String url = project.getUrl();
        if (Strings.isNotBlank(url)) {
            connector.setIssueTrackerUrl(URLUtils.pathJoin(url, "issues"));
            connector.setTeamUrl(URLUtils.pathJoin(url, "graphs/contributors"));
            connector.setReleasesUrl(URLUtils.pathJoin(url, "tags"));
            connector.setRepositoryBrowseLink(url);
        }
        ProjectConfig config = ProjectConfigs.loadFromUrl(URLUtils.pathJoin(url, "blob/master/fabric8.yml"));
        if (config == null) {
            config = new ProjectConfig();
            // lets add a dummy build so we can at least build snapshots on demand in OpenShift
            config.setPipeline("maven/Deploy.groovy");
        }
        config.setBuildName(buildName);
        connector.setProjectConfig(config);
        connector.setRegisterWebHooks(false);
        System.out.println("Created config " + config.getBuildName() + " with flow " + config.getPipeline());
    }
    return connector;
}
Also used : ProjectConfig(io.fabric8.devops.ProjectConfig)

Example 18 with Dummy

use of io.fabric8.kubernetes.examples.crds.Dummy in project fabric8 by fabric8io.

the class OpenShiftPipelineTest method testPipelinesFromConfigMap.

@Test
public void testPipelinesFromConfigMap() throws Exception {
    String namespace = "myproject";
    final ConfigMap configMap = loadTestConfigMap();
    server.expect().withPath("/api/v1/namespaces/" + namespace + "/configmaps/" + FABRIC8_PIPELINES).andReturn(200, configMap).once();
    PipelineConfiguration configuration = PipelineConfiguration.loadPipelineConfiguration(getKubernetesClient(), namespace);
    assertJobName(configuration, "foo", "dummy", PipelineKind.CD);
    assertJobName(configuration, "bar", "dummy", PipelineKind.CI);
    assertJobName(configuration, "whatnot", "dummy", PipelineKind.Developer);
    assertJobName(configuration, "random", "master", "git@github.com:fabric8io/random.git", PipelineKind.CD);
    assertJobName(configuration, "random", "master", "https://github.com/fabric8io/random.git", PipelineKind.CD);
    assertJobName(configuration, "random", "not-master", "https://github.com/fabric8io/random.git", PipelineKind.Developer);
    assertJobName(configuration, "random", "master", "https://github.com/bar/foo.git", PipelineKind.Developer);
    assertJobName(configuration, "random", "master", "git@github.com:bar/foo.git", PipelineKind.Developer);
    // lets show we can opt out of CD pipelines for specific builds in an organisation if required
    assertJobName(configuration, "random", "master", "https://github.com/random/whatnot.git", PipelineKind.Developer);
    assertJobName(configuration, "random", "release", "https://github.com/random/whatnot.git", PipelineKind.CD);
    assertJobName(configuration, "random", "whatever", "https://github.com/random/whatnot.git", PipelineKind.CI);
}
Also used : PipelineConfigurationParseTest.loadTestConfigMap(io.fabric8.kubernetes.api.pipelines.PipelineConfigurationParseTest.loadTestConfigMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Test(org.junit.Test)

Example 19 with Dummy

use of io.fabric8.kubernetes.examples.crds.Dummy in project strimzi by strimzi.

the class ClusterCaTest method testNotRemoveOldCertificateWithCustomCa.

@ParallelTest
public void testNotRemoveOldCertificateWithCustomCa() {
    Map<String, String> clusterCaCertData = new HashMap<>();
    clusterCaCertData.put(Ca.CA_CRT, Base64.getEncoder().encodeToString("dummy-crt".getBytes()));
    clusterCaCertData.put(Ca.CA_STORE, Base64.getEncoder().encodeToString("dummy-p12".getBytes()));
    clusterCaCertData.put(Ca.CA_STORE_PASSWORD, Base64.getEncoder().encodeToString("dummy-password".getBytes()));
    Secret clusterCaCert = new SecretBuilder().withNewMetadata().withName("my-cluster-cluster-ca-cert").endMetadata().withData(clusterCaCertData).build();
    Map<String, String> clusterCaKeyData = new HashMap<>();
    clusterCaKeyData.put(Ca.CA_KEY, Base64.getEncoder().encodeToString("dummy-key".getBytes()));
    Secret clusterCaKey = new SecretBuilder().withNewMetadata().withName("my-cluster-cluster-ca").endMetadata().withData(clusterCaKeyData).build();
    ClusterCa clusterCa = new ClusterCa(Reconciliation.DUMMY_RECONCILIATION, new OpenSslCertManager(), new PasswordGenerator(10, "a", "a"), cluster, clusterCaCert, clusterCaKey, 0, 0, false, CertificateExpirationPolicy.RENEW_CERTIFICATE);
    // simulate a renewal with new private key ...
    clusterCaKeyData.put(Ca.CA_KEY, Base64.getEncoder().encodeToString("new-dummy-key".getBytes()));
    clusterCaKey.setData(clusterCaKeyData);
    // ... also saving the old certificate
    clusterCaCertData.put("ca-2023-03-23T09-00-00Z.crt", clusterCaCertData.get(Ca.CA_CRT));
    clusterCaCertData.put(Ca.CA_CRT, Base64.getEncoder().encodeToString("new-dummy-crt".getBytes()));
    clusterCaCertData.put(Ca.CA_STORE, Base64.getEncoder().encodeToString("updated-dummy-p12".getBytes()));
    clusterCaCert.setData(clusterCaCertData);
    clusterCa.maybeDeleteOldCerts();
    // checking that the cluster CA related Secret was not touched by the operator
    Map<String, String> clusterCaCertDataInSecret = clusterCa.caCertSecret().getData();
    assertThat(clusterCaCertDataInSecret.size(), is(4));
    assertThat(new String(Base64.getDecoder().decode(clusterCaCertDataInSecret.get(Ca.CA_CRT))).equals("new-dummy-crt"), is(true));
    assertThat(new String(Base64.getDecoder().decode(clusterCaCertDataInSecret.get(Ca.CA_STORE))).equals("updated-dummy-p12"), is(true));
    assertThat(new String(Base64.getDecoder().decode(clusterCaCertDataInSecret.get(Ca.CA_STORE_PASSWORD))).equals("dummy-password"), is(true));
    assertThat(new String(Base64.getDecoder().decode(clusterCaCertDataInSecret.get("ca-2023-03-23T09-00-00Z.crt"))).equals("dummy-crt"), is(true));
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) OpenSslCertManager(io.strimzi.certs.OpenSslCertManager) HashMap(java.util.HashMap) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 20 with Dummy

use of io.fabric8.kubernetes.examples.crds.Dummy 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

Test (org.junit.jupiter.api.Test)16 Test (org.junit.Test)12 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)8 Pod (io.fabric8.kubernetes.api.model.Pod)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 Secret (io.fabric8.kubernetes.api.model.Secret)6 List (java.util.List)6 GenericKubernetesResource (io.fabric8.kubernetes.api.model.GenericKubernetesResource)5 KubernetesClientBuilder (io.fabric8.kubernetes.client.KubernetesClientBuilder)5 Resource (io.fabric8.kubernetes.client.dsl.Resource)5 Date (java.util.Date)5 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)4 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)4 KubernetesVersion (io.strimzi.operator.KubernetesVersion)4 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)4 ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)4 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)4 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)4 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)4