Search in sources :

Example 86 with Project

use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.

the class DeploymentHandlerTest method deploymentTemplateHandlerWithInvalidNameTest.

@Test(expected = IllegalArgumentException.class)
public void deploymentTemplateHandlerWithInvalidNameTest() {
    // invalid controller name
    ContainerHandler containerHandler = new ContainerHandler(project, envVarHandler, probeHandler);
    PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);
    DeploymentHandler deploymentHandler = new DeploymentHandler(podTemplateHandler);
    // with invalid controller name
    ResourceConfig config = new ResourceConfig.Builder().imagePullPolicy("IfNotPresent").controllerName("TesTing").withServiceAccount("test-account").withReplicas(5).volumes(volumes1).build();
    deploymentHandler.getDeployment(config, images);
}
Also used : ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) Test(org.junit.Test)

Example 87 with Project

use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.

the class AutoTLSEnricherTest method testSecretName.

@Test
public void testSecretName() throws Exception {
    final SecretNameTestConfig[] data = new SecretNameTestConfig[] { new SecretNameTestConfig(PlatformMode.kubernetes, null, null), new SecretNameTestConfig(PlatformMode.openshift, null, "projectA-tls"), new SecretNameTestConfig(PlatformMode.openshift, "custom-secret", "custom-secret") };
    for (final SecretNameTestConfig tc : data) {
        final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(AutoTLSEnricher.ENRICHER_NAME, new TreeMap(Collections.singletonMap(AutoTLSEnricher.Config.tlsSecretName.name(), tc.tlsSecretNameConfig))));
        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);
        Map<String, String> annotations = enricher.getAnnotations(Kind.SERVICE);
        if (tc.mode == PlatformMode.kubernetes) {
            assertNull(annotations);
            continue;
        }
        assertEquals(1, annotations.size());
        assertEquals(tc.tlsSecretName, annotations.get(AutoTLSEnricher.AUTOTLS_ANNOTATION_KEY));
    }
}
Also used : Expectations(mockit.Expectations) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Example 88 with Project

use of io.fabric8.openshift.api.model.Project 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"));
    }
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) Test(org.junit.Test)

Example 89 with Project

use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.

the class AbstractSpringBootHealthCheckEnricherSupport method init.

@Before
public void init() {
    String version = getSpringBootVersion();
    this.propertyHelper = new SpringBootConfigurationHelper(version);
    final MavenProject project = new MavenProject();
    Set<Artifact> artifacts = new HashSet<>();
    Artifact a = new DefaultArtifact("org.springframework.boot", "spring-boot", version, "compile", "jar", "", null);
    a.setResolved(true);
    artifacts.add(a);
    project.setArtifacts(artifacts);
    new Expectations() {

        {
            context.getProject();
            result = project;
        }
    };
}
Also used : Expectations(mockit.Expectations) SpringBootConfigurationHelper(io.fabric8.maven.core.util.SpringBootConfigurationHelper) MavenProject(org.apache.maven.project.MavenProject) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Before(org.junit.Before)

Example 90 with Project

use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.

the class ImportMojo method createGithubProjectAndUserDetails.

protected UserDetails createGithubProjectAndUserDetails(KubernetesClient kubernetes, String namespace) throws MojoExecutionException {
    log.info("Creating Project on GitHub");
    String url = "https://api.github.com";
    UserDetails userDetails = null;
    String secretNamespace = getSecretNamespace();
    ensureNamespaceExists(kubernetes, secretNamespace);
    ConfigMap configMap = getSecretGitConfigMap(kubernetes, namespace, secretNamespace);
    String host = convertToValidDnsLabel(currentUserName() + "-github.com");
    String currentSecretName = configMap.getData().get(host);
    if (currentSecretName == null) {
        currentSecretName = createGitSecretName(namespace, host);
    }
    Secret secret = findOrCreateGitSecret(kubernetes, currentSecretName, host);
    // FIXME: Rename the methods to be generic
    // if empty or retrying lets re-enter the user/pwd
    gitUserName = getGogsSecretField(kubernetes, secret, host, "username");
    gitPassword = getGogsSecretField(kubernetes, secret, host, "password");
    if (Strings.isNullOrBlank(gitEmail)) {
        gitEmail = findEmailFromDotGitConfig();
    }
    createOrUpdateSecret(kubernetes, secret);
    updateSecretGitConfigMap(kubernetes, secretNamespace, configMap, host, currentSecretName);
    return new UserDetails("https://api.github.com", "https://api.github.com", gitUserName, gitPassword, gitEmail);
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) UserDetails(io.fabric8.project.support.UserDetails) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap)

Aggregations

Test (org.junit.Test)51 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)29 File (java.io.File)14 Expectations (mockit.Expectations)14 ArrayList (java.util.ArrayList)13 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)11 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)11 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)9 IOException (java.io.IOException)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)7 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)6 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)6 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)5 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)5 MojoFailureException (org.apache.maven.plugin.MojoFailureException)5 MavenProject (org.apache.maven.project.MavenProject)5 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3