Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

What's new in Fabric8 Kubernetes Java client 4.12.0

October 30, 2020
Rohan Kumar
Related topics:
JavaCI/CDDevOpsKubernetes

Share:

    The recent Fabric8 Kubernetes Java client 4.12.0 release includes many new features and bug fixes. This article introduces the major features we've added between the 4.11.0 and 4.12.0 releases.

    I will show you how to get started with the new VolumeSnapshot extension, CertificateSigningRequests, and Tekton triggers in the Fabric8 Tekton client (to name just a few). I'll also point out several minor changes that break backward compatibility with older releases. Knowing about these changes will help you avoid problems when you upgrade to the latest version of Fabric8's Java client for Kubernetes or Red Hat OpenShift.

    How to get the new Fabric8 Java client

    You will find the most current Fabric8 Java client release on Maven Central. To start using the new Java client, add it as a dependency in your Maven pom.xml. For Kubernetes, the dependency is:

    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>kubernetes-client</artifactId>
      <version>4.12.0</version>
    </dependency>
    

    For OpenShift, it's:

    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>openshift-client</artifactId>
      <version>4.12.0</version>
    </dependency>
    

    Breaking changes in this release

    We have moved several classes for this release, so upgrading to the new version of the Fabric8 Kubernetes Java client might not be completely smooth. The changes are as follows:

    • We moved the CustomResourceDefinition to io.fabric8.kubernetes.api.model.apiextensions.v1 and io.fabric8.kubernetes.api.model.apiextensions.v1beta1.
    • We moved SubjectAccessReview, SelfSubjectAccessReview, LocalSubjectAccessReview, and SelfSubjectRulesReview to io.fabric8.kubernetes.api.model.authorization.v1 and io.fabric8.kubernetes.api.model.authorization.v1beta1.
    • The io.fabric8.tekton.pipeline.v1beta1.WorkspacePipelineDeclaration is now io.fabric8.tekton.pipeline.v1beta1.PipelineWorkspaceDeclaration.
    • We introduced a new interface, WatchAndWaitable, which is used by WatchListDeletable and other interfaces. This change should not affect you if you are using the Fabric8 Kubernetes Java client's domain-specific language (DSL).

    The new VolumeSnapshot extension

    You might know about the Fabric8 Kubernetes Java client extensions for Knative, Tekton, Istio, and Service Catalog. In this release, we've added a new Container Storage Interface (CSI) VolumeSnapshot extension. VolumeSnapshots are in the snapshot.storage.k8s.io/v1beta1 directory. To start using the new extension, add the following dependency to your Maven pom.xml:

    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>volumesnapshot-client</artifactId>
      <version>4.12.0</version>
    </dependency>
    

    Once you've added the dependency, you can start using the VolumeSnapshotClient. Here's an example of how to create a VolumeSnapshot:

    try (VolumeSnapshotClient client = new DefaultVolumeSnapshotClient()) {
          System.out.println("Creating a volume snapshot");
          client.volumeSnapshots().inNamespace("default").createNew()
            .withNewMetadata()
            .withName("my-snapshot")
            .endMetadata()
            .withNewSpec()
            .withNewSource()
            .withNewPersistentVolumeClaimName("my-pvc")
            .endSource()
            .endSpec()
            .done();
        }
    

    Spin up a single pod with client.run()

    Just like you would with kubectl run, you can quickly spin up a pod with the Fabric8 Kubernetes Java client. You only need to provide a name and image:

    try (KubernetesClient client = new DefaultKubernetesClient()) {
        client.run().inNamespace("default").withName("hello-openshift")
                .withImage("openshift/hello-openshift:latest")
                .done();
    }
    

    Authentication API support

    A new authentication API lets you use the Fabric8 Kubernetes Java client to query a Kubernetes cluster. You should be able to use the API for all operations equivalent to kubectl auth can-i. Here's an example:

    try (KubernetesClient client = new DefaultKubernetesClient()) {
        SelfSubjectAccessReview ssar = new SelfSubjectAccessReviewBuilder()
                .withNewSpec()
                .withNewResourceAttributes()
                .withGroup("apps")
                .withResource("deployments")
                .withVerb("create")
                .withNamespace("dev")
                .endResourceAttributes()
                .endSpec()
                .build();
    
        ssar = client.authorization().v1().selfSubjectAccessReview().create(ssar);
    
        System.out.println("Allowed: "+  ssar.getStatus().getAllowed());
    }
    

    OpenShift 4 resources

    The Fabric8 Kubernetes Java client now supports all of the new OpenShift 4 resources in its OpenShift model. Additional resources added in operators.coreos.com, operators.openshift.io, console.openshift.io, and monitoring.coreos.com are also available within the OpenShift model. Here is an example of using PrometheusRule to monitor a Prometheus instance:

    try (OpenShiftClient client = new DefaultOpenShiftClient()) {
        PrometheusRule prometheusRule = new PrometheusRuleBuilder()
                .withNewMetadata().withName("foo").endMetadata()
                .withNewSpec()
                .addNewGroup()
                .withName("./example-rules")
                .addNewRule()
                .withAlert("ExampleAlert")
                .withNewExpr().withStrVal("vector(1)").endExpr()
                .endRule()
                .endGroup()
                .endSpec()
                .build();
    
        client.monitoring().prometheusRules().inNamespace("rokumar").createOrReplace(prometheusRule);
        System.out.println("Created");
    
        PrometheusRuleList prometheusRuleList = client.monitoring().prometheusRules().inNamespace("rokumar").list();
        System.out.println(prometheusRuleList.getItems().size() + " items found");
    }
    

    Certificate signing requests

    We've added a new entry point, certificateSigningRequests(), in the main KubernetesClient interface. This means you can use CertificateSigningRequest resources in all of your applications developed with Fabric8:

    try (KubernetesClient client = new DefaultKubernetesClient()) {
    
        CertificateSigningRequest csr = new CertificateSigningRequestBuilder()
                .withNewMetadata().withName("test-k8s-csr").endMetadata()
                .withNewSpec()
                .addNewGroup("system:authenticated")
                .withRequest("<your-req>")
                .addNewUsage("client auth")
                .endSpec()
                .build();
        client.certificateSigningRequests().create(csr);
    }
    

    Custom resource definitions

    We've moved the apiextensions/v1 CustomResourceDefinition (CRD) to the io.fabric8.kubernetes.api.model.apiextensions.v1beta1 and io.fabric8.kubernetes.api.model.apiextensions.v1 packages. You can now use CustomResourceDefinition objects inside apiextensions() like this:

    try (KubernetesClient client = new DefaultKubernetesClient()) {
        client.apiextensions().v1()
                .customResourceDefinitions()
                .list()
                .getItems().forEach(crd -> System.out.println(crd.getMetadata().getName()));
    }
    

    Creating bootstrap project templates

    We've provided a new, built-in way to create a project with all of the role bindings you need. It works like OpenShift's oc adm create-bootstrap-project-template command. Specify the parameters that the template requires in the DSL method. The method then creates the Project and related RoleBindings for you:

    try (OpenShiftClient client = new DefaultOpenShiftClient()) {
        client.projects().createProjectAndRoleBindings("default", "Rohan Kumar", "default", "developer", "developer");
    }
    

    Tekton model 0.15.1

    We've updated the Tekton model to version 0.15.1 so that you can take advantage of all the newest upstream features and enhancements for Tekton. This example creates a simple Task and TaskRun to echo "hello world" in a pod. Instead of YAML, we use the Fabric8 TektonClient:

    try (TektonClient tkn = new DefaultTektonClient()) {
        // Create Task
        tkn.v1beta1().tasks().inNamespace(NAMESPACE).createOrReplaceWithNew()
                .withNewMetadata().withName("echo-hello-world").endMetadata()
                .withNewSpec()
                .addNewStep()
                .withName("echo")
                .withImage("alpine:3.12")
                .withCommand("echo")
                .withArgs("Hello World")
                .endStep()
                .endSpec()
                .done();
    
        // Create TaskRun
        tkn.v1beta1().taskRuns().inNamespace(NAMESPACE).createOrReplaceWithNew()
                .withNewMetadata().withName("echo-hello-world-task-run").endMetadata()
                .withNewSpec()
                .withNewTaskRef()
                .withName("echo-hello-world")
                .endTaskRef()
                .endSpec()
                .done();
    }
    

    When you run this code, you will see the Task and TaskRun being created. The TaskRun, in turn, creates a pod, which prints the "Hello World" message:

    tekton-java-client-demo : $ tkn taskrun list
    NAME                        STARTED         DURATION     STATUS
    echo-hello-world-task-run   2 minutes ago   19 seconds   Succeeded
    tekton-java-client-demo : $ kubectl get pods
    NAME                                  READY   STATUS      RESTARTS   AGE
    echo-hello-world-task-run-pod-4gczw   0/1     Completed   0          2m17s
    tekton-java-client-demo : $ kubectl logs pod/echo-hello-world-task-run-pod-4gczw
    Hello World
    

    Tekton triggers in the Fabric8 Tekton client

    The Fabric8 Tekton client and model now support Tekton triggers. You can use triggers to automate the creation of Tekton pipelines. All you have to do is embed your triggers in the Tekton continuous deployment (CD) pipeline. Here is an example of using the Fabric8 Tekton client to create a Tekton trigger template:

    try (TektonClient tkn = new DefaultTektonClient()) {
        tkn.v1alpha1().triggerTemplates().inNamespace(NAMESPACE).createOrReplaceWithNew()
                .withNewMetadata().withName("pipeline-template").endMetadata()
                .withNewSpec()
                    .addNewParam()
                        .withName("gitrepositoryurl")
                        .withDescription("The git repository url")
                    .endParam()
                    .addNewParam()
                        .withName("gitrevision")
                        .withDescription("The git revision")
                    .endParam()
                    .addNewParam()
                        .withName("message")
                        .withDescription("The message to print")
                        .withDefault("This is default message")
                    .endParam()
                    .addNewParam()
                        .withName("contenttype")
                        .withDescription(" The Content-Type of the event")
                    .endParam()
                .withResourcetemplates(Collections.singletonList(new PipelineRunBuilder()
                        .withNewMetadata().withGenerateName("simple-pipeline-run-").endMetadata()
                        .withNewSpec()
                            .withNewPipelineRef().withName("simple-pipeline").endPipelineRef()
                            .addNewParam()
                                .withName("message")
                                .withValue(new ArrayOrString("$(tt.params.message)"))
                            .endParam()
                            .addNewParam()
                                .withName("contenttype")
                                .withValue(new ArrayOrString("$(tt.params.contenttype)"))
                            .endParam()
                            .addNewResource()
                                .withName("git-source")
                                .withNewResourceSpec()
                                    .withType("git")
                                    .addNewParam()
                                    .withName("revision")
                                    .withValue("$(tt.params.gitrevision)")
                                    .endParam()
                                    .addNewParam()
                                    .withName("url")
                                    .withValue("$(tt.params.gitrepositoryurl)")
                                    .endParam()
                                .endResourceSpec()
                            .endResource()
                        .endSpec()
                        .build()))
                .endSpec()
                .done();
    }
    

    Automatically refresh OpenID Connect tokens

    If your Kubernetes provider uses OpenID Connect tokens (like IBM Cloud), you don't need to worry about your tokens expiring. The new Fabric8 Kubernetes Java client automatically refreshes your tokens by contacting the OpenID Connect provider, which is listed in the ~/.kube/config.

    Support for Knative 0.17.2 and Knative Eventing Contrib

    For this release, we've updated the Knative model to the latest version. We also added new support for the additional resources from Knative Eventing Contrib, which involves sources and channel implementations that integrate with Apache CouchDB, Apache Kafka, Amazon Simple Queue Service (AWS SQS), GitHub, GitLab, and so on.

    Here's an example of creating an AwsSqsSource using KnativeClient:

    try (KnativeClient client = new DefaultKnativeClient()) {
        AwsSqsSource awsSqsSource = new AwsSqsSourceBuilder()
                .withNewMetadata().withName("awssqs-sample-source").endMetadata()
                .withNewSpec()
                .withNewAwsCredsSecret("credentials", "aws-credentials", true)
                .withQueueUrl("QUEUE_URL")
                .withSink(new ObjectReferenceBuilder()
                        .withApiVersion("messaging.knative.dev/v1alpha1")
                        .withKind("Channel")
                        .withName("awssqs-test")
                        .build())
                .endSpec()
                .build();
        client.awsSqsSources().inNamespace("default").createOrReplace(awsSqsSource);
    }
    

    Get involved!

    There are a few ways to get involved with the development of the Fabric8 Kubernetes Java client:

    • Create GitHub issues to let us know when features don't work as expected.
    • Send pull requests for bug fixes and enhancements.
    • Chat with us on the Fabric8 Kubernetes Java client Gitter channel.
    • Follow us on Twitter.

    Recent Posts

    • The benefits of auto-merging GitHub and GitLab repositories

    • Supercharging AI isolation: microVMs with RamaLama & libkrun

    • Simplify multi-VPC connectivity with amazon.aws 9.0.0

    • How HaProxy router settings affect middleware applications

    • Fly Eagle(3) fly: Faster inference with vLLM & speculative decoding

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue