github.com/argoproj/argo-events@v1.9.1/controllers/eventbus/validate.go (about) 1 package eventbus 2 3 import ( 4 "fmt" 5 6 "github.com/argoproj/argo-events/pkg/apis/eventbus/v1alpha1" 7 ) 8 9 // ValidateEventBus accepts an EventBus and performs validation against it 10 func ValidateEventBus(eb *v1alpha1.EventBus) error { 11 if eb.Spec.NATS == nil && eb.Spec.JetStream == nil && eb.Spec.Kafka == nil && eb.Spec.JetStreamExotic == nil { 12 return fmt.Errorf("invalid spec: either \"nats\", \"jetstream\", \"jetstreamExotic\", or \"kafka\" needs to be specified") 13 } 14 if x := eb.Spec.NATS; x != nil { 15 if x.Native != nil && x.Exotic != nil { 16 return fmt.Errorf("\"spec.nats.native\" and \"spec.nats.exotic\" can not be defined together") 17 } 18 if x.Native == nil && x.Exotic == nil { 19 return fmt.Errorf("either \"native\" or \"exotic\" must be defined") 20 } 21 if x.Exotic != nil { 22 e := x.Exotic 23 if e.ClusterID == nil { 24 return fmt.Errorf("\"spec.nats.exotic.clusterID\" is missing") 25 } 26 if e.URL == "" { 27 return fmt.Errorf("\"spec.nats.exotic.url\" is missing") 28 } 29 } 30 } 31 if x := eb.Spec.JetStream; x != nil { 32 if x.Version == "" { 33 return fmt.Errorf("invalid spec: a version for jetstream needs to be specified") 34 } 35 if x.Replicas != nil && (*x.Replicas == 2 || *x.Replicas <= 0) { 36 return fmt.Errorf("invalid spec: a jetstream eventbus requires 1 replica or >= 3 replicas") 37 } 38 } 39 if x := eb.Spec.Kafka; x != nil { 40 if x.URL == "" { 41 return fmt.Errorf("\"spec.kafka.url\" is missing") 42 } 43 } 44 if x := eb.Spec.JetStreamExotic; x != nil { 45 if x.URL == "" { 46 return fmt.Errorf("\"spec.jetstreamExotic.url\" is missing") 47 } 48 } 49 return nil 50 }