1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

783 fixing panic

This commit is contained in:
shravan 2020-04-02 09:09:49 +05:30
parent 0c87269a79
commit e3fcc2c4e5

View file

@ -104,6 +104,11 @@ func (o *Controller) parseCRD(crd unstructured.Unstructured) {
var schema yaml.MapSlice
schemaRaw, _ := json.Marshal(crdDefinition.Spec.Versions[0].Schema.OpenAPIV3Schema)
if len(schemaRaw) < 1 {
log.Log.V(4).Info("could not parse crd schema")
return
}
schemaRaw = addingDefaultFieldsToSchema(schemaRaw)
_ = yaml.Unmarshal(schemaRaw, &schema)
@ -126,8 +131,11 @@ func addingDefaultFieldsToSchema(schemaRaw []byte) []byte {
}
_ = json.Unmarshal(schemaRaw, &schema)
if schema.Properties["apiVersion"] == nil {
if len(schemaRaw) < 1 {
schema.Properties = make(map[string]interface{})
}
if schema.Properties["apiVersion"] == nil {
apiVersionDefRaw := `{"description":"APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources","type":"string"}`
apiVersionDef := make(map[string]interface{})
_ = json.Unmarshal([]byte(apiVersionDefRaw), &apiVersionDef)