diff --git a/internal/policy-template/paramdef-util.go b/internal/policy-template/paramdef-util.go index e87ffbb2..a0e4c64d 100644 --- a/internal/policy-template/paramdef-util.go +++ b/internal/policy-template/paramdef-util.go @@ -141,21 +141,26 @@ func CompareParamDefAndExtractedParamDef(paramdef *domain.ParameterDef, extracte return true } -func ParamDefsToJSONSchemaProeprties(paramdefs []*domain.ParameterDef) *apiextensionsv1.JSONSchemaProps { +func ParamDefsToJSONSchemaProeprties(paramdefs []*domain.ParameterDef, forValidation bool) *apiextensionsv1.JSONSchemaProps { if len(paramdefs) == 0 { return nil } result := apiextensionsv1.JSONSchemaProps{ - Type: "object", - Properties: convert(paramdefs), - AdditionalProperties: &apiextensionsv1.JSONSchemaPropsOrBool{Allows: false}, + Type: "object", + Properties: convert(paramdefs, forValidation), + } + + // 파라미터 validation인 경우에는 AddtionalProperties로 스키마에 없는 필드가 처리되지 않아야 함 + // Operator에 보낼때는 해당 속성이 없어야 함 + if forValidation { + result.AdditionalProperties = &apiextensionsv1.JSONSchemaPropsOrBool{Allows: false} } return &result } -func convert(paramdefs []*domain.ParameterDef) map[string]apiextensionsv1.JSONSchemaProps { +func convert(paramdefs []*domain.ParameterDef, forValidation bool) map[string]apiextensionsv1.JSONSchemaProps { result := map[string]apiextensionsv1.JSONSchemaProps{} for _, paramdef := range paramdefs { @@ -167,7 +172,7 @@ func convert(paramdefs []*domain.ParameterDef) map[string]apiextensionsv1.JSONSc result[paramdef.Key] = apiextensionsv1.JSONSchemaProps{ Type: "array", Items: &apiextensionsv1.JSONSchemaPropsOrArray{ - Schema: ParamDefsToJSONSchemaProeprties(paramdef.Children), + Schema: ParamDefsToJSONSchemaProeprties(paramdef.Children, forValidation), }, } case isArary: @@ -178,7 +183,7 @@ func convert(paramdefs []*domain.ParameterDef) map[string]apiextensionsv1.JSONSc }, } case isObject: - props := ParamDefsToJSONSchemaProeprties(paramdef.Children) + props := ParamDefsToJSONSchemaProeprties(paramdef.Children, forValidation) if props != nil { result[paramdef.Key] = *props diff --git a/internal/policy-template/policy-operator.go b/internal/policy-template/policy-operator.go index ad192c00..1d1fd9a6 100644 --- a/internal/policy-template/policy-operator.go +++ b/internal/policy-template/policy-operator.go @@ -104,7 +104,7 @@ func PolicyTemplateToTksPolicyTemplateCR(policyTemplate *model.PolicyTemplate) * Kind: policyTemplate.Kind, }, Validation: &Validation{ - OpenAPIV3Schema: ParamDefsToJSONSchemaProeprties(policyTemplate.ParametersSchema), + OpenAPIV3Schema: ParamDefsToJSONSchemaProeprties(policyTemplate.ParametersSchema, false), }, }, }, diff --git a/internal/policy-template/validation.go b/internal/policy-template/validation.go index 5cb01946..ccb83b00 100644 --- a/internal/policy-template/validation.go +++ b/internal/policy-template/validation.go @@ -47,7 +47,7 @@ func ValidateParamDefs(paramdefs []*domain.ParameterDef) error { } func ValidateJSONusingParamdefs(paramdefs []*domain.ParameterDef, jsonStr string) error { - jsonSchema := ParamDefsToJSONSchemaProeprties(paramdefs) + jsonSchema := ParamDefsToJSONSchemaProeprties(paramdefs, true) if jsonSchema == nil { // 파라미터가 없는데 "{}" 이나 ""이면 에러가 아님