Skip to content

Commit

Permalink
fix: make it go1.21 and linter compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
antiphp committed Sep 27, 2024
1 parent c9c6f70 commit 9113391
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 11 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75
go.opencensus.io v0.24.0
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
golang.org/x/net v0.23.0
golang.org/x/oauth2 v0.12.0
golang.org/x/time v0.3.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
2 changes: 1 addition & 1 deletion pkg/sdkserver/localsdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func TestLocalSDKServerSetAnnotations(t *testing.T) {
assertInitialWatchUpdate(t, stream)

// make sure length of l.updateObservers is at least 1
err = wait.PollImmediate(time.Second, 10*time.Second, func() (bool, error) {
err = wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, func(ctx context.Context) (bool, error) {
ret := false
l.updateObservers.Range(func(_, _ interface{}) bool {
ret = true
Expand Down
18 changes: 16 additions & 2 deletions sdks/go/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import (
"fmt"
"io"
"os"
"sort"
"time"

"github.com/pkg/errors"
"google.golang.org/grpc/credentials/insecure"

"golang.org/x/exp/maps"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"agones.dev/agones/pkg/sdk"
)
Expand Down Expand Up @@ -138,6 +139,19 @@ func (s *SDK) SetAnnotation(key, value string) error {
return errors.Wrap(err, "could not set annotation")
}

// SetAnnotations sets a metadata annotation on the `GameServer` with the prefix "agones.dev/sdk-".
func (s *SDK) SetAnnotations(keyVals map[string]string) error {
keys := maps.Keys(keyVals)
sort.Strings(keys)

kvs := make([]*sdk.KeyValue, 0, len(keyVals))
for _, key := range keys {
kvs = append(kvs, &sdk.KeyValue{Key: key, Value: keyVals[key]})
}
_, err := s.client.SetAnnotations(s.ctx, &sdk.KeyValues{KeyValues: kvs})
return errors.Wrap(err, "could not set annotations")
}

// GameServer retrieve the GameServer details.
func (s *SDK) GameServer() (*sdk.GameServer, error) {
gs, err := s.client.GetGameServer(s.ctx, &sdk.Empty{})
Expand Down
23 changes: 23 additions & 0 deletions sdks/go/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ func TestSDKSetAnnotation(t *testing.T) {
assert.Equal(t, expected, sm.annotations["agones.dev/sdk-foo"])
}

func TestSDKSetAnnotations(t *testing.T) {
t.Parallel()
sm := &sdkMock{
annotations: map[string]string{},
}
s := SDK{
ctx: context.Background(),
client: sm,
}

err := s.SetAnnotations(map[string]string{"foo": "bar", "bar": "baz"})
assert.Nil(t, err)
assert.Equal(t, "bar", sm.annotations["agones.dev/sdk-foo"])
assert.Equal(t, "baz", sm.annotations["agones.dev/sdk-bar"])
}

var _ sdk.SDKClient = &sdkMock{}
var _ sdk.SDK_HealthClient = &healthMock{}
var _ sdk.SDK_WatchGameServerClient = &watchMock{}
Expand All @@ -153,6 +169,13 @@ func (m *sdkMock) SetAnnotation(ctx context.Context, in *sdk.KeyValue, opts ...g
return &sdk.Empty{}, nil
}

func (m *sdkMock) SetAnnotations(ctx context.Context, in *sdk.KeyValues, opts ...grpc.CallOption) (*sdk.Empty, error) {
for _, kv := range in.KeyValues {
m.annotations["agones.dev/sdk-"+kv.Key] = kv.Value
}
return &sdk.Empty{}, nil
}

func (m *sdkMock) WatchGameServer(ctx context.Context, in *sdk.Empty, opts ...grpc.CallOption) (sdk.SDK_WatchGameServerClient, error) {
return m.wm, nil
}
Expand Down
27 changes: 27 additions & 0 deletions vendor/golang.org/x/exp/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/golang.org/x/exp/PATENTS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions vendor/golang.org/x/exp/maps/maps.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/k8s.io/client-go/tools/cache/reflector.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ golang.org/x/crypto/cryptobyte/asn1
golang.org/x/crypto/hkdf
golang.org/x/crypto/internal/alias
golang.org/x/crypto/internal/poly1305
# golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
## explicit; go 1.18
golang.org/x/exp/maps
# golang.org/x/mod v0.14.0
## explicit; go 1.18
golang.org/x/mod/internal/lazyregexp
Expand Down Expand Up @@ -1086,6 +1089,7 @@ k8s.io/utils/clock/testing
k8s.io/utils/integer
k8s.io/utils/internal/third_party/forked/golang/net
k8s.io/utils/net
k8s.io/utils/pointer
k8s.io/utils/ptr
k8s.io/utils/strings/slices
k8s.io/utils/trace
Expand Down

0 comments on commit 9113391

Please sign in to comment.