This repository has been archived by the owner on Sep 22, 2020. It is now read-only.
forked from redhat-developer/odo
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from chetan-rns/bootstrap
Issue-38: Add functions to generate Tekton task objects
- Loading branch information
Showing
12 changed files
with
558 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package tasks | ||
|
||
import ( | ||
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha2" | ||
) | ||
|
||
func generateDeployFromSourceTask() pipelinev1.Task { | ||
task := pipelinev1.Task{ | ||
TypeMeta: createTaskTypeMeta(), | ||
ObjectMeta: createTaskObjectMeta("deploy-from-source-task"), | ||
Spec: pipelinev1.TaskSpec{ | ||
Inputs: createInputsForDeployFromSourceTask(), | ||
TaskSpec: v1alpha2.TaskSpec{ | ||
Steps: createStepsForDeployFromSourceTask(), | ||
}, | ||
}, | ||
} | ||
return task | ||
} | ||
|
||
func createStepsForDeployFromSourceTask() []pipelinev1.Step { | ||
return []pipelinev1.Step{ | ||
pipelinev1.Step{ | ||
Container: createContainer( | ||
"run-kubectl", | ||
"quay.io/kmcdermo/k8s-kubectl:latest", | ||
"/workspace/source", | ||
[]string{"kubectl"}, | ||
argsForRunKubectlStep, | ||
), | ||
}, | ||
} | ||
} | ||
|
||
var argsForRunKubectlStep = []string{ | ||
"apply", | ||
"--dry-run=$(inputs.params.DRYRUN)", | ||
"-n", | ||
"$(inputs.params.NAMESPACE)", | ||
"-k", | ||
"$(inputs.params.PATHTODEPLOYMENT)", | ||
} | ||
|
||
func createInputsForDeployFromSourceTask() *pipelinev1.Inputs { | ||
return &pipelinev1.Inputs{ | ||
Resources: []pipelinev1.TaskResource{ | ||
createTaskResource("source", "git"), | ||
}, | ||
Params: []pipelinev1.ParamSpec{ | ||
createTaskParamWithDefault( | ||
"PATHTODEPLOYMENT", | ||
"Path to the manifest to apply", | ||
pipelinev1.ParamTypeString, | ||
"deploy", | ||
), | ||
createTaskParam( | ||
"NAMESPACE", | ||
"Namespace to deploy into", | ||
pipelinev1.ParamTypeString, | ||
), | ||
createTaskParamWithDefault( | ||
"DRYRUN", | ||
"If true run a server-side dryrun.", | ||
pipelinev1.ParamTypeString, | ||
"false", | ||
), | ||
}, | ||
} | ||
|
||
} |
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,91 @@ | ||
package tasks | ||
|
||
import ( | ||
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha2" | ||
) | ||
|
||
func generateDeployUsingKubectlTask() pipelinev1.Task { | ||
return pipelinev1.Task{ | ||
TypeMeta: createTaskTypeMeta(), | ||
ObjectMeta: createTaskObjectMeta("deploy-using-kubectl-task"), | ||
Spec: pipelinev1.TaskSpec{ | ||
Inputs: createInputsForDeployKubectlTask(), | ||
TaskSpec: v1alpha2.TaskSpec{ | ||
Steps: createStepsForDeployKubectlTask(), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
var argsForReplaceImageStep = []string{ | ||
"w", | ||
"-i", | ||
"$(inputs.params.PATHTODEPLOYMENT)/deployment.yaml", | ||
"$(inputs.params.YAMLPATHTOIMAGE)", | ||
"$(inputs.resources.image.url)", | ||
} | ||
|
||
var argsForKubectlStep = []string{ | ||
"apply", | ||
"-n", | ||
"$(inputs.params.NAMESPACE)", | ||
"-k", | ||
"$(inputs.params.PATHTODEPLOYMENT)", | ||
} | ||
|
||
func createStepsForDeployKubectlTask() []pipelinev1.Step { | ||
return []pipelinev1.Step{ | ||
pipelinev1.Step{ | ||
Container: createContainer( | ||
"replace-image", | ||
"mikefarah/yq", | ||
"/workspace/source", | ||
[]string{"yq"}, | ||
argsForReplaceImageStep, | ||
), | ||
}, | ||
pipelinev1.Step{ | ||
Container: createContainer( | ||
"run-kubectl", | ||
"quay.io/kmcdermo/k8s-kubectl:latest", | ||
"/workspace/source", | ||
[]string{"kubectl"}, | ||
argsForKubectlStep, | ||
), | ||
}, | ||
} | ||
} | ||
|
||
func createInputsForDeployKubectlTask() *pipelinev1.Inputs { | ||
return &pipelinev1.Inputs{ | ||
Resources: []pipelinev1.TaskResource{ | ||
createTaskResource("source", "git"), | ||
createTaskResource("image", "image"), | ||
}, | ||
Params: []pipelinev1.ParamSpec{ | ||
createTaskParamWithDefault( | ||
"PATHTODEPLOYMENT", | ||
"Path to the manifest to apply", | ||
"string", | ||
"deploy", | ||
), | ||
createTaskParam( | ||
"NAMESPACE", | ||
"Namespace to deploy into", | ||
"string", | ||
), | ||
createTaskParamWithDefault( | ||
"DRYRUN", | ||
"If true run a server-side dryrun.", | ||
"string", | ||
"false", | ||
), | ||
createTaskParam( | ||
"YAMLPATHTOIMAGE", | ||
"The path to the image to replace in the yaml manifest (arg to yq)", | ||
"string", | ||
), | ||
}, | ||
} | ||
} |
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,92 @@ | ||
package tasks | ||
|
||
import ( | ||
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha2" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func generateGithubStatusTask(secretName string) pipelinev1.Task { | ||
task := pipelinev1.Task{ | ||
TypeMeta: createTaskTypeMeta(), | ||
ObjectMeta: createTaskObjectMeta("create-github-status-task"), | ||
Spec: pipelinev1.TaskSpec{ | ||
Inputs: createInputsForGithubStatusTask(), | ||
TaskSpec: v1alpha2.TaskSpec{ | ||
Steps: createStepsForGithubStatusTask(secretName), | ||
}, | ||
}, | ||
} | ||
return task | ||
} | ||
|
||
var argsForStartStatusStep = []string{ | ||
"create-status", | ||
"--repo", | ||
"$(inputs.params.REPO)", | ||
"--sha", | ||
"$(inputs.params.COMMIT_SHA)", | ||
"--state", | ||
"$(inputs.params.STATE)", | ||
"--target-url", | ||
"$(inputs.params.TARGET_URL)", | ||
"--description", | ||
"$(inputs.params.DESCRIPTION)", | ||
"--context", | ||
"$(inputs.params.CONTEXT)", | ||
} | ||
|
||
func createInputsForGithubStatusTask() *pipelinev1.Inputs { | ||
return &pipelinev1.Inputs{ | ||
Params: []pipelinev1.ParamSpec{ | ||
createTaskParam( | ||
"REPO", | ||
"The repo to publish the status update for e.g. tektoncd/triggers", | ||
pipelinev1.ParamTypeString, | ||
), | ||
createTaskParam( | ||
"COMMIT_SHA", | ||
"The specific commit to report a status for.", | ||
pipelinev1.ParamTypeString, | ||
), | ||
createTaskParam( | ||
"STATE", | ||
"The state to report error, failure, pending, or success.", | ||
pipelinev1.ParamTypeString, | ||
), | ||
createTaskParamWithDefault( | ||
"TARGET_URL", | ||
"The target URL to associate with this status.", | ||
pipelinev1.ParamTypeString, | ||
"", | ||
), | ||
createTaskParam( | ||
"DESCRIPTION", | ||
"A short description of the status.", | ||
pipelinev1.ParamTypeString, | ||
), | ||
createTaskParam( | ||
"CONTEXT", | ||
"A string label to differentiate this status from the status of other systems.", | ||
pipelinev1.ParamTypeString, | ||
), | ||
}, | ||
} | ||
} | ||
|
||
func createStepsForGithubStatusTask(secretName string) []pipelinev1.Step { | ||
return []pipelinev1.Step{ | ||
pipelinev1.Step{ | ||
Container: corev1.Container{ | ||
Name: "start-status", | ||
Image: "quay.io/kmcdermo/github-tool:latest", | ||
WorkingDir: "/workspace/source", | ||
Env: []corev1.EnvVar{ | ||
createEnvFromSecret("GITHUB_TOKEN", secretName, "token"), | ||
}, | ||
Command: []string{"github-tools"}, | ||
Args: argsForStartStatusStep, | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.