use of org.eclipse.jkube.kit.enricher.api.model.Configuration in project jkube by eclipse.
the class AutoTLSEnricherTest method testAdapt.
@Test
public void testAdapt() {
final AdaptTestConfig[] data = new AdaptTestConfig[] { AdaptTestConfig.builder().mode(RuntimeMode.KUBERNETES).build(), new AdaptTestConfig(RuntimeMode.OPENSHIFT, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", null, "tls-pem", null, "tls-jks"), new AdaptTestConfig(RuntimeMode.OPENSHIFT, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", "tls-a", "tls-a", null, "tls-jks"), new AdaptTestConfig(RuntimeMode.OPENSHIFT, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", null, "tls-pem", "jks-b", "jks-b"), new AdaptTestConfig(RuntimeMode.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<String, Object> configMap = new TreeMap<>();
configMap.put("pemToJKSInitContainerName", tc.initContainerNameConfig);
configMap.put("pemToJKSInitContainerImage", tc.initContainerImageConfig);
configMap.put("tlsSecretVolumeName", tc.tlsSecretVolumeNameConfig);
configMap.put("jksVolumeName", tc.jksVolumeNameConfig);
final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap("jkube-openshift-autotls", configMap));
final Properties properties = new Properties();
properties.put(RuntimeMode.JKUBE_EFFECTIVE_PLATFORM_MODE, tc.mode.name());
// @formatter:off
new Expectations() {
{
Configuration configuration = Configuration.builder().processorConfig(config).build();
context.getProperties();
result = properties;
context.getConfiguration();
result = configuration;
}
};
// @formatter:on
AutoTLSEnricher enricher = new AutoTLSEnricher(context);
KubernetesListBuilder klb = new KubernetesListBuilder().addNewPodTemplateItem().withNewMetadata().and().withNewTemplate().withNewMetadata().and().withNewSpec().and().and().and().addNewServiceItem().and();
enricher.enrich(PlatformMode.kubernetes, klb);
PodTemplate pt = (PodTemplate) klb.buildItems().get(0);
Service service = (Service) klb.buildItems().get(1);
ObjectMeta om = service.getMetadata();
List<Container> initContainers = pt.getTemplate().getSpec().getInitContainers();
assertEquals(tc.mode == RuntimeMode.OPENSHIFT, !initContainers.isEmpty());
if (tc.mode == RuntimeMode.KUBERNETES) {
continue;
}
// Test metadata annotation
Map<String, String> generatedAnnotation = om.getAnnotations();
Assert.assertTrue(generatedAnnotation.containsKey(AutoTLSEnricher.AUTOTLS_ANNOTATION_KEY));
Assert.assertTrue(generatedAnnotation.containsValue(context.getGav().getArtifactId() + "-tls"));
// Test Pod template
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.initContainerImage, jo.get("image").getAsString());
// Test volumes are created
List<Volume> volumes = pt.getTemplate().getSpec().getVolumes();
assertEquals(2, volumes.size());
List<String> volumeNames = volumes.stream().map(Volume::getName).collect(Collectors.toList());
Assert.assertTrue(volumeNames.contains(tc.tlsSecretVolumeName));
Assert.assertTrue(volumeNames.contains(tc.jksVolumeName));
// Test volume mounts are created
JsonArray mounts = jo.get("volumeMounts").getAsJsonArray();
assertEquals(2, mounts.size());
JsonObject mount = mounts.get(0).getAsJsonObject();
assertEquals(tc.tlsSecretVolumeName, mount.get("name").getAsString());
mount = mounts.get(1).getAsJsonObject();
assertEquals(tc.jksVolumeName, mount.get("name").getAsString());
}
}
use of org.eclipse.jkube.kit.enricher.api.model.Configuration in project jkube by eclipse.
the class ImageEnricherTest method givenResourceConfigWithEnvVar.
private void givenResourceConfigWithEnvVar(String name, String value) {
// @formatter:off
new Expectations() {
{
Configuration configuration = Configuration.builder().resource(ResourceConfig.builder().env(Collections.singletonMap(name, value)).build()).image(imageConfiguration).build();
context.getConfiguration();
result = configuration;
}
};
// @formatter:on
}
use of org.eclipse.jkube.kit.enricher.api.model.Configuration 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.enricher.api.model.Configuration in project jkube by eclipse.
the class DefaultMetadataEnricherTest method setUp.
@Before
public void setUp() throws Exception {
Configuration configuration = Configuration.builder().resource(ResourceConfig.builder().annotations(MetaDataConfig.builder().all(properties("all-annotation", 1)).deployment(properties("deployment", "Deployment")).ingress(properties("ingress", "Ingress")).serviceAccount(properties("service-account", "ServiceAccount")).build()).labels(MetaDataConfig.builder().all(properties("all-label", 10L)).deployment(properties("deployment-label", "Deployment")).ingress(properties("ingress-label", "Ingress")).serviceAccount(properties("service-account-label", "ServiceAccount")).build()).build()).build();
// @formatter:off
new Expectations() {
{
buildContext.getConfiguration();
result = configuration;
}
};
// @formatter:on
defaultMetadataEnricher = new DefaultMetadataEnricher(buildContext);
configMap = new ConfigMapBuilder().withNewMetadata().endMetadata();
deployment = new DeploymentBuilder();
genericResource = new GenericKubernetesResourceBuilder().withNewMetadata().endMetadata();
ingressV1 = new io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder();
ingressV1beta1 = new io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder();
serviceAccount = new ServiceAccountBuilder();
klb = new KubernetesListBuilder().addToItems(configMap).addToItems(deployment).addToItems(genericResource).addToItems(ingressV1).addToItems(ingressV1beta1).addToItems(serviceAccount);
}
use of org.eclipse.jkube.kit.enricher.api.model.Configuration in project jkube by eclipse.
the class DefaultServiceEnricherTest method setupExpectations.
private void setupExpectations(final boolean withPorts, String... configParams) {
// Setup mock behaviour
final TreeMap<String, Object> config = new TreeMap<>();
for (int i = 0; i < configParams.length; i += 2) {
config.put(configParams[i], configParams[i + 1]);
}
new Expectations() {
{
Configuration configuration = Configuration.builder().image(imageConfiguration).processorConfig(new ProcessorConfig(null, null, Collections.singletonMap("jkube-service", config))).build();
context.getConfiguration();
result = configuration;
imageConfiguration.getBuildConfiguration();
result = initBuildConfig(withPorts);
}
};
}
Aggregations