-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathservice.go
More file actions
1245 lines (1137 loc) · 48.9 KB
/
service.go
File metadata and controls
1245 lines (1137 loc) · 48.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Code generated by goa v3.23.4, DO NOT EDIT.
//
// control-plane service
//
// Command:
// $ goa gen github.com/pgEdge/control-plane/api/apiv1/design -o apiv1
package controlplane
import (
"context"
goa "goa.design/goa/v3/pkg"
)
// Service is the control-plane service interface.
type Service interface {
// Initializes a new cluster.
InitCluster(context.Context, *InitClusterRequest) (res *ClusterJoinToken, err error)
// Joins this host to an existing cluster.
JoinCluster(context.Context, *ClusterJoinToken) (err error)
// Gets the join token for this cluster.
GetJoinToken(context.Context) (res *ClusterJoinToken, err error)
// Internal endpoint for other cluster members seeking to join this cluster.
GetJoinOptions(context.Context, *ClusterJoinRequest) (res *ClusterJoinOptions, err error)
// Returns information about the cluster.
GetCluster(context.Context) (res *Cluster, err error)
// Lists all hosts within the cluster.
ListHosts(context.Context) (res *ListHostsResponse, err error)
// Returns information about a particular host in the cluster.
GetHost(context.Context, *GetHostPayload) (res *Host, err error)
// Removes a host from the cluster.
RemoveHost(context.Context, *RemoveHostPayload) (res *RemoveHostResponse, err error)
// Lists all databases in the cluster.
ListDatabases(context.Context) (res *ListDatabasesResponse, err error)
// Creates a new database in the cluster.
CreateDatabase(context.Context, *CreateDatabaseRequest) (res *CreateDatabaseResponse, err error)
// Returns information about a particular database in the cluster.
GetDatabase(context.Context, *GetDatabasePayload) (res *Database, err error)
// Updates a database with the given specification.
UpdateDatabase(context.Context, *UpdateDatabasePayload) (res *UpdateDatabaseResponse, err error)
// Deletes a database from the cluster.
DeleteDatabase(context.Context, *DeleteDatabasePayload) (res *DeleteDatabaseResponse, err error)
// Initiates a backup for a database node.
BackupDatabaseNode(context.Context, *BackupDatabaseNodePayload) (res *BackupDatabaseNodeResponse, err error)
// Performs a planned switchover for a node's primary to a replica candidate.
SwitchoverDatabaseNode(context.Context, *SwitchoverDatabaseNodePayload) (res *SwitchoverDatabaseNodeResponse, err error)
// Performs a failover for a node to a replica candidate.
FailoverDatabaseNode(context.Context, *FailoverDatabaseNodeRequest) (res *FailoverDatabaseNodeResponse, err error)
// Lists all tasks for a database.
ListDatabaseTasks(context.Context, *ListDatabaseTasksPayload) (res *ListDatabaseTasksResponse, err error)
// Returns information about a particular task.
GetDatabaseTask(context.Context, *GetDatabaseTaskPayload) (res *Task, err error)
// Returns the log of a particular task for a database.
GetDatabaseTaskLog(context.Context, *GetDatabaseTaskLogPayload) (res *TaskLog, err error)
// Lists all tasks for a host.
ListHostTasks(context.Context, *ListHostTasksPayload) (res *ListHostTasksResponse, err error)
// Returns information about a particular task for a host.
GetHostTask(context.Context, *GetHostTaskPayload) (res *Task, err error)
// Returns the log of a particular task for a host.
GetHostTaskLog(context.Context, *GetHostTaskLogPayload) (res *TaskLog, err error)
// Lists tasks across all scopes with optional filtering by scope and entity ID.
ListTasks(context.Context, *ListTasksPayload) (res *ListTasksResponse, err error)
// Perform an in-place restore of one or more nodes using the given restore
// configuration.
RestoreDatabase(context.Context, *RestoreDatabasePayload) (res *RestoreDatabaseResponse, err error)
// Returns version information for this Control Plane server.
GetVersion(context.Context) (res *VersionInfo, err error)
// Restarts a specific instance within a database. Supports immediate or
// scheduled restarts.
RestartInstance(context.Context, *RestartInstancePayload) (res *RestartInstanceResponse, err error)
// Stops a specific instance within a database. Supports immediate stops.
StopInstance(context.Context, *StopInstancePayload) (res *StopInstanceResponse, err error)
// Starts a specific instance within a database. Supports immediate starts
StartInstance(context.Context, *StartInstancePayload) (res *StartInstanceResponse, err error)
// Cancels a running or pending task for a database.
CancelDatabaseTask(context.Context, *CancelDatabaseTaskPayload) (res *Task, err error)
}
// APIName is the name of the API as defined in the design.
const APIName = "control-plane"
// APIVersion is the version of the API as defined in the design.
const APIVersion = "v0.7.0"
// ServiceName is the name of the service as defined in the design. This is the
// same value that is set in the endpoint request contexts under the ServiceKey
// key.
const ServiceName = "control-plane"
// MethodNames lists the service method names as defined in the design. These
// are the same values that are set in the endpoint request contexts under the
// MethodKey key.
var MethodNames = [29]string{"init-cluster", "join-cluster", "get-join-token", "get-join-options", "get-cluster", "list-hosts", "get-host", "remove-host", "list-databases", "create-database", "get-database", "update-database", "delete-database", "backup-database-node", "switchover-database-node", "failover-database-node", "list-database-tasks", "get-database-task", "get-database-task-log", "list-host-tasks", "get-host-task", "get-host-task-log", "list-tasks", "restore-database", "get-version", "restart-instance", "stop-instance", "start-instance", "cancel-database-task"}
// A Control Plane API error.
type APIError struct {
// The name of the error.
Name string `json:"name"`
// The error message.
Message string `json:"message"`
}
type BackupConfigSpec struct {
// The repositories for this backup configuration.
Repositories []*BackupRepositorySpec `json:"repositories"`
// The schedules for this backup configuration.
Schedules []*BackupScheduleSpec `json:"schedules,omitempty"`
}
// BackupDatabaseNodePayload is the payload type of the control-plane service
// backup-database-node method.
type BackupDatabaseNodePayload struct {
// ID of the database to back up.
DatabaseID Identifier
// Name of the node to back up.
NodeName string
Options *BackupOptions
// Forcibly attempt backup even in unmodifiable state
Force bool
}
// BackupDatabaseNodeResponse is the result type of the control-plane service
// backup-database-node method.
type BackupDatabaseNodeResponse struct {
// The task that will backup this database node.
Task *Task `json:"task"`
}
type BackupOptions struct {
// The type of backup.
Type string `json:"type"`
// Annotations for the backup.
Annotations map[string]string `json:"annotations,omitempty"`
// Options for the backup.
BackupOptions map[string]string `json:"backup_options,omitempty"`
}
type BackupRepositorySpec struct {
// The unique identifier of this repository.
ID *Identifier `json:"id,omitempty"`
// The type of this repository.
Type string `json:"type"`
// The S3 bucket name for this repository. Only applies when type = 's3'.
S3Bucket *string `json:"s3_bucket,omitempty"`
// The region of the S3 bucket for this repository. Only applies when type =
// 's3'.
S3Region *string `json:"s3_region,omitempty"`
// The optional S3 endpoint for this repository. Only applies when type = 's3'.
S3Endpoint *string `json:"s3_endpoint,omitempty"`
// An optional AWS access key ID to use for this repository. If not provided,
// pgbackrest will use the default credential provider chain. This field will
// be excluded from the response of all endpoints. It can also be omitted from
// update requests to keep the current value.
S3Key *string `json:"s3_key,omitempty"`
// The corresponding secret for the AWS access key ID in s3_key. This field
// will be excluded from the response of all endpoints. It can also be omitted
// from update requests to keep the current value.
S3KeySecret *string `json:"s3_key_secret,omitempty"`
// The GCS bucket name for this repository. Only applies when type = 'gcs'.
GcsBucket *string `json:"gcs_bucket,omitempty"`
// The optional GCS endpoint for this repository. Only applies when type =
// 'gcs'.
GcsEndpoint *string `json:"gcs_endpoint,omitempty"`
// Optional base64-encoded private key data. If omitted, pgbackrest will use
// the service account attached to the instance profile. This field will be
// excluded from the response of all endpoints. It can also be omitted from
// update requests to keep the current value.
GcsKey *string `json:"gcs_key,omitempty"`
// The Azure account name for this repository. Only applies when type = 'azure'.
AzureAccount *string `json:"azure_account,omitempty"`
// The Azure container name for this repository. Only applies when type =
// 'azure'.
AzureContainer *string `json:"azure_container,omitempty"`
// The optional Azure endpoint for this repository. Only applies when type =
// 'azure'.
AzureEndpoint *string `json:"azure_endpoint,omitempty"`
// The Azure storage account access key to use for this repository. This field
// will be excluded from the response of all endpoints. It can also be omitted
// from update requests to keep the current value.
AzureKey *string `json:"azure_key,omitempty"`
// The count of full backups to retain or the time to retain full backups.
RetentionFull *int `json:"retention_full,omitempty"`
// The type of measure used for retention_full.
RetentionFullType *string `json:"retention_full_type,omitempty"`
// The base path within the repository to store backups. Required for type =
// 'posix' and 'cifs'.
BasePath *string `json:"base_path,omitempty"`
// Additional options to apply to this repository.
CustomOptions map[string]string `json:"custom_options,omitempty"`
}
type BackupScheduleSpec struct {
// The unique identifier for this backup schedule.
ID string `json:"id"`
// The type of backup to take on this schedule.
Type string `json:"type"`
// The cron expression for this schedule.
CronExpression string `json:"cron_expression"`
}
// CancelDatabaseTaskPayload is the payload type of the control-plane service
// cancel-database-task method.
type CancelDatabaseTaskPayload struct {
// ID of the database that owns the task.
DatabaseID Identifier
// ID of the task to cancel.
TaskID Identifier
}
// Cluster is the result type of the control-plane service get-cluster method.
type Cluster struct {
// Unique identifier for the cluster.
ID Identifier `json:"id"`
// Current status of the cluster.
Status *ClusterStatus `json:"status"`
// All of the hosts in the cluster.
Hosts []*Host `json:"hosts"`
}
type ClusterCredentials struct {
// The Etcd username for the new host.
Username string `json:"username"`
// The Etcd password for the new host.
Password string `json:"password"`
// The base64-encoded CA certificate for the cluster.
CaCert string `json:"ca_cert"`
// The base64-encoded etcd client certificate for the new cluster member.
ClientCert string `json:"client_cert"`
// The base64-encoded etcd client key for the new cluster member.
ClientKey string `json:"client_key"`
// The base64-encoded etcd server certificate for the new cluster member.
ServerCert string `json:"server_cert"`
// The base64-encoded etcd server key for the new cluster member.
ServerKey string `json:"server_key"`
}
// ClusterJoinOptions is the result type of the control-plane service
// get-join-options method.
type ClusterJoinOptions struct {
// Connection information for the etcd cluster leader
Leader *EtcdClusterMember `json:"leader"`
// Credentials for the new host joining the cluster.
Credentials *ClusterCredentials `json:"credentials"`
}
// ClusterJoinRequest is the payload type of the control-plane service
// get-join-options method.
type ClusterJoinRequest struct {
// Token to join the cluster.
Token string `json:"token"`
// The unique identifier for the host that's joining the cluster.
HostID Identifier `json:"host_id"`
// The peer addresses of the host that's joining the cluster.
Addresses []string `json:"addresses"`
// True if the joining member is configured to run an embedded an etcd server.
EmbeddedEtcdEnabled bool `json:"embedded_etcd_enabled"`
}
// ClusterJoinToken is the result type of the control-plane service
// init-cluster method.
type ClusterJoinToken struct {
// Token to join an existing cluster.
Token string `json:"token"`
// Existing server to join
ServerUrls []string `json:"server_urls"`
}
type ClusterStatus struct {
// The current state of the cluster.
State string `json:"state"`
}
type ComponentStatus struct {
// Indicates if the component is healthy.
Healthy bool `json:"healthy"`
// Error message from any errors that occurred during the health check.
Error *string `json:"error,omitempty"`
// Additional details about the component.
Details map[string]any `json:"details,omitempty"`
}
// CreateDatabaseRequest is the payload type of the control-plane service
// create-database method.
type CreateDatabaseRequest struct {
// Unique identifier for the database.
ID *Identifier `json:"id,omitempty"`
// Unique identifier for the database's owner.
TenantID *Identifier `json:"tenant_id,omitempty"`
// The specification for the database.
Spec *DatabaseSpec `json:"spec"`
}
// CreateDatabaseResponse is the result type of the control-plane service
// create-database method.
type CreateDatabaseResponse struct {
// The task that will create this database.
Task *Task `json:"task"`
// The database being created.
Database *Database `json:"database"`
}
// Database is the result type of the control-plane service get-database method.
type Database struct {
// Unique identifier for the database.
ID Identifier `json:"id"`
// Unique identifier for the database's owner.
TenantID *Identifier `json:"tenant_id,omitempty"`
// The time that the database was created.
CreatedAt string `json:"created_at"`
// The time that the database was last updated.
UpdatedAt string `json:"updated_at"`
// Current state of the database.
State string `json:"state"`
// All of the instances in the database.
Instances []*Instance `json:"instances,omitempty"`
// Service instances running alongside this database.
ServiceInstances []*ServiceInstance `json:"service_instances,omitempty"`
// The user-provided specification for the database.
Spec *DatabaseSpec `json:"spec,omitempty"`
}
// Controls how the service connects to the database. When omitted, all nodes
// are included with the local node first and target_session_attrs is derived
// from the service config.
type DatabaseConnection struct {
// Optional ordered list of database node names. When set, the service's
// database connection includes only the listed nodes in the specified order.
TargetNodes []string `json:"target_nodes,omitempty"`
// Optional libpq target_session_attrs value. When set, overrides the default
// derived from the service config. Valid values: primary, prefer-standby,
// standby, read-write, any.
TargetSessionAttrs *string `json:"target_session_attrs,omitempty"`
}
type DatabaseNodeSpec struct {
// The name of the database node.
Name string `json:"name"`
// The IDs of the hosts that should run this node. When multiple hosts are
// specified, one host will chosen as a primary, and the others will be read
// replicas.
HostIds []Identifier `json:"host_ids"`
// The Postgres version for this node in 'major.minor' format. Overrides the
// Postgres version set in the DatabaseSpec.
PostgresVersion *string `json:"postgres_version,omitempty"`
// The port used by the Postgres database for this node. Overrides the Postgres
// port set in the DatabaseSpec.
Port *int `json:"port,omitempty"`
// The port used by Patroni for this node. Overrides the Patroni port set in
// the DatabaseSpec. NOTE: This field is not currently supported for Docker
// Swarm.
PatroniPort *int `json:"patroni_port,omitempty"`
// The number of CPUs to allocate for the database on this node and to use for
// tuning Postgres. It can include the SI suffix 'm', e.g. '500m' for 500
// millicpus. Cannot allocate units smaller than 1m. Defaults to the number of
// available CPUs on the host if 0 or unspecified. Cannot allocate more CPUs
// than are available on the host. Whether this limit is enforced depends on
// the orchestrator.
Cpus *string `json:"cpus,omitempty"`
// The amount of memory in SI or IEC notation to allocate for the database on
// this node and to use for tuning Postgres. Defaults to the total available
// memory on the host. Whether this limit is enforced depends on the
// orchestrator.
Memory *string `json:"memory,omitempty"`
// Additional postgresql.conf settings for this particular node. Will be merged
// with the settings provided by control-plane.
PostgresqlConf map[string]any `json:"postgresql_conf,omitempty"`
// The backup configuration for this node. Overrides the backup configuration
// set in the DatabaseSpec.
BackupConfig *BackupConfigSpec `json:"backup_config,omitempty"`
// The restore configuration for this node. Overrides the restore configuration
// set in the DatabaseSpec.
RestoreConfig *RestoreConfigSpec `json:"restore_config,omitempty"`
// Orchestrator-specific configuration options.
OrchestratorOpts *OrchestratorOpts `json:"orchestrator_opts,omitempty"`
// The name of the source node to use for sync. This is typically the node
// (like 'n1') from which the data will be copied to initialize this new node.
SourceNode *string `json:"source_node,omitempty"`
}
type DatabaseSpec struct {
// The name of the Postgres database.
DatabaseName string `json:"database_name"`
// The Postgres version in 'major.minor' format.
PostgresVersion *string `json:"postgres_version,omitempty"`
// The major version of the Spock extension.
SpockVersion *string `json:"spock_version,omitempty"`
// The port used by the Postgres database. If the port is 0, each instance will
// be assigned a random port. If the port is unspecified, the database will not
// be exposed on any port, dependent on orchestrator support for that feature.
Port *int `json:"port,omitempty"`
// The port used by Patroni for this database. NOTE: This field is not
// currently supported for Docker Swarm.
PatroniPort *int `json:"patroni_port,omitempty"`
// The number of CPUs to allocate for the database and to use for tuning
// Postgres. Defaults to the number of available CPUs on the host. Can include
// an SI suffix, e.g. '500m' for 500 millicpus. Whether this limit is enforced
// depends on the orchestrator.
Cpus *string `json:"cpus,omitempty"`
// The amount of memory in SI or IEC notation to allocate for the database and
// to use for tuning Postgres. Defaults to the total available memory on the
// host. Whether this limit is enforced depends on the orchestrator.
Memory *string `json:"memory,omitempty"`
// The Spock nodes for this database.
Nodes []*DatabaseNodeSpec `json:"nodes"`
// The users to create for this database.
DatabaseUsers []*DatabaseUserSpec `json:"database_users,omitempty"`
// Service instances to run alongside the database (e.g., MCP servers).
Services []*ServiceSpec `json:"services,omitempty"`
// The backup configuration for this database.
BackupConfig *BackupConfigSpec `json:"backup_config,omitempty"`
// The restore configuration for this database.
RestoreConfig *RestoreConfigSpec `json:"restore_config,omitempty"`
// Additional postgresql.conf settings. Will be merged with the settings
// provided by control-plane.
PostgresqlConf map[string]any `json:"postgresql_conf,omitempty"`
// Orchestrator-specific configuration options.
OrchestratorOpts *OrchestratorOpts `json:"orchestrator_opts,omitempty"`
}
type DatabaseSummary struct {
// Unique identifier for the database.
ID Identifier `json:"id"`
// Unique identifier for the database's owner.
TenantID *Identifier `json:"tenant_id,omitempty"`
// The time that the database was created.
CreatedAt string `json:"created_at"`
// The time that the database was last updated.
UpdatedAt string `json:"updated_at"`
// Current state of the database.
State string `json:"state"`
// All of the instances in the database.
Instances []*Instance `json:"instances,omitempty"`
}
type DatabaseUserSpec struct {
// The username for this database user.
Username string `json:"username"`
// The password for this database user. This field will be excluded from the
// response of all endpoints. It can also be omitted from update requests to
// keep the current value.
Password *string `json:"password,omitempty"`
// If true, this user will be granted database ownership.
DbOwner *bool `json:"db_owner,omitempty"`
// The attributes to assign to this database user.
Attributes []string `json:"attributes,omitempty"`
// The roles to assign to this database user.
Roles []string `json:"roles,omitempty"`
}
// DeleteDatabasePayload is the payload type of the control-plane service
// delete-database method.
type DeleteDatabasePayload struct {
// ID of the database to delete.
DatabaseID Identifier
// Force deletion of a database even in an unmodifiable state
Force bool
}
// DeleteDatabaseResponse is the result type of the control-plane service
// delete-database method.
type DeleteDatabaseResponse struct {
// The task that will delete this database.
Task *Task `json:"task"`
}
type EtcdClusterMember struct {
// The name of the Etcd cluster member.
Name string `json:"name"`
// The Etcd peer endpoint for this cluster member.
PeerUrls []string `json:"peer_urls"`
// The Etcd client endpoint for this cluster member.
ClientUrls []string `json:"client_urls"`
}
// Describes an additional Docker network to attach the container to.
type ExtraNetworkSpec struct {
// The name or ID of the network to connect to.
ID string `json:"id"`
// Optional network-scoped aliases for the container.
Aliases []string `json:"aliases,omitempty"`
// Optional driver options for the network connection.
DriverOpts map[string]string `json:"driver_opts,omitempty"`
}
// Extra volumes to mount from the host to the database container.
type ExtraVolumesSpec struct {
// The host path for the volume.
HostPath string `json:"host_path"`
// The path inside the container where the volume will be mounted.
DestinationPath string `json:"destination_path"`
}
// FailoverDatabaseNodeRequest is the payload type of the control-plane service
// failover-database-node method.
type FailoverDatabaseNodeRequest struct {
// ID of the database to perform the failover for.
DatabaseID Identifier `json:"database_id"`
// Name of the node to initiate the failover from.
NodeName string `json:"node_name"`
// Optional instance_id of the replica to promote. If omitted, a candidate will
// be selected.
CandidateInstanceID *string `json:"candidate_instance_id,omitempty"`
// If true, skip the health validations that prevent running failover on a
// healthy cluster.
SkipValidation bool `json:"skip_validation,omitempty"`
}
// FailoverDatabaseNodeResponse is the result type of the control-plane service
// failover-database-node method.
type FailoverDatabaseNodeResponse struct {
// The task that will perform the failover.
Task *Task `json:"task"`
}
// GetDatabasePayload is the payload type of the control-plane service
// get-database method.
type GetDatabasePayload struct {
// ID of the database to get.
DatabaseID Identifier
}
// GetDatabaseTaskLogPayload is the payload type of the control-plane service
// get-database-task-log method.
type GetDatabaseTaskLogPayload struct {
// ID of the database to get the task log for.
DatabaseID Identifier
// ID of the task to get the log for.
TaskID string
// ID of the entry to start from.
AfterEntryID *string
// Maximum number of entries to return.
Limit *int
}
// GetDatabaseTaskPayload is the payload type of the control-plane service
// get-database-task method.
type GetDatabaseTaskPayload struct {
// ID of the database the task belongs to.
DatabaseID Identifier
// ID of the task to get.
TaskID string
}
// GetHostPayload is the payload type of the control-plane service get-host
// method.
type GetHostPayload struct {
// ID of the host to get.
HostID Identifier
}
// GetHostTaskLogPayload is the payload type of the control-plane service
// get-host-task-log method.
type GetHostTaskLogPayload struct {
// ID of the host to get the task logs for.
HostID Identifier
// ID of the task to get the logs for.
TaskID string
// ID of the entry to start from.
AfterEntryID *string
// Maximum number of entries to return.
Limit *int
}
// GetHostTaskPayload is the payload type of the control-plane service
// get-host-task method.
type GetHostTaskPayload struct {
// ID of the host the task belongs to.
HostID Identifier
// ID of the task to get.
TaskID string
}
// Health check result for a service instance.
type HealthCheckResult struct {
// The health status.
Status string `json:"status"`
// Optional message about the health status.
Message *string `json:"message,omitempty"`
// The time this health check was performed.
CheckedAt string `json:"checked_at"`
}
// Host is the result type of the control-plane service get-host method.
type Host struct {
// Unique identifier for the host.
ID Identifier `json:"id"`
// The orchestrator used by this host.
Orchestrator string `json:"orchestrator"`
// The data directory for the host.
DataDir string `json:"data_dir"`
// The cohort that this host belongs to.
Cohort *HostCohort `json:"cohort,omitempty"`
// The addresses that this host advertises to other hosts.
PeerAddresses []string `json:"peer_addresses"`
// The addresses that this host advertises to client applications.
ClientAddresses []string `json:"client_addresses"`
// The number of CPUs on this host.
Cpus *int `json:"cpus,omitempty"`
// The amount of memory available on this host.
Memory *string `json:"memory,omitempty"`
// Current status of the host.
Status *HostStatus `json:"status"`
// The default PgEdge version for this host.
DefaultPgedgeVersion *PgEdgeVersion `json:"default_pgedge_version,omitempty"`
// The PgEdge versions supported by this host.
SupportedPgedgeVersions []*PgEdgeVersion `json:"supported_pgedge_versions,omitempty"`
// The etcd mode for this host.
EtcdMode *string `json:"etcd_mode,omitempty"`
}
type HostCohort struct {
// The type of cohort that the host belongs to.
Type string `json:"type"`
// The member ID of the host within the cohort.
MemberID string `json:"member_id"`
// Indicates if the host is a control node in the cohort.
ControlAvailable bool `json:"control_available"`
}
type HostStatus struct {
State string `json:"state"`
// The last time the host status was updated.
UpdatedAt string `json:"updated_at"`
// The status of each component of the host.
Components map[string]*ComponentStatus `json:"components"`
}
// A user-specified identifier. Must be 1-63 characters, contain only
// lower-cased letters and hyphens, start and end with a letter or number, and
// not contain consecutive hyphens.
type Identifier string
// InitClusterRequest is the payload type of the control-plane service
// init-cluster method.
type InitClusterRequest struct {
// Optional id for the cluster, omit for default generated id
ClusterID *Identifier `json:"cluster_id,omitempty"`
}
// An instance of pgEdge Postgres running on a host.
type Instance struct {
// Unique identifier for the instance.
ID string `json:"id"`
// The ID of the host this instance is running on.
HostID string `json:"host_id"`
// The Spock node name for this instance.
NodeName string `json:"node_name"`
// The time that the instance was created.
CreatedAt string `json:"created_at"`
// The time that the instance was last modified.
UpdatedAt string `json:"updated_at"`
// The time that the instance status information was last updated.
StatusUpdatedAt *string `json:"status_updated_at,omitempty"`
State string `json:"state"`
// Connection information for the instance.
ConnectionInfo *InstanceConnectionInfo `json:"connection_info,omitempty"`
// Postgres status information for the instance.
Postgres *InstancePostgresStatus `json:"postgres,omitempty"`
// Spock status information for the instance.
Spock *InstanceSpockStatus `json:"spock,omitempty"`
// An error message if the instance is in an error state.
Error *string `json:"error,omitempty"`
}
// Connection information for a pgEdge instance.
type InstanceConnectionInfo struct {
// The addresses of the host that's running this instance.
Addresses []string `json:"addresses,omitempty"`
// The host port that Postgres is listening on for this instance.
Port *int `json:"port,omitempty"`
}
// Postgres status information for a pgEdge instance.
type InstancePostgresStatus struct {
// The version of Postgres for this instance.
Version *string `json:"version,omitempty"`
PatroniState *string `json:"patroni_state,omitempty"`
Role *string `json:"role,omitempty"`
// True if this instance has a pending restart from a configuration change.
PendingRestart *bool `json:"pending_restart,omitempty"`
// True if Patroni is paused for this instance.
PatroniPaused *bool `json:"patroni_paused,omitempty"`
}
// Spock status information for a pgEdge instance.
type InstanceSpockStatus struct {
// The current spock.readonly setting.
ReadOnly *string `json:"read_only,omitempty"`
// The version of Spock for this instance.
Version *string `json:"version,omitempty"`
// Status information for this instance's Spock subscriptions.
Subscriptions []*InstanceSubscription `json:"subscriptions,omitempty"`
}
// Status information for a Spock subscription.
type InstanceSubscription struct {
// The Spock node name of the provider for this subscription.
ProviderNode string `json:"provider_node"`
// The name of the subscription.
Name string `json:"name"`
// The current status of the subscription.
Status string `json:"status"`
}
// ListDatabaseTasksPayload is the payload type of the control-plane service
// list-database-tasks method.
type ListDatabaseTasksPayload struct {
// ID of the database to list tasks for.
DatabaseID Identifier
// ID of the task to start from.
AfterTaskID *string
// Maximum number of tasks to return.
Limit *int
// Sort order for the tasks.
SortOrder *string
}
// ListDatabaseTasksResponse is the result type of the control-plane service
// list-database-tasks method.
type ListDatabaseTasksResponse struct {
// The tasks for the given database.
Tasks []*Task `json:"tasks"`
}
// ListDatabasesResponse is the result type of the control-plane service
// list-databases method.
type ListDatabasesResponse struct {
// The databases managed by this cluster.
Databases []*DatabaseSummary `json:"databases"`
}
// ListHostTasksPayload is the payload type of the control-plane service
// list-host-tasks method.
type ListHostTasksPayload struct {
// ID of the host to list tasks for.
HostID Identifier
// ID of the task to start from.
AfterTaskID *string
// Maximum number of tasks to return.
Limit *int
// Sort order for the tasks.
SortOrder *string
}
// ListHostTasksResponse is the result type of the control-plane service
// list-host-tasks method.
type ListHostTasksResponse struct {
// The tasks for the given host.
Tasks []*Task `json:"tasks"`
}
// ListHostsResponse is the result type of the control-plane service list-hosts
// method.
type ListHostsResponse struct {
// List of hosts in the cluster
Hosts []*Host `json:"hosts"`
}
// ListTasksPayload is the payload type of the control-plane service list-tasks
// method.
type ListTasksPayload struct {
// Optional scope to filter tasks (database or host).
Scope *string
// Optional entity ID to filter tasks. Requires scope to be set.
EntityID *Identifier
// ID of the task to start from.
AfterTaskID *string
// Maximum number of tasks to return.
Limit *int
// Sort order for the tasks.
SortOrder *string
}
// ListTasksResponse is the result type of the control-plane service list-tasks
// method.
type ListTasksResponse struct {
// The tasks for the given entity.
Tasks []*Task `json:"tasks"`
}
// Options specific to the selected orchestrator.
type OrchestratorOpts struct {
// Swarm-specific configuration.
Swarm *SwarmOpts `json:"swarm,omitempty"`
}
type PgEdgeVersion struct {
// The Postgres major and minor version.
PostgresVersion string `json:"postgres_version"`
// The Spock major version.
SpockVersion string `json:"spock_version"`
}
// Port mapping information for a service instance.
type PortMapping struct {
// The name of the port (e.g., 'http', 'web-client').
Name string `json:"name"`
// The port number inside the container.
ContainerPort *int `json:"container_port,omitempty"`
// The port number on the host (if port-forwarded).
HostPort *int `json:"host_port,omitempty"`
}
// RemoveHostPayload is the payload type of the control-plane service
// remove-host method.
type RemoveHostPayload struct {
// ID of the host to remove.
HostID Identifier
// Force removal even if instances exist or quorum would be violated. Use only
// for disaster recovery when a host is permanently lost.
Force bool
}
// RemoveHostResponse is the result type of the control-plane service
// remove-host method.
type RemoveHostResponse struct {
// The task that tracks the overall host removal operation.
Task *Task `json:"task"`
// The tasks that will update databases affected by the host removal.
UpdateDatabaseTasks []*Task `json:"update_database_tasks"`
}
// RestartInstancePayload is the payload type of the control-plane service
// restart-instance method.
type RestartInstancePayload struct {
// The ID of the database that owns the instance.
DatabaseID Identifier
// The ID of the instance to restart.
InstanceID Identifier
// The time at which the restart is scheduled.
ScheduledAt *string
}
// Returns a task representing the restart operation.
type RestartInstanceResponse struct {
// Task representing the restart operation
Task *Task `json:"task"`
}
type RestoreConfigSpec struct {
// The ID of the database to restore this database from.
SourceDatabaseID Identifier `json:"source_database_id"`
// The name of the node to restore this database from.
SourceNodeName string `json:"source_node_name"`
// The name of the database in this repository. The database will be renamed to
// the database_name in the DatabaseSpec after it's restored.
SourceDatabaseName string `json:"source_database_name"`
// The repository to restore this database from.
Repository *RestoreRepositorySpec `json:"repository"`
// Additional options to use when restoring this database. If omitted, the
// database will be restored to the latest point in the given repository.
RestoreOptions map[string]string `json:"restore_options,omitempty"`
}
// RestoreDatabasePayload is the payload type of the control-plane service
// restore-database method.
type RestoreDatabasePayload struct {
// ID of the database to restore.
DatabaseID Identifier
Request *RestoreDatabaseRequest
// Force restoration of a database even in an unmodifiable state
Force bool
}
type RestoreDatabaseRequest struct {
// Configuration for the restore process.
RestoreConfig *RestoreConfigSpec `json:"restore_config"`
// The nodes to restore. Defaults to all nodes if empty or unspecified.
TargetNodes []string `json:"target_nodes,omitempty"`
}
// RestoreDatabaseResponse is the result type of the control-plane service
// restore-database method.
type RestoreDatabaseResponse struct {
// The task that will restore this database.
Task *Task `json:"task"`
// The tasks that will restore each database node.
NodeTasks []*Task `json:"node_tasks"`
// The database being restored.
Database *Database `json:"database"`
}
type RestoreRepositorySpec struct {
// The unique identifier of this repository.
ID *Identifier `json:"id,omitempty"`
// The type of this repository.
Type string `json:"type"`
// The S3 bucket name for this repository. Only applies when type = 's3'.
S3Bucket *string `json:"s3_bucket,omitempty"`
// The region of the S3 bucket for this repository. Only applies when type =
// 's3'.
S3Region *string `json:"s3_region,omitempty"`
// The optional S3 endpoint for this repository. Only applies when type = 's3'.
S3Endpoint *string `json:"s3_endpoint,omitempty"`
// An optional AWS access key ID to use for this repository. If not provided,
// pgbackrest will use the default credential provider chain.
S3Key *string `json:"s3_key,omitempty"`
// The corresponding secret for the AWS access key ID in s3_key.
S3KeySecret *string `json:"s3_key_secret,omitempty"`
// The GCS bucket name for this repository. Only applies when type = 'gcs'.
GcsBucket *string `json:"gcs_bucket,omitempty"`
// The optional GCS endpoint for this repository. Only applies when type =
// 'gcs'.
GcsEndpoint *string `json:"gcs_endpoint,omitempty"`
// Optional base64-encoded private key data. If omitted, pgbackrest will use
// the service account attached to the instance profile.
GcsKey *string `json:"gcs_key,omitempty"`
// The Azure account name for this repository. Only applies when type = 'azure'.
AzureAccount *string `json:"azure_account,omitempty"`
// The Azure container name for this repository. Only applies when type =
// 'azure'.
AzureContainer *string `json:"azure_container,omitempty"`
// The optional Azure endpoint for this repository. Only applies when type =
// 'azure'.
AzureEndpoint *string `json:"azure_endpoint,omitempty"`
// An optional Azure storage account access key to use for this repository. If
// not provided, pgbackrest will use the VM's managed identity.
AzureKey *string `json:"azure_key,omitempty"`
// The base path within the repository to store backups. Required for type =
// 'posix' and 'cifs'.
BasePath *string `json:"base_path,omitempty"`
// Additional options to apply to this repository.
CustomOptions map[string]string `json:"custom_options,omitempty"`
}
// A service instance running on a host alongside the database.
type ServiceInstance struct {
// Unique identifier for the service instance.
ServiceInstanceID string `json:"service_instance_id"`
// The service ID from the DatabaseSpec.
ServiceID string `json:"service_id"`
// The ID of the database this service belongs to.
DatabaseID Identifier `json:"database_id"`
// The ID of the host this service instance is running on.
HostID string `json:"host_id"`
// Current state of the service instance.
State string `json:"state"`
// Runtime status information for the service instance.
Status *ServiceInstanceStatus `json:"status,omitempty"`
// The time that the service instance was created.
CreatedAt string `json:"created_at"`
// The time that the service instance was last updated.
UpdatedAt string `json:"updated_at"`
// An error message if the service instance is in an error state.
Error *string `json:"error,omitempty"`
}
// Runtime status information for a service instance.
type ServiceInstanceStatus struct {
// The Docker container ID.
ContainerID *string `json:"container_id,omitempty"`
// The container image version currently running.
ImageVersion *string `json:"image_version,omitempty"`
// The addresses of the host that's running this service instance.
Addresses []string `json:"addresses,omitempty"`
// Port mappings for this service instance.
Ports []*PortMapping `json:"ports,omitempty"`
// Most recent health check result.
HealthCheck *HealthCheckResult `json:"health_check,omitempty"`
// The time of the last health check attempt.
LastHealthAt *string `json:"last_health_at,omitempty"`
// Whether the service is ready to accept requests.
ServiceReady *bool `json:"service_ready,omitempty"`
}
type ServiceSpec struct {
// The unique identifier for this service.
ServiceID Identifier `json:"service_id"`
// The type of service to run.
ServiceType string `json:"service_type"`
// The version of the service (e.g., '1.0.0', '14.5') or the literal 'latest'.
Version string `json:"version"`
// The IDs of the hosts that should run this service. One service instance will
// be created per host.
HostIds []Identifier `json:"host_ids"`
// The port to publish the service on the host. If 0, Docker assigns a random
// port. If unspecified, no port is published and the service is not accessible
// from outside the Docker network.
Port *int `json:"port,omitempty"`
// Service-specific configuration. For MCP services, this includes
// llm_provider, llm_model, and provider-specific API keys.
Config map[string]any `json:"config"`
// The number of CPUs to allocate for this service. It can include the SI
// suffix 'm', e.g. '500m' for 500 millicpus. Defaults to container defaults if
// unspecified.
Cpus *string `json:"cpus,omitempty"`
// The amount of memory in SI or IEC notation to allocate for this service.
// Defaults to container defaults if unspecified.
Memory *string `json:"memory,omitempty"`
// Orchestrator-specific options for this service.
OrchestratorOpts *OrchestratorOpts `json:"orchestrator_opts,omitempty"`
// Optional database connection routing configuration.
DatabaseConnection *DatabaseConnection `json:"database_connection,omitempty"`
}
// StartInstancePayload is the payload type of the control-plane service
// start-instance method.
type StartInstancePayload struct {
// The ID of the database that owns the instance.