forked from fabric8io/kubernetes-client
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix fabric8io#1987: Added example of Task and TaskRun in tekton with …
…updated model + Added TaskRunCreate and TaskCreate example + Updated Tekton model to v0.11.0
- Loading branch information
1 parent
2ccc79c
commit 4a5fe45
Showing
9 changed files
with
138 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
extensions/tekton/examples/src/main/java/io/fabric8/tekton/api/examples/TaskCreate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
extensions/tekton/examples/src/main/java/io/fabric8/tekton/api/examples/TaskRunCreate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters