Lock artifact on helm index download

- cleanup locks with GC
This commit is contained in:
stefanprodan 2020-04-10 16:09:29 +03:00
parent 98deb3fa54
commit 131b9b8e33
2 changed files with 14 additions and 0 deletions

View File

@ -13,6 +13,7 @@ RUN go mod download
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY internal/ internal/
# build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o source-controller main.go

View File

@ -209,6 +209,19 @@ func (r *HelmRepositoryReconciler) index(repository sourcev1.HelmRepository) (so
}, "", err
}
// acquire lock
unlock, err := r.Storage.Lock(artifact)
if err != nil {
err = fmt.Errorf("unable to acquire lock: %w", err)
return sourcev1.SourceCondition{
Type: sourcev1.ReadyCondition,
Status: corev1.ConditionFalse,
Reason: sourcev1.IndexFetchFailedReason,
Message: err.Error(),
}, "", err
}
defer unlock()
// save artifact to storage
err = r.Storage.WriteFile(artifact, index)
if err != nil {