Search in sources :

Example 66 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8 by fabric8io.

the class OpenShiftPipelineTest method testPipelinesFromConfigMap.

@Test
public void testPipelinesFromConfigMap() throws Exception {
    String namespace = "myproject";
    final ConfigMap configMap = loadTestConfigMap();
    server.expect().withPath("/api/v1/namespaces/" + namespace + "/configmaps/" + FABRIC8_PIPELINES).andReturn(200, configMap).once();
    PipelineConfiguration configuration = PipelineConfiguration.loadPipelineConfiguration(getKubernetesClient(), namespace);
    assertJobName(configuration, "foo", "dummy", PipelineKind.CD);
    assertJobName(configuration, "bar", "dummy", PipelineKind.CI);
    assertJobName(configuration, "whatnot", "dummy", PipelineKind.Developer);
    assertJobName(configuration, "random", "master", "git@github.com:fabric8io/random.git", PipelineKind.CD);
    assertJobName(configuration, "random", "master", "https://github.com/fabric8io/random.git", PipelineKind.CD);
    assertJobName(configuration, "random", "not-master", "https://github.com/fabric8io/random.git", PipelineKind.Developer);
    assertJobName(configuration, "random", "master", "https://github.com/bar/foo.git", PipelineKind.Developer);
    assertJobName(configuration, "random", "master", "git@github.com:bar/foo.git", PipelineKind.Developer);
    // lets show we can opt out of CD pipelines for specific builds in an organisation if required
    assertJobName(configuration, "random", "master", "https://github.com/random/whatnot.git", PipelineKind.Developer);
    assertJobName(configuration, "random", "release", "https://github.com/random/whatnot.git", PipelineKind.CD);
    assertJobName(configuration, "random", "whatever", "https://github.com/random/whatnot.git", PipelineKind.CI);
}
Also used : PipelineConfigurationParseTest.loadTestConfigMap(io.fabric8.kubernetes.api.pipelines.PipelineConfigurationParseTest.loadTestConfigMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Test(org.junit.Test)

Example 67 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8 by fabric8io.

the class PipelineConfigurationParseTest method testLoadMutateAndLoadPipelineConfiguration.

@Test
public void testLoadMutateAndLoadPipelineConfiguration() throws Exception {
    ConfigMap configMap = loadTestConfigMap();
    PipelineConfiguration pipelineConfiguration = PipelineConfiguration.getPipelineConfiguration(configMap);
    pipelineConfiguration.setCdBranchPatterns(Arrays.asList("cd-1", "cd-2"));
    pipelineConfiguration.setCiBranchPatterns(Arrays.asList("ci-1", "ci-2"));
    pipelineConfiguration.setJobNameToKindMap(new HashMap<>());
    pipelineConfiguration.setJobNamesCD("job-cd");
    pipelineConfiguration.setJobNamesCI("job-ci");
    HashMap<String, List<String>> cdGitHostAndOrganisationToBranchPatterns = new HashMap<>();
    cdGitHostAndOrganisationToBranchPatterns.put("github.com/acme", Arrays.asList("release1"));
    cdGitHostAndOrganisationToBranchPatterns.put("github.com/another", Arrays.asList("release2"));
    pipelineConfiguration.setCdGitHostAndOrganisationToBranchPatterns(cdGitHostAndOrganisationToBranchPatterns);
    // reload the modified configuration
    configMap = pipelineConfiguration.createConfigMap();
    pipelineConfiguration = PipelineConfiguration.getPipelineConfiguration(configMap);
    assertThat(pipelineConfiguration.getCdBranchPatterns()).describedAs("getCdBranchPatterns()").contains("cd-1").contains("cd-2");
    assertThat(pipelineConfiguration.getCiBranchPatterns()).describedAs("getCiBranchPatterns()").contains("ci-1").contains("ci-2");
    assertThat(pipelineConfiguration.getJobNameToKindMap()).describedAs("getJobNameToKindMap()").containsEntry("job-cd", PipelineKind.CD).containsEntry("job-ci", PipelineKind.CI);
    assertThat(pipelineConfiguration.getCdGitHostAndOrganisationToBranchPatterns()).describedAs("getCdGitHostAndOrganisationToBranchPatterns()").containsEntry("github.com/acme", Arrays.asList("release1")).containsEntry("github.com/another", Arrays.asList("release2"));
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) List(java.util.List) Test(org.junit.Test)

Example 68 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8 by fabric8io.

the class ConfigurationTest method testNamespaceFoundFromConfigMap.

@Test
public void testNamespaceFoundFromConfigMap() {
    String devNamespace = "myproject";
    String environmentKey = "testing";
    String testNamespace = "myproject-testing";
    Map<String, String> data = new HashMap<>();
    data.put(environmentKey, "    name: Testing\n" + "    namespace: " + testNamespace + "\n" + "    order: 0");
    server.expect().withPath("/api/v1/namespaces/" + devNamespace + "/configmaps/fabric8-environments").andReturn(200, new ConfigMapBuilder().withNewMetadata().withName("fabric8-environments").endMetadata().withData(data).build()).once();
    Map<String, String> map = new HashMap<>();
    map.put(FABRIC8_ENVIRONMENT, environmentKey);
    map.put(DEVELOPMENT_NAMESPACE, devNamespace);
    Configuration configuration = Configuration.fromMap(map, getKubernetesClient());
    assertEquals(testNamespace, configuration.getNamespace());
    assertTrue(configuration.isAnsiLoggerEnabled());
    assertTrue(configuration.isEnvironmentInitEnabled());
    assertTrue(configuration.isNamespaceLazyCreateEnabled());
    assertFalse(configuration.isNamespaceCleanupEnabled());
    assertFalse(configuration.isCreateNamespaceForTest());
}
Also used : HashMap(java.util.HashMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Test(org.junit.Test)

Example 69 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8 by fabric8io.

the class ConfigurationTest method testEnvironmentKeyButNoConfigMap.

@Test
public void testEnvironmentKeyButNoConfigMap() {
    String devNamespace = "myproject";
    String environmentKey = "testing";
    String testNamespace = devNamespace;
    Map<String, String> data = new HashMap<>();
    data.put("staging", "    name: Staging\n" + "    namespace: myproject-staging\n" + "    order: 0");
    server.expect().withPath("/api/v1/namespaces/" + devNamespace + "/configmaps/fabric8-environments").andReturn(404, "Not found").once();
    Map<String, String> map = new HashMap<>();
    map.put(FABRIC8_ENVIRONMENT, environmentKey);
    map.put(DEVELOPMENT_NAMESPACE, devNamespace);
    KubernetesClient kubernetesClient = getKubernetesClient();
    Config config = new Config();
    config.setNamespace(devNamespace);
    config.setMasterUrl(kubernetesClient.getMasterUrl().toString());
    DefaultKubernetesClient clientWithDefaultNamespace = new DefaultKubernetesClient(config);
    Configuration configuration = Configuration.fromMap(map, clientWithDefaultNamespace);
    assertEquals(testNamespace, configuration.getNamespace());
    assertTrue(configuration.isAnsiLoggerEnabled());
    assertTrue(configuration.isEnvironmentInitEnabled());
    assertTrue(configuration.isNamespaceLazyCreateEnabled());
    assertFalse(configuration.isNamespaceCleanupEnabled());
    assertFalse(configuration.isCreateNamespaceForTest());
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) HashMap(java.util.HashMap) Config(io.fabric8.kubernetes.client.Config) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Test(org.junit.Test)

Example 70 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8 by fabric8io.

the class ConfigurationTest method testNamespaceNotFoundFromConfigMap.

@Ignore
public void testNamespaceNotFoundFromConfigMap() {
    String devNamespace = "myproject";
    String environmentKey = "testing";
    String testNamespace = devNamespace;
    Map<String, String> data = new HashMap<>();
    data.put("staging", "    name: Staging\n" + "    namespace: myproject-staging\n" + "    order: 0");
    server.expect().withPath("/api/v1/namespaces/" + devNamespace + "/configmaps/fabric8-environments").andReturn(200, new ConfigMapBuilder().withNewMetadata().withName("fabric8-environments").endMetadata().withData(data).build()).once();
    Map<String, String> map = new HashMap<>();
    map.put(FABRIC8_ENVIRONMENT, environmentKey);
    map.put(DEVELOPMENT_NAMESPACE, devNamespace);
    Configuration configuration = Configuration.fromMap(map, kubernetesClient);
    assertEquals(testNamespace, configuration.getNamespace());
    assertTrue(configuration.isAnsiLoggerEnabled());
    assertTrue(configuration.isEnvironmentInitEnabled());
    assertTrue(configuration.isNamespaceLazyCreateEnabled());
    assertFalse(configuration.isNamespaceCleanupEnabled());
    assertFalse(configuration.isCreateNamespaceForTest());
}
Also used : HashMap(java.util.HashMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Ignore(org.junit.Ignore)

Aggregations

IOException (java.io.IOException)29 HashMap (java.util.HashMap)23 File (java.io.File)22 Configuration (org.osgi.service.cm.Configuration)20 Map (java.util.Map)16 BootstrapConfiguration (io.fabric8.zookeeper.bootstrap.BootstrapConfiguration)15 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)12 Container (io.fabric8.api.Container)11 Profile (io.fabric8.api.Profile)11 RuntimeProperties (io.fabric8.api.RuntimeProperties)9 HashSet (java.util.HashSet)9 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 FabricException (io.fabric8.api.FabricException)7 FabricService (io.fabric8.api.FabricService)7 Properties (java.util.Properties)7 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)6 Util.readAsString (io.fabric8.arquillian.utils.Util.readAsString)5 URL (java.net.URL)5