io.fabric8.openshift.api.model.ImageStreamBuilder Java Examples

The following examples show how to use io.fabric8.openshift.api.model.ImageStreamBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenshiftBuildService.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private void checkOrCreateImageStream(BuildServiceConfig config, OpenShiftClient client, KubernetesListBuilder builder, String imageStreamName) {
    boolean hasImageStream = client.imageStreams().withName(imageStreamName).get() != null;
    if (hasImageStream && config.getBuildRecreateMode().isImageStream()) {
        client.imageStreams().withName(imageStreamName).delete();
        hasImageStream = false;
    }
    if (!hasImageStream) {
        log.info("Creating ImageStream %s", imageStreamName);
        builder.addToItems(new ImageStreamBuilder()
            .withNewMetadata()
                .withName(imageStreamName)
            .endMetadata()
            .withNewSpec()
                .withNewLookupPolicy()
                    .withLocal(config.isS2iImageStreamLookupPolicyLocal())
                .endLookupPolicy()
            .endSpec()
            .build()
        );
    } else {
        log.info("Adding to ImageStream %s", imageStreamName);
    }
}
 
Example #2
Source File: AddBuilderImageStreamResourceDecorator.java    From dekorate with Apache License 2.0 6 votes vote down vote up
public void visit(KubernetesListBuilder list) {
  ObjectMeta meta = getMandatoryDeploymentMetadata(list);

  String repository = Images.getRepository(config.getBuilderImage());

  String name = !repository.contains("/")
    ? repository
    : repository.substring(repository.lastIndexOf("/") + 1);

  String dockerImageRepo = Images.removeTag(config.getBuilderImage());

  list.addToItems(new ImageStreamBuilder()
    .withNewMetadata()
    .withName(name)
    .withLabels(meta.getLabels())
    .endMetadata()
    .withNewSpec()
    .withDockerImageRepository(dockerImageRepo)
    .endSpec());
}
 
Example #3
Source File: KafkaConnectS2ICluster.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
/**
 * Generate new target ImageStream
 *
 * @return      Target ImageStream resource definition
 */
public ImageStream generateTargetImageStream() {
    ImageStream imageStream = new ImageStreamBuilder()
            .withNewMetadata()
                .withName(KafkaConnectS2IResources.targetImageStreamName(cluster))
                .withNamespace(namespace)
                .withLabels(getLabelsWithStrimziName(name, null).toMap())
                .withOwnerReferences(createOwnerReference())
            .endMetadata()
            .withNewSpec()
                .withLookupPolicy(new ImageLookupPolicyBuilder().withLocal(true).build())
            .endSpec()
            .build();

    return imageStream;
}
 
Example #4
Source File: ImageStreamServiceTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private ImageStream lookupImageStream(String sha) {
    NamedTagEventList list = new NamedTagEventList();
    TagEvent tag = new TagEvent();
    tag.setImage(sha);
    list.setItems(new ArrayList<TagEvent>(Arrays.asList(tag)));

    return new ImageStreamBuilder()
        .withNewStatus()
        .addToTags(list)
        .endStatus()
        .build();
}
 
Example #5
Source File: OpenShiftImageStreamHandler.java    From module-ballerina-kubernetes with Apache License 2.0 5 votes vote down vote up
private void generate(OpenShiftBuildExtensionModel buildConfigModel) throws KubernetesPluginException {
    try {
        buildConfigModel.setLabels(new LinkedHashMap<>());
        if (null != buildConfigModel.getLabels() && !buildConfigModel.getLabels().containsKey("build")) {
            buildConfigModel.getLabels().put("build", buildConfigModel.getName());
        }
        
        String dockerImageName = new DockerImageName(dataHolder.getDockerModel().getName()).getRepository();
        
        ImageStream is = new ImageStreamBuilder()
                .withNewMetadata()
                .withName(dockerImageName)
                .withLabels(buildConfigModel.getLabels())
                .withAnnotations(buildConfigModel.getAnnotations())
                .withNamespace(dataHolder.getNamespace())
                .endMetadata()
                .build();
        
        String resourceQuotaContent = SerializationUtils.dumpWithoutRuntimeStateAsYaml(is);
        KubernetesUtils.writeToFile(dataHolder.getK8sArtifactOutputPath().resolve(OPENSHIFT), resourceQuotaContent,
                OPENSHIFT_IMAGE_STREAM_TAG_FILE_POSTFIX + YAML);
    } catch (IOException e) {
        String errorMessage = "error while generating OpenShift Image Stream yaml file: " +
                              buildConfigModel.getName();
        throw new KubernetesPluginException(errorMessage, e);
    }
}
 
Example #6
Source File: AddDockerImageStreamResourceDecorator.java    From dekorate with Apache License 2.0 5 votes vote down vote up
public void visit(KubernetesListBuilder list) {
  ObjectMeta meta = getMandatoryDeploymentMetadata(list);

  list.addToItems(new ImageStreamBuilder()
    .withNewMetadata()
      .withName(config.getName())
    .withLabels(meta.getLabels())
    .endMetadata()
    .withNewSpec()
      .withDockerImageRepository(dockerImageRepository)
    .endSpec());
}
 
