Search in sources :

Example 76 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.

the class ListEnvironments method main.

public static void main(String[] args) {
    KubernetesClient kubernetesClient = new DefaultKubernetesClient();
    Environments environments;
    if (args.length > 0) {
        String namespace = args[0];
        System.out.println("Listing environments for namespace: " + namespace);
        environments = Environments.load(namespace);
    } else {
        environments = Environments.load();
    }
    String environmentKey = "testing";
    if (args.length > 1) {
        environmentKey = args[1];
    }
    System.out.println("Space namespace: " + environments.getNamespace());
    SortedSet<Environment> set = environments.getEnvironmentSet();
    for (Environment environment : set) {
        String onCluster = "";
        String clusterAPiServer = environment.getClusterAPiServer();
        if (Strings.isNotBlank(clusterAPiServer)) {
            onCluster += " on API server: " + clusterAPiServer;
        }
        System.out.println("Environment " + environment.getName() + " maps to namespace: " + environment.getNamespace() + onCluster);
    }
    System.out.println("Namespace for environment key: " + environmentKey + " is " + Environments.namespaceForEnvironment(environmentKey));
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 77 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace 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 78 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.

the class SpacesTest method testLoadSpaces.

@Test
public void testLoadSpaces() {
    String namespace = "myproject";
    String resourceName = "fabric8-spaces.yml";
    KubernetesClient client = getKubernetesClient();
    URL resource = getClass().getClassLoader().getResource(resourceName);
    assertNotNull("Failed to load resource from classpath: " + resourceName, resourceName);
    InputStream inputStream = null;
    try {
        inputStream = resource.openStream();
    } catch (IOException e) {
        fail("Failed to open " + resourceName + ". " + e);
    }
    assertNotNull("Failed to open resource from classpath: " + resourceName, resourceName);
    ConfigMap configMap = null;
    try {
        configMap = KubernetesHelper.loadYaml(inputStream, ConfigMap.class);
    } catch (IOException e) {
        fail("Failed to parse YAML: " + resourceName + ". " + e);
    }
    server.expect().withPath("/api/v1/namespaces/" + namespace + "/configmaps/" + FABRIC8_SPACES).andReturn(200, configMap).once();
    Spaces spaces = Spaces.load(kubernetesClient, namespace);
    List<Space> spaceList = new ArrayList<>(spaces.getSpaceSet());
    assertEquals("Size of spaceList: " + spaceList, 3, spaceList.size());
    Space space0 = spaceList.get(0);
    assertEquals("space0.name", "Foo", space0.getName());
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL) Test(org.junit.Test)

Example 79 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.

the class ViewEndpoints method main.

public static void main(String... args) {
    System.out.println("Usage: [serviceId] [namespace]");
    KubernetesClient client = new DefaultKubernetesClient();
    try {
        String service = null;
        String namespace = null;
        if (args.length > 0) {
            service = args[0];
        }
        if (args.length > 1) {
            namespace = args[1];
        }
        listEndpoints(client, service, namespace);
    } catch (Exception e) {
        System.out.println("FAILED: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 80 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.

the class Routes method createRouteForService.

public static Route createRouteForService(String routeDomainPostfix, String namespace, Service service, Logger log) {
    Route route = null;
    String id = KubernetesHelper.getName(service);
    if (Strings.isNotBlank(id) && shouldCreateRouteForService(log, service, id)) {
        route = new Route();
        String routeId = id;
        KubernetesHelper.setName(route, namespace, routeId);
        RouteSpec routeSpec = new RouteSpec();
        RouteTargetReference objectRef = new RouteTargetReferenceBuilder().withName(id).build();
        // objectRef.setNamespace(namespace);
        routeSpec.setTo(objectRef);
        if (Strings.isNotBlank(routeDomainPostfix)) {
            // Let Openshift determine the route host when the domain is not set
            String host = Strings.stripSuffix(Strings.stripSuffix(id, "-service"), ".");
            String namespaceSuffix = "-" + namespace;
            routeSpec.setHost(host + namespaceSuffix + "." + Strings.stripPrefix(routeDomainPostfix, "."));
        }
        route.setSpec(routeSpec);
        String json = null;
        try {
            json = KubernetesHelper.toJson(route);
        } catch (JsonProcessingException e) {
            json = e.getMessage() + ". object: " + route;
        }
    }
    return route;
}
Also used : RouteTargetReference(io.fabric8.openshift.api.model.RouteTargetReference) RouteTargetReferenceBuilder(io.fabric8.openshift.api.model.RouteTargetReferenceBuilder) RouteSpec(io.fabric8.openshift.api.model.RouteSpec) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Route(io.fabric8.openshift.api.model.Route)

Aggregations

IOException (java.io.IOException)81 Test (org.junit.Test)78 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)74 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)65 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)60 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)59 HashMap (java.util.HashMap)59 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)58 FileNotFoundException (java.io.FileNotFoundException)49 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)48 OpenShiftNotAvailableException (io.fabric8.openshift.client.OpenShiftNotAvailableException)48 JSONObject (org.json.JSONObject)44 Service (io.fabric8.kubernetes.api.model.Service)38 Pod (io.fabric8.kubernetes.api.model.Pod)36 ArrayList (java.util.ArrayList)32 File (java.io.File)25 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)24 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)24 Map (java.util.Map)22 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)21