Skip to content

Commit

Permalink
Update resource to be namepaced under path "workspace/task_resource_n…
Browse files Browse the repository at this point in the history
…ame"

- In PR tektoncd#393 resource was placed under path "/workspace/resource_name",
there is a use case where a resource can be used by a task multiple
times as source with duplicate names.
- Add more unit test to have more coverage for this use case.
- Enable helm deploy task in this PR (tektoncd#393 PR disabled it as there is
cyclic dependency)
  • Loading branch information
Shash Reddy committed Jan 18, 2019
1 parent 8557df4 commit 0cec835
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 21 deletions.
88 changes: 83 additions & 5 deletions pkg/reconciler/v1alpha1/taskrun/resources/input_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,23 @@ func TestAddResourceToBuild(t *testing.T) {
},
},
}

taskWithMultipleGitSources := &v1alpha1.Task{
ObjectMeta: metav1.ObjectMeta{
Name: "build-from-repo",
Namespace: "marshmallow",
},
Spec: v1alpha1.TaskSpec{
Inputs: &v1alpha1.Inputs{
Resources: []v1alpha1.TaskResource{{
Name: "gitspace",
Type: "git",
}, {
Name: "git-duplicate-space",
Type: "git",
}},
},
},
}
taskWithTargetPath := &v1alpha1.Task{
ObjectMeta: metav1.ObjectMeta{
Name: "task-with-targetpath",
Expand Down Expand Up @@ -270,7 +286,7 @@ func TestAddResourceToBuild(t *testing.T) {
Url: "https://github.com/grafeas/kritis",
Revision: "master",
},
Name: "the-git",
Name: "gitspace",
}},
},
},
Expand Down Expand Up @@ -317,7 +333,69 @@ func TestAddResourceToBuild(t *testing.T) {
},
Spec: buildv1alpha1.BuildSpec{
Sources: []buildv1alpha1.SourceSpec{{
Name: "the-git-with-branch",
Name: "gitspace",
Git: &buildv1alpha1.GitSourceSpec{
Url: "https://github.com/grafeas/kritis",
Revision: "branch",
},
}},
},
},
}, {
desc: "same git input resource for task with diff resource name",
task: taskWithMultipleGitSources,
taskRun: &v1alpha1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Name: "build-from-repo-run",
Namespace: "marshmallow",
},
Spec: v1alpha1.TaskRunSpec{
TaskRef: &v1alpha1.TaskRef{
Name: "simpleTask",
},
Inputs: v1alpha1.TaskRunInputs{
Resources: []v1alpha1.TaskResourceBinding{{
ResourceRef: v1alpha1.PipelineResourceRef{
Name: "the-git-with-branch",
},
Name: "gitspace",
}, {
ResourceRef: v1alpha1.PipelineResourceRef{
Name: "the-git-with-branch",
},
Name: "git-duplicate-space",
}},
},
},
},
build: build(),
wantErr: false,
want: &buildv1alpha1.Build{
TypeMeta: metav1.TypeMeta{
Kind: "Build",
APIVersion: "build.knative.dev/v1alpha1"},
ObjectMeta: metav1.ObjectMeta{
Name: "build-from-repo",
Namespace: "marshmallow",
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "pipeline.knative.dev/v1alpha1",
Kind: "TaskRun",
Name: "build-from-repo-run",
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
},
},
},
Spec: buildv1alpha1.BuildSpec{
Sources: []buildv1alpha1.SourceSpec{{
Name: "gitspace",
Git: &buildv1alpha1.GitSourceSpec{
Url: "https://github.com/grafeas/kritis",
Revision: "branch",
},
}, {
Name: "git-duplicate-space",
Git: &buildv1alpha1.GitSourceSpec{
Url: "https://github.com/grafeas/kritis",
Revision: "branch",
Expand Down Expand Up @@ -370,7 +448,7 @@ func TestAddResourceToBuild(t *testing.T) {
Url: "https://github.com/grafeas/kritis",
Revision: "master",
},
Name: "the-git",
Name: "gitspace",
}},
},
},
Expand Down Expand Up @@ -420,7 +498,7 @@ func TestAddResourceToBuild(t *testing.T) {
Url: "https://github.com/grafeas/kritis",
Revision: "branch",
},
Name: "the-git-with-branch",
Name: "gitspace",
}},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func AddInputResource(
build.Spec.Sources = append(build.Spec.Sources, buildv1alpha1.SourceSpec{
Git: gitSourceSpec,
TargetPath: input.TargetPath,
Name: gitResource.Name,
Name: input.Name,
})
}
case v1alpha1.PipelineResourceTypeCluster:
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/v1alpha1/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func TestReconcile(t *testing.T) {
name: "params",
taskRun: taskRunTemplating,
wantBuildSpec: tb.BuildSpec(
tb.BuildSource("git-resource", tb.BuildSourceGit("https://foo.git", "master")),
tb.BuildSource("workspace", tb.BuildSourceGit("https://foo.git", "master")),
entrypointCopyStep,
tb.BuildStep("mycontainer", "myimage", tb.Command(entrypointLocation),
tb.EnvVar("ENTRYPOINT_OPTIONS", `{"args":["/mycmd","--my-arg=foo","--my-arg-with-default=bar","--my-arg-with-default2=thedefault","--my-additional-arg=gcr.io/kristoff/sven"],"process_log":"/tools/process-log.txt","marker_file":"/tools/marker-file.txt"}`),
Expand Down Expand Up @@ -307,7 +307,7 @@ func TestReconcile(t *testing.T) {
name: "taskrun-with-taskspec",
taskRun: taskRunWithTaskSpec,
wantBuildSpec: tb.BuildSpec(
tb.BuildSource("git-resource", tb.BuildSourceGit("https://foo.git", "master")),
tb.BuildSource("workspace", tb.BuildSourceGit("https://foo.git", "master")),
entrypointCopyStep,
tb.BuildStep("mycontainer", "myimage", tb.Command(entrypointLocation),
tb.EnvVar("ENTRYPOINT_OPTIONS", `{"args":["/mycmd","--my-arg=foo"],"process_log":"/tools/process-log.txt","marker_file":"/tools/marker-file.txt"}`),
Expand Down
17 changes: 8 additions & 9 deletions test/helm_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ var (
// TestHelmDeployPipelineRun is an integration test that will verify a pipeline build an image
// and then using helm to deploy it
func TestHelmDeployPipelineRun(t *testing.T) {
t.Skip()
logger := logging.GetContextLogger(t.Name())
c, namespace := setup(t, logger)
setupClusterBindingForHelm(c, t, namespace, logger)
Expand Down Expand Up @@ -159,9 +158,10 @@ func getCreateImageTask(namespace string, t *testing.T) *v1alpha1.Task {
t.Logf("Image to be pusblished: %s", imageName)

return tb.Task(createImageTaskName, namespace, tb.TaskSpec(
tb.TaskInputs(tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit)),
tb.TaskInputs(tb.InputsResource("gitsource", v1alpha1.PipelineResourceTypeGit)),
tb.Step("kaniko", "gcr.io/kaniko-project/executor", tb.Args(
"--dockerfile=/workspace/test/gohelloworld/Dockerfile",
"--dockerfile=/workspace/gitsource/test/gohelloworld/Dockerfile",
"--context=/workspace/gitsource/",
fmt.Sprintf("--destination=%s", imageName),
)),
))
Expand All @@ -170,7 +170,7 @@ func getCreateImageTask(namespace string, t *testing.T) *v1alpha1.Task {
func getHelmDeployTask(namespace string) *v1alpha1.Task {
return tb.Task(helmDeployTaskName, namespace, tb.TaskSpec(
tb.TaskInputs(
tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit),
tb.InputsResource("gitsource", v1alpha1.PipelineResourceTypeGit),
tb.InputsParam("pathToHelmCharts", tb.ParamDescription("Path to the helm charts")),
tb.InputsParam("image"), tb.InputsParam("chartname"),
),
Expand All @@ -190,9 +190,8 @@ func getHelmDeployPipeline(namespace string) *v1alpha1.Pipeline {
return tb.Pipeline(helmDeployPipelineName, namespace, tb.PipelineSpec(
tb.PipelineTask("push-image", createImageTaskName),
tb.PipelineTask("helm-deploy", helmDeployTaskName,
tb.PipelineTaskResourceDependency("workspace"), // tb.ProvidedBy(createImageTaskName), //TODO: https://github.com/knative/build-pipeline/issues/148

tb.PipelineTaskParam("pathToHelmCharts", "/workspace/test/gohelloworld/gohelloworld-chart"),
tb.PipelineTaskResourceDependency("gitsource"), // tb.ProvidedBy(createImageTaskName), //TODO: https://github.com/knative/build-pipeline/issues/148
tb.PipelineTaskParam("pathToHelmCharts", "/workspace/gitsource/test/gohelloworld/gohelloworld-chart"),
tb.PipelineTaskParam("chartname", "gohelloworld"),
tb.PipelineTaskParam("image", imageName),
),
Expand All @@ -203,10 +202,10 @@ func getHelmDeployPipelineRun(namespace string) *v1alpha1.PipelineRun {
return tb.PipelineRun(helmDeployPipelineRunName, namespace, tb.PipelineRunSpec(
helmDeployPipelineName,
tb.PipelineRunTaskResource("helm-deploy",
tb.PipelineTaskResourceInputs("workspace", tb.ResourceBindingRef(sourceResourceName)),
tb.PipelineTaskResourceInputs("gitsource", tb.ResourceBindingRef(sourceResourceName)),
),
tb.PipelineRunTaskResource("push-image",
tb.PipelineTaskResourceInputs("workspace", tb.ResourceBindingRef(sourceResourceName)),
tb.PipelineTaskResourceInputs("gitsource", tb.ResourceBindingRef(sourceResourceName)),
),
))
}
Expand Down
8 changes: 4 additions & 4 deletions test/kaniko_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ func createSecret(c *knativetest.KubeClient, namespace string) (bool, error) {

func getTask(repo, namespace string, withSecretConfig bool) *v1alpha1.Task {
taskSpecOps := []tb.TaskSpecOp{
tb.TaskInputs(tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit)),
tb.TaskInputs(tb.InputsResource("gitsource", v1alpha1.PipelineResourceTypeGit)),
tb.TaskTimeout(2 * time.Minute),
}
stepOps := []tb.ContainerOp{
tb.Args(
"--dockerfile=/workspace/go-example-git/Dockerfile",
"--dockerfile=/workspace/gitsource/Dockerfile",
fmt.Sprintf("--destination=%s", repo),
"--context=/workspace/go-example-git",
"--context=/workspace/gitsource",
),
}
if withSecretConfig {
Expand All @@ -118,7 +118,7 @@ func getTask(repo, namespace string, withSecretConfig bool) *v1alpha1.Task {
func getTaskRun(namespace string) *v1alpha1.TaskRun {
return tb.TaskRun(kanikoTaskRunName, namespace, tb.TaskRunSpec(
tb.TaskRunTaskRef(kanikoTaskName),
tb.TaskRunInputs(tb.TaskRunInputsResource("workspace", tb.ResourceBindingRef(kanikoResourceName))),
tb.TaskRunInputs(tb.TaskRunInputsResource("gitsource", tb.ResourceBindingRef(kanikoResourceName))),
))
}

Expand Down

0 comments on commit 0cec835

Please sign in to comment.