mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
Merge pull request #1095 from NoSkillGirl/feature/support_openapi_v3
added validation for openapi_v3
This commit is contained in:
commit
154b1c1eb9
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,10 @@ 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
|
||||
v3valueFound := isOpenV3Error(err)
|
||||
if v3valueFound == false {
|
||||
log.Log.Error(err, "could not parse crd schema", "name", crdName)
|
||||
}
|
||||
}
|
||||
|
||||
o.crdList = append(o.crdList, crdName)
|
||||
|
@ -166,6 +169,18 @@ func (o *Controller) ParseCRD(crd unstructured.Unstructured) {
|
|||
o.definitions[crdName] = parsedSchema
|
||||
}
|
||||
|
||||
func isOpenV3Error(err error) bool {
|
||||
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
|
||||
}
|
||||
}
|
||||
return v3valueFound
|
||||
}
|
||||
|
||||
// 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