use of org.eclipse.jkube.kit.config.resource.ProcessorConfig in project jkube by eclipse.
the class MicronautHealthCheckEnricherTest method setUp.
@Before
public void setUp() {
properties = new Properties();
processorConfig = new ProcessorConfig();
klb = new KubernetesListBuilder();
klb.addToItems(new ServiceBuilder().withNewMetadata().withName("make-it-real").endMetadata().build());
// @formatter:off
new Expectations() {
{
context.getProperties();
result = properties;
context.getConfiguration().getProcessorConfig();
result = processorConfig;
}
};
// @formatter:on
micronautHealthCheckEnricher = new MicronautHealthCheckEnricher(context);
}
use of org.eclipse.jkube.kit.config.resource.ProcessorConfig in project jkube by eclipse.
the class IngressEnricherTest method testNetworkingV1IngressIsGenerated.
@Test
public void testNetworkingV1IngressIsGenerated() {
// Given
final TreeMap<String, Object> config = new TreeMap<>();
config.put("host", "test.192.168.39.25.nip.io");
config.put("targetApiVersion", "networking.k8s.io/v1");
new Expectations() {
{
Configuration configuration = Configuration.builder().image(imageConfiguration).processorConfig(new ProcessorConfig(null, null, Collections.singletonMap("jkube-ingress", config))).build();
context.getConfiguration();
result = configuration;
context.getProperty("jkube.createExternalUrls");
result = "true";
}
};
KubernetesListBuilder kubernetesListBuilder = new KubernetesListBuilder();
kubernetesListBuilder.addToItems(initTestService().build());
// When
ingressEnricher.create(PlatformMode.kubernetes, kubernetesListBuilder);
// Then
assertThat(kubernetesListBuilder).extracting(KubernetesListBuilder::buildItems).asList().hasSize(2).element(1).extracting("spec.rules").asList().extracting("host").containsExactly("test.192.168.39.25.nip.io");
}
use of org.eclipse.jkube.kit.config.resource.ProcessorConfig in project jkube by eclipse.
the class VolumePermissionEnricherTest method testAdapt.
@Test
public void testAdapt() {
final TestConfig[] data = new TestConfig[] { new TestConfig("busybox", null, null), new TestConfig("busybox1", null, null), new TestConfig("busybox", null, VolumePermissionEnricher.ENRICHER_NAME, "volumeA"), new TestConfig("busybox", null, VolumePermissionEnricher.ENRICHER_NAME, "volumeA", "volumeB") };
for (final TestConfig tc : data) {
final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(VolumePermissionEnricher.ENRICHER_NAME, Collections.singletonMap("permission", tc.permission)));
// Setup mock behaviour
new Expectations() {
{
context.getConfiguration();
result = Configuration.builder().processorConfig(config).build();
}
};
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.enrich(PlatformMode.kubernetes, klb);
PodTemplate pt = (PodTemplate) klb.buildItem(0);
List<Container> initContainers = pt.getTemplate().getSpec().getInitContainers();
boolean shouldHaveInitContainer = tc.volumeNames.length > 0;
assertEquals(shouldHaveInitContainer, !initContainers.isEmpty());
if (!shouldHaveInitContainer) {
continue;
}
Gson gson = new Gson();
JsonArray ja = new JsonParser().parse(gson.toJson(initContainers, new TypeToken<Collection<Container>>() {
}.getType())).getAsJsonArray();
assertEquals(1, ja.size());
JsonObject jo = ja.get(0).getAsJsonObject();
assertEquals(tc.initContainerName, jo.get("name").getAsString());
assertEquals(tc.imageName, jo.get("image").getAsString());
String permission = StringUtils.isBlank(tc.permission) ? "777" : tc.permission;
JsonArray chmodCmd = new JsonArray();
chmodCmd.add("chmod");
chmodCmd.add(permission);
for (String vn : tc.volumeNames) {
chmodCmd.add("/tmp/" + vn);
}
assertEquals(chmodCmd.toString(), jo.getAsJsonArray("command").toString());
}
}
use of org.eclipse.jkube.kit.config.resource.ProcessorConfig in project jkube by eclipse.
the class EnricherConfigTest method simple.
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
public void simple(@Mocked EnricherContext context) {
Map<String, Map<String, Object>> configMap = Collections.singletonMap("default.service", Collections.singletonMap("TYPE", "LoadBalancer"));
// @formatter:off
new Expectations() {
{
context.getConfiguration().getProcessorConfig();
result = new ProcessorConfig(null, null, configMap);
}
};
// @formatter:on
EnricherConfig config = new EnricherConfig("default.service", context);
assertEquals("LoadBalancer", config.get(EnricherConfigTest.Config.TYPE));
}
use of org.eclipse.jkube.kit.config.resource.ProcessorConfig in project jkube by eclipse.
the class DebugEnricherTest method setUp.
@Before
public void setUp() {
properties = new Properties();
processorConfig = new ProcessorConfig();
klb = new KubernetesListBuilder();
// @formatter:off
klb.addToItems(new DeploymentBuilder().editOrNewSpec().editOrNewTemplate().editOrNewMetadata().withName("template-name").endMetadata().editOrNewSpec().addNewContainer().withImage("container/image").endContainer().endSpec().endTemplate().endSpec().build());
new Expectations() {
{
context.getProperties();
result = properties;
context.getConfiguration().getProcessorConfig();
result = processorConfig;
}
};
// @formatter:on
}
Aggregations