mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
cfef8a089a
Signed-off-by: Frank Jogeleit <frank.jogeleit@web.de> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
37 lines
761 B
Go
37 lines
761 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
|
)
|
|
|
|
type OneOf struct {
|
|
Value any
|
|
}
|
|
|
|
func (m OneOf) ApplyToSchema(schema *apiext.JSONSchemaProps) error {
|
|
var props apiext.JSONSchemaProps
|
|
if data, err := json.Marshal(m.Value); err != nil {
|
|
return err
|
|
} else if err := json.Unmarshal(data, &props); err != nil {
|
|
return err
|
|
}
|
|
schema.OneOf = append(schema.OneOf, props)
|
|
return nil
|
|
}
|
|
|
|
type Not struct {
|
|
Value any
|
|
}
|
|
|
|
func (m Not) ApplyToSchema(schema *apiext.JSONSchemaProps) error {
|
|
var props apiext.JSONSchemaProps
|
|
if data, err := json.Marshal(m.Value); err != nil {
|
|
return err
|
|
} else if err := json.Unmarshal(data, &props); err != nil {
|
|
return err
|
|
}
|
|
schema.Not = &props
|
|
return nil
|
|
}
|