stackrox / kube-linter

KubeLinter is a static analysis tool that checks Kubernetes YAML files and Helm charts to ensure the applications represented in them adhere to best practices.
https://docs.kubelinter.io/
Apache License 2.0
2.91k stars 232 forks source link

[BUG] failed to decode: no kind "Pipeline" is registered for version "tekton.dev/v1beta1" #606

Open PascalTurbo opened 1 year ago

PascalTurbo commented 1 year ago

System info:

Describe the bug kube-linter returns an error (see below) but the HelmChart is valid and installable

To Reproduce Checkout this code https://github.com/PascalTurbo/stackrox-kube-linter-bug-example and run kube-linter lint -v chart

Output

kube-linter lint -v chart

Warning: failed to load object from chart/templates/pipeline.yaml: failed to decode: no kind "Pipeline" is registered for version "tekton.dev/v1beta1" in scheme "pkg/runtime/scheme.go:100"
Warning: no valid objects found.
janisz commented 1 year ago

We do not registered tekton schema. Probably we should do that. We have an issue about this:

Below patch solves this issue but it adds new dependency and that will be hard to maintain. On the other hand we could add schemas for mature project that are part of CNCF or some other org (e.g. we already have exception for OpenShift)

diff --git a/go.mod b/go.mod
index 3d2db6e..4d36d51 100644
--- a/go.mod
+++ b/go.mod
@@ -18,17 +18,20 @@ require (
    github.com/spf13/pflag v1.0.5
    github.com/spf13/viper v1.16.0
    github.com/stretchr/testify v1.8.4
+   github.com/tektoncd/pipeline v0.40.0
    helm.sh/helm/v3 v3.12.2
    k8s.io/api v0.27.4
    k8s.io/apimachinery v0.27.4
    k8s.io/cli-runtime v0.27.4
    k8s.io/client-go v0.27.4
-   k8s.io/gengo v0.0.0-20220902162205-c0856e24416d
+   k8s.io/gengo v0.0.0-20221011193443-fad74ee6edd9
 )

diff --git a/pkg/lintcontext/parse_yaml.go b/pkg/lintcontext/parse_yaml.go
index 6a6b6f3..ce5b84e 100644
--- a/pkg/lintcontext/parse_yaml.go
+++ b/pkg/lintcontext/parse_yaml.go
@@ -13,6 +13,7 @@ import (
    y "github.com/ghodss/yaml"
    ocsAppsV1 "github.com/openshift/api/apps/v1"
    "github.com/pkg/errors"
+   tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
    "golang.stackrox.io/kube-linter/pkg/k8sutil"
    "helm.sh/helm/v3/pkg/chart"
    "helm.sh/helm/v3/pkg/chart/loader"
(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? y
@@ -41,7 +42,7 @@ func init() {
    clientScheme := scheme.Scheme

    // Add OpenShift and Autoscaling schema
-   schemeBuilder := runtime.NewSchemeBuilder(ocsAppsV1.AddToScheme, autoscalingV2Beta1.AddToScheme)
+   schemeBuilder := runtime.NewSchemeBuilder(ocsAppsV1.AddToScheme, autoscalingV2Beta1.AddToScheme, tekton.AddToScheme)
    if err := schemeBuilder.AddToScheme(clientScheme); err != nil {
        panic(fmt.Sprintf("Can not add OpenShift schema %v", err))
    }