github.com/argoproj/argo-events@v1.9.1/controllers/eventsource/validate.go (about) 1 package eventsource 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/argoproj/argo-events/eventsources" 8 apicommon "github.com/argoproj/argo-events/pkg/apis/common" 9 "github.com/argoproj/argo-events/pkg/apis/eventsource/v1alpha1" 10 ) 11 12 // ValidateEventSource validates if the eventSource is valid 13 func ValidateEventSource(eventSource *v1alpha1.EventSource) error { 14 recreateTypes := make(map[apicommon.EventSourceType]bool) 15 for _, esType := range apicommon.RecreateStrategyEventSources { 16 recreateTypes[esType] = true 17 } 18 19 servers, _ := eventsources.GetEventingServers(eventSource, nil) 20 21 eventNames := make(map[string]bool) 22 rollingUpdates, recreates := 0, 0 23 ctx := context.Background() 24 for eventType, ss := range servers { 25 if _, ok := recreateTypes[eventType]; ok { 26 recreates++ 27 } else { 28 rollingUpdates++ 29 } 30 31 for _, server := range ss { 32 eName := server.GetEventName() 33 if _, ok := eventNames[eName]; !ok { 34 eventNames[eName] = true 35 } else { 36 // Duplicated event name not allowed in one EventSource, even they are in different EventSourceType. 37 eventSource.Status.MarkSourcesNotProvided("InvalidEventSource", fmt.Sprintf("more than one \"%s\" found", eName)) 38 return fmt.Errorf("more than one %q found in the spec", eName) 39 } 40 41 err := server.ValidateEventSource(ctx) 42 if err != nil { 43 eventSource.Status.MarkSourcesNotProvided("InvalidEventSource", fmt.Sprintf("Invalid spec: %s - %s", server.GetEventSourceName(), server.GetEventName())) 44 return err 45 } 46 } 47 } 48 49 if rollingUpdates > 0 && recreates > 0 { 50 // We don't allow this as if we use recreate strategy for the deployment it will have downtime 51 eventSource.Status.MarkSourcesNotProvided("InvalidEventSource", "Some types of event sources can not be put in one spec") 52 return fmt.Errorf("event sources with rolling update and recreate update strategy can not be put together") 53 } 54 55 eventSource.Status.MarkSourcesProvided() 56 return nil 57 }