Skip to content

Commit cd077ec

Browse files
khrmtekton-robot
authored andcommitted
Add Support for Tekton Pipeline v1 APIs
Add support for storing PipelineRun and TaskRun objects as v1. These CR are reconciled as v1 version of Pipelines API and then stored in DB as v1. Existing v1beta1 resources are kept as it is. An ability to convert these older record to v1 will be added.
1 parent 1e174ec commit cd077ec

File tree

39 files changed

+1438
-1268
lines changed

39 files changed

+1438
-1268
lines changed

pkg/api/server/cel/cel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/google/cel-go/checker/decls"
2424
"github.com/google/cel-go/common/types"
2525
"github.com/google/cel-go/common/types/ref"
26-
ppb "github.com/tektoncd/results/proto/pipeline/v1beta1/pipeline_go_proto"
26+
ppb "github.com/tektoncd/results/proto/pipeline/v1/pipeline_go_proto"
2727
pb "github.com/tektoncd/results/proto/v1alpha2/results_go_proto"
2828
"google.golang.org/grpc/codes"
2929
"google.golang.org/grpc/status"

pkg/api/server/v1alpha2/logs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ func TestListLogs(t *testing.T) {
519519
name: "unknown type",
520520
req: &pb.ListRecordsRequest{
521521
Parent: res.GetName(),
522-
Filter: `type(record.data) == tekton.pipeline.v1beta1.Unknown`,
522+
Filter: `type(record.data) == tekton.pipeline.v1.Unknown`,
523523
},
524524
status: codes.InvalidArgument,
525525
},

pkg/api/server/v1alpha2/record/record.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/tektoncd/results/pkg/apis/v1alpha3"
2626

