@@ -23,8 +23,12 @@ import (
2323 "context"
2424 "text/template"
2525
26+ "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
27+ apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
28+ "k8s.io/apiextensions-apiserver/pkg/apiserver/validation"
2629 "k8s.io/apimachinery/pkg/runtime"
2730 "k8s.io/client-go/tools/record"
31+ "k8s.io/kube-openapi/pkg/validation/spec"
2832 ctrl "sigs.k8s.io/controller-runtime"
2933 "sigs.k8s.io/controller-runtime/pkg/client"
3034 "sigs.k8s.io/controller-runtime/pkg/log"
@@ -74,13 +78,19 @@ func (r *OpsDefinitionReconciler) Reconcile(ctx context.Context, req ctrl.Reques
7478 continue
7579 }
7680 if _ , err = template .New ("opsDefTemplate" ).Parse (v .Rule .Expression ); err != nil {
77- if patchErr := r .updateStatusUnavailable (reqCtx , opsDef , err ); patchErr != nil {
78- return intctrlutil .CheckedRequeueWithError (err , reqCtx .Log , "" )
79- }
80- return intctrlutil .Reconciled ()
81+ return r .updateStatusUnavailable (reqCtx , opsDef , err )
82+ }
83+ }
84+ if opsDef .Spec .ParametersSchema != nil {
85+ out := & apiextensions.JSONSchemaProps {}
86+ if err = apiextensionsv1 .Convert_v1_JSONSchemaProps_To_apiextensions_JSONSchemaProps (opsDef .Spec .ParametersSchema .OpenAPIV3Schema , out , nil ); err != nil {
87+ return r .updateStatusUnavailable (reqCtx , opsDef , err )
88+ }
89+ openapiSchema := & spec.Schema {}
90+ if err = validation .ConvertJSONSchemaPropsWithPostProcess (out , openapiSchema , validation .StripUnsupportedFormatsPostProcess ); err != nil {
91+ return r .updateStatusUnavailable (reqCtx , opsDef , err )
8192 }
8293 }
83-
8494 // TODO: check serviceKind, connectionCredentialName and serviceName
8595 statusPatch := client .MergeFrom (opsDef .DeepCopy ())
8696 opsDef .Status .ObservedGeneration = opsDef .Generation
@@ -92,12 +102,15 @@ func (r *OpsDefinitionReconciler) Reconcile(ctx context.Context, req ctrl.Reques
92102 return intctrlutil .Reconciled ()
93103}
94104
95- func (r * OpsDefinitionReconciler ) updateStatusUnavailable (reqCtx intctrlutil.RequestCtx , opsDef * opsv1alpha1.OpsDefinition , err error ) error {
105+ func (r * OpsDefinitionReconciler ) updateStatusUnavailable (reqCtx intctrlutil.RequestCtx , opsDef * opsv1alpha1.OpsDefinition , err error ) (ctrl. Result , error ) {
96106 statusPatch := client .MergeFrom (opsDef .DeepCopy ())
97107 opsDef .Status .Phase = opsv1alpha1 .UnavailablePhase
98108 opsDef .Status .ObservedGeneration = opsDef .Generation
99109 opsDef .Status .Message = err .Error ()
100- return r .Client .Status ().Patch (reqCtx .Ctx , opsDef , statusPatch )
110+ if err = r .Client .Status ().Patch (reqCtx .Ctx , opsDef , statusPatch ); err != nil {
111+ return intctrlutil .CheckedRequeueWithError (err , reqCtx .Log , "" )
112+ }
113+ return intctrlutil .Reconciled ()
101114}
102115
103116// SetupWithManager sets up the controller with the Manager.
0 commit comments