Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding ResourceVersion in deletes #152

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions pkg/operator/controllers/gameserverbuild_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -172,7 +173,16 @@ func (r *GameServerBuildReconciler) Reconcile(ctx context.Context, req ctrl.Requ
gs := gameServers.Items[i]
// we're deleting only initializing/pending/standingBy servers, never touching active
if gs.Status.State == "" || gs.Status.State == mpsv1alpha1.GameServerStateInitializing || gs.Status.State == mpsv1alpha1.GameServerStateStandingBy {
if err := r.Delete(ctx, &gs); err != nil {
// we're requesting the GameServer to be deleted to have the same ResourceVersion
// since it might have been updated (e.g. allocated) and the cache hasn't been updated yet
if err := r.Delete(ctx, &gs, &client.DeleteOptions{
Preconditions: &metav1.Preconditions{
ResourceVersion: &gs.ResourceVersion,
},
}); err != nil {
if errors.IsConflict(err) { // this GameServer has been updated, skip it
continue
}
return ctrl.Result{}, err
}
GameServersDeletedCounter.WithLabelValues(gsb.Name).Inc()
Expand All @@ -196,7 +206,16 @@ func (r *GameServerBuildReconciler) Reconcile(ctx context.Context, req ctrl.Requ
gs := gameServers.Items[i]
// we're deleting only standingBy or initializing servers
if gs.Status.State == "" || gs.Status.State == mpsv1alpha1.GameServerStateInitializing || gs.Status.State == mpsv1alpha1.GameServerStateStandingBy {
if err := r.Delete(ctx, &gs); err != nil {
// we're requesting the GameServer to be deleted to have the same ResourceVersion
// since it might have been updated (e.g. allocated) and the cache hasn't been updated yet
if err := r.Delete(ctx, &gs, &client.DeleteOptions{
Preconditions: &metav1.Preconditions{
ResourceVersion: &gs.ResourceVersion,
},
}); err != nil {
if errors.IsConflict(err) { // this GameServer has been updated, skip it
continue
}
return ctrl.Result{}, err
}
GameServersDeletedCounter.WithLabelValues(gsb.Name).Inc()
Expand Down