@@ -49,6 +49,28 @@ const (
49
49
defaultRegistryName = "cloudrunci"
50
50
)
51
51
52
+ // HTTPGetProbe describes a probe definition using HTTP Get.
53
+ type HTTPGetProbe struct {
54
+ Path string
55
+ Port int
56
+ }
57
+
58
+ // GRPCProbe describes a probe definition using gRPC.
59
+ type GRPCProbe struct {
60
+ Port int
61
+ Service string
62
+ }
63
+
64
+ // ReadinessProbe describes the readiness probe for a Cloud Run service.
65
+ type ReadinessProbe struct {
66
+ TimeoutSeconds int
67
+ PeriodSeconds int
68
+ SuccessThreshold int
69
+ FailureThreshold int
70
+ HttpGet * HTTPGetProbe
71
+ GRPC * GRPCProbe
72
+ }
73
+
52
74
// Service describes a Cloud Run service
53
75
type Service struct {
54
76
// Name is an ID, used for logging and to generate a unique version to this run.
@@ -85,6 +107,9 @@ type Service struct {
85
107
86
108
// Location to deploy the Service, and related artifacts
87
109
Location string
110
+
111
+ // ReadinessProbe description
112
+ Readiness * ReadinessProbe
88
113
}
89
114
90
115
// runID is an identifier that changes between runs.
@@ -272,7 +297,7 @@ func (s *Service) validate() error {
272
297
273
298
// revision returns the revision that the service will be deployed to.
274
299
// NOTE: Until traffic splitting is available, this will be used as the service name.
275
- func (s * Service ) version () string {
300
+ func (s * Service ) Version () string {
276
301
return s .Name + "-" + runID
277
302
}
278
303
@@ -293,7 +318,7 @@ func (s *Service) Deploy() error {
293
318
}
294
319
295
320
if _ , err := gcloud (s .operationLabel (labelOperationDeploy ), s .deployCmd ()); err != nil {
296
- return fmt .Errorf ("gcloud: %s: %q" , s .version (), err )
321
+ return fmt .Errorf ("gcloud: %s: %q" , s .Version (), err )
297
322
}
298
323
299
324
s .deployed = true
@@ -339,15 +364,15 @@ func (s *Service) Clean() error {
339
364
}
340
365
341
366
if _ , err := gcloud (s .operationLabel (labelOperationDeleteService ), s .deleteServiceCmd ()); err != nil {
342
- return fmt .Errorf ("gcloud: %v: %q" , s .version (), err )
367
+ return fmt .Errorf ("gcloud: %v: %q" , s .Version (), err )
343
368
}
344
369
s .deployed = false
345
370
346
371
// If s.built is false no image was created or is not managed by cloudrun-ci.
347
372
if s .built {
348
373
_ , err := gcloud (s .operationLabel ("delete container image" ), s .deleteImageCmd ())
349
374
if err != nil {
350
- return fmt .Errorf ("gcloud: %v: %q" , s .version (), err )
375
+ return fmt .Errorf ("gcloud: %v: %q" , s .Version (), err )
351
376
}
352
377
s .built = false
353
378
}
@@ -365,7 +390,7 @@ func (s *Service) deployCmd() *exec.Cmd {
365
390
"alpha" , // TODO until --use-http2 goes GA
366
391
"run" ,
367
392
"deploy" ,
368
- s .version (),
393
+ s .Version (),
369
394
"--project" ,
370
395
s .ProjectID ,
371
396
"--image" ,
@@ -384,6 +409,40 @@ func (s *Service) deployCmd() *exec.Cmd {
384
409
args = append (args , "--use-http2" )
385
410
}
386
411
412
+ if s .Readiness != nil {
413
+ var readinessProbeParts []string
414
+ if s .Readiness .TimeoutSeconds > 0 {
415
+ readinessProbeParts = append (readinessProbeParts , fmt .Sprintf ("timeoutSeconds=%d" , s .Readiness .TimeoutSeconds ))
416
+ }
417
+ if s .Readiness .PeriodSeconds > 0 {
418
+ readinessProbeParts = append (readinessProbeParts , fmt .Sprintf ("periodSeconds=%d" , s .Readiness .PeriodSeconds ))
419
+ }
420
+ if s .Readiness .SuccessThreshold > 0 {
421
+ readinessProbeParts = append (readinessProbeParts , fmt .Sprintf ("successThreshold=%d" , s .Readiness .SuccessThreshold ))
422
+ }
423
+ if s .Readiness .FailureThreshold > 0 {
424
+ readinessProbeParts = append (readinessProbeParts , fmt .Sprintf ("failureThreshold=%d" , s .Readiness .FailureThreshold ))
425
+ }
426
+ if s .Readiness .HttpGet != nil {
427
+ if s .Readiness .HttpGet .Path != "" {
428
+ readinessProbeParts = append (readinessProbeParts , fmt .Sprintf ("httpGet.path=%s" , s .Readiness .HttpGet .Path ))
429
+ }
430
+ if s .Readiness .HttpGet .Port > 0 {
431
+ readinessProbeParts = append (readinessProbeParts , fmt .Sprintf ("httpGet.port=%d" , s .Readiness .HttpGet .Port ))
432
+ }
433
+ } else if s .Readiness .GRPC != nil {
434
+ if s .Readiness .GRPC .Service != "" {
435
+ readinessProbeParts = append (readinessProbeParts , fmt .Sprintf ("grpc.service=%s" , s .Readiness .GRPC .Service ))
436
+ }
437
+ if s .Readiness .GRPC .Port > 0 {
438
+ readinessProbeParts = append (readinessProbeParts , fmt .Sprintf ("grpc.port=%d" , s .Readiness .GRPC .Port ))
439
+ }
440
+ }
441
+ if len (readinessProbeParts ) > 0 {
442
+ args = append (args , "--readiness-probe=" + strings .Join (readinessProbeParts , "," ))
443
+ }
444
+ }
445
+
387
446
// NOTE: if the "beta" component is not available, and this is run in parallel,
388
447
// gcloud will attempt to install those components multiple
389
448
// times and will eventually fail on IO.
@@ -439,7 +498,7 @@ func (s *Service) deleteServiceCmd() *exec.Cmd {
439
498
"run" ,
440
499
"services" ,
441
500
"delete" ,
442
- s .version (),
501
+ s .Version (),
443
502
"--project" ,
444
503
s .ProjectID ,
445
504
}, s .Platform .CommandFlags ()... )
@@ -458,7 +517,7 @@ func (s *Service) urlCmd() *exec.Cmd {
458
517
"run" ,
459
518
"services" ,
460
519
"describe" ,
461
- s .version (),
520
+ s .Version (),
462
521
"--project" ,
463
522
s .ProjectID ,
464
523
"--format" ,
@@ -481,7 +540,7 @@ func (s *Service) LogEntries(filter string, find string, maxAttempts int) (bool,
481
540
}
482
541
defer client .Close ()
483
542
484
- preparedFilter := fmt .Sprintf (`resource.type="cloud_run_revision" resource.labels.service_name="%s" %s` , s .version (), filter )
543
+ preparedFilter := fmt .Sprintf (`resource.type="cloud_run_revision" resource.labels.service_name="%s" %s` , s .Version (), filter )
485
544
log .Printf ("Using log filter: %s\n " , preparedFilter )
486
545
487
546
log .Println ("Waiting for logs..." )
0 commit comments