@@ -210,6 +210,11 @@ func (s *Manifest) Validate() error {
210
210
return nil
211
211
}
212
212
213
+ const (
214
+ ProtocolUDP = "udp"
215
+ ProtocolTCP = "tcp"
216
+ )
217
+
213
218
// Port describes a port that a service exposes
214
219
type Port struct {
215
220
// Name is the name of the port
@@ -218,6 +223,9 @@ type Port struct {
218
223
// Port is the port number
219
224
Port int
220
225
226
+ // Protocol (tcp or udp)
227
+ Protocol string
228
+
221
229
// HostPort is the port number assigned on the host machine for this
222
230
// container port. It is populated by the local runner
223
231
// TODO: We might want to move this to the runner itself.
@@ -356,18 +364,30 @@ func (s *service) WithTag(tag string) *service {
356
364
return s
357
365
}
358
366
359
- func (s * service ) WithPort (name string , portNumber int ) * service {
367
+ func (s * service ) WithPort (name string , portNumber int , protocolVar ... string ) * service {
368
+ protocol := ProtocolTCP
369
+ if len (protocol ) > 0 {
370
+ if protocolVar [0 ] != ProtocolTCP && protocolVar [0 ] != ProtocolUDP {
371
+ panic (fmt .Sprintf ("protocol %s not supported" , protocolVar [0 ]))
372
+ }
373
+ protocol = protocolVar [0 ]
374
+ }
375
+
360
376
// add the port if not already present with the same name.
361
377
// if preset with the same name, they must have same port number
362
378
for _ , p := range s .ports {
363
379
if p .Name == name {
364
380
if p .Port != portNumber {
365
381
panic (fmt .Sprintf ("port %s already defined with different port number" , name ))
366
382
}
383
+ if p .Protocol != protocol {
384
+ // If they have different protocols they are different ports
385
+ continue
386
+ }
367
387
return s
368
388
}
369
389
}
370
- s .ports = append (s .ports , & Port {Name : name , Port : portNumber })
390
+ s .ports = append (s .ports , & Port {Name : name , Port : portNumber , Protocol : protocol })
371
391
return s
372
392
}
373
393
@@ -376,7 +396,7 @@ func (s *service) applyTemplate(arg string) {
376
396
var nodeRef []NodeRef
377
397
_ , port , nodeRef = applyTemplate (arg )
378
398
for _ , p := range port {
379
- s .WithPort (p .Name , p .Port )
399
+ s .WithPort (p .Name , p .Port , p . Protocol )
380
400
}
381
401
for _ , n := range nodeRef {
382
402
s .nodeRefs = append (s .nodeRefs , & n )
@@ -445,9 +465,13 @@ func applyTemplate(templateStr string) (string, []Port, []NodeRef) {
445
465
return fmt .Sprintf (`{{Service "%s" "%s"}}` , name , portLabel )
446
466
},
447
467
"Port" : func (name string , defaultPort int ) string {
448
- portRef = append (portRef , Port {Name : name , Port : defaultPort })
468
+ portRef = append (portRef , Port {Name : name , Port : defaultPort , Protocol : ProtocolTCP })
449
469
return fmt .Sprintf (`{{Port "%s" %d}}` , name , defaultPort )
450
470
},
471
+ "PortUDP" : func (name string , defaultPort int ) string {
472
+ portRef = append (portRef , Port {Name : name , Port : defaultPort , Protocol : ProtocolUDP })
473
+ return fmt .Sprintf (`{{PortUDP "%s" %d}}` , name , defaultPort )
474
+ },
451
475
}
452
476
453
477
tpl , err := template .New ("" ).Funcs (funcs ).Parse (templateStr )
0 commit comments