mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-28 02:18:15 +00:00
added validation for openapi_v3
This commit is contained in:
parent
9a210e24d9
commit
fcdbc054c9
1 changed files with 19 additions and 4 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
|
@ -13,11 +14,11 @@ import (
|
|||
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"sigs.k8s.io/controller-runtime/pkg/log"
|
||||
|
||||
"github.com/googleapis/gnostic/compiler"
|
||||
|
||||
openapi_v2 "github.com/googleapis/gnostic/OpenAPIv2"
|
||||
"sigs.k8s.io/controller-runtime/pkg/log"
|
||||
|
||||
"github.com/nirmata/kyverno/pkg/constant"
|
||||
client "github.com/nirmata/kyverno/pkg/dclient"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
|
@ -157,8 +158,7 @@ func (o *Controller) ParseCRD(crd unstructured.Unstructured) {
|
|||
|
||||
parsedSchema, err := openapi_v2.NewSchema(schema, compiler.NewContext("schema", nil))
|
||||
if err != nil {
|
||||
log.Log.Error(err, "could not parse crd schema", "name", crdName)
|
||||
return
|
||||
isOpenV3Error(err, crdName)
|
||||
}
|
||||
|
||||
o.crdList = append(o.crdList, crdName)
|
||||
|
@ -166,6 +166,21 @@ func (o *Controller) ParseCRD(crd unstructured.Unstructured) {
|
|||
o.definitions[crdName] = parsedSchema
|
||||
}
|
||||
|
||||
func isOpenV3Error(err error, crdName string) {
|
||||
unsupportedValues := []string{"anyOf", "allOf", "not"}
|
||||
v3valueFound := false
|
||||
for _, value := range unsupportedValues {
|
||||
if !strings.Contains(err.Error(), fmt.Sprintf("has invalid property: %s", value)) {
|
||||
v3valueFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if v3valueFound == false {
|
||||
log.Log.Error(err, "could not parse crd schema", "name", crdName)
|
||||
}
|
||||
}
|
||||
|
||||
// addingDefaultFieldsToSchema will add any default missing fields like apiVersion, metadata
|
||||
func addingDefaultFieldsToSchema(schemaRaw []byte) ([]byte, error) {
|
||||
var schema struct {
|
||||
|
|
Loading…
Add table
Reference in a new issue