Skip to content

Commit

Permalink
fix: missing false resets
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Sep 19, 2023
1 parent 5d82335 commit 108c490
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion controllers/v1beta1/build_qoshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ var runningProcessQueue bool
// this just allows the controller to update any builds that are in the queue periodically
// if this ran on every single event, it would flood the queue with messages, so it is restricted using `runningProcessQueue` global
// to only run the process at any one time til it is complete
// buildsToStart is the number of builds that can be started at the time the process is called
// limitHit is used to determine if the build limit has been hit, this is used to prevent new builds from being started inside this process
func (r *LagoonBuildReconciler) processQueue(ctx context.Context, opLog logr.Logger, buildsToStart int, limitHit bool) error {
// this should only ever be able to run one instance of at a time within a single controller
// this is because this process is quite heavy when it goes to submit the queue messages to the api
Expand All @@ -94,6 +96,7 @@ func (r *LagoonBuildReconciler) processQueue(ctx context.Context, opLog logr.Log
})
pendingBuilds := &lagoonv1beta1.LagoonBuildList{}
if err := r.List(ctx, pendingBuilds, listOption); err != nil {
runningProcessQueue = false
return fmt.Errorf("Unable to list builds in the cluster, there may be none or something went wrong: %v", err)
}
if len(pendingBuilds.Items) > 0 {
Expand All @@ -120,13 +123,15 @@ func (r *LagoonBuildReconciler) processQueue(ctx context.Context, opLog logr.Log
})
// list any builds that are running
if err := r.List(ctx, runningNSBuilds, listOption); err != nil {
runningProcessQueue = false
return fmt.Errorf("Unable to list builds in the namespace, there may be none or something went wrong: %v", err)
}
// if there are no running builds, check if there are any pending builds that can be started
if len(runningNSBuilds.Items) == 0 {
if err := helpers.CancelExtraBuilds(ctx, r.Client, opLog, pBuild.ObjectMeta.Namespace, "Running"); err != nil {
// only return if there is an error doing this operation
// continue on otherwise to allow the queued status updater to run
runningProcessQueue = false
return err
}
// don't handle the queued process for this build, continue to next in the list
Expand All @@ -144,14 +149,18 @@ func (r *LagoonBuildReconciler) processQueue(ctx context.Context, opLog logr.Log
},
})
if err := r.Patch(ctx, &pBuild, client.RawPatch(types.MergePatchType, mergePatch)); err != nil {
runningProcessQueue = false
return err
}
}
}
// update the build to be queued, and add a log message with the build log with the current position in the queue
// this position will update as builds are created/processed, so the position of a build could change depending on
// higher or lower priority builds being created
r.updateQueuedBuild(ctx, pBuild, (idx + 1), len(pendingBuilds.Items), opLog)
if err := r.updateQueuedBuild(ctx, pBuild, (idx + 1), len(pendingBuilds.Items), opLog); err != nil {
runningProcessQueue = false
return nil
}
}
}
runningProcessQueue = false
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/cheshir/go-mq/v2 v2.0.1
github.com/coreos/go-semver v0.3.1
github.com/go-logr/logr v1.2.4
github.com/google/go-cmp v0.5.9
github.com/hashicorp/go-version v1.6.0
github.com/k8up-io/k8up/v2 v2.7.1
github.com/mittwald/goharbor-client/v3 v3.3.0
Expand Down Expand Up @@ -51,7 +52,6 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
Expand Down

0 comments on commit 108c490

Please sign in to comment.