Skip to content

Commit

Permalink
Fixes AppendManifest used to read files from kodata
Browse files Browse the repository at this point in the history
Previously, if we pass a path to AppendManifest
for ex. `/kodata/tekton/abc.yaml` and later
        `/kodata/tekton/`
both use to read the file and add in the manifest, which
would make manifest to have the same resource twice.

This updates the func to skip reading from path if it is
a directory and read the data from path only if it is a file.
so this will read the resource for path `kodata/tekton/abc.yaml`
and skip for other one.

Signed-off-by: Shivam Mukhade <[email protected]>
  • Loading branch information
Shivam Mukhade committed Sep 27, 2021
1 parent 3c77c77 commit e3e4b24
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 12 deletions.
15 changes: 3 additions & 12 deletions pkg/reconciler/common/releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,10 @@ func latestRelease(instance v1alpha1.TektonComponent) string {
}

func AppendManifest(manifest *mf.Manifest, yamlLocation string) error {
var files []string
if err := filepath.Walk(yamlLocation, func(path string, info os.FileInfo, err error) error {
files = append(files, path)
return nil
}); err != nil {
m, err := mf.ManifestFrom(mf.Recursive(yamlLocation))
if err != nil {
return err
}
for i := range files {
m, err := Fetch(files[i])
if err != nil {
return err
}
*manifest = manifest.Append(m)
}
*manifest = manifest.Append(m)
return nil
}
26 changes: 26 additions & 0 deletions pkg/reconciler/common/releases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"testing"

mf "github.com/manifestival/manifestival"
"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
util "github.com/tektoncd/operator/pkg/reconciler/common/testing"
)
Expand Down Expand Up @@ -47,3 +48,28 @@ func TestListReleases(t *testing.T) {
util.AssertEqual(t, err, nil)
util.AssertDeepEqual(t, version, expectedVersionList)
}

func TestAppendManifest(t *testing.T) {

// Case 1
var manifest mf.Manifest
err := AppendManifest(&manifest, "testdata/kodata/tekton-addon")
if err != nil {
t.Fatal("failed to read yaml: ", err)
}

if len(manifest.Resources()) != 3 {
t.Fatalf("failed to find expected number of resource: %d found, expected 3", len(manifest.Resources()))
}

// Case 2
var newManifest mf.Manifest
err = AppendManifest(&newManifest, "testdata/kodata/tekton-addon/0.0.1")
if err != nil {
t.Fatal("failed to read yaml: ", err)
}

if len(newManifest.Resources()) != 1 {
t.Fatalf("failed to find expected number of resource: %d found, expected 3", len(newManifest.Resources()))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: triggers.tekton.dev/v1alpha1
kind: ClusterTriggerBinding
metadata:
name: bitbucket-pullreq-0.0.2
spec:
params:
- name: gitrepo-url
value: $(body.pullRequest.fromRef.repository.links.clone[0].href)
- name: pullreq-sha
value: $(body.pullRequest.fromRef.latestCommit)
- name: pullreq-state
value: $(body.pullRequest.state)
- name: pullreq-number
value: $(body.pullRequest.id)
- name: pullreq-repo-name
value: $(body.pullRequest.toRef.repository.name)
- name: pullreq-html-url
value: $(body.pullRequest.links.self[0].href)
- name: pullreq-title
value: $(body.pullRequest.title)
- name: user-type
value: $(body.pullRequest.author.user.type)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: triggers.tekton.dev/v1alpha1
kind: ClusterTriggerBinding
metadata:
name: bitbucket-pullreq-no-version
spec:
params:
- name: gitrepo-url
value: $(body.pullRequest.fromRef.repository.links.clone[0].href)
- name: pullreq-sha
value: $(body.pullRequest.fromRef.latestCommit)
- name: pullreq-state
value: $(body.pullRequest.state)
- name: pullreq-number
value: $(body.pullRequest.id)
- name: pullreq-repo-name
value: $(body.pullRequest.toRef.repository.name)
- name: pullreq-html-url
value: $(body.pullRequest.links.self[0].href)
- name: pullreq-title
value: $(body.pullRequest.title)
- name: user-type
value: $(body.pullRequest.author.user.type)

0 comments on commit e3e4b24

Please sign in to comment.