Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture Remote StepAction Location in TaskRun Status #8106

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions docs/pipeline-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3437,7 +3437,7 @@ ParamType
<h3 id="tekton.dev/v1.Provenance">Provenance
</h3>
<p>
(<em>Appears on:</em><a href="#tekton.dev/v1.PipelineRunStatusFields">PipelineRunStatusFields</a>, <a href="#tekton.dev/v1.TaskRunStatusFields">TaskRunStatusFields</a>)
(<em>Appears on:</em><a href="#tekton.dev/v1.PipelineRunStatusFields">PipelineRunStatusFields</a>, <a href="#tekton.dev/v1.StepState">StepState</a>, <a href="#tekton.dev/v1.TaskRunStatusFields">TaskRunStatusFields</a>)
</p>
<div>
<p>Provenance contains metadata about resources used in the TaskRun/PipelineRun
Expand Down Expand Up @@ -4858,6 +4858,18 @@ string
</tr>
<tr>
<td>
<code>provenance</code><br/>
<em>
<a href="#tekton.dev/v1.Provenance">
Provenance
</a>
</em>
</td>
<td>
</td>
</tr>
<tr>
<td>
<code>terminationReason</code><br/>
<em>
string
Expand Down Expand Up @@ -12776,7 +12788,7 @@ ParamType
<h3 id="tekton.dev/v1beta1.Provenance">Provenance
</h3>
<p>
(<em>Appears on:</em><a href="#tekton.dev/v1beta1.PipelineRunStatusFields">PipelineRunStatusFields</a>, <a href="#tekton.dev/v1beta1.TaskRunStatusFields">TaskRunStatusFields</a>)
(<em>Appears on:</em><a href="#tekton.dev/v1beta1.PipelineRunStatusFields">PipelineRunStatusFields</a>, <a href="#tekton.dev/v1beta1.StepState">StepState</a>, <a href="#tekton.dev/v1beta1.TaskRunStatusFields">TaskRunStatusFields</a>)
</p>
<div>
<p>Provenance contains metadata about resources used in the TaskRun/PipelineRun
Expand Down Expand Up @@ -14444,6 +14456,18 @@ string
</tr>
<tr>
<td>
<code>provenance</code><br/>
<em>
<a href="#tekton.dev/v1beta1.Provenance">
Provenance
</a>
</em>
</td>
<td>
</td>
</tr>
<tr>
<td>
<code>inputs</code><br/>
<em>
<a href="#tekton.dev/v1beta1.Artifact">
Expand Down
7 changes: 6 additions & 1 deletion pkg/apis/pipeline/v1/openapi_generated.go

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

