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");
}
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;
}
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);
}
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));
}
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();
})));
}
Aggregations