mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +00:00
fix resource schema not found error
This commit is contained in:
parent
07e93e0638
commit
52d45ec3c5
4 changed files with 17 additions and 17 deletions
|
@ -110,7 +110,7 @@ func (vc StatusControl) IncrementAnnotation() error {
|
|||
var err error
|
||||
deploy, err := vc.client.GetResource("Deployment", deployNamespace, deployName)
|
||||
if err != nil {
|
||||
logger.Error(err, "failed to find deployment %s in namespace %s", deployName, deployNamespace)
|
||||
logger.Error(err, "failed to find Kyverno", "deploymeny", deployName, "namespace", deployNamespace)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ func patchedResourceHasPodControllerAnnotation(resource unstructured.Unstructure
|
|||
|
||||
val, ok := podController.Spec.Template.Metadata.Annotations[PodTemplateAnnotation]
|
||||
|
||||
log.Log.Info("patchedResourceHasPodControllerAnnotation", "resourceRaw", string(resourceRaw), "val", val, "ok", ok)
|
||||
log.Log.V(4).Info("patchedResourceHasPodControllerAnnotation", "resourceRaw", string(resourceRaw), "val", val, "ok", ok)
|
||||
|
||||
return ok
|
||||
}
|
||||
|
|
|
@ -107,17 +107,12 @@ func (c *crdSync) sync() {
|
|||
}
|
||||
|
||||
func (o *Controller) deleteCRDFromPreviousSync() {
|
||||
for k := range o.kindToDefinitionName {
|
||||
delete(o.kindToDefinitionName, k)
|
||||
for _, crd := range o.crdList {
|
||||
delete(o.kindToDefinitionName, crd)
|
||||
delete(o.definitions, crd)
|
||||
}
|
||||
|
||||
o.kindToDefinitionName = make(map[string]string, 0)
|
||||
|
||||
for k := range o.definitions {
|
||||
delete(o.definitions, k)
|
||||
}
|
||||
|
||||
o.definitions = make(map[string]*openapi_v2.Schema, 0)
|
||||
o.crdList = make([]string, 0)
|
||||
}
|
||||
|
||||
func (o *Controller) parseCRD(crd unstructured.Unstructured) {
|
||||
|
@ -166,6 +161,7 @@ func (o *Controller) parseCRD(crd unstructured.Unstructured) {
|
|||
return
|
||||
}
|
||||
|
||||
o.crdList = append(o.crdList, crdName)
|
||||
o.kindToDefinitionName[crdName] = crdName
|
||||
o.definitions[crdName] = parsedSchema
|
||||
}
|
||||
|
|
|
@ -26,14 +26,20 @@ import (
|
|||
)
|
||||
|
||||
type Controller struct {
|
||||
mutex sync.RWMutex
|
||||
definitions map[string]*openapi_v2.Schema
|
||||
mutex sync.RWMutex
|
||||
definitions map[string]*openapi_v2.Schema
|
||||
// kindToDefinitionName holds the kind - definition map
|
||||
// i.e. - Namespace: io.k8s.api.core.v1.Namespace
|
||||
kindToDefinitionName map[string]string
|
||||
crdList []string
|
||||
models proto.Models
|
||||
}
|
||||
|
||||
func NewOpenAPIController() (*Controller, error) {
|
||||
controller := &Controller{}
|
||||
controller := &Controller{
|
||||
definitions: make(map[string]*openapi_v2.Schema),
|
||||
kindToDefinitionName: make(map[string]string),
|
||||
}
|
||||
|
||||
defaultDoc, err := getSchemaDocument()
|
||||
if err != nil {
|
||||
|
@ -82,7 +88,7 @@ func (o *Controller) ValidateResource(patchedResource unstructured.Unstructured,
|
|||
// Check if kind is a CRD
|
||||
schema, err = o.getCRDSchema(kind)
|
||||
if err != nil || schema == nil {
|
||||
return fmt.Errorf("pre-validation: couldn't find model %s", kind)
|
||||
return fmt.Errorf("pre-validation: couldn't find model %s, err: %v", kind, err)
|
||||
}
|
||||
delete(patchedResource.Object, "kind")
|
||||
}
|
||||
|
@ -146,8 +152,6 @@ func (o *Controller) useOpenApiDocument(doc *openapi_v2.Document) error {
|
|||
o.mutex.Lock()
|
||||
defer o.mutex.Unlock()
|
||||
|
||||
o.definitions = make(map[string]*openapi_v2.Schema)
|
||||
o.kindToDefinitionName = make(map[string]string)
|
||||
for _, definition := range doc.GetDefinitions().AdditionalProperties {
|
||||
o.definitions[definition.GetName()] = definition.GetValue()
|
||||
path := strings.Split(definition.GetName(), ".")
|
||||
|
|
Loading…
Reference in a new issue