@@ -232,6 +232,16 @@ func validateSecretsMap(secrets map[string]v1alpha1.SecretRef) *field.Error {
232232
233233func validateInputOutput (input * v1alpha1.InputConf , output * v1alpha1.OutputConf ,
234234 skipInputValidation bool , skipOutputValidation bool ) []* field.Error {
235+ return validateInputOutputWithTopicNameValidation (input , output , skipInputValidation , skipOutputValidation , true )
236+ }
237+
238+ func validateKafkaInputOutput (input * v1alpha1.InputConf , output * v1alpha1.OutputConf ,
239+ skipInputValidation bool , skipOutputValidation bool ) []* field.Error {
240+ return validateInputOutputWithTopicNameValidation (input , output , skipInputValidation , skipOutputValidation , false )
241+ }
242+
243+ func validateInputOutputWithTopicNameValidation (input * v1alpha1.InputConf , output * v1alpha1.OutputConf ,
244+ skipInputValidation bool , skipOutputValidation bool , validateTopicNames bool ) []* field.Error {
235245 var allErrs field.ErrorList
236246 allInputTopics := []string {}
237247 if input != nil {
@@ -243,12 +253,14 @@ func validateInputOutput(input *v1alpha1.InputConf, output *v1alpha1.OutputConf,
243253 allErrs = append (allErrs , e )
244254 }
245255
246- for _ , topic := range allInputTopics {
247- err := isValidTopicName (topic )
248- if err != nil {
249- e := field .Invalid (field .NewPath ("spec" ).Child ("input" ), * input ,
250- fmt .Sprintf ("Input topic %s is invalid" , topic ))
251- allErrs = append (allErrs , e )
256+ if validateTopicNames {
257+ for _ , topic := range allInputTopics {
258+ err := isValidTopicName (topic )
259+ if err != nil {
260+ e := field .Invalid (field .NewPath ("spec" ).Child ("input" ), * input ,
261+ fmt .Sprintf ("Input topic %s is invalid" , topic ))
262+ allErrs = append (allErrs , e )
263+ }
252264 }
253265 }
254266
@@ -270,11 +282,13 @@ func validateInputOutput(input *v1alpha1.InputConf, output *v1alpha1.OutputConf,
270282
271283 if output != nil && ! skipOutputValidation {
272284 if output .Topic != "" {
273- err := isValidTopicName (output .Topic )
274- if err != nil {
275- e := field .Invalid (field .NewPath ("spec" ).Child ("output" , "topic" ), output .Topic ,
276- fmt .Sprintf ("Output topic %s is invalid" , output .Topic ))
277- allErrs = append (allErrs , e )
285+ if validateTopicNames {
286+ err := isValidTopicName (output .Topic )
287+ if err != nil {
288+ e := field .Invalid (field .NewPath ("spec" ).Child ("output" , "topic" ), output .Topic ,
289+ fmt .Sprintf ("Output topic %s is invalid" , output .Topic ))
290+ allErrs = append (allErrs , e )
291+ }
278292 }
279293 for _ , v := range allInputTopics {
280294 if v == output .Topic {
@@ -307,49 +321,6 @@ func validateInputOutput(input *v1alpha1.InputConf, output *v1alpha1.OutputConf,
307321 return allErrs
308322}
309323
310- func validateKafkaInputOutput (input * v1alpha1.InputConf , output * v1alpha1.OutputConf ,
311- skipInputValidation bool , skipOutputValidation bool ) []* field.Error {
312- var allErrs field.ErrorList
313- allInputTopics := []string {}
314- if input != nil {
315- allInputTopics = collectAllInputTopics (* input )
316- if ! skipInputValidation {
317- if len (allInputTopics ) == 0 {
318- e := field .Invalid (field .NewPath ("spec" ).Child ("input" ), * input ,
319- "No input topic(s) specified for the function" )
320- allErrs = append (allErrs , e )
321- }
322-
323- for topicName , conf := range input .SourceSpecs {
324- if conf .ReceiverQueueSize != nil && * conf .ReceiverQueueSize < 0 {
325- e := field .Invalid (field .NewPath ("spec" ).Child ("input" , "sourceSpecs" ),
326- input .SourceSpecs , fmt .Sprintf ("%s receiver queue size should be >= zero" , topicName ))
327- allErrs = append (allErrs , e )
328- }
329-
330- if conf .CryptoConfig != nil && conf .CryptoConfig .CryptoKeyReaderClassName == "" {
331- e := field .Invalid (field .NewPath ("spec" ).Child ("input" , "sourceSpecs" ),
332- input .SourceSpecs , fmt .Sprintf ("%s cryptoKeyReader class name required" , topicName ))
333- allErrs = append (allErrs , e )
334- }
335- }
336- }
337- }
338-
339- if output != nil && ! skipOutputValidation && output .Topic != "" {
340- for _ , v := range allInputTopics {
341- if v == output .Topic {
342- e := field .Invalid (field .NewPath ("spec" ).Child ("output" , "topic" ), output .Topic ,
343- fmt .Sprintf ("Output topic %s is also being used as an input topic (topics must be one or the other)" ,
344- output .Topic ))
345- allErrs = append (allErrs , e )
346- }
347- }
348- }
349-
350- return allErrs
351- }
352-
353324func validateLogTopic (logTopic string ) * field.Error {
354325 if logTopic != "" {
355326 err := isValidTopicName (logTopic )
@@ -488,6 +459,10 @@ func validateKafkaMessagingRuntime(runtime v1alpha1.Runtime, kafka *v1alpha1.Kaf
488459 return field .Invalid (field .NewPath ("spec" ).Child ("kafka" ), kafka ,
489460 "only genericRuntime supports kafka messaging" )
490461 }
462+ if runtime .GenericRuntime .FunctionFile == "" {
463+ return field .Invalid (field .NewPath ("spec" ).Child ("runtime" , "genericRuntime" , "functionFile" ),
464+ runtime .GenericRuntime .FunctionFile , "genericRuntime.functionFile needs to be set for kafka messaging" )
465+ }
491466 return nil
492467}
493468
0 commit comments