@@ -1057,10 +1057,22 @@ func stringSlicesEqual(a, b []string) bool {
10571057}
10581058
10591059func (c * CoordinatorClient ) UpdateLeaseTailscale (ctx context.Context , id string , meta TailscaleMetadata ) (CoordinatorLease , error ) {
1060+ return c .UpdateLeaseTailscaleForProvider (ctx , id , "" , meta )
1061+ }
1062+
1063+ func (c * CoordinatorClient ) UpdateLeaseTailscaleForProvider (ctx context.Context , id , expectedProvider string , meta TailscaleMetadata ) (CoordinatorLease , error ) {
10601064 var res struct {
10611065 Lease CoordinatorLease `json:"lease"`
10621066 }
1063- err := c .do (ctx , http .MethodPost , "/v1/leases/" + url .PathEscape (id )+ "/tailscale" , meta , & res )
1067+ expectedProvider , err := canonicalCoordinatorMutationProvider (expectedProvider )
1068+ if err != nil {
1069+ return res .Lease , err
1070+ }
1071+ body := struct {
1072+ TailscaleMetadata
1073+ ExpectedProvider string `json:"expectedProvider,omitempty"`
1074+ }{TailscaleMetadata : meta , ExpectedProvider : expectedProvider }
1075+ err = c .do (ctx , http .MethodPost , "/v1/leases/" + url .PathEscape (id )+ "/tailscale" , body , & res )
10641076 return res .Lease , err
10651077}
10661078
@@ -1116,10 +1128,22 @@ func (c *CoordinatorClient) DeleteLeaseShare(ctx context.Context, id, user strin
11161128}
11171129
11181130func (c * CoordinatorClient ) ReleaseLease (ctx context.Context , id string , deleteServer bool ) (CoordinatorLease , error ) {
1131+ return c .ReleaseLeaseForProvider (ctx , id , deleteServer , "" )
1132+ }
1133+
1134+ func (c * CoordinatorClient ) ReleaseLeaseForProvider (ctx context.Context , id string , deleteServer bool , expectedProvider string ) (CoordinatorLease , error ) {
11191135 var res struct {
11201136 Lease CoordinatorLease `json:"lease"`
11211137 }
1122- err := c .do (ctx , http .MethodPost , "/v1/leases/" + url .PathEscape (id )+ "/release" , map [string ]any {"delete" : deleteServer }, & res )
1138+ expectedProvider , err := canonicalCoordinatorMutationProvider (expectedProvider )
1139+ if err != nil {
1140+ return res .Lease , err
1141+ }
1142+ body := map [string ]any {"delete" : deleteServer }
1143+ if expectedProvider != "" {
1144+ body ["expectedProvider" ] = expectedProvider
1145+ }
1146+ err = c .do (ctx , http .MethodPost , "/v1/leases/" + url .PathEscape (id )+ "/release" , body , & res )
11231147 return res .Lease , err
11241148}
11251149
@@ -1130,60 +1154,107 @@ func (c *CoordinatorClient) CancelLeaseCreate(ctx context.Context, id, createAtt
11301154}
11311155
11321156func (c * CoordinatorClient ) CompleteRuntimeAdapterDelete (ctx context.Context , id , adapterID , workspaceID , registrationID string ) (CoordinatorLease , error ) {
1157+ return c .CompleteRuntimeAdapterDeleteForProvider (ctx , id , "" , adapterID , workspaceID , registrationID )
1158+ }
1159+
1160+ func (c * CoordinatorClient ) CompleteRuntimeAdapterDeleteForProvider (ctx context.Context , id , expectedProvider , adapterID , workspaceID , registrationID string ) (CoordinatorLease , error ) {
11331161 var res struct {
11341162 Lease CoordinatorLease `json:"lease"`
11351163 }
1136- err := c .do (ctx , http .MethodPost , "/v1/leases/" + url .PathEscape (id )+ "/release" , map [string ]any {
1164+ expectedProvider , err := canonicalCoordinatorMutationProvider (expectedProvider )
1165+ if err != nil {
1166+ return res .Lease , err
1167+ }
1168+ body := map [string ]any {
11371169 "runtimeAdapterDeleteCompletion" : map [string ]string {
11381170 "adapterID" : adapterID ,
11391171 "workspaceID" : workspaceID ,
11401172 "registrationID" : registrationID ,
11411173 "status" : "absent" ,
11421174 },
1143- }, & res )
1175+ }
1176+ if expectedProvider != "" {
1177+ body ["expectedProvider" ] = expectedProvider
1178+ }
1179+ err = c .do (ctx , http .MethodPost , "/v1/leases/" + url .PathEscape (id )+ "/release" , body , & res )
11441180 return res .Lease , err
11451181}
11461182
11471183func (c * CoordinatorClient ) CompleteLegacyRuntimeAdapterDelete (ctx context.Context , id , adapterID , workspaceID string ) (CoordinatorLease , error ) {
1184+ return c .CompleteLegacyRuntimeAdapterDeleteForProvider (ctx , id , "" , adapterID , workspaceID )
1185+ }
1186+
1187+ func (c * CoordinatorClient ) CompleteLegacyRuntimeAdapterDeleteForProvider (ctx context.Context , id , expectedProvider , adapterID , workspaceID string ) (CoordinatorLease , error ) {
11481188 var res struct {
11491189 Lease CoordinatorLease `json:"lease"`
11501190 }
1151- err := c .do (ctx , http .MethodPost , "/v1/leases/" + url .PathEscape (id )+ "/release" , map [string ]any {
1191+ expectedProvider , err := canonicalCoordinatorMutationProvider (expectedProvider )
1192+ if err != nil {
1193+ return res .Lease , err
1194+ }
1195+ body := map [string ]any {
11521196 "runtimeAdapterLegacyDeleteCompletion" : map [string ]string {
11531197 "adapterID" : adapterID ,
11541198 "workspaceID" : workspaceID ,
11551199 "status" : "absent" ,
11561200 },
1157- }, & res )
1201+ }
1202+ if expectedProvider != "" {
1203+ body ["expectedProvider" ] = expectedProvider
1204+ }
1205+ err = c .do (ctx , http .MethodPost , "/v1/leases/" + url .PathEscape (id )+ "/release" , body , & res )
11581206 return res .Lease , err
11591207}
11601208
11611209func (c * CoordinatorClient ) TouchLease (ctx context.Context , id string ) (CoordinatorLease , error ) {
1162- return c .heartbeatLease (ctx , id , nil , nil )
1210+ return c .heartbeatLease (ctx , id , "" , nil , nil )
1211+ }
1212+
1213+ func (c * CoordinatorClient ) TouchLeaseForProvider (ctx context.Context , id , expectedProvider string ) (CoordinatorLease , error ) {
1214+ return c .heartbeatLease (ctx , id , expectedProvider , nil , nil )
11631215}
11641216
11651217func (c * CoordinatorClient ) TouchLeaseWithTelemetry (ctx context.Context , id string , telemetry * LeaseTelemetry ) (CoordinatorLease , error ) {
1166- return c .heartbeatLease (ctx , id , nil , telemetry )
1218+ return c .heartbeatLease (ctx , id , "" , nil , telemetry )
1219+ }
1220+
1221+ func (c * CoordinatorClient ) TouchLeaseWithTelemetryForProvider (ctx context.Context , id , expectedProvider string , telemetry * LeaseTelemetry ) (CoordinatorLease , error ) {
1222+ return c .heartbeatLease (ctx , id , expectedProvider , nil , telemetry )
11671223}
11681224
11691225func (c * CoordinatorClient ) UpdateLeaseIdleTimeout (ctx context.Context , id string , idleTimeout time.Duration ) (CoordinatorLease , error ) {
1170- return c .heartbeatLease (ctx , id , & idleTimeout , nil )
1226+ return c .heartbeatLease (ctx , id , "" , & idleTimeout , nil )
1227+ }
1228+
1229+ func (c * CoordinatorClient ) UpdateLeaseIdleTimeoutForProvider (ctx context.Context , id , expectedProvider string , idleTimeout time.Duration ) (CoordinatorLease , error ) {
1230+ return c .heartbeatLease (ctx , id , expectedProvider , & idleTimeout , nil )
11711231}
11721232
11731233func (c * CoordinatorClient ) UpdateLeaseIdleTimeoutWithTelemetry (ctx context.Context , id string , idleTimeout time.Duration , telemetry * LeaseTelemetry ) (CoordinatorLease , error ) {
1174- return c .heartbeatLease (ctx , id , & idleTimeout , telemetry )
1234+ return c .heartbeatLease (ctx , id , "" , & idleTimeout , telemetry )
1235+ }
1236+
1237+ func (c * CoordinatorClient ) UpdateLeaseIdleTimeoutWithTelemetryForProvider (ctx context.Context , id , expectedProvider string , idleTimeout time.Duration , telemetry * LeaseTelemetry ) (CoordinatorLease , error ) {
1238+ return c .heartbeatLease (ctx , id , expectedProvider , & idleTimeout , telemetry )
11751239}
11761240
1177- func (c * CoordinatorClient ) heartbeatLease (ctx context.Context , id string , idleTimeout * time.Duration , telemetry * LeaseTelemetry ) (CoordinatorLease , error ) {
1241+ func (c * CoordinatorClient ) heartbeatLease (ctx context.Context , id , expectedProvider string , idleTimeout * time.Duration , telemetry * LeaseTelemetry ) (CoordinatorLease , error ) {
11781242 var res struct {
11791243 Lease CoordinatorLease `json:"lease"`
11801244 }
1181- err := c .do (ctx , http .MethodPost , "/v1/leases/" + url .PathEscape (id )+ "/heartbeat" , heartbeatRequestBody (idleTimeout , telemetry ), & res )
1245+ expectedProvider , err := canonicalCoordinatorMutationProvider (expectedProvider )
1246+ if err != nil {
1247+ return res .Lease , err
1248+ }
1249+ err = c .do (ctx , http .MethodPost , "/v1/leases/" + url .PathEscape (id )+ "/heartbeat" , heartbeatRequestBody (expectedProvider , idleTimeout , telemetry ), & res )
11821250 return res .Lease , err
11831251}
11841252
1185- func heartbeatRequestBody (idleTimeout * time.Duration , telemetry * LeaseTelemetry ) map [string ]any {
1253+ func heartbeatRequestBody (expectedProvider string , idleTimeout * time.Duration , telemetry * LeaseTelemetry ) map [string ]any {
11861254 body := map [string ]any {}
1255+ if expectedProvider != "" {
1256+ body ["expectedProvider" ] = expectedProvider
1257+ }
11871258 if idleTimeout != nil && * idleTimeout > 0 {
11881259 body ["idleTimeoutSeconds" ] = int (idleTimeout .Seconds ())
11891260 }
@@ -1193,6 +1264,13 @@ func heartbeatRequestBody(idleTimeout *time.Duration, telemetry *LeaseTelemetry)
11931264 return body
11941265}
11951266
1267+ func canonicalCoordinatorMutationProvider (expectedProvider string ) (string , error ) {
1268+ if expectedProvider == "" {
1269+ return "" , nil
1270+ }
1271+ return canonicalProviderName (expectedProvider )
1272+ }
1273+
11961274func (c * CoordinatorClient ) Pool (ctx context.Context , cfg Config ) ([]CoordinatorMachine , error ) {
11971275 var res struct {
11981276 Machines []CoordinatorMachine `json:"machines"`
@@ -1500,10 +1578,22 @@ func (c *CoordinatorClient) AdminLeaseAudit(ctx context.Context, state, provider
15001578}
15011579
15021580func (c * CoordinatorClient ) AdminReleaseLease (ctx context.Context , id string , deleteServer bool ) (CoordinatorLease , error ) {
1581+ return c .AdminReleaseLeaseForProvider (ctx , id , deleteServer , "" )
1582+ }
1583+
1584+ func (c * CoordinatorClient ) AdminReleaseLeaseForProvider (ctx context.Context , id string , deleteServer bool , expectedProvider string ) (CoordinatorLease , error ) {
15031585 var res struct {
15041586 Lease CoordinatorLease `json:"lease"`
15051587 }
1506- err := c .do (ctx , http .MethodPost , "/v1/admin/leases/" + url .PathEscape (id )+ "/release" , map [string ]any {"delete" : deleteServer }, & res )
1588+ expectedProvider , err := canonicalCoordinatorMutationProvider (expectedProvider )
1589+ if err != nil {
1590+ return res .Lease , err
1591+ }
1592+ body := map [string ]any {"delete" : deleteServer }
1593+ if expectedProvider != "" {
1594+ body ["expectedProvider" ] = expectedProvider
1595+ }
1596+ err = c .do (ctx , http .MethodPost , "/v1/admin/leases/" + url .PathEscape (id )+ "/release" , body , & res )
15071597 return res .Lease , err
15081598}
15091599
0 commit comments