Skip to content

Commit

Permalink
Remove deprecated fields from PipelineResourceResult 🍠
Browse files Browse the repository at this point in the history
The `Name` and `Digest` field have been deprecated in a previous
release. This removes the fields from the struct. See
tektoncd#1392 for the inital issue.

It also reduce code duplication by aliasing some types between
v1alpha1 and v1alpha2.

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
  • Loading branch information
vdemeester committed Feb 7, 2020
1 parent 259cf76 commit 9668bb2
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 77 deletions.
6 changes: 0 additions & 6 deletions cmd/imagedigestexporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ func main() {
if err != nil {
logger.Fatalf("Unexpected error getting image digest for %s: %v", imageResource.Name, err)
}
// We need to write both the old Name/Digest style and the new Key/Value styles.
output = append(output, v1alpha1.PipelineResourceResult{
Name: imageResource.Name,
Digest: digest.String(),
})

output = append(output, v1alpha1.PipelineResourceResult{
Key: "digest",
Value: digest.String(),
Expand Down
8 changes: 5 additions & 3 deletions docs/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ URLs should be of the form: https://github.com/tektoncd/pipeline/pull/1

The PullRequest resource works with self hosted or enterprise GitHub/GitLab
instances. Simply provide the pull request URL and set the `provider` parameter.
If you need to skip certificate validation set the `insecure-skip-tls-verify`
If you need to skip certificate validation set the `insecure-skip-tls-verify`
parameter to `"true"`.

```yaml
Expand Down Expand Up @@ -574,8 +574,10 @@ for example:
status:
...
resourcesResult:
- digest: sha256:eed29cd0b6feeb1a92bc3c4f977fd203c63b376a638731c88cacefe3adb1c660
name: skaffold-image-leeroy-web
- key: "digest"
value: "sha256:eed29cd0b6feeb1a92bc3c4f977fd203c63b376a638731c88cacefe3adb1c660"
resourceRef:
name: skaffold-image-leeroy-web
...
```

Expand Down
4 changes: 2 additions & 2 deletions examples/taskruns/cloud-event.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ spec:
if response.status == 200:
print("Got it!")
taskrun = json.loads(response.read().decode('utf-8'))
digest = taskrun['taskRun']['status']['resourcesResult'][0]['digest']
image_name = taskrun['taskRun']['status']['resourcesResult'][0]['name']
digest = taskrun['taskRun']['status']['resourcesResult'][0]['value']
image_name = taskrun['taskRun']['status']['resourcesResult'][0]['resourceRef']['name']
print("Got digest %s for image %s" % (digest, image_name))
if image_name == "myimage" and digest:
break
Expand Down
8 changes: 1 addition & 7 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,7 @@ const (
)

// PipelineResourceRef can be used to refer to a specific instance of a Resource
type PipelineResourceRef struct {
// Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names
Name string `json:"name,omitempty"`
// API version of the referent
// +optional
APIVersion string `json:"apiVersion,omitempty"`
}
type PipelineResourceRef = v1alpha2.PipelineResourceRef

// PipelineRef can be used to refer to a specific instance of a Pipeline.
// Copied from CrossVersionObjectReference: https://github.com/kubernetes/kubernetes/blob/169df7434155cbbc22f1532cba8e0a9588e29ad8/pkg/apis/autoscaling/types.go#L64
Expand Down
13 changes: 2 additions & 11 deletions pkg/apis/pipeline/v1alpha1/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,10 @@ type PipelineResourceBinding struct {
}

// PipelineResourceResult used to export the image name and digest as json
type PipelineResourceResult struct {
// Name and Digest are deprecated.
Name string `json:"name"`
Digest string `json:"digest"`
// These will replace Name and Digest (https://github.com/tektoncd/pipeline/issues/1392)
Key string `json:"key"`
Value string `json:"value"`
ResourceRef PipelineResourceRef `json:"resourceRef,omitempty"`
ResultType ResultType `json:"type,omitempty"`
}
type PipelineResourceResult = v1alpha2.PipelineResourceResult

// ResultType used to find out whether a PipelineResourceResult is from a task result or not
type ResultType string
type ResultType = v1alpha2.ResultType

// ResourceFromType returns an instance of the correct PipelineResource object type which can be
// used to add input and output containers as well as volumes to a TaskRun's pod in order to realize
Expand Down
37 changes: 2 additions & 35 deletions pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1alpha2/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,12 @@ type PipelineResourceResult struct {
Key string `json:"key"`
Value string `json:"value"`
ResourceRef PipelineResourceRef `json:"resourceRef,omitempty"`
ResultType ResultType `json:"type,omitempty"`
}

// ResultType used to find out whether a PipelineResourceResult is from a task result or not
type ResultType string

// PipelineResourceRef can be used to refer to a specific instance of a Resource
type PipelineResourceRef struct {
// Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names
Expand Down
23 changes: 13 additions & 10 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1643,14 +1643,15 @@ func TestUpdateTaskRunResourceResult(t *testing.T) {
ContainerStatuses: []corev1.ContainerStatus{{
State: corev1.ContainerState{
Terminated: &corev1.ContainerStateTerminated{
Message: `[{"name":"source-image","digest":"sha256:1234"}]`,
Message: `[{"key":"digest","value":"sha256:1234","resourceRef":{"name":"source-image"}}]`,
},
},
}},
},
want: []v1alpha1.PipelineResourceResult{{
Name: "source-image",
Digest: "sha256:1234",
Key: "digest",
Value: "sha256:1234",
ResourceRef: v1alpha1.PipelineResourceRef{Name: "source-image"},
}},
}} {
t.Run(c.desc, func(t *testing.T) {
Expand Down Expand Up @@ -1683,7 +1684,7 @@ func TestUpdateTaskRunResult(t *testing.T) {
ContainerStatuses: []corev1.ContainerStatus{{
State: corev1.ContainerState{
Terminated: &corev1.ContainerStateTerminated{
Message: `[{"key":"resultName","value":"resultValue", "type": "TaskRunResult"}, {"name":"source-image","digest":"sha256:1234", "type": "PipelineResourceResult"}]`,
Message: `[{"key":"resultName","value":"resultValue", "type": "TaskRunResult"}, {"key":"digest","value":"sha256:1234","resourceRef":{"name":"source-image"}, "type": "PipelineResourceResult"}]`,
},
},
}},
Expand All @@ -1693,9 +1694,10 @@ func TestUpdateTaskRunResult(t *testing.T) {
Value: "resultValue",
}},
want: []v1alpha1.PipelineResourceResult{{
Name: "source-image",
Digest: "sha256:1234",
ResultType: "PipelineResourceResult",
Key: "digest",
Value: "sha256:1234",
ResourceRef: v1alpha1.PipelineResourceRef{Name: "source-image"},
ResultType: "PipelineResourceResult",
}},
}} {
t.Run(c.desc, func(t *testing.T) {
Expand Down Expand Up @@ -1730,7 +1732,7 @@ func TestUpdateTaskRunResult2(t *testing.T) {
ContainerStatuses: []corev1.ContainerStatus{{
State: corev1.ContainerState{
Terminated: &corev1.ContainerStateTerminated{
Message: `[{"key":"resultName","value":"resultValue", "type": "TaskRunResult"}, {"name":"source-image","digest":"sha256:1234"}]`,
Message: `[{"key":"resultName","value":"resultValue", "type": "TaskRunResult"}, {"key":"digest","value":"sha256:1234","resourceRef":{"name":"source-image"}}]`,
},
},
}},
Expand All @@ -1740,8 +1742,9 @@ func TestUpdateTaskRunResult2(t *testing.T) {
Value: "resultValue",
}},
want: []v1alpha1.PipelineResourceResult{{
Name: "source-image",
Digest: "sha256:1234",
Key: "digest",
Value: "sha256:1234",
ResourceRef: v1alpha1.PipelineResourceRef{Name: "source-image"},
}},
}} {
t.Run(c.desc, func(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/termination/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ func TestParseMessage(t *testing.T) {
want []v1alpha1.PipelineResourceResult
}{{
desc: "valid message",
msg: `[{"digest":"foo"},{"key":"foo","value":"bar"}]`,
msg: `[{"key": "digest","value":"hereisthedigest"},{"key":"foo","value":"bar"}]`,
want: []v1alpha1.PipelineResourceResult{{
Digest: "foo",
Key: "digest",
Value: "hereisthedigest",
}, {
Key: "foo",
Value: "bar",
Expand Down
2 changes: 1 addition & 1 deletion pkg/termination/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestExistingFile(t *testing.T) {
if fileContents, err := ioutil.ReadFile(tmpFile.Name()); err != nil {
logger.Fatalf("Unexpected error reading %v: %v", tmpFile.Name(), err)
} else {
want := `[{"name":"","digest":"","key":"key1","value":"hello","resourceRef":{}},{"name":"","digest":"","key":"key2","value":"world","resourceRef":{}}]`
want := `[{"key":"key1","value":"hello","resourceRef":{}},{"key":"key2","value":"world","resourceRef":{}}]`
if d := cmp.Diff(want, string(fileContents)); d != "" {
t.Fatalf("Diff(-want, got): %s", d)
}
Expand Down

0 comments on commit 9668bb2

Please sign in to comment.