Skip to content

Commit

Permalink
chore: always use resolved path
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzzzzzzz committed Apr 25, 2024
1 parent acacd4f commit 9a3f3a2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 54 deletions.
9 changes: 4 additions & 5 deletions pkg/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,24 +751,23 @@ func usesWindows(tr *v1.TaskRun) bool {
}

func artifactsPathReferenced(steps []v1.Step) bool {
unresolvedPath := "$(step.artifacts.path)"
for i, step := range steps {
path := filepath.Join(pipeline.StepsDir, StepName(step.Name, i), "artifacts", "provenance.json")
if strings.Contains(step.Script, path) || strings.Contains(step.Script, unresolvedPath) {
if strings.Contains(step.Script, path) {
return true
}
for _, arg := range step.Args {
if strings.Contains(arg, path) || strings.Contains(arg, unresolvedPath) {
if strings.Contains(arg, path) {
return true
}
}
for _, c := range step.Command {
if strings.Contains(c, path) || strings.Contains(c, unresolvedPath) {
if strings.Contains(c, path) {
return true
}
}
for _, e := range step.Env {
if strings.Contains(e.Value, path) || strings.Contains(e.Value, unresolvedPath) {
if strings.Contains(e.Value, path) {
return true
}
}
Expand Down
46 changes: 0 additions & 46 deletions pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3942,52 +3942,6 @@ func Test_artifactsPathReferenced(t *testing.T) {
},
want: true,
},
{
name: "Unresolved reference in Script",
steps: []v1.Step{
{
Name: "name",
Script: "echo aaa >> $(step.artifacts.path)",
},
},
want: true,
},
{
name: "Unresolved reference in Args",
steps: []v1.Step{
{
Name: "name",
Command: []string{"cat"},
Args: []string{"$(step.artifacts.path)"},
},
},
want: true,
},
{
name: "Unresolved reference in Command",
steps: []v1.Step{
{
Name: "name",
Command: []string{"cat", "$(step.artifacts.path)"},
},
},
want: true,
},
{
name: "Unresolved reference in Env",
steps: []v1.Step{
{
Name: "name",
Env: []corev1.EnvVar{
{
Name: "MY_VAR",
Value: "$(step.artifacts.path)",
},
},
},
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions pkg/pod/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ func setTaskRunStatusBasedOnStepStatus(ctx context.Context, logger *zap.SugaredL
// Extract results from sidecar logs
sidecarLogsResultsEnabled := config.FromContextOrDefaults(ctx).FeatureFlags.ResultExtractionMethod == config.ResultExtractionMethodSidecarLogs
// temporary solution to check if artifacts sidecar created in taskRun as we don't have the api for users to declare if a step/task is producing artifacts yet
artifactsSidecarCreated := artifactsPathReferenced(ts.Steps)
artifactsSidecarCreated := false
if tr.Spec.TaskSpec != nil {
artifactsSidecarCreated = artifactsPathReferenced(tr.Spec.TaskSpec.Steps)
}
sidecarLogResults := []result.RunResult{}

sidecarArtifacts := map[string]v1.Artifacts{}

if sidecarLogsResultsEnabled {
Expand Down
3 changes: 2 additions & 1 deletion pkg/pod/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func TestSetTaskRunStatusBasedOnStepStatus_sidecar_logs(t *testing.T) {
PodName: "task-run-pod",
},
},
Spec: v1.TaskRunSpec{TaskSpec: &v1.TaskSpec{Steps: []v1.Step{{Name: "name", Script: `echo aaa >> /tekton/steps/step-name/artifacts/provenance.json`}}}},
},
maxResultSize: 1,
wantErr: sidecarlogresults.ErrSizeExceeded,
Expand All @@ -191,6 +192,7 @@ func TestSetTaskRunStatusBasedOnStepStatus_sidecar_logs(t *testing.T) {
PodName: "task-run-pod",
},
},
Spec: v1.TaskRunSpec{TaskSpec: &v1.TaskSpec{Steps: []v1.Step{{Name: "name", Script: `echo aaa >> /tekton/steps/step-name/artifacts/provenance.json`}}}},
},
maxResultSize: 4096,
wantErr: fmt.Errorf("%s", "invalid result \"\": invalid character 'k' in literal false (expecting 'l')"),
Expand Down Expand Up @@ -231,7 +233,6 @@ func TestSetTaskRunStatusBasedOnStepStatus_sidecar_logs(t *testing.T) {
ts := &v1.TaskSpec{}
if c.enableArtifacts {
featureFlags.EnableArtifacts = true
ts.Steps = []v1.Step{{Name: "name", Script: `echo aaa >> /tekton/steps/step-name/artifacts/provenance.json`}}
}
ctx := config.ToContext(context.Background(), &config.Config{
FeatureFlags: featureFlags,
Expand Down

0 comments on commit 9a3f3a2

Please sign in to comment.