Skip to content

Commit

Permalink
Fix failure due to the Results API upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: divyansh42 <[email protected]>
  • Loading branch information
divyansh42 authored and sayan-biswas committed Jan 13, 2025
1 parent a389503 commit c9f7aba
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 39 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,5 @@ Get TaskRun logs
kubectl tekton logs tr testtr -n default --uid="436dd41a-fd8a-4a29-b4f3-389b221af5dc"
```

### Deleting Resources

Delete all resources with name matching the keyword. All other flags for get are also available for delete.
Delete command will also delete any child resources matching the `OwnerReferences`.
```shell
kubectl tekton delete pr z56b6 -n default
```
4 changes: 2 additions & 2 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/sayan-biswas/kubectl-tekton/internal/cmd/config"
remove "github.com/sayan-biswas/kubectl-tekton/internal/cmd/delete"
"github.com/sayan-biswas/kubectl-tekton/internal/cmd/get"
"github.com/sayan-biswas/kubectl-tekton/internal/cmd/logs"
"github.com/sayan-biswas/kubectl-tekton/internal/cmd/version"
Expand Down Expand Up @@ -42,7 +41,8 @@ func Command() *cobra.Command {
config.Command(ios, f),
get.Command(ios, f),
logs.Command(ios, f),
remove.Command(ios, f),
// Delete command not supported
//remove.Command(ios, f),
version.Command(ios),
)

Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (o *Options) Run(_ *cobra.Command, _ []string) error {
}

// TODO: Version override is not required after tekton results migration to V1 APIs
gvk.Version = "v1beta1"
//gvk.Version = "v1beta1"

v, k := gvk.ToAPIVersionAndKind()

Expand Down Expand Up @@ -249,7 +249,6 @@ func (o *Options) Run(_ *cobra.Command, _ []string) error {
}
}
}

return nil
}

Expand Down
7 changes: 5 additions & 2 deletions internal/cmd/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"k8s.io/kubectl/pkg/scheme"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
"strings"
)

type Options struct {
Expand Down Expand Up @@ -131,7 +132,7 @@ func (o *Options) Run(_ *cobra.Command, _ []string) error {
gvk, err := o.RESTMapper.KindFor(gvr)

// TODO: remove after tekton results migration to V1 APIs
gvk.Version = "v1beta1"
//gvk.Version = "v1beta1"

v, k := gvk.ToAPIVersionAndKind()

Expand Down Expand Up @@ -164,10 +165,12 @@ func (o *Options) Run(_ *cobra.Command, _ []string) error {
break
}

a, ok := ul.Items[0].GetAnnotations()[annotation.Log]
a, ok := ul.Items[0].GetAnnotations()[annotation.Record]
if !ok || a == "" {
return printers.WriteEscaped(o.IOStreams.Out, "No logs found")
}
// with v1alpha3 API, end point has changed from records to logs
a = strings.Replace(a, "records", "logs", -1)
log, err := action.Log(o.Client, &action.Options{
ObjectMeta: metav1.ObjectMeta{
Name: a,
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

// TODO: remove this hard coding.
const clientVersion = "v0.1.1"
const serverVersion = "v0.9.0"
const clientVersion = "v0.1.2"
const serverVersion = "v0.13.2"

var (
short = i18n.T("Print the client and server version information")
Expand Down
9 changes: 0 additions & 9 deletions internal/results/action/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ func Delete(c client.Client, o *Options) error {
}
}

// Delete log metadata and data
if a, ok := o.Annotations[annotation.Log]; ok {
if _, err := c.DeleteLog(context.Background(), &results.DeleteLogRequest{
Name: a,
}); err != nil && client.Status(err) != http.StatusNotFound {
return err
}
}

//Delete record entries
if a, ok := o.Annotations[annotation.Record]; ok {
if _, err := c.DeleteRecord(context.Background(), &results.DeleteRecordRequest{
Expand Down
2 changes: 1 addition & 1 deletion internal/results/action/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package action
import (
"context"
"github.com/sayan-biswas/kubectl-tekton/internal/results/client"
results "github.com/tektoncd/results/proto/v1alpha2/results_go_proto"
results "github.com/tektoncd/results/proto/v1alpha3/results_go_proto"
)

func Log(c client.Client, o *Options) ([]byte, error) {
Expand Down
3 changes: 2 additions & 1 deletion internal/results/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
resultsv1alpha2 "github.com/tektoncd/results/proto/v1alpha2/results_go_proto"
resultsv1alpha3 "github.com/tektoncd/results/proto/v1alpha3/results_go_proto"
"google.golang.org/grpc/status"
"k8s.io/client-go/transport"
"net/url"
Expand All @@ -16,7 +17,7 @@ const (
)

type Client interface {
resultsv1alpha2.LogsClient
resultsv1alpha3.LogsClient
resultsv1alpha2.ResultsClient
}

Expand Down
5 changes: 3 additions & 2 deletions internal/results/client/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
resultsv1alpha2 "github.com/tektoncd/results/proto/v1alpha2/results_go_proto"
resultsv1alpha3 "github.com/tektoncd/results/proto/v1alpha3/results_go_proto"
"golang.org/x/oauth2"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand All @@ -17,7 +18,7 @@ import (
)

type GRPCClient struct {
resultsv1alpha2.LogsClient
resultsv1alpha3.LogsClient
resultsv1alpha2.ResultsClient
}

Expand Down Expand Up @@ -71,7 +72,7 @@ func NewGRPCClient(c *Config) (Client, error) {
}

return &GRPCClient{
resultsv1alpha2.NewLogsClient(clientConn),
resultsv1alpha3.NewLogsClient(clientConn),
resultsv1alpha2.NewResultsClient(clientConn),
}, nil
}
Expand Down
31 changes: 18 additions & 13 deletions internal/results/client/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
v1alpha2 "github.com/tektoncd/results/proto/v1alpha2/results_go_proto"
v1alpha3 "github.com/tektoncd/results/proto/v1alpha3/results_go_proto"
"google.golang.org/genproto/googleapis/api/httpbody"
"google.golang.org/grpc"
"google.golang.org/protobuf/encoding/protojson"
Expand Down Expand Up @@ -145,7 +146,7 @@ func (c logsGetLogClient) Recv() (*httpbody.HttpBody, error) {
}, nil
}

func (c *RESTClient) GetLog(ctx context.Context, in *v1alpha2.GetLogRequest, _ ...grpc.CallOption) (v1alpha2.Logs_GetLogClient, error) {
func (c *RESTClient) GetLog(ctx context.Context, in *v1alpha3.GetLogRequest, _ ...grpc.CallOption) (v1alpha2.Logs_GetLogClient, error) {
b, err := c.send(ctx, http.MethodGet, []string{in.Name}, in)
if err != nil {
return nil, err
Expand All @@ -158,22 +159,26 @@ func (c *RESTClient) GetLog(ctx context.Context, in *v1alpha2.GetLogRequest, _ .
return out, nil
}

// ListLogs Functionality not supported now
func (c *RESTClient) ListLogs(ctx context.Context, in *v1alpha2.ListRecordsRequest, _ ...grpc.CallOption) (*v1alpha2.ListRecordsResponse, error) {
out := &v1alpha2.ListRecordsResponse{}
b, err := c.send(ctx, http.MethodGet, []string{in.Parent, "records"}, in)
if err != nil {
return nil, err
}
return out, protojson.Unmarshal(b, out)
//out := &v1alpha2.ListRecordsResponse{}
//b, err := c.send(ctx, http.MethodGet, []string{in.Parent, "records"}, in)
//if err != nil {
// return nil, err
//}
//return out, protojson.Unmarshal(b, out)
panic("This is not supported")
}

// DeleteLog Functionality not supported now
func (c *RESTClient) DeleteLog(ctx context.Context, in *v1alpha2.DeleteLogRequest, _ ...grpc.CallOption) (*emptypb.Empty, error) {
out := &emptypb.Empty{}
b, err := c.send(ctx, http.MethodDelete, []string{in.Name}, in)
if err != nil {
return nil, err
}
return out, protojson.Unmarshal(b, out)
//out := &emptypb.Empty{}
//b, err := c.send(ctx, http.MethodDelete, []string{in.Name}, in)
//if err != nil {
// return nil, err
//}
//return out, protojson.Unmarshal(b, out)
panic("This is not supported")
}

func (c *RESTClient) UpdateLog(_ context.Context, _ ...grpc.CallOption) (v1alpha2.Logs_UpdateLogClient, error) {
Expand Down

0 comments on commit c9f7aba

Please sign in to comment.