Skip to content

Commit

Permalink
Fix for commented yaml files in Kyverno CLI (#1849)
Browse files Browse the repository at this point in the history
* fix for commented policy yaml file

Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>

* fix for commented resource yaml file

Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
  • Loading branch information
NoSkillGirl committed Apr 29, 2021
1 parent 1e4c950 commit d3e4fed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/kyverno/common/fetch.go
Expand Up @@ -160,6 +160,10 @@ func GetResource(resourceBytes []byte) ([]*unstructured.Unstructured, error) {
for _, resourceYaml := range files {
resource, err := convertResourceToUnstructured(resourceYaml)
if err != nil {
if strings.Contains(err.Error(), "Object 'Kind' is missing") {
log.Log.V(3).Info("skipping resource as kind not found")
continue
}
getErrString = getErrString + err.Error() + "\n"
}
resources = append(resources, resource)
Expand Down
6 changes: 6 additions & 0 deletions pkg/utils/loadpolicy.go
Expand Up @@ -9,6 +9,7 @@ import (

v1 "github.com/kyverno/kyverno/pkg/api/kyverno/v1"
"k8s.io/apimachinery/pkg/util/yaml"
"sigs.k8s.io/controller-runtime/pkg/log"
)

// GetPolicy - extracts policies from YAML bytes
Expand All @@ -29,6 +30,11 @@ func GetPolicy(bytes []byte) (clusterPolicies []*v1.ClusterPolicy, err error) {
return nil, fmt.Errorf("failed to decode policy: %v", err)
}

if policy.TypeMeta.Kind == "" {
log.Log.V(3).Info("skipping file as policy.TypeMeta.Kind not found")
continue
}

if !(policy.TypeMeta.Kind == "ClusterPolicy" || policy.TypeMeta.Kind == "Policy") {
msg := fmt.Sprintf("resource %s/%s is not a Policy or a ClusterPolicy", policy.Kind, policy.Name)
return nil, fmt.Errorf(msg)
Expand Down

0 comments on commit d3e4fed

Please sign in to comment.