Skip to content

Commit f81e6ea

Browse files
committed
fix: CRs
Signed-off-by: Matthias Riegler <[email protected]>
1 parent 1e5ea29 commit f81e6ea

File tree

4 files changed

+11
-46
lines changed

4 files changed

+11
-46
lines changed

Readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
The LeaseProvider is a server that provides the ability to manage distributed leases among multiple github action runs, letting the highest priority run _win_ the lease. This process is helpful when there are multiple runs running that need access to a shared resource. It allows them to agree on the _winner_ of a race for the resource, and subsequently provide the _winner_ with a lease until it is released.
88
Depending on the release status (success/failure), the lease is completed and confirmation is awaited or the request from the failing lease is discarded and the process restarts.
99

10-
It exposes two endpoints:
10+
It exposes the following endpoints:
1111
- GET `/healthz` Kubernetes health endpoint
1212
- GET `/readyz` Kubernetes readiness endpoint
1313
- GET `/metrics` Prometheus metric endpoint

internal/github/types.go

-35
This file was deleted.

internal/lease/leaseprovider.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (lp *leaseProviderImpl) insert(leaseRequest *LeaseRequest) (*LeaseRequest,
145145
return lp.known[leaseRequest.HeadSHA], nil
146146
}
147147

148-
func (lp *leaseProviderImpl) isWinningLeaseRequest(req *LeaseRequest) *LeaseRequest {
148+
func (lp *leaseProviderImpl) evaluateRequest(req *LeaseRequest) *LeaseRequest {
149149
// Prereq: we can expect the arg to be already part of the map!
150150

151151
if lp.aquired != nil && !(pointer.StringDeref(lp.aquired.Status, STATUS_AQUIRED) == STATUS_FAILURE) {
@@ -197,7 +197,7 @@ func (lp *leaseProviderImpl) Aquire(leaseRequest *LeaseRequest) (*LeaseRequest,
197197
}
198198

199199
// Return the request object with the correct status
200-
return lp.isWinningLeaseRequest(req), nil
200+
return lp.evaluateRequest(req), nil
201201
}
202202

203203
func (lp *leaseProviderImpl) Release(leaseRequest *LeaseRequest) (*LeaseRequest, error) {

internal/lease/leaseprovider_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func Test_leaseProviderImpl_evictTTL_aquired(t *testing.T) {
213213
assert.Equal(t, 1, len(lpImpl.known))
214214
}
215215

216-
func Test_leaseProviderImpl_isWinningLeaseRequest_timePassed(t *testing.T) {
216+
func Test_leaseProviderImpl_evaluateRequest_timePassed(t *testing.T) {
217217
lp := NewLeaseProvider(&LeaseProviderOpts{TTL: 1 * time.Hour, StabilizeDuration: 1 * time.Minute, ExpectedRequestCount: 4})
218218
lpImpl, ok := lp.(*leaseProviderImpl)
219219
assert.True(t, ok)
@@ -235,16 +235,16 @@ func Test_leaseProviderImpl_isWinningLeaseRequest_timePassed(t *testing.T) {
235235
assert.NoError(t, err)
236236

237237
// Immediately check if req2 gets the lease (it should not!)
238-
_ = lpImpl.isWinningLeaseRequest(req2)
238+
_ = lpImpl.evaluateRequest(req2)
239239
assert.Equal(t, *req2.Status, STATUS_PENDING)
240240

241241
// Simulate a time passed by setting the last updated timestamp in the past
242242
lpImpl.lastUpdatedAt = time.Now().Add(-2 * time.Minute)
243-
_ = lpImpl.isWinningLeaseRequest(req2)
243+
_ = lpImpl.evaluateRequest(req2)
244244
assert.Equal(t, *req2.Status, STATUS_AQUIRED)
245245
}
246246

247-
func Test_leaseProviderImpl_isWinningLeaseRequest_reachedExpectedRequestCount(t *testing.T) {
247+
func Test_leaseProviderImpl_evaluateRequest_reachedExpectedRequestCount(t *testing.T) {
248248
lp := NewLeaseProvider(&LeaseProviderOpts{TTL: 1 * time.Hour, StabilizeDuration: 1 * time.Minute, ExpectedRequestCount: 3})
249249
lpImpl, ok := lp.(*leaseProviderImpl)
250250
assert.True(t, ok)
@@ -269,17 +269,17 @@ func Test_leaseProviderImpl_isWinningLeaseRequest_reachedExpectedRequestCount(t
269269
assert.NoError(t, err)
270270

271271
// Immediately check if req2 gets the lease (it should not!)
272-
_ = lpImpl.isWinningLeaseRequest(req2)
272+
_ = lpImpl.evaluateRequest(req2)
273273
assert.Equal(t, *req2.Status, STATUS_PENDING)
274274

275275
// Add 3rd request, making it complete (it has a lower priority compared to req2)
276276
_, err = lpImpl.insert(req3)
277277
assert.NoError(t, err)
278-
_ = lpImpl.isWinningLeaseRequest(req2)
278+
_ = lpImpl.evaluateRequest(req2)
279279
assert.Equal(t, *req2.Status, STATUS_AQUIRED)
280280
}
281281

282-
func Test_leaseProviderImpl_isWinningLeaseRequest_errorNoLeaseAssigned(t *testing.T) {
282+
func Test_leaseProviderImpl_evaluateRequest_errorNoLeaseAssigned(t *testing.T) {
283283
lp := NewLeaseProvider(&LeaseProviderOpts{TTL: 1 * time.Hour, StabilizeDuration: 1 * time.Minute, ExpectedRequestCount: 3})
284284
lpImpl, ok := lp.(*leaseProviderImpl)
285285
assert.True(t, ok)
@@ -305,7 +305,7 @@ func Test_leaseProviderImpl_isWinningLeaseRequest_errorNoLeaseAssigned(t *testin
305305
lpImpl.aquired = req2
306306

307307
// Make sure there's no status modification when checking if a lease is the winner
308-
req1copy := lpImpl.isWinningLeaseRequest(&LeaseRequest{
308+
req1copy := lpImpl.evaluateRequest(&LeaseRequest{
309309
HeadSHA: req1.HeadSHA,
310310
Priority: req1.Priority,
311311
Status: pointer.String(STATUS_PENDING),

0 commit comments

Comments
 (0)