2727
"github.com/google/cel-go/cel"
28-
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
28+
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
2929
resultscel "github.com/tektoncd/results/pkg/api/server/cel"
3030
"github.com/tektoncd/results/pkg/api/server/db"
3131
pb "github.com/tektoncd/results/proto/v1alpha2/results_go_proto"
@@ -181,9 +181,9 @@ func validateData(m *pb.Any) error {
181181
}
182182
switch m.GetType() {
183183
case "pipeline.tekton.dev/TaskRun":
184-
return json.Unmarshal(m.GetValue(), &v1beta1.TaskRun{})
184+
return json.Unmarshal(m.GetValue(), &v1.TaskRun{})
185185
case "pipeline.tekton.dev/PipelineRun":
186-
return json.Unmarshal(m.GetValue(), &v1beta1.PipelineRun{})
186+
return json.Unmarshal(m.GetValue(), &v1.PipelineRun{})
187187
case "results.tekton.dev/v1alpha3.Log":
188188
return json.Unmarshal(m.GetValue(), &v1alpha3.Log{})
189189
default:

pkg/api/server/v1alpha2/record/record_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323

2424
"github.com/google/go-cmp/cmp"
2525
cw "github.com/jonboulle/clockwork"
26-
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
26+
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
2727
"github.com/tektoncd/results/pkg/api/server/db"
2828
"github.com/tektoncd/results/pkg/internal/jsonutil"
29-
ppb "github.com/tektoncd/results/proto/pipeline/v1beta1/pipeline_go_proto"
29+
ppb "github.com/tektoncd/results/proto/pipeline/v1/pipeline_go_proto"
3030
pb "github.com/tektoncd/results/proto/v1alpha2/results_go_proto"
3131
"google.golang.org/grpc/codes"
3232
"google.golang.org/grpc/status"
@@ -230,7 +230,7 @@ func TestToStorage(t *testing.T) {
230230
}
231231

232232
func TestToAPI(t *testing.T) {
233-
data := &v1beta1.TaskRun{ObjectMeta: v1.ObjectMeta{Name: "tacocat"}}
233+
data := &pipelinev1.TaskRun{ObjectMeta: v1.ObjectMeta{Name: "tacocat"}}
234234
for _, tc := range []struct {
235235
name string
236236
in *db.Record

pkg/api/server/v1alpha2/records_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ import (
2727
"github.com/tektoncd/results/pkg/api/server/logger"
2828

2929
"github.com/google/go-cmp/cmp"
30-
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
30+
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
3131
"github.com/tektoncd/results/pkg/api/server/test"
3232
"github.com/tektoncd/results/pkg/api/server/v1alpha2/record"
3333
recordutil "github.com/tektoncd/results/pkg/api/server/v1alpha2/record"
3434
"github.com/tektoncd/results/pkg/api/server/v1alpha2/result"
3535
resultutil "github.com/tektoncd/results/pkg/api/server/v1alpha2/result"
3636
"github.com/tektoncd/results/pkg/internal/jsonutil"
37-
ppb "github.com/tektoncd/results/proto/pipeline/v1beta1/pipeline_go_proto"
37+
ppb "github.com/tektoncd/results/proto/pipeline/v1/pipeline_go_proto"
3838
pb "github.com/tektoncd/results/proto/v1alpha2/results_go_proto"
3939
"google.golang.org/grpc/codes"
4040
"google.golang.org/grpc/status"
@@ -67,7 +67,7 @@ func TestCreateRecord(t *testing.T) {
6767
Name: recordutil.FormatName(result.GetName(), "baz"),
6868
Data: &pb.Any{
6969
Type: "TaskRun",
70-
Value: jsonutil.AnyBytes(t, &v1beta1.TaskRun{ObjectMeta: v1.ObjectMeta{Name: "tacocat"}}),
70+
Value: jsonutil.AnyBytes(t, &pipelinev1.TaskRun{ObjectMeta: v1.ObjectMeta{Name: "tacocat"}}),
7171
},
7272
},
7373
}
@@ -276,7 +276,7 @@ func TestListRecords(t *testing.T) {
276276
Name: fmt.Sprintf("%s/records/%d", result.GetName(), i),
277277
Data: &pb.Any{
278278
Type: "TaskRun",
279-
Value: jsonutil.AnyBytes(t, &v1beta1.TaskRun{ObjectMeta: v1.ObjectMeta{
279+
Value: jsonutil.AnyBytes(t, &pipelinev1.TaskRun{ObjectMeta: v1.ObjectMeta{
280280
Name: fmt.Sprintf("%d", i),
281281
}}),
282282
},
@@ -298,7 +298,7 @@ func TestListRecords(t *testing.T) {
298298
Name: fmt.Sprintf("%s/records/%d", result.GetName(), i),
299299
Data: &pb.Any{
300300
Type: "PipelineRun",
301-
Value: jsonutil.AnyBytes(t, &v1beta1.PipelineRun{ObjectMeta: v1.ObjectMeta{
301+
Value: jsonutil.AnyBytes(t, &pipelinev1.PipelineRun{ObjectMeta: v1.ObjectMeta{
302302
Name: fmt.Sprintf("%d", i),
303303
}}),
304304
},
@@ -433,7 +433,7 @@ func TestListRecords(t *testing.T) {
433433
name: "unknown type",
434434
req: &pb.ListRecordsRequest{
435435
Parent: result.GetName(),
436-
Filter: `type(record.data) == tekton.pipeline.v1beta1.Unknown`,
436+
Filter: `type(record.data) == tekton.pipeline.v1.Unknown`,
437437
},
438438
status: codes.InvalidArgument,
439439
},

pkg/watcher/convert/convert.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package convert provides a method to convert v1beta1 API objects to Results
17+
// Package convert provides a method to convert Pipeline v1 API objects to Results
1818
// API proto objects.
1919
package convert
2020

@@ -27,7 +27,8 @@ import (
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/apimachinery/pkg/types"
2929

30-
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
30+
pipelineV1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
31+
3132
"github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme"
3233
"github.com/tektoncd/pipeline/pkg/pod"
3334
rpb "github.com/tektoncd/results/proto/v1alpha2/results_go_proto"
@@ -93,7 +94,7 @@ func ToLogProto(in metav1.Object, kind, name string) (*rpb.Any, error) {
9394
// versions. Standard GVK string formatting does not produce something that's
9495
// payload friendly (i.e. includes spaces).
9596
// To get around this we append API Version + Kind
96-
// (e.g. tekton.dev/v1beta1.TaskRun).
97+
// (e.g. tekton.dev/v1.TaskRun).
9798
func TypeName(in runtime.Object) string {
9899
gvk := in.GetObjectKind().GroupVersionKind()
99100
if gvk.Empty() {
@@ -133,29 +134,29 @@ func Status(ca apis.ConditionAccessor) rpb.RecordSummary_Status {
133134
return rpb.RecordSummary_UNKNOWN
134135
}
135136

136-
switch v1beta1.TaskRunReason(c.Reason) {
137-
case v1beta1.TaskRunReasonSuccessful:
137+
switch pipelineV1.TaskRunReason(c.Reason) {
138+
case pipelineV1.TaskRunReasonSuccessful:
138139
return rpb.RecordSummary_SUCCESS
139-
case v1beta1.TaskRunReasonFailed:
140+
case pipelineV1.TaskRunReasonFailed:
140141
return rpb.RecordSummary_FAILURE
141-
case v1beta1.TaskRunReasonTimedOut:
142+
case pipelineV1.TaskRunReasonTimedOut:
142143
return rpb.RecordSummary_TIMEOUT
143-
case v1beta1.TaskRunReasonCancelled:
144+
case pipelineV1.TaskRunReasonCancelled:
144145
return rpb.RecordSummary_CANCELLED
145-
case v1beta1.TaskRunReasonRunning, v1beta1.TaskRunReasonStarted:
146+
case pipelineV1.TaskRunReasonRunning, pipelineV1.TaskRunReasonStarted:
146147
return rpb.RecordSummary_UNKNOWN
147148
}
148149

149-
switch v1beta1.PipelineRunReason(c.Reason) {
150-
case v1beta1.PipelineRunReasonSuccessful, v1beta1.PipelineRunReasonCompleted:
150+
switch pipelineV1.PipelineRunReason(c.Reason) {
151+
case pipelineV1.PipelineRunReasonSuccessful, pipelineV1.PipelineRunReasonCompleted:
151152
return rpb.RecordSummary_SUCCESS
152-
case v1beta1.PipelineRunReasonFailed:
153+
case pipelineV1.PipelineRunReasonFailed:
153154
return rpb.RecordSummary_FAILURE
154-
case v1beta1.PipelineRunReasonTimedOut:
155+
case pipelineV1.PipelineRunReasonTimedOut:
155156
return rpb.RecordSummary_TIMEOUT
156-
case v1beta1.PipelineRunReasonCancelled:
157+
case pipelineV1.PipelineRunReasonCancelled:
157158
return rpb.RecordSummary_CANCELLED
158-
case v1beta1.PipelineRunReasonRunning, v1beta1.PipelineRunReasonStarted, v1beta1.PipelineRunReasonPending, v1beta1.PipelineRunReasonStopping, v1beta1.PipelineRunReasonCancelledRunningFinally, v1beta1.PipelineRunReasonStoppedRunningFinally:
159+
case pipelineV1.PipelineRunReasonRunning, pipelineV1.PipelineRunReasonStarted, pipelineV1.PipelineRunReasonPending, pipelineV1.PipelineRunReasonStopping, pipelineV1.PipelineRunReasonCancelledRunningFinally, pipelineV1.PipelineRunReasonStoppedRunningFinally:
159160
return rpb.RecordSummary_UNKNOWN
160161
}
161162

0 commit comments

Comments
 (0)