Skip to content

Commit

Permalink
SDK update Lists uses Patch instead of Update
Browse files Browse the repository at this point in the history
  • Loading branch information
igooch committed Apr 29, 2024
1 parent 2ab7cba commit 12f18ec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
7 changes: 6 additions & 1 deletion pkg/sdkserver/sdkserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,12 @@ func (s *SDKServer) updateList(ctx context.Context) error {
names = append(names, name)
}

gs, err = s.gameServerGetter.GameServers(s.namespace).Update(ctx, gsCopy, metav1.UpdateOptions{})
patch, err := gs.Patch(gsCopy)
if err != nil {
return err
}

_, err = s.gameServerGetter.GameServers(s.namespace).Patch(ctx, gs.GetObjectMeta().GetName(), types.JSONPatchType, patch, metav1.PatchOptions{})
if err != nil {
return err
}
Expand Down
48 changes: 29 additions & 19 deletions pkg/sdkserver/sdkserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1519,31 +1519,41 @@ func TestSDKServerAddListValue(t *testing.T) {
t.Run(test, func(t *testing.T) {
m := agtesting.NewMocks()

m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) {
gs := agonesv1.GameServer{
ObjectMeta: metav1.ObjectMeta{
Name: "test", Namespace: "default", Generation: 1,
},
Spec: agonesv1.GameServerSpec{
SdkServer: agonesv1.SdkServer{
LogLevel: "Debug",
},
},
Status: agonesv1.GameServerStatus{
Lists: lists,
gs := agonesv1.GameServer{
ObjectMeta: metav1.ObjectMeta{
Name: "test", Namespace: "default", Generation: 1,
},
Spec: agonesv1.GameServerSpec{
SdkServer: agonesv1.SdkServer{
LogLevel: "Debug",
},
}
gs.ApplyDefaults()
},
Status: agonesv1.GameServerStatus{
Lists: lists,
},
}
gs.ApplyDefaults()

m.AgonesClient.AddReactor("list", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) {
return true, &agonesv1.GameServerList{Items: []agonesv1.GameServer{gs}}, nil
})

updated := make(chan map[string]agonesv1.ListStatus, 10)
m.AgonesClient.AddReactor("update", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) {
ua := action.(k8stesting.UpdateAction)
gs := ua.GetObject().(*agonesv1.GameServer)
gs.ObjectMeta.Generation++

m.AgonesClient.AddReactor("patch", "gameservers", func(action k8stesting.Action) (bool, runtime.Object, error) {
pa := action.(k8stesting.PatchAction)
patchJSON := pa.GetPatch()
patch, err := jsonpatch.DecodePatch(patchJSON)
assert.NoError(t, err)
gsJSON, err := json.Marshal(gs)
assert.NoError(t, err)
patchedGs, err := patch.Apply(gsJSON)
assert.NoError(t, err)
err = json.Unmarshal(patchedGs, &gs)
assert.NoError(t, err)

updated <- gs.Status.Lists
return true, gs, nil
return false, &gs, nil
})

ctx, cancel := context.WithCancel(context.Background())
Expand Down

0 comments on commit 12f18ec

Please sign in to comment.