Search in sources :

Example 21 with ImageStream

use of io.fabric8.openshift.api.model.ImageStream in project che by eclipse.

the class OpenShiftConnector method pull.

/**
     * Creates an ImageStream that tracks the repository.
     *
     * <p>Note: This method does not cause the relevant image to actually be pulled to the local
     * repository, but creating the ImageStream is necessary as it is used to obtain
     * the address of the internal Docker registry later.
     *
     * @see DockerConnector#pull(PullParams, ProgressMonitor)
     */
@Override
public void pull(final PullParams params, final ProgressMonitor progressMonitor) throws IOException {
    // image to be pulled
    String repo = params.getFullRepo();
    // e.g. latest, usually
    String tag = params.getTag();
    String imageStreamName = KubernetesStringUtils.convertPullSpecToImageStreamName(repo);
    ImageStream existingImageStream = openShiftClient.imageStreams().inNamespace(openShiftCheProjectName).withName(imageStreamName).get();
    if (existingImageStream == null) {
        openShiftClient.imageStreams().inNamespace(openShiftCheProjectName).createNew().withNewMetadata().withName(// imagestream id
        imageStreamName).endMetadata().withNewSpec().addNewTag().withName(tag).endTag().withDockerImageRepository(// tracking repo
        repo).endSpec().withNewStatus().withDockerImageRepository("").endStatus().done();
    }
    // Wait for Image metadata to be obtained.
    ImageStream createdImageStream;
    for (int waitCount = 0; waitCount < OPENSHIFT_IMAGESTREAM_MAX_WAIT_COUNT; waitCount++) {
        try {
            Thread.sleep(OPENSHIFT_IMAGESTREAM_WAIT_DELAY);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        createdImageStream = openShiftClient.imageStreams().inNamespace(openShiftCheProjectName).withName(imageStreamName).get();
        if (createdImageStream != null && createdImageStream.getStatus().getDockerImageRepository() != null) {
            LOG.info(String.format("Created ImageStream %s.", imageStreamName));
            return;
        }
    }
    throw new OpenShiftException(String.format("Failed to create ImageStream %s.", imageStreamName));
}
Also used : OpenShiftException(org.eclipse.che.plugin.openshift.client.exception.OpenShiftException) ImageStream(io.fabric8.openshift.api.model.ImageStream)

Example 22 with ImageStream

use of io.fabric8.openshift.api.model.ImageStream in project che by eclipse.

the class OpenShiftConnector method createImageStreamTag.

/**
     * Creates a new ImageStreamTag
     *
     * @param sourceImageWithTag the image that the ImageStreamTag will track
     * @param imageStreamTagName the name of the imageStream tag (e.g. {@code <ImageStream name>:<Tag name>})
     * @return the created ImageStreamTag
     * @throws IOException When {@code sourceImageWithTag} metadata cannot be found
     */
private ImageStreamTag createImageStreamTag(String sourceImageWithTag, String imageStreamTagName) throws IOException {
    try {
        openShiftClient.imageStreamTags().inNamespace(openShiftCheProjectName).createOrReplaceWithNew().withNewMetadata().withName(imageStreamTagName).endMetadata().withNewTag().withNewFrom().withKind("DockerImage").withName(sourceImageWithTag).endFrom().endTag().done();
        // Wait for image metadata to be pulled
        for (int waitCount = 0; waitCount < OPENSHIFT_IMAGESTREAM_MAX_WAIT_COUNT; waitCount++) {
            Thread.sleep(OPENSHIFT_IMAGESTREAM_WAIT_DELAY);
            ImageStreamTag createdTag = openShiftClient.imageStreamTags().inNamespace(openShiftCheProjectName).withName(imageStreamTagName).get();
            if (createdTag != null) {
                LOG.info(String.format("Created ImageStreamTag %s in namespace %s", createdTag.getMetadata().getName(), openShiftCheProjectName));
                return createdTag;
            }
        }
        throw new ImageNotFoundException(String.format("Image %s not found.", sourceImageWithTag));
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException(e.getLocalizedMessage(), e);
    }
}
Also used : ImageStreamTag(io.fabric8.openshift.api.model.ImageStreamTag) IOException(java.io.IOException) ImageNotFoundException(org.eclipse.che.plugin.docker.client.exception.ImageNotFoundException)

Example 23 with ImageStream

use of io.fabric8.openshift.api.model.ImageStream in project vertx-openshift-it by cescoffier.

the class Deployment method findImageStream.

public static ImageStream findImageStream(KubernetesClient client, String name) {
    List<ImageStream> items = oc(client).imageStreams().list().getItems();
    for (ImageStream item : items) {
        if (item.getMetadata().getName().equalsIgnoreCase(name)) {
            return item;
        }
    }
    // Try in the "default" namespace
    items = oc(client).imageStreams().inNamespace("default").list().getItems();
    for (ImageStream item : items) {
        if (item.getMetadata().getName().equalsIgnoreCase(name)) {
            return item;
        }
    }
    return null;
}
Also used : ImageStream(io.fabric8.openshift.api.model.ImageStream)

Example 24 with ImageStream

use of io.fabric8.openshift.api.model.ImageStream in project jointware by isdream.

the class KubernetesKeyValueStyleGeneratorTest method testOpenShiftWithAllKind.

protected static void testOpenShiftWithAllKind() throws Exception {
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Policy());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Group());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new User());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new OAuthClient());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new ClusterRoleBinding());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new ImageStreamTag());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new ImageStream());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Build());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new BuildConfig());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new RoleBinding());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Route());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new PolicyBinding());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new OAuthAuthorizeToken());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Role());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Project());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new OAuthAccessToken());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new DeploymentConfig());
}
Also used : NetworkPolicy(io.fabric8.kubernetes.api.model.extensions.NetworkPolicy) Policy(io.fabric8.openshift.api.model.Policy) Group(io.fabric8.openshift.api.model.Group) User(io.fabric8.openshift.api.model.User) OAuthClient(io.fabric8.openshift.api.model.OAuthClient) ClusterRoleBinding(io.fabric8.openshift.api.model.ClusterRoleBinding) ImageStreamTag(io.fabric8.openshift.api.model.ImageStreamTag) ImageStream(io.fabric8.openshift.api.model.ImageStream) PolicyBinding(io.fabric8.openshift.api.model.PolicyBinding) OAuthAuthorizeToken(io.fabric8.openshift.api.model.OAuthAuthorizeToken) Role(io.fabric8.openshift.api.model.Role) Project(io.fabric8.openshift.api.model.Project) Build(io.fabric8.openshift.api.model.Build) OpenShiftDocumentKeyValueStyleGenerator(com.github.isdream.chameleon.docs.OpenShiftDocumentKeyValueStyleGenerator) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) OAuthAccessToken(io.fabric8.openshift.api.model.OAuthAccessToken) ClusterRoleBinding(io.fabric8.openshift.api.model.ClusterRoleBinding) RoleBinding(io.fabric8.openshift.api.model.RoleBinding) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Route(io.fabric8.openshift.api.model.Route)

