Skip to content

Commit

Permalink
Keeps Deprecated Fields in Step and StepTemplate When Switching Versions
Browse files Browse the repository at this point in the history
Prior to this commit, we have information loss when converting the
step and steptemplate from v1beta1 to v1. This commit preserves
those information by serializing steps and steptemplate, saving
them in object annoations when converting from v1beta1 to v1, then
deserializing when converting back.
  • Loading branch information
XinruZhang committed May 15, 2023
1 parent a3683b7 commit 564483f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
16 changes: 11 additions & 5 deletions pkg/apis/pipeline/v1beta1/openapi_generated.go

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

1 change: 0 additions & 1 deletion pkg/apis/pipeline/v1beta1/pipeline_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,4 @@ func TestPipelineConversion(t *testing.T) {
}
})
}

}
13 changes: 6 additions & 7 deletions pkg/apis/pipeline/v1beta1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3242,20 +3242,19 @@
"v1beta1.taskDeprecation": {
"description": "taskDeprecation contains deprecated fields of a Task",
"type": "object",
"required": [
"DeprecatedSteps",
"DeprecatedStepTemplate"
],
"properties": {
"DeprecatedStepTemplate": {
"deprecatedStepTemplate": {
"description": "DeprecatedStepTemplate contains stepTemplate of a Task that with deprecated fields defined.",
"$ref": "#/definitions/v1beta1.StepTemplate"
},
"DeprecatedSteps": {
"deprecatedSteps": {
"description": "DeprecatedSteps contains Steps of a Task that with deprecated fields defined.",
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/v1beta1.Step"
}
},
"x-kubernetes-list-type": "atomic"
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/apis/pipeline/v1beta1/task_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ func (ts *TaskSpec) ConvertFrom(ctx context.Context, source *v1.TaskSpec, meta *
new.convertFrom(ctx, s)
ts.Steps = append(ts.Steps, new)
}
//if err := deserializeStepsDeprecatedFields(meta, ts, taskName); err != nil {
// return err
//}
ts.Volumes = source.Volumes
if source.StepTemplate != nil {
new := StepTemplate{}
Expand Down Expand Up @@ -205,8 +202,7 @@ func deserializeTaskDeprecations(meta *metav1.ObjectMeta, spec *TaskSpec, taskNa
if len(spec.Steps) != len(td.DeprecatedSteps) {
return fmt.Errorf("length of deserialized steps mismatch the length of target steps")
}
var i int
for i, _ = range spec.Steps {
for i := 0; i < len(spec.Steps); i++ {
spec.Steps[i].DeprecatedPorts = td.DeprecatedSteps[i].DeprecatedPorts
spec.Steps[i].DeprecatedLivenessProbe = td.DeprecatedSteps[i].DeprecatedLivenessProbe
spec.Steps[i].DeprecatedReadinessProbe = td.DeprecatedSteps[i].DeprecatedReadinessProbe
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/pipeline/v1beta1/task_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ package v1beta1_test

import (
"context"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/test/diff"
"github.com/tektoncd/pipeline/test/parse"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"testing"
)

func TestTaskConversionBadType(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/pipeline/v1beta1/task_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ func (ts *TaskSpec) HasDeprecatedFields() bool {
s.DeprecatedLifecycle != nil ||
s.DeprecatedTerminationMessagePath != "" ||
s.DeprecatedTerminationMessagePolicy != "" ||
s.DeprecatedStdin != false ||
s.DeprecatedStdinOnce != false ||
s.DeprecatedTTY != false {
s.DeprecatedStdin ||
s.DeprecatedStdinOnce ||
s.DeprecatedTTY {
return true
}
}
Expand All @@ -159,9 +159,9 @@ func (ts *TaskSpec) HasDeprecatedFields() bool {
ts.StepTemplate.DeprecatedLifecycle != nil ||
ts.StepTemplate.DeprecatedTerminationMessagePath != "" ||
ts.StepTemplate.DeprecatedTerminationMessagePolicy != "" ||
ts.StepTemplate.DeprecatedStdin != false ||
ts.StepTemplate.DeprecatedStdinOnce != false ||
ts.StepTemplate.DeprecatedTTY != false {
ts.StepTemplate.DeprecatedStdin ||
ts.StepTemplate.DeprecatedStdinOnce ||
ts.StepTemplate.DeprecatedTTY {
return true
}
}
Expand Down

0 comments on commit 564483f

Please sign in to comment.