3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,9 @@
"$ref": "#/definitions/v1.Artifact"
}
},
"provenance": {
"$ref": "#/definitions/v1.Provenance"
},
"results": {
"type": "array",
"items": {
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/pipeline/v1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ type StepState struct {
Container string `json:"container,omitempty"`
ImageID string `json:"imageID,omitempty"`
Results []TaskRunStepResult `json:"results,omitempty"`
Provenance *Provenance `json:"provenance,omitempty"`
TerminationReason string `json:"terminationReason,omitempty"`
Inputs []TaskRunStepArtifact `json:"inputs,omitempty"`
Outputs []TaskRunStepArtifact `json:"outputs,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/pipeline/v1/zz_generated.deepcopy.go

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

7 changes: 6 additions & 1 deletion pkg/apis/pipeline/v1beta1/openapi_generated.go

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

3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1beta1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,9 @@
"$ref": "#/definitions/v1beta1.Artifact"
}
},
"provenance": {
"$ref": "#/definitions/v1beta1.Provenance"
},
"results": {
"type": "array",
"items": {
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/pipeline/v1beta1/taskrun_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ func (ss StepState) convertTo(ctx context.Context, sink *v1.StepState) {
sink.ImageID = ss.ImageID
sink.Results = nil

if ss.Provenance != nil {
new := v1.Provenance{}
ss.Provenance.convertTo(ctx, &new)
sink.Provenance = &new
}

if ss.ContainerState.Terminated != nil {
sink.TerminationReason = ss.ContainerState.Terminated.Reason
}
Expand Down Expand Up @@ -379,6 +385,11 @@ func (ss *StepState) convertFrom(ctx context.Context, source v1.StepState) {
new.convertFrom(ctx, r)
ss.Results = append(ss.Results, new)
}
if source.Provenance != nil {
new := Provenance{}
new.convertFrom(ctx, *source.Provenance)
ss.Provenance = &new
}
for _, o := range source.Outputs {
new := TaskRunStepArtifact{}
new.convertFrom(ctx, o)
Expand Down
21 changes: 21 additions & 0 deletions pkg/apis/pipeline/v1beta1/taskrun_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ func TestTaskRunConversion(t *testing.T) {
},
},
},
}, {
name: "taskrun with provenance in step state",
in: &v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "bar",
},
Spec: v1beta1.TaskRunSpec{},
Status: v1beta1.TaskRunStatus{
TaskRunStatusFields: v1beta1.TaskRunStatusFields{
Steps: []v1beta1.StepState{{
Provenance: &v1beta1.Provenance{
RefSource: &v1beta1.RefSource{
URI: "test-uri",
Digest: map[string]string{"sha256": "digest"},
},
},
}},
},
},
},
}, {
name: "taskrun conversion all non deprecated fields",
in: &v1beta1.TaskRun{
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/pipeline/v1beta1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ type StepState struct {
ContainerName string `json:"container,omitempty"`
ImageID string `json:"imageID,omitempty"`
Results []TaskRunStepResult `json:"results,omitempty"`
Provenance *Provenance `json:"provenance,omitempty"`
Inputs []TaskRunStepArtifact `json:"inputs,omitempty"`
Outputs []TaskRunStepArtifact `json:"outputs,omitempty"`
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions pkg/pod/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ func IsContainerStep(name string) bool { return strings.HasPrefix(name, stepPref
// represents a sidecar.
func IsContainerSidecar(name string) bool { return strings.HasPrefix(name, sidecarPrefix) }

// trimStepPrefix returns the container name, stripped of its step prefix.
func trimStepPrefix(name string) string { return strings.TrimPrefix(name, stepPrefix) }
// TrimStepPrefix returns the container name, stripped of its step prefix.
func TrimStepPrefix(name string) string { return strings.TrimPrefix(name, stepPrefix) }

// TrimSidecarPrefix returns the container name, stripped of its sidecar
// prefix.
Expand Down
20 changes: 15 additions & 5 deletions pkg/pod/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func MakeTaskRunStatus(ctx context.Context, logger *zap.SugaredLogger, tr v1.Tas
}

trs.PodName = pod.Name
trs.Steps = []v1.StepState{}
dibyom marked this conversation as resolved.
Show resolved Hide resolved
trs.Sidecars = []v1.SidecarState{}

var stepStatuses []corev1.ContainerStatus
Expand Down Expand Up @@ -365,17 +364,28 @@ func setTaskRunStatusBasedOnStepStatus(ctx context.Context, logger *zap.SugaredL
terminationReason = getTerminationReason(state.Terminated.Reason, terminationFromResults, exitCode)
}
}

trs.Steps = append(trs.Steps, v1.StepState{
stepState := v1.StepState{
ContainerState: *state,
Name: trimStepPrefix(s.Name),
Name: TrimStepPrefix(s.Name),
Container: s.Name,
ImageID: s.ImageID,
Results: taskRunStepResults,
TerminationReason: terminationReason,
Inputs: sas.Inputs,
Outputs: sas.Outputs,
})
}
foundStep := false
for i, ss := range trs.Steps {
if ss.Name == stepState.Name {
stepState.Provenance = ss.Provenance
trs.Steps[i] = stepState
foundStep = true
break
}
}
if !foundStep {
trs.Steps = append(trs.Steps, stepState)
}
}

return merr
Expand Down
Loading