use of io.fabric8.openshift.api.model.ImageStream in project strimzi by strimzi.
the class KafkaConnectS2ICluster method generateSourceImageStream.
/**
* Generate new source ImageStream
*
* @return Source ImageStream resource definition
*/
public ImageStream generateSourceImageStream() {
ObjectReference image = new ObjectReference();
image.setKind("DockerImage");
image.setName(sourceImageBaseName + ":" + sourceImageTag);
TagReference sourceTag = new TagReference();
sourceTag.setName(sourceImageTag);
sourceTag.setFrom(image);
ImageStream imageStream = new ImageStreamBuilder().withNewMetadata().withName(getSourceImageStreamName()).withNamespace(namespace).withLabels(getLabelsWithName(getSourceImageStreamName())).endMetadata().withNewSpec().withLookupPolicy(new ImageLookupPolicyBuilder().withLocal(false).build()).withTags(sourceTag).endSpec().build();
return imageStream;
}
use of io.fabric8.openshift.api.model.ImageStream in project strimzi by strimzi.
the class KafkaConnectS2ICluster method generateDeploymentConfig.
/**
* Generate new DeploymentConfig
*
* @return Source ImageStream resource definition
*/
public DeploymentConfig generateDeploymentConfig() {
Container container = new ContainerBuilder().withName(name).withImage(image).withEnv(getEnvVars()).withPorts(Collections.singletonList(createContainerPort(REST_API_PORT_NAME, REST_API_PORT, "TCP"))).withLivenessProbe(createHttpProbe(healthCheckPath, REST_API_PORT_NAME, healthCheckInitialDelay, healthCheckTimeout)).withReadinessProbe(createHttpProbe(healthCheckPath, REST_API_PORT_NAME, healthCheckInitialDelay, healthCheckTimeout)).build();
DeploymentTriggerPolicy configChangeTrigger = new DeploymentTriggerPolicyBuilder().withType("ConfigChange").build();
DeploymentTriggerPolicy imageChangeTrigger = new DeploymentTriggerPolicyBuilder().withType("ImageChange").withNewImageChangeParams().withAutomatic(true).withContainerNames(name).withNewFrom().withKind("ImageStreamTag").withName(image).endFrom().endImageChangeParams().build();
DeploymentStrategy updateStrategy = new DeploymentStrategyBuilder().withType("Rolling").withNewRollingParams().withMaxSurge(new IntOrString(1)).withMaxUnavailable(new IntOrString(0)).endRollingParams().build();
DeploymentConfig dc = new DeploymentConfigBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithName()).withNamespace(namespace).endMetadata().withNewSpec().withReplicas(replicas).withNewTemplate().withNewMetadata().withLabels(getLabelsWithName()).endMetadata().withNewSpec().withContainers(container).endSpec().endTemplate().withTriggers(configChangeTrigger, imageChangeTrigger).withStrategy(updateStrategy).endSpec().build();
return dc;
}
use of io.fabric8.openshift.api.model.ImageStream in project fabric8-maven-plugin by fabric8io.
the class ImageStreamService method appendImageStreamResource.
/**
* Save the images stream to a file
* @param imageName name of the image for which the stream should be extracted
* @param target file to store the image stream
*/
public void appendImageStreamResource(ImageName imageName, File target) throws MojoExecutionException {
String tag = Strings.isNullOrBlank(imageName.getTag()) ? "latest" : imageName.getTag();
try {
ImageStream is = new ImageStreamBuilder().withNewMetadata().withName(imageName.getSimpleName()).endMetadata().withNewSpec().addNewTag().withName(tag).withNewFrom().withKind("ImageStreamImage").endFrom().endTag().endSpec().build();
createOrUpdateImageStreamTag(client, imageName, is);
File fullTargetFile = appendImageStreamToFile(is, target);
log.info("ImageStream %s written to %s", imageName.getSimpleName(), fullTargetFile);
} catch (KubernetesClientException e) {
KubernetesResourceUtil.handleKubernetesClientException(e, this.log);
} catch (IOException e) {
throw new MojoExecutionException(String.format("Cannot write ImageStream descriptor for %s to %s : %s", imageName.getFullName(), target.getAbsoluteFile(), e.getMessage()), e);
}
}
use of io.fabric8.openshift.api.model.ImageStream in project fabric8-maven-plugin by fabric8io.
the class ImageStreamServiceTest method simple.
@Test
public void simple() throws IOException, MojoExecutionException {
ImageStreamService service = new ImageStreamService(client, log);
final ImageStream lookedUpIs = lookupImageStream("ab12cd");
setupClientMock(lookedUpIs, "test");
ImageName name = new ImageName("test:1.0");
File target = File.createTempFile("ImageStreamServiceTest", ".yml");
service.appendImageStreamResource(name, target);
assertTrue(target.exists());
Map result = readImageStreamDescriptor(target);
Yaml yaml;
System.out.println(result.toString());
assertNotNull(result);
List<Map> items = getItemsList(result);
assertEquals(1, items.size());
Map isRead = (Map<String, Object>) items.get(0);
assertNotNull(isRead);
assertEquals("ImageStream", isRead.get("kind"));
Map spec = (Map<String, Object>) isRead.get("spec");
assertNotNull(spec);
List tags = (List) spec.get("tags");
assertNotNull(tags);
assertEquals(1, tags.size());
Map tag = (Map) tags.get(0);
Map from = (Map) tag.get("from");
assertEquals("ImageStreamImage", from.get("kind"));
assertEquals("test@ab12cd", from.get("name"));
assertEquals("default", from.get("namespace"));
// Add a second image stream
ImageStream secondIs = lookupImageStream("secondIS");
setupClientMock(secondIs, "second-test");
ImageName name2 = new ImageName("second-test:1.0");
service.appendImageStreamResource(name2, target);
result = readImageStreamDescriptor(target);
System.out.println(result.toString());
items = getItemsList(result);
assertEquals(2, items.size());
Set<String> names = new HashSet<>(Arrays.asList("second-test", "test"));
for (Map item : items) {
assertTrue(names.remove(((Map) item.get("metadata")).get("name")));
}
assertTrue(names.isEmpty());
}
use of io.fabric8.openshift.api.model.ImageStream in project kie-wb-common by kiegroup.
the class OpenShiftClient method destroy.
public void destroy(String id) throws OpenShiftClientException {
try {
OpenShiftRuntimeId runtimeId = OpenShiftRuntimeId.fromString(id);
String prjName = runtimeId.project();
String svcName = runtimeId.service();
// TODO: should we always depend on the app label being specified, or gotten from the service?
String appName = runtimeId.application();
if (appName == null || appName.isEmpty()) {
Service service = delegate.services().inNamespace(prjName).withName(svcName).get();
if (service != null) {
appName = service.getMetadata().getLabels().get(APP_LABEL);
}
}
/*
* cascading delete of deploymentConfigs means we don't have to also do the following:
* delegate.deploymentConfigs().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
* delegate.replicationControllers().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
* delegate.pods().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
* , but deleting services and routes are still necessary:
*/
delegate.deploymentConfigs().inNamespace(prjName).withName(svcName).cascading(true).delete();
if (appName != null) {
delegate.services().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
delegate.routes().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
} else {
delegate.services().inNamespace(prjName).delete();
delegate.routes().inNamespace(prjName).delete();
}
// clean up any generated image streams, secrets, and service accounts
for (ImageStream item : delegate.imageStreams().inNamespace(prjName).list().getItems()) {
if (isGuvnorAlaGenerated(item)) {
delegate.imageStreams().inNamespace(prjName).delete(item);
}
}
for (Secret item : delegate.secrets().inNamespace(prjName).list().getItems()) {
if (isGuvnorAlaGenerated(item)) {
delegate.secrets().inNamespace(prjName).delete(item);
}
}
for (ServiceAccount item : delegate.serviceAccounts().inNamespace(prjName).list().getItems()) {
if (isGuvnorAlaGenerated(item)) {
delegate.serviceAccounts().inNamespace(prjName).delete(item);
}
}
// clean up generated project
if (isGuvnorAlaGenerated(delegate.projects().withName(prjName).get())) {
delegate.projects().withName(prjName).delete();
}
} catch (Throwable t) {
throw new OpenShiftClientException(t.getMessage(), t);
}
}
Aggregations