diff --git a/.golangci.yml b/.golangci.yml index 2269e0d2eb6..963ff69ae5a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -24,6 +24,8 @@ run: issues-exit-code: 1 build-tags: - e2e + skip-files: + - .*/zz_generated.deepcopy.go skip-dirs: - vendor - pkg/client diff --git a/pkg/pod/status.go b/pkg/pod/status.go index 55046be8bc5..fb35ee310d7 100644 --- a/pkg/pod/status.go +++ b/pkg/pod/status.go @@ -116,9 +116,14 @@ func MakeTaskRunStatus(logger *zap.SugaredLogger, tr v1beta1.TaskRun, pod *corev for _, s := range pod.Status.ContainerStatuses { if IsContainerStep(s.Name) { if s.State.Terminated != nil && len(s.State.Terminated.Message) != 0 { - if err := updateStatusStartTime(&s); err != nil { + message, time, err := removeStartInfoFromTerminationMessage(s) + if err != nil { logger.Errorf("error setting the start time of step %q in taskrun %q: %w", s.Name, tr.Name, err) } + if time != nil { + s.State.Terminated.StartedAt = *time + s.State.Terminated.Message = message + } } trs.Steps = append(trs.Steps, v1beta1.StepState{ ContainerState: *s.State.DeepCopy(), @@ -151,34 +156,35 @@ func MakeTaskRunStatus(logger *zap.SugaredLogger, tr v1beta1.TaskRun, pod *corev return *trs } -// updateStatusStartTime searches for a result called "StartedAt" in the JSON-formatted termination message -// of a step and sets the State.Terminated.StartedAt field to this time if it's found. The "StartedAt" result -// is also removed from the list of results in the container status. -func updateStatusStartTime(s *corev1.ContainerStatus) error { +// removeStartInfoFromTerminationMessage searches for a result called "StartedAt" in the JSON-formatted +// termination message of a step and returns the values to use for sets State.Terminated if it's +// found. The "StartedAt" result is also removed from the list of results in the container status. +func removeStartInfoFromTerminationMessage(s corev1.ContainerStatus) (string, *metav1.Time, error) { r, err := termination.ParseMessage(s.State.Terminated.Message) if err != nil { - return fmt.Errorf("termination message could not be parsed as JSON: %w", err) + return "", nil, fmt.Errorf("termination message could not be parsed as JSON: %w", err) } for index, result := range r { if result.Key == "StartedAt" { t, err := time.Parse(timeFormat, result.Value) if err != nil { - return fmt.Errorf("could not parse time value %q in StartedAt field: %w", result.Value, err) + return "", nil, fmt.Errorf("could not parse time value %q in StartedAt field: %w", result.Value, err) } - s.State.Terminated.StartedAt = metav1.NewTime(t) + message := "" + startedAt := metav1.NewTime(t) // remove the entry for the starting time r = append(r[:index], r[index+1:]...) if len(r) == 0 { - s.State.Terminated.Message = "" + message = "" } else if bytes, err := json.Marshal(r); err != nil { - return fmt.Errorf("error marshalling remaining results back into termination message: %w", err) + return "", nil, fmt.Errorf("error marshalling remaining results back into termination message: %w", err) } else { - s.State.Terminated.Message = string(bytes) + message = string(bytes) } - break + return message, &startedAt, nil } } - return nil + return "", nil, nil } func updateCompletedTaskRun(trs *v1beta1.TaskRunStatus, pod *corev1.Pod) { diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go index 4a2b143f50b..14a0dad982f 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go @@ -234,7 +234,7 @@ type GetTaskRun func(name string) (*v1beta1.TaskRun, error) func GetResourcesFromBindings(pr *v1beta1.PipelineRun, getResource resources.GetResource) (map[string]*resourcev1alpha1.PipelineResource, error) { rs := map[string]*resourcev1alpha1.PipelineResource{} for _, resource := range pr.Spec.Resources { - r, err := resources.GetResourceFromBinding(&resource, getResource) + r, err := resources.GetResourceFromBinding(resource, getResource) if err != nil { return rs, fmt.Errorf("error following resource reference for %s: %w", resource.Name, err) } diff --git a/pkg/reconciler/taskrun/resources/image_exporter.go b/pkg/reconciler/taskrun/resources/image_exporter.go index f9b19a9568f..8634378cb36 100644 --- a/pkg/reconciler/taskrun/resources/image_exporter.go +++ b/pkg/reconciler/taskrun/resources/image_exporter.go @@ -45,7 +45,7 @@ func AddOutputImageDigestExporter( return fmt.Errorf("failed to get bound resource: %w while adding output image digest exporter", err) } - resource, err := GetResourceFromBinding(&boundResource.PipelineResourceBinding, gr) + resource, err := GetResourceFromBinding(boundResource.PipelineResourceBinding, gr) if err != nil { return fmt.Errorf("failed to get output pipeline Resource for taskRun %q resource %v; error: %w while adding output image digest exporter", tr.Name, boundResource, err) } diff --git a/pkg/reconciler/taskrun/resources/taskresourceresolution.go b/pkg/reconciler/taskrun/resources/taskresourceresolution.go index e01efe83cb5..83d2a0646a9 100644 --- a/pkg/reconciler/taskrun/resources/taskresourceresolution.go +++ b/pkg/reconciler/taskrun/resources/taskresourceresolution.go @@ -55,7 +55,7 @@ func ResolveTaskResources(ts *v1beta1.TaskSpec, taskName string, kind v1beta1.Ta } for _, r := range inputs { - rr, err := GetResourceFromBinding(&r.PipelineResourceBinding, gr) + rr, err := GetResourceFromBinding(r.PipelineResourceBinding, gr) if err != nil { return nil, fmt.Errorf("couldn't retrieve referenced input PipelineResource: %w", err) } @@ -64,7 +64,7 @@ func ResolveTaskResources(ts *v1beta1.TaskSpec, taskName string, kind v1beta1.Ta } for _, r := range outputs { - rr, err := GetResourceFromBinding(&r.PipelineResourceBinding, gr) + rr, err := GetResourceFromBinding(r.PipelineResourceBinding, gr) if err != nil { return nil, fmt.Errorf("couldn't retrieve referenced output PipelineResource: %w", err) @@ -77,7 +77,7 @@ func ResolveTaskResources(ts *v1beta1.TaskSpec, taskName string, kind v1beta1.Ta // GetResourceFromBinding will return an instance of a PipelineResource to use for r, either by getting it with getter or by // instantiating it from the embedded spec. -func GetResourceFromBinding(r *v1beta1.PipelineResourceBinding, getter GetResource) (*resourcev1alpha1.PipelineResource, error) { +func GetResourceFromBinding(r v1beta1.PipelineResourceBinding, getter GetResource) (*resourcev1alpha1.PipelineResource, error) { if (r.ResourceRef != nil && r.ResourceRef.Name != "") && r.ResourceSpec != nil { return nil, errors.New("Both ResourseRef and ResourceSpec are defined. Expected only one") } diff --git a/pkg/reconciler/taskrun/resources/taskresourceresolution_test.go b/pkg/reconciler/taskrun/resources/taskresourceresolution_test.go index da0974088a5..cc72c424b96 100644 --- a/pkg/reconciler/taskrun/resources/taskresourceresolution_test.go +++ b/pkg/reconciler/taskrun/resources/taskresourceresolution_test.go @@ -273,7 +273,7 @@ func TestGetResourceFromBinding_Ref(t *testing.T) { Name: "git-repo", }, } - binding := &v1beta1.PipelineResourceBinding{ + binding := v1beta1.PipelineResourceBinding{ ResourceRef: &v1beta1.PipelineResourceRef{ Name: "foo-resource", }, @@ -292,7 +292,7 @@ func TestGetResourceFromBinding_Ref(t *testing.T) { } func TestGetResourceFromBinding_Spec(t *testing.T) { - binding := &v1beta1.PipelineResourceBinding{ + binding := v1beta1.PipelineResourceBinding{ ResourceSpec: &resourcev1alpha1.PipelineResourceSpec{ Type: resourcev1alpha1.PipelineResourceTypeGit, Params: []resourcev1alpha1.ResourceParam{{ @@ -318,7 +318,7 @@ func TestGetResourceFromBinding_Spec(t *testing.T) { } func TestGetResourceFromBinding_NoNameOrSpec(t *testing.T) { - binding := &v1beta1.PipelineResourceBinding{} + binding := v1beta1.PipelineResourceBinding{} gr := func(n string) (*resourcev1alpha1.PipelineResource, error) { return nil, nil } @@ -330,7 +330,7 @@ func TestGetResourceFromBinding_NoNameOrSpec(t *testing.T) { } func TestGetResourceFromBinding_NameAndSpec(t *testing.T) { - binding := &v1beta1.PipelineResourceBinding{ + binding := v1beta1.PipelineResourceBinding{ ResourceSpec: &resourcev1alpha1.PipelineResourceSpec{ Type: resourcev1alpha1.PipelineResourceTypeGit, Params: []resourcev1alpha1.ResourceParam{{ @@ -353,7 +353,7 @@ func TestGetResourceFromBinding_NameAndSpec(t *testing.T) { } func TestGetResourceFromBinding_ErrorGettingResource(t *testing.T) { - binding := &v1beta1.PipelineResourceBinding{ + binding := v1beta1.PipelineResourceBinding{ ResourceRef: &v1beta1.PipelineResourceRef{ Name: "foo-resource", },