Example #7
Source File: AddOutputImageStreamResourceDecorator.java    From dekorate with Apache License 2.0 5 votes vote down vote up
public void visit(KubernetesListBuilder list) {
  ObjectMeta meta = getMandatoryDeploymentMetadata(list);

  list.addToItems(new ImageStreamBuilder()
    .withNewMetadata()
    .withName(config.getName())
    .withLabels(meta.getLabels())
    .endMetadata()
    .withNewSpec()
    .endSpec());
}
 
Example #8
Source File: KafkaConnectS2ICluster.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    sourceTag.setReferencePolicy(new TagReferencePolicyBuilder().withType("Local").build());

    if (insecureSourceRepository)   {
        sourceTag.setImportPolicy(new TagImportPolicyBuilder().withInsecure(true).build());
    }

    ImageStream imageStream = new ImageStreamBuilder()
            .withNewMetadata()
                .withName(KafkaConnectS2IResources.sourceImageStreamName(cluster))
                .withNamespace(namespace)
                .withLabels(getLabelsWithStrimziName(KafkaConnectS2IResources.sourceImageStreamName(cluster), null).toMap())
                .withOwnerReferences(createOwnerReference())
            .endMetadata()
            .withNewSpec()
                .withLookupPolicy(new ImageLookupPolicyBuilder().withLocal(false).build())
                .withTags(sourceTag)
            .endSpec()
            .build();

    return imageStream;
}
 
Example #9
Source File: ImageStreamIT.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
  currentNamespace = session.getNamespace();
  imageStream1 = new ImageStreamBuilder()
    .withNewMetadata()
    .withName("example-camel-cdi")
    .endMetadata()
    .withNewSpec()
    .addNewTag()
    .withName("latest")
    .endTag()
    .withDockerImageRepository("fabric8/example-camel-cdi")
    .endSpec()
    .withNewStatus().withDockerImageRepository("").endStatus()
    .build();

  imageStream2 = new ImageStreamBuilder()
    .withNewMetadata()
    .withName("java-sti")
    .endMetadata()
    .withNewSpec()
    .addNewTag()
    .withName("latest")
    .endTag()
    .withDockerImageRepository("fabric8/java-sti")
    .endSpec()
    .withNewStatus().withDockerImageRepository("").endStatus()
    .build();

  client.imageStreams().inNamespace(currentNamespace).createOrReplace(imageStream1);
  client.imageStreams().inNamespace(currentNamespace).createOrReplace(imageStream2);
}
 
Example #10
Source File: MetadataVisitor.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ObjectMeta getOrCreateMetadata(ImageStreamBuilder item) {
    return addEmptyLabelsAndAnnotations(item::hasMetadata, item::withNewMetadata, item::editMetadata, item::buildMetadata)
            .endMetadata().buildMetadata();
}
 
Example #11
Source File: BuildConfigs.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
public static ImageStream imageRepository(String buildName, Map<String, String> labels) {
    return new ImageStreamBuilder().
            withNewMetadata().withLabels(labels).withName(buildName).endMetadata().
            build();
}
 
Example #12
Source File: ImageStreamOperatorTest.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Override
protected ImageStream resource() {
    return new ImageStreamBuilder().withNewMetadata().withNamespace(NAMESPACE).withName(RESOURCE_NAME).endMetadata().build();
}
 
Example #13
Source File: ImageStreamExample.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws InterruptedException {

    String namespace = "myproject";
    String master = "CLUSTER_URL";
    Config config = new ConfigBuilder().withMasterUrl(master).build();
    OpenShiftClient client = new DefaultOpenShiftClient(config);

    HashMap annotations = new HashMap();
    annotations.put("role", "jenkins-slave");
    annotations.put("slave-label", "jenkins-slave");

    try {

      ImageStream imageStream = new ImageStreamBuilder()
        .withNewMetadata()
          .withName("slave-jenkins")
        .endMetadata()
        .withNewSpec()
          .addToTags(0, new TagReferenceBuilder()
            .withName("base")
            .withFrom(new ObjectReferenceBuilder()
              .withKind("DockerImage")
              .withName("docker.io/openshift/jenkins-slave-maven-centos7:latest")
              .build()
            )
            .build()
          )
          .addToTags(1, new TagReferenceBuilder()
            .withAnnotations(annotations)
            .withName("latest")
            .withFrom(new ObjectReferenceBuilder()
              .withKind("ImageStreamTag")
              .withName("base")
              .build()
            )
            .build()
          )
        .endSpec()
        .build();

      log("Created ImageStream", client.imageStreams().inNamespace(namespace).create(imageStream));

    }finally {

      log("Tags in ImageStream are");
      log("First Tag is " + client.imageStreams().inNamespace(namespace).withName("slave-jenkins").get().getSpec().getTags().get(0).getName());
      log("Second Tag is " + client.imageStreams().inNamespace(namespace).withName("slave-jenkins").get().getSpec().getTags().get(1).getName());

      client.imageStreams().inNamespace(namespace).withName("slave-jenkins").delete();
      client.close();
    }
  }