use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.
the class AutoTLSEnricherTest method testAdapt.
@Test
public void testAdapt() throws Exception {
final AdaptTestConfig[] data = new AdaptTestConfig[] { new AdaptTestConfig(PlatformMode.kubernetes, null, null, null, null, null, null, null, null), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", null, "tls-pem", null, "tls-jks"), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", "tls-a", "tls-a", null, "tls-jks"), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", null, "tls-pem", "jks-b", "jks-b"), new AdaptTestConfig(PlatformMode.openshift, "test-container-name", "test-container-name", "image/123", "image/123", "tls-a", "tls-a", "jks-b", "jks-b") };
for (final AdaptTestConfig tc : data) {
TreeMap configMap = new TreeMap() {
{
put(AutoTLSEnricher.Config.pemToJKSInitContainerName.name(), tc.initContainerNameConfig);
put(AutoTLSEnricher.Config.pemToJKSInitContainerImage.name(), tc.initContainerImageConfig);
put(AutoTLSEnricher.Config.tlsSecretVolumeName.name(), tc.tlsSecretVolumeNameConfig);
put(AutoTLSEnricher.Config.jksVolumeName.name(), tc.jksVolumeNameConfig);
}
};
final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(AutoTLSEnricher.ENRICHER_NAME, configMap));
final Properties projectProps = new Properties();
projectProps.put(PlatformMode.FABRIC8_EFFECTIVE_PLATFORM_MODE, tc.mode.name());
// Setup mock behaviour
new Expectations() {
{
project.getProperties();
result = projectProps;
project.getArtifactId();
result = "projectA";
minTimes = 0;
context.getProject();
result = project;
context.getConfig();
result = config;
}
};
AutoTLSEnricher enricher = new AutoTLSEnricher(context);
KubernetesListBuilder klb = new KubernetesListBuilder().addNewPodTemplateItem().withNewMetadata().and().withNewTemplate().withNewMetadata().and().withNewSpec().and().and().and();
enricher.adapt(klb);
PodTemplate pt = (PodTemplate) klb.getItems().get(0);
String initContainers = pt.getTemplate().getMetadata().getAnnotations().get(InitContainerHandler.INIT_CONTAINER_ANNOTATION);
assertEquals(tc.mode == PlatformMode.openshift, initContainers != null);
if (tc.mode == PlatformMode.kubernetes) {
continue;
}
JSONArray ja = new JSONArray(initContainers);
assertEquals(1, ja.length());
JSONObject jo = ja.getJSONObject(0);
assertEquals(tc.initContainerName, jo.get("name"));
assertEquals(tc.initContainerImage, jo.get("image"));
JSONArray mounts = jo.getJSONArray("volumeMounts");
assertEquals(2, mounts.length());
JSONObject mount = mounts.getJSONObject(0);
assertEquals(tc.tlsSecretVolumeName, mount.get("name"));
mount = mounts.getJSONObject(1);
assertEquals(tc.jksVolumeName, mount.get("name"));
}
}
use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.
the class PrometheusEnricherTest method testCustomPrometheusPort.
// *******************************
// Tests
// *******************************
@Test
public void testCustomPrometheusPort() throws Exception {
final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(PrometheusEnricher.ENRICHER_NAME, new TreeMap(Collections.singletonMap(Config.prometheusPort.name(), "1234"))));
// Setup mock behaviour
new Expectations() {
{
context.getConfig();
result = config;
}
};
PrometheusEnricher enricher = new PrometheusEnricher(context);
Map<String, String> annotations = enricher.getAnnotations(Kind.SERVICE);
assertEquals(2, annotations.size());
assertEquals("1234", annotations.get(Annotations.Management.PROMETHEUS_PORT));
assertEquals("true", annotations.get(Annotations.Management.PROMETHEUS_SCRAPE));
}
use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.
the class PrometheusEnricherTest method testDetectPrometheusPort.
@Test
public void testDetectPrometheusPort() throws Exception {
final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(PrometheusEnricher.ENRICHER_NAME, new TreeMap()));
final BuildImageConfiguration imageConfig = new BuildImageConfiguration.Builder().ports(Arrays.asList(PrometheusEnricher.PROMETHEUS_PORT)).build();
// Setup mock behaviour
new Expectations() {
{
context.getConfig();
result = config;
imageConfiguration.getBuildConfiguration();
result = imageConfig;
context.getImages();
result = Arrays.asList(imageConfiguration);
}
};
PrometheusEnricher enricher = new PrometheusEnricher(context);
Map<String, String> annotations = enricher.getAnnotations(Kind.SERVICE);
assertEquals(2, annotations.size());
assertEquals("9779", annotations.get(Annotations.Management.PROMETHEUS_PORT));
assertEquals("true", annotations.get(Annotations.Management.PROMETHEUS_SCRAPE));
}
use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.
the class DefaultServiceEnricherTest method setupExpectations.
private void setupExpectations(final boolean withPorts, String... configParams) {
// Setup mock behaviour
final TreeMap config = new TreeMap();
for (int i = 0; i < configParams.length; i += 2) {
config.put(configParams[i], configParams[i + 1]);
}
new Expectations() {
{
context.getConfig();
result = new ProcessorConfig(null, null, Collections.singletonMap("fmp-service", config));
imageConfiguration.getBuildConfiguration();
result = getBuildConfig(withPorts);
context.getImages();
result = Arrays.asList(imageConfiguration);
}
};
}
use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.
the class VolumePermissionEnricherTest method testAdapt.
@Test
public void testAdapt() throws Exception {
final TestConfig[] data = new TestConfig[] { new TestConfig(null, null), new TestConfig(null, VolumePermissionEnricher.ENRICHER_NAME, "volumeA"), new TestConfig(null, VolumePermissionEnricher.ENRICHER_NAME, "volumeA", "volumeB") };
for (final TestConfig tc : data) {
final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(VolumePermissionEnricher.ENRICHER_NAME, new TreeMap(Collections.singletonMap(VolumePermissionEnricher.Config.permission.name(), tc.permission))));
// Setup mock behaviour
new Expectations() {
{
context.getConfig();
result = config;
}
};
VolumePermissionEnricher enricher = new VolumePermissionEnricher(context);
PodTemplateBuilder ptb = createEmptyPodTemplate();
for (String vn : tc.volumeNames) {
ptb = addVolume(ptb, vn);
}
KubernetesListBuilder klb = new KubernetesListBuilder().addToPodTemplateItems(ptb.build());
enricher.adapt(klb);
PodTemplate pt = (PodTemplate) klb.buildItem(0);
String initContainers = pt.getTemplate().getMetadata().getAnnotations().get(InitContainerHandler.INIT_CONTAINER_ANNOTATION);
boolean shouldHaveInitContainer = tc.volumeNames.length > 0;
assertEquals(shouldHaveInitContainer, initContainers != null);
if (!shouldHaveInitContainer) {
continue;
}
JSONArray ja = new JSONArray(initContainers);
assertEquals(1, ja.length());
JSONObject jo = ja.getJSONObject(0);
assertEquals(tc.initContainerName, jo.get("name"));
String permission = Strings.isNullOrBlank(tc.permission) ? "777" : tc.permission;
JSONArray chmodCmd = new JSONArray();
chmodCmd.put("chmod");
chmodCmd.put(permission);
for (String vn : tc.volumeNames) {
chmodCmd.put("/tmp/" + vn);
}
assertEquals(chmodCmd.toString(), jo.getJSONArray("command").toString());
}
}
Aggregations