Search in sources :

Example 26 with User

use of io.fabric8.openshift.api.model.User in project strimzi by strimzi.

the class KafkaConnectS2IClusterTest method testGenerateSourceImageStream.

@Test
public void testGenerateSourceImageStream() {
    ImageStream is = kc.generateSourceImageStream();
    assertEquals(kc.getSourceImageStreamName(), is.getMetadata().getName());
    assertEquals(namespace, is.getMetadata().getNamespace());
    assertEquals(ResourceUtils.labels(Labels.STRIMZI_CLUSTER_LABEL, cluster, Labels.STRIMZI_TYPE_LABEL, "kafka-connect-s2i", "my-user-label", "cromulent", Labels.STRIMZI_NAME_LABEL, kc.getSourceImageStreamName()), is.getMetadata().getLabels());
    assertEquals(false, is.getSpec().getLookupPolicy().getLocal());
    assertEquals(1, is.getSpec().getTags().size());
    assertEquals(image.substring(image.lastIndexOf(":") + 1), is.getSpec().getTags().get(0).getName());
    assertEquals("DockerImage", is.getSpec().getTags().get(0).getFrom().getKind());
    assertEquals(image, is.getSpec().getTags().get(0).getFrom().getName());
}
Also used : ImageStream(io.fabric8.openshift.api.model.ImageStream) Test(org.junit.Test)

Example 27 with User

use of io.fabric8.openshift.api.model.User in project strimzi by strimzi.

the class KafkaConnectS2IClusterTest method testGenerateTargetImageStream.

@Test
public void testGenerateTargetImageStream() {
    ImageStream is = kc.generateTargetImageStream();
    assertEquals(kc.kafkaConnectClusterName(cluster), is.getMetadata().getName());
    assertEquals(namespace, is.getMetadata().getNamespace());
    assertEquals(ResourceUtils.labels(Labels.STRIMZI_CLUSTER_LABEL, cluster, Labels.STRIMZI_TYPE_LABEL, "kafka-connect-s2i", "my-user-label", "cromulent", Labels.STRIMZI_NAME_LABEL, kc.kafkaConnectClusterName(cluster)), is.getMetadata().getLabels());
    assertEquals(true, is.getSpec().getLookupPolicy().getLocal());
}
Also used : ImageStream(io.fabric8.openshift.api.model.ImageStream) Test(org.junit.Test)

Example 28 with User

use of io.fabric8.openshift.api.model.User in project strimzi by strimzi.

the class KafkaConnectS2IClusterTest method testGenerateService.

@Test
public void testGenerateService() {
    Service svc = kc.generateService();
    assertEquals("ClusterIP", svc.getSpec().getType());
    Map<String, String> expectedLabels = ResourceUtils.labels("my-user-label", "cromulent", Labels.STRIMZI_CLUSTER_LABEL, cluster, Labels.STRIMZI_TYPE_LABEL, "kafka-connect-s2i", Labels.STRIMZI_NAME_LABEL, kc.kafkaConnectClusterName(cluster));
    assertEquals(expectedLabels, svc.getMetadata().getLabels());
    assertEquals(expectedLabels, svc.getSpec().getSelector());
    assertEquals(1, svc.getSpec().getPorts().size());
    assertEquals(new Integer(KafkaConnectCluster.REST_API_PORT), svc.getSpec().getPorts().get(0).getPort());
    assertEquals(KafkaConnectCluster.REST_API_PORT_NAME, svc.getSpec().getPorts().get(0).getName());
    assertEquals("TCP", svc.getSpec().getPorts().get(0).getProtocol());
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) Test(org.junit.Test)

Example 29 with User

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

the class RunService method createContainerConfig.

// visible for testing
ContainerCreateConfig createContainerConfig(String imageName, RunImageConfiguration runConfig, PortMapping mappedPorts, GavLabel gavLabel, Properties mavenProps, File baseDir) throws DockerAccessException {
    try {
        ContainerCreateConfig config = new ContainerCreateConfig(imageName).hostname(runConfig.getHostname()).domainname(runConfig.getDomainname()).user(runConfig.getUser()).workingDir(runConfig.getWorkingDir()).entrypoint(runConfig.getEntrypoint()).exposedPorts(mappedPorts.getContainerPorts()).environment(runConfig.getEnvPropertyFile(), runConfig.getEnv(), mavenProps).labels(mergeLabels(runConfig.getLabels(), gavLabel)).command(runConfig.getCmd()).hostConfig(createContainerHostConfig(runConfig, mappedPorts, baseDir));
        RunVolumeConfiguration volumeConfig = runConfig.getVolumeConfiguration();
        if (volumeConfig != null) {
            resolveRelativeVolumeBindings(baseDir, volumeConfig);
            config.binds(volumeConfig.getBind());
        }
        NetworkConfig networkConfig = runConfig.getNetworkingConfig();
        if (networkConfig.isCustomNetwork() && networkConfig.hasAliases()) {
            ContainerNetworkingConfig networkingConfig = new ContainerNetworkingConfig().aliases(networkConfig);
            config.networkingConfig(networkingConfig);
        }
        return config;
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(String.format("Failed to create contained configuration for [%s]", imageName), e);
    }
}
Also used : RunVolumeConfiguration(io.fabric8.maven.docker.config.RunVolumeConfiguration) NetworkConfig(io.fabric8.maven.docker.config.NetworkConfig) ContainerCreateConfig(io.fabric8.maven.docker.access.ContainerCreateConfig) ContainerNetworkingConfig(io.fabric8.maven.docker.access.ContainerNetworkingConfig)

Example 30 with User

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

the class AuthConfigFactory method readAwsCredentials.

private AuthConfig readAwsCredentials(CloseableHttpClient client, HttpGet request) throws IOException {
    try (CloseableHttpResponse response = client.execute(request)) {
        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            log.debug("No security credential found, return code was %d", response.getStatusLine().getStatusCode());
            // no instance role found
            return null;
        }
        // read instance role
        try (Reader r = new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8)) {
            JsonObject securityCredentials = new Gson().fromJson(r, JsonObject.class);
            String user = securityCredentials.getAsJsonPrimitive("AccessKeyId").getAsString();
            String password = securityCredentials.getAsJsonPrimitive("SecretAccessKey").getAsString();
            String token = securityCredentials.getAsJsonPrimitive("Token").getAsString();
            log.debug("Received temporary access key %s...", user.substring(0, 8));
            return new AuthConfig(user, password, "none", token);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) AuthConfig(io.fabric8.maven.docker.access.AuthConfig)

Aggregations

Test (org.junit.Test)31 File (java.io.File)19 IOException (java.io.IOException)17 HashMap (java.util.HashMap)16 Git (org.eclipse.jgit.api.Git)12 AuthConfig (io.fabric8.maven.docker.access.AuthConfig)10 Map (java.util.Map)10 LinkedList (java.util.LinkedList)8 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 ObjectId (org.eclipse.jgit.lib.ObjectId)7 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)6 ArrayList (java.util.ArrayList)6 PatchException (io.fabric8.patch.management.PatchException)5 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)5 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)4 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)4 URL (java.net.URL)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)3