Search in sources :

Example 1 with ProcessorConfig

use of org.eclipse.jkube.kit.config.resource.ProcessorConfig in project jkube by eclipse.

the class VertxHealthCheckEnricherTest method setupExpectations.

private void setupExpectations(Map<String, Object> config, TreeMap<String, String> plexusMavenConfig) {
    final ProcessorConfig processorConfig = new ProcessorConfig();
    processorConfig.setConfig(Collections.singletonMap("jkube-healthcheck-vertx", plexusMavenConfig));
    // @formatter:off
    new Expectations() {

        {
            context.hasPlugin(VertxHealthCheckEnricher.VERTX_MAVEN_PLUGIN_GROUP, VertxHealthCheckEnricher.VERTX_MAVEN_PLUGIN_ARTIFACT);
            result = true;
            context.getConfiguration().getProcessorConfig();
            result = processorConfig;
            minTimes = 0;
            context.getConfiguration().getPluginConfiguration(anyString, anyString);
            result = Optional.of(config);
            context.getConfiguration().getPluginConfigLookup();
            result = getProjectLookup(config);
            minTimes = 0;
        }
    };
// @formatter:on
}
Also used : Expectations(mockit.Expectations) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig)

Example 2 with ProcessorConfig

use of org.eclipse.jkube.kit.config.resource.ProcessorConfig in project jkube by eclipse.

the class DefaultResourceService method generateProfiledResourcesFromSubdirectories.

private List<HasMetadata> generateProfiledResourcesFromSubdirectories(PlatformMode platformMode, EnricherManager enricherManager) throws IOException {
    final List<HasMetadata> ret = new ArrayList<>();
    final File resourceDir = resourceServiceConfig.getResourceDir();
    File[] profileDirs = resourceDir.listFiles(File::isDirectory);
    if (profileDirs != null) {
        for (File profileDir : profileDirs) {
            Profile foundProfile = ProfileUtil.findProfile(profileDir.getName(), resourceDir);
            ProcessorConfig enricherConfig = foundProfile.getEnricherConfig();
            File[] resourceFiles = listResourceFragments(profileDir);
            final File[] processedResources = processResourceFiles(resourceFiles);
            if (processedResources.length > 0) {
                KubernetesListBuilder profileBuilder = readResourceFragments(platformMode, processedResources);
                enricherManager.createDefaultResources(platformMode, enricherConfig, profileBuilder);
                enricherManager.enrich(platformMode, enricherConfig, profileBuilder);
                ret.addAll(profileBuilder.buildItems());
            }
        }
    }
    return ret;
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ArrayList(java.util.ArrayList) File(java.io.File) Profile(org.eclipse.jkube.kit.profile.Profile) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig)

Example 3 with ProcessorConfig

use of org.eclipse.jkube.kit.config.resource.ProcessorConfig in project jkube by eclipse.

the class QuarkusGeneratorTest method setUp.

@Before
public void setUp() throws IOException {
    config = new ProcessorConfig();
    projectProps = new Properties();
    projectProps.put("jkube.generator.name", "quarkus");
    baseDir = temporaryFolder.newFolder("target");
    // @formatter:off
    new Expectations() {

        {
            project.getVersion();
            result = "0.0.1-SNAPSHOT";
            minTimes = 0;
            project.getBaseDirectory();
            result = baseDir;
            minTimes = 0;
            project.getBuildDirectory();
            result = baseDir.getAbsolutePath();
            minTimes = 0;
            project.getProperties();
            result = projectProps;
            project.getCompileClassPathElements();
            result = Collections.emptyList();
            minTimes = 0;
            project.getOutputDirectory();
            result = baseDir;
            ctx.getProject();
            result = project;
            ctx.getConfig();
            result = config;
            ctx.getStrategy();
            result = JKubeBuildStrategy.s2i;
            minTimes = 0;
            defaultImageLookup.getImageName("java.upstream.docker");
            result = "quarkus/docker";
            defaultImageLookup.getImageName("java.upstream.s2i");
            result = "quarkus/s2i";
        }
    };
// @formatter:on
}
Also used : Expectations(mockit.Expectations) Properties(java.util.Properties) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig) Before(org.junit.Before)

Example 4 with ProcessorConfig

use of org.eclipse.jkube.kit.config.resource.ProcessorConfig 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());
    }
}
Also used : Configuration(org.eclipse.jkube.kit.enricher.api.model.Configuration) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) Properties(java.util.Properties) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig) Container(io.fabric8.kubernetes.api.model.Container) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) JsonParser(com.google.gson.JsonParser) Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Service(io.fabric8.kubernetes.api.model.Service) TreeMap(java.util.TreeMap) JsonArray(com.google.gson.JsonArray) Volume(io.fabric8.kubernetes.api.model.Volume) TypeToken(com.google.common.reflect.TypeToken) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Example 5 with ProcessorConfig

use of org.eclipse.jkube.kit.config.resource.ProcessorConfig in project jkube by eclipse.

the class RouteEnricherTest method setUpExpectations.

@Before
public void setUpExpectations() {
    properties = new Properties();
    processorConfig = new ProcessorConfig();
    klb = new KubernetesListBuilder();
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) Properties(java.util.Properties) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig) Before(org.junit.Before)

Aggregations

ProcessorConfig (org.eclipse.jkube.kit.config.resource.ProcessorConfig)33 Expectations (mockit.Expectations)22 Before (org.junit.Before)14 Test (org.junit.Test)13 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)12 Properties (java.util.Properties)12 TreeMap (java.util.TreeMap)6 Configuration (org.eclipse.jkube.kit.enricher.api.model.Configuration)6 ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)4 DeploymentBuilder (io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)4 ArrayList (java.util.ArrayList)4 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)4 File (java.io.File)3 URLClassLoader (java.net.URLClassLoader)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ProjectClassLoaders (org.eclipse.jkube.kit.common.util.ProjectClassLoaders)3 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)3 TypeToken (com.google.common.reflect.TypeToken)2 Gson (com.google.gson.Gson)2