Tekton Cancelled Task Status

Canceling a Tekton TaskRun with Fabric8 Kubernetes Java Client

This work is being done as part of my open-source contribution to Boomerang Flow, a low-code cloud-native workflow automation project.

The Fabric8 Java Kubernetes Client helps you integrate with Kubernetes and it has an extension for integrating with Tekton.

It makes building out Java code extremely easy, however, you still need to know what or how to update the objects. This is where examples and references really help and is a great place to start as a contributor!

The Code

As the name says, this article is all about how to Cancel TaskRuns in Tekton using the Fabric8 Tekton client. You can see the latest example code here

But there is no Cancel action

create(), list(), delete()

Unlike the above methods there is no corresponding action for cancel instead you need to use:

updateStatus()

This comes down to the fact that Kubernetes itself doesn’t understand Cancel, and in fact, you are inserting a new Status for the Kubernetes object.

Let’s update the Status

In reading the Tekton TaskRun documentation all you have to do is stick “TaskRunCancelled” in the Status object.

apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
name: go-example-git
spec:
# […]
status: “TaskRunCancelled”

Seems easy enough, right?

🚧 …not so fast!

This doesn’t actually work…or at least I could not get it to work.

So what does work?

What worked for me was updating the Condition block in the Status.

1. Retrieve the particular TaskRun
2. Build up a Condition block and set the type, status, reason, and message.
3. Replace all existing Conditions. _If you don’t replace the existing conditions, you will receive a message back saying “Not all Steps in the Task have finished executing”.

TaskRun taskRun = client.v1beta1().taskRuns().inNamespace(“default”).list().getItems().get(0);

List<Condition> taskRunConditions = new ArrayList<>();
Condition taskRunCancelCondition = new Condition();
taskRunCancelCondition.setType(“Succeeded”);
taskRunCancelCondition.setStatus(“False”);
taskRunCancelCondition.setReason(“TaskRunCancelled”);
taskRunCancelCondition.setMessage(“The TaskRun was cancelled successfully.”);
taskRunConditions.add(taskRunCancelCondition);

taskRun.getStatus().setConditions(taskRunConditions);
client.v1beta1().taskRuns().updateStatus(taskRun);

There is a really great table in the Tekton TaskRun documentation for the different execution statuses you can expect.

Show your support

Do not hesitate to support us if this helped you:

- ⭐️ the GitHub repository
- 💬 Follow us on Twitter
- Install the project on your own Kubernetes cluster
- 🙏 Join us and help contribute

--

--

--

A software engineer and automation enthusiast, made in Australia, Ex New Yorker.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

A Guide to Opening Flutter Hyperlinks on Web and Mobile

A Win-Win-Win situation on Exploratory Testing

How to Create a RESTful Web Service in Spring Boot

Caching Strategy with DynamoDB Streams, AWS Lambda and ElastiCache

Working with deployments in kubernetes : Updates and rollbacks

Animating a Sprite with Unity’s Animation Window

COSS.IO January 2nd, 2019 Updates

How to Perform Serverless Canary Release on Lambda via Terraform?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tyson Lawrie

Tyson Lawrie

A software engineer and automation enthusiast, made in Australia, Ex New Yorker.

More from Medium

[Prometheus] What is the difference between rate and irate

OAuth2 Proxy 3- Integrated with Keycloak Server

Installing Red Hat Advanced Cluster Manager on OpenShift Cluster

Kubernetes HPA