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));
}
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);
}
}
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;
}
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());
}
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;
}
Aggregations