Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump clustertask describe to v1beta1 #888

Merged
merged 2 commits into from
Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ check: lint test
test: test-unit ## run all tests

.PHONY: lint
test: lint-go lint-yaml ## run all linters
lint: lint-go lint-yaml ## run all linters

.PHONY: lint-go
lint: ## runs go linter on all go files
lint-go: ## runs go linter on all go files
@echo "Linting go files..."
@golangci-lint run ./... --modules-download-mode=vendor \
--max-issues-per-linter=0 \
Expand Down
102 changes: 102 additions & 0 deletions pkg/clustertask/clustertask.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright © 2020 The Tekton Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package clustertask

import (
"context"
"fmt"
"os"

"github.com/tektoncd/cli/pkg/actions"
"github.com/tektoncd/cli/pkg/cli"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
)

var clustertaskGroupResource = schema.GroupVersionResource{Group: "tekton.dev", Resource: "clustertasks"}

func List(c *cli.Clients, opts metav1.ListOptions) (*v1beta1.ClusterTaskList, error) {
unstructuredCT, err := actions.List(clustertaskGroupResource, c, "", opts)
if err != nil {
return nil, err
}

var clustertasks *v1beta1.ClusterTaskList
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredCT.UnstructuredContent(), &clustertasks); err != nil {
return nil, err
}
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to list clustertasks\n")
return nil, err
}

return clustertasks, nil
}

// It will fetch the resource based on the api available and return v1beta1 form
func Get(c *cli.Clients, clustertaskname string, opts metav1.GetOptions, discovery discovery.DiscoveryInterface) (*v1beta1.ClusterTask, error) {
gvr, err := actions.GetGroupVersionResource(clustertaskGroupResource, discovery)
if err != nil {
return nil, err
}

if gvr.Version == "v1alpha1" {
clustertask, err := getV1alpha1(c, clustertaskname, opts)
if err != nil {
return nil, err
}
var clustertaskConverted v1beta1.ClusterTask
err = clustertask.ConvertUp(context.Background(), &clustertaskConverted)
if err != nil {
return nil, err
}
return &clustertaskConverted, nil
}
return GetV1beta1(c, clustertaskname, opts)
}

// It will fetch the resource in v1beta1 struct format
func GetV1beta1(c *cli.Clients, clustertaskname string, opts metav1.GetOptions) (*v1beta1.ClusterTask, error) {
unstructuredCT, err := actions.Get(clustertaskGroupResource, c, clustertaskname, "", opts)
if err != nil {
return nil, err
}

var clustertask *v1beta1.ClusterTask
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredCT.UnstructuredContent(), &clustertask); err != nil {
fmt.Fprintf(os.Stderr, "failed to get clustertask\n")
return nil, err
}
return clustertask, nil
}

// It will fetch the resource in v1alpha1 struct format
func getV1alpha1(c *cli.Clients, clustertaskname string, opts metav1.GetOptions) (*v1alpha1.ClusterTask, error) {
unstructuredCT, err := actions.Get(clustertaskGroupResource, c, clustertaskname, "", opts)
if err != nil {
return nil, err
}

var clustertask *v1alpha1.ClusterTask
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredCT.UnstructuredContent(), &clustertask); err != nil {
fmt.Fprintf(os.Stderr, "failed to get clustertask")
return nil, err
}
return clustertask, nil
}
Loading