Search in sources :

Example 26 with ImageStream

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;
}
Also used : ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) ObjectReference(io.fabric8.kubernetes.api.model.ObjectReference) ImageStream(io.fabric8.openshift.api.model.ImageStream) TagReference(io.fabric8.openshift.api.model.TagReference) ImageLookupPolicyBuilder(io.fabric8.openshift.api.model.ImageLookupPolicyBuilder)

Example 27 with 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;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) DeploymentConfigBuilder(io.fabric8.openshift.api.model.DeploymentConfigBuilder) DeploymentStrategyBuilder(io.fabric8.openshift.api.model.DeploymentStrategyBuilder) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) DeploymentTriggerPolicy(io.fabric8.openshift.api.model.DeploymentTriggerPolicy) DeploymentTriggerPolicyBuilder(io.fabric8.openshift.api.model.DeploymentTriggerPolicyBuilder) DeploymentStrategy(io.fabric8.openshift.api.model.DeploymentStrategy)

Example 28 with ImageStream

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) File(java.io.File) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 29 with ImageStream

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());
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) Yaml(org.yaml.snakeyaml.Yaml) Test(org.junit.Test)

Example 30 with ImageStream

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);
    }
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) Service(io.fabric8.kubernetes.api.model.Service) ImageStream(io.fabric8.openshift.api.model.ImageStream) OpenShiftClientException(org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException) 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