Example 25 with ImageStream

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

the class KafkaConnectS2ICluster method fromAssembly.

/**
 * Create a Kafka Connect cluster from the deployed Deployment resource
 *
 * @param namespace Kubernetes/OpenShift namespace where cluster resources belong to
 * @param cluster   overall cluster name
 * @param dep The deployment from which to recover the cluster state
 * @param sis ImageStream
 * @return  Kafka Connect cluster instance
 */
public static KafkaConnectS2ICluster fromAssembly(String namespace, String cluster, DeploymentConfig dep, ImageStream sis) {
    KafkaConnectS2ICluster kafkaConnect = new KafkaConnectS2ICluster(namespace, cluster, Labels.fromResource(dep));
    kafkaConnect.setReplicas(dep.getSpec().getReplicas());
    kafkaConnect.setHealthCheckInitialDelay(dep.getSpec().getTemplate().getSpec().getContainers().get(0).getReadinessProbe().getInitialDelaySeconds());
    kafkaConnect.setHealthCheckTimeout(dep.getSpec().getTemplate().getSpec().getContainers().get(0).getReadinessProbe().getTimeoutSeconds());
    Map<String, String> vars = containerEnvVars(dep.getSpec().getTemplate().getSpec().getContainers().get(0));
    kafkaConnect.setBootstrapServers(vars.getOrDefault(KEY_BOOTSTRAP_SERVERS, DEFAULT_BOOTSTRAP_SERVERS));
    kafkaConnect.setGroupId(vars.getOrDefault(KEY_GROUP_ID, DEFAULT_GROUP_ID));
    kafkaConnect.setKeyConverter(vars.getOrDefault(KEY_KEY_CONVERTER, DEFAULT_KEY_CONVERTER));
    kafkaConnect.setKeyConverterSchemasEnable(Boolean.parseBoolean(vars.getOrDefault(KEY_KEY_CONVERTER_SCHEMAS_EXAMPLE, String.valueOf(DEFAULT_KEY_CONVERTER_SCHEMAS_EXAMPLE))));
    kafkaConnect.setValueConverter(vars.getOrDefault(KEY_VALUE_CONVERTER, DEFAULT_VALUE_CONVERTER));
    kafkaConnect.setValueConverterSchemasEnable(Boolean.parseBoolean(vars.getOrDefault(KEY_VALUE_CONVERTER_SCHEMAS_EXAMPLE, String.valueOf(DEFAULT_VALUE_CONVERTER_SCHEMAS_EXAMPLE))));
    kafkaConnect.setConfigStorageReplicationFactor(Integer.parseInt(vars.getOrDefault(KEY_CONFIG_STORAGE_REPLICATION_FACTOR, String.valueOf(DEFAULT_CONFIG_STORAGE_REPLICATION_FACTOR))));
    kafkaConnect.setOffsetStorageReplicationFactor(Integer.parseInt(vars.getOrDefault(KEY_OFFSET_STORAGE_REPLICATION_FACTOR, String.valueOf(DEFAULT_OFFSET_STORAGE_REPLICATION_FACTOR))));
    kafkaConnect.setStatusStorageReplicationFactor(Integer.parseInt(vars.getOrDefault(KEY_STATUS_STORAGE_REPLICATION_FACTOR, String.valueOf(DEFAULT_STATUS_STORAGE_REPLICATION_FACTOR))));
    String sourceImage = sis.getSpec().getTags().get(0).getFrom().getName();
    kafkaConnect.setImage(sourceImage);
    return kafkaConnect;
}
Also used : IntOrString(io.fabric8.kubernetes.api.model.IntOrString)

Aggregations

ImageStream (io.fabric8.openshift.api.model.ImageStream)21 IOException (java.io.IOException)11 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)9 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)9 Service (io.fabric8.kubernetes.api.model.Service)7 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)7 Test (org.junit.Test)7 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)6 Secret (io.fabric8.kubernetes.api.model.Secret)5 File (java.io.File)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)4 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)4 DoneableImageStream (io.fabric8.openshift.api.model.DoneableImageStream)4 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)4 Reconciliation (io.strimzi.controller.cluster.Reconciliation)4 KafkaConnectS2ICluster (io.strimzi.controller.cluster.model.KafkaConnectS2ICluster)4 BuildConfigOperator (io.strimzi.controller.cluster.operator.resource.BuildConfigOperator)4 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)4 DeploymentConfigOperator (io.strimzi.controller.cluster.operator.resource.DeploymentConfigOperator)4