-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from depot/feat/delete-load-lease
feat(load): remove lease for exported image
- Loading branch information
Showing
7 changed files
with
68 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package load | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
leasesapi "github.com/containerd/containerd/api/services/leases/v1" | ||
depotbuild "github.com/depot/cli/pkg/buildx/build" | ||
"github.com/moby/buildkit/depot" | ||
) | ||
|
||
// DeleteExportLeases removes the long-lived leases we use to inhibit garbage collection of exported images. | ||
func DeleteExportLeases(ctx context.Context, responses []depotbuild.DepotBuildResponse) { | ||
for _, res := range responses { | ||
for _, nodeRes := range res.NodeResponses { | ||
if nodeRes.SolveResponse == nil { | ||
continue | ||
} | ||
leaseID := nodeRes.SolveResponse.ExporterResponse[depot.ExportLeaseLabel] | ||
if leaseID == "" { | ||
continue | ||
} | ||
|
||
leasesClient, err := leasesClient(ctx, nodeRes) | ||
if err != nil { | ||
// Older versions of buildkitd may not have the leases API exposed. | ||
continue | ||
} | ||
_, _ = leasesClient.Delete(ctx, &leasesapi.DeleteRequest{ID: leaseID}) | ||
} | ||
} | ||
} | ||
|
||
func leasesClient(ctx context.Context, nodeResponse depotbuild.DepotNodeResponse) (leasesapi.LeasesClient, error) { | ||
if nodeResponse.Node.Driver == nil { | ||
return nil, fmt.Errorf("node %s does not have a driver", nodeResponse.Node.Name) | ||
} | ||
|
||
client, err := nodeResponse.Node.Driver.Client(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if client == nil { | ||
return nil, fmt.Errorf("node %s does not have a client", nodeResponse.Node.Name) | ||
} | ||
|
||
return client.LeasesClient(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters