Skip to content

Commit

Permalink
fix: race condition when updating registry settings (#4036)
Browse files Browse the repository at this point in the history
Craig O'Donnell authored Sep 13, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 49e75c4 commit 9f8e40a
Showing 2 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/actions/kots-gke-create/reserve-capacity.yaml
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ metadata:
name: capacity-res-job
spec:
parallelism: 4
backoffLimit: 0
backoffLimit: 6
template:
metadata:
labels:
34 changes: 22 additions & 12 deletions pkg/handlers/registry.go
Original file line number Diff line number Diff line change
@@ -210,21 +210,31 @@ func (h *Handler) UpdateAppRegistry(w http.ResponseWriter, r *http.Request) {
return
}

skipImagePush := updateAppRegistryRequest.IsReadOnly
if foundApp.IsAirgap {
// TODO: pushing images not yet supported in airgapped instances.
skipImagePush = true
}

latestSequence, err := store.GetStore().GetLatestAppSequence(foundApp.ID, true)
if err != nil {
logger.Error(errors.Wrapf(err, "failed to get latest app sequence for app %s", foundApp.Slug))
updateAppRegistryResponse.Error = err.Error()
JSON(w, http.StatusInternalServerError, updateAppRegistryResponse)
return
}

// set task status before starting the goroutine so that the UI can show the status
if err := store.GetStore().SetTaskStatus("image-rewrite", "Updating registry settings", "running"); err != nil {
logger.Error(errors.Wrap(err, "failed to set task status"))
updateAppRegistryResponse.Error = err.Error()
JSON(w, http.StatusInternalServerError, updateAppRegistryResponse)
return
}

// in a goroutine, start pushing the images to the remote registry
// we will let this function return while this happens
go func() {
skipImagePush := updateAppRegistryRequest.IsReadOnly
if foundApp.IsAirgap {
// TODO: pushing images not yet supported in airgapped instances.
skipImagePush = true
}

latestSequence, err := store.GetStore().GetLatestAppSequence(foundApp.ID, true)
if err != nil {
logger.Error(errors.Wrapf(err, "failed to get latest app sequence for app %s", foundApp.Slug))
return
}

appDir, err := registry.RewriteImages(
foundApp.ID, latestSequence, updateAppRegistryRequest.Hostname,
updateAppRegistryRequest.Username, registryPassword,

0 comments on commit 9f8e40a

Please sign in to comment.