Skip to content

Commit

Permalink
Fix fabric8io#1987: Added example of Task and TaskRun in tekton with …
Browse files Browse the repository at this point in the history
…updated model

+ Added TaskRunCreate and TaskCreate example
+ Updated Tekton model to v0.11.0
  • Loading branch information
rohanKanojia committed Apr 3, 2020
1 parent 2ccc79c commit 4a5fe45
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
* Fix #2046: OpenshiftClient getVersion returns null for Openshift ContainerPlatform v4

#### Improvements
* Fix #1987: Added an example for Task and TaskRun with updated model
* Fix #2019: Added CustomResourceCrudTest
* Fix #2054: JobExample doesn't work

#### Dependency Upgrade
* Updated Knative model to v0.13.0
* Updated Tekton Model to v0.11.0

#### New Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class PipelineResourceCreate {

public static void main(String[] args) {
try ( TektonClient client = ClientFactory.newClient(args)) {
String namespace = "default";
PipelineResource resource = new PipelineResourceBuilder()
.withNewMetadata()
.withName("client-repo")
Expand All @@ -40,7 +41,7 @@ public static void main(String[] args) {
.endSpec()
.build();

System.out.println("Created:" + client.pipelineResources().create(resource).getMetadata().getName());
System.out.println("Created:" + client.pipelineResources().inNamespace(namespace).create(resource).getMetadata().getName());
}
System.exit(0);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.tekton.api.examples;

import io.fabric8.tekton.client.DefaultTektonClient;
import io.fabric8.tekton.client.TektonClient;
import io.fabric8.tekton.pipeline.v1beta1.Task;
import io.fabric8.tekton.pipeline.v1beta1.TaskBuilder;
import io.fabric8.tekton.pipeline.v1beta1.TaskList;

public class TaskCreate {
public static void main(String[] args) {
try (TektonClient tektonClient = new DefaultTektonClient()) {
String namespace = "default";
Task task = new TaskBuilder()
.withNewMetadata().withName("read-task").endMetadata()
.withNewSpec()
.withNewResources()
.addNewInput()
.withName("workspace").withType("git")
.endInput()
.endResources()
.addNewStep()
.withName("readme").withImage("ubuntu").withScript("cat workspace/README.md")
.endStep()
.endSpec()
.build();

// Create Task
task = tektonClient.tasks().inNamespace(namespace).create(task);
System.out.println("Created: " + task.getMetadata().getName());

// List Task
TaskList taskList = tektonClient.tasks().inNamespace(namespace).list();
System.out.println("There are " + taskList.getItems().size() + " Tasks in " + namespace);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.tekton.api.examples;

import io.fabric8.tekton.client.DefaultTektonClient;
import io.fabric8.tekton.client.TektonClient;
import io.fabric8.tekton.pipeline.v1beta1.TaskRun;
import io.fabric8.tekton.pipeline.v1beta1.TaskRunBuilder;
import io.fabric8.tekton.pipeline.v1beta1.TaskRunList;

public class TaskRunCreate {
public static void main(String[] args) {
try (TektonClient tektonClient = new DefaultTektonClient()) {
String namespace = "default";
TaskRun taskRun = new TaskRunBuilder()
.withNewMetadata().withGenerateName("build-gcs-targz-").endMetadata()
.withNewSpec()
.withNewTaskSpec()
.withNewResources()
.addNewInput().withName("source").withType("storage").endInput()
.endResources()
.addNewStep().withImage("ubuntu").withScript("cat source/file.txt").endStep()
.endTaskSpec()
.withNewResources()
.addNewInput()
.withName("source")
.withNewResourceSpec()
.withType("storage")
.addNewParam().withName("location").withValue("gs://build-crd-tests/archive.tar.gz").endParam()
.addNewParam().withName("artifactType").withValue("TarGzArchive").endParam()
.addNewParam().withName("type").withValue("build-gcs").endParam()
.endResourceSpec()
.endInput()
.endResources()
.endSpec()
.build();

// Create TaskRun
taskRun = tektonClient.taskRuns().inNamespace(namespace).create(taskRun);
System.out.println("Created: " + taskRun.getMetadata().getName());

// List TaskRun
TaskRunList taskRunList = tektonClient.taskRuns().inNamespace(namespace).list();
System.out.println("There are " + taskRunList.getItems().size() + " TaskRun objects in " + namespace);
}
}
}
Binary file modified extensions/tekton/generator/generate
Binary file not shown.
2 changes: 1 addition & 1 deletion extensions/tekton/generator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/knative/pkg v0.0.0-20190617142447-13b093adc272 // indirect
github.com/knative/serving v0.6.0
github.com/knative/test-infra v0.0.0-20190702025031-91d37e4abc30 // indirect
github.com/tektoncd/pipeline v0.11.0-rc2
github.com/tektoncd/pipeline v0.11.0
k8s.io/cli-runtime v0.0.0-20190325194458-f2b4781c3ae1 // indirect
)

Expand Down
3 changes: 3 additions & 0 deletions extensions/tekton/generator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ github.com/tektoncd/pipeline v0.10.1 h1:pDsYK2b70o/Ze/CE1nisELwKVVE54FxwyfLznsW1
github.com/tektoncd/pipeline v0.10.1/go.mod h1:D2X0exT46zYx95BU7ByM8+erpjoN7thmUBvlKThOszU=
github.com/tektoncd/pipeline v0.11.0-rc2 h1:dMdrmxGt5J+BpDf6uv1QyvfnJBmjd/7X5fEQLcCmu+Q=
github.com/tektoncd/pipeline v0.11.0-rc2/go.mod h1:QL3YmLzeKBdKk1THeQ6zmq2UXoPN+KdxeiU/7ynPtqY=
github.com/tektoncd/pipeline v0.11.0 h1:kGeWm53R5ggajD/L2KU8kcsZ2lVd4ruN3kdqK1A/NwQ=
github.com/tektoncd/pipeline v0.11.0/go.mod h1:hlkH32S92+/UODROH0dmxzyuMxfRFp/Nc3e29MewLn8=
github.com/tektoncd/plumbing v0.0.0-20191216083742-847dcf196de9/go.mod h1:QZHgU07PRBTRF6N57w4+ApRu8OgfYLFNqCDlfEZaD9Y=
github.com/tektoncd/plumbing v0.0.0-20200217163359-cd0db6e567d2/go.mod h1:QZHgU07PRBTRF6N57w4+ApRu8OgfYLFNqCDlfEZaD9Y=
github.com/tektoncd/plumbing/pipelinerun-logs v0.0.0-20191206114338-712d544c2c21/go.mod h1:S62EUWtqmejjJgUMOGB1CCCHRp6C706laH06BoALkzU=
Expand Down Expand Up @@ -625,6 +627,7 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+y
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gomodules.xyz/jsonpatch/v2 v2.1.0/go.mod h1:IhYNNY4jnS53ZnfE4PAmpKtDpTCj1JFXc+3mwe7XcUU=
gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0=
gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e/go.mod h1:kS+toOQn6AQKjmKJ7gzohV1XkqsFehRA2FbsbkopSuQ=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5626,25 +5626,29 @@
},
"condition": {
"properties": {
"apiVersion": {
"lastTransitionTime": {
"$ref": "#/definitions/knative_VolatileTime",
"javaType": "io.fabric8.knative.v1.VolatileTime"
},
"message": {
"type": "string",
"description": "",
"default": "tekton.dev/v1alpha1",
"required": true
"description": "human-readable message indicating details about last transition"
},
"kind": {
"reason": {
"type": "string",
"description": "",
"default": "Condition",
"required": true
"description": "one-word CamelCase reason for the condition's last transition"
},
"metadata": {
"$ref": "#/definitions/kubernetes_meta_ObjectMeta",
"javaType": "io.fabric8.kubernetes.api.model.ObjectMeta"
"severity": {
"type": "string",
"description": "how to interpret failures of this condition"
},
"spec": {
"$ref": "#/definitions/tekton_v1alpha1_ConditionSpec",
"javaType": "io.fabric8.tekton.pipeline.v1alpha1.ConditionSpec"
"status": {
"type": "string",
"description": "status of the condition"
},
"type": {
"type": "string",
"description": "type of status condition"
}
},
"additionalProperties": true
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@
<id>sonar</id>
<properties>
<sonar.projectKey>fabric8io_kubernetes-client</sonar.projectKey>
<sonar.moduleKey>${artifactId}</sonar.moduleKey>
<sonar.moduleKey>${project.artifactId}</sonar.moduleKey>
<sonar.organization>fabric8io</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.login>${env.SONAR_LOGIN_TOKEN}</sonar.login>
Expand Down

0 comments on commit 4a5fe45

Please sign in to comment.