Skip to content

Commit

Permalink
Change multicluster allocation API version to stable
Browse files Browse the repository at this point in the history
  • Loading branch information
pooneh-m committed May 15, 2020
1 parent da3bc27 commit 415ee32
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 144 deletions.
4 changes: 2 additions & 2 deletions build/build-allocation-images/go/gen.sh
Expand Up @@ -25,8 +25,8 @@ cd /go/src/agones.dev/agones
go install -mod=vendor github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go install -mod=vendor github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger

outputpath=pkg/allocation/go/v1alpha1
protopath=proto/allocation/v1alpha1
outputpath=pkg/allocation/go
protopath=proto/allocation
googleapis=/go/src/agones.dev/agones/proto/googleapis
protofile=${protopath}/allocation.proto

Expand Down
6 changes: 3 additions & 3 deletions cmd/allocator/main.go
Expand Up @@ -29,7 +29,7 @@ import (

"agones.dev/agones/pkg"
"agones.dev/agones/pkg/allocation/converters"
pb "agones.dev/agones/pkg/allocation/go/v1alpha1"
pb "agones.dev/agones/pkg/allocation/go"
allocationv1 "agones.dev/agones/pkg/apis/allocation/v1"
"agones.dev/agones/pkg/client/clientset/versioned"
"agones.dev/agones/pkg/client/informers/externalversions"
Expand Down Expand Up @@ -281,7 +281,7 @@ type serviceHandler struct {
// Allocate implements the Allocate gRPC method definition
func (h *serviceHandler) Allocate(ctx context.Context, in *pb.AllocationRequest) (*pb.AllocationResponse, error) {
logger.WithField("request", in).Infof("allocation request received.")
gsa := converters.ConvertAllocationRequestV1Alpha1ToGSAV1(in)
gsa := converters.ConvertAllocationRequestToGSA(in)
resultObj, err := h.allocationCallback(gsa)
if err != nil {
logger.WithField("gsa", gsa).WithError(err).Info("allocation failed")
Expand All @@ -297,7 +297,7 @@ func (h *serviceHandler) Allocate(ctx context.Context, in *pb.AllocationRequest)
logger.Errorf("internal server error - Bad GSA format %v", resultObj)
return nil, status.Errorf(codes.Internal, "internal server error- Bad GSA format %v", resultObj)
}
response, err := converters.ConvertGSAV1ToAllocationResponseV1Alpha1(allocatedGsa)
response, err := converters.ConvertGSAToAllocationResponse(allocatedGsa)
logger.WithField("response", response).WithError(err).Infof("allocation response is being sent")

return response, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/allocator/main_test.go
Expand Up @@ -22,7 +22,7 @@ import (
"os"
"testing"

pb "agones.dev/agones/pkg/allocation/go/v1alpha1"
pb "agones.dev/agones/pkg/allocation/go"
allocationv1 "agones.dev/agones/pkg/apis/allocation/v1"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
Expand Down
4 changes: 2 additions & 2 deletions examples/allocator-client-csharp/Program.cs
Expand Up @@ -3,7 +3,7 @@
using System.Threading.Tasks;
using System.IO;
using Grpc.Core;
using V1Alpha1;
using Allocation;
using System.Net.Http;

namespace AllocatorClient
Expand All @@ -30,7 +30,7 @@ static async Task Main(string[] args)
try {
var response = await client.AllocateAsync(new AllocationRequest {
Namespace = namespaceArg,
MultiClusterSetting = new V1Alpha1.MultiClusterSetting {
MultiClusterSetting = new Allocation.MultiClusterSetting {
Enabled = multicluster,
}
});
Expand Down
Expand Up @@ -14,6 +14,6 @@
</ItemGroup>

<ItemGroup>
<Protobuf Include="allocation.proto" ProtoRoot="../../proto/allocation/v1alpha1;../../proto/googleapis" GrpcServices="Client"/>
<Protobuf Include="allocation.proto" ProtoRoot="../../proto/allocation;../../proto/googleapis" GrpcServices="Client"/>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion examples/allocator-client/main.go
Expand Up @@ -22,7 +22,7 @@ import (
"fmt"
"io/ioutil"

pb "agones.dev/agones/pkg/allocation/go/v1alpha1"
pb "agones.dev/agones/pkg/allocation/go"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand Down
44 changes: 22 additions & 22 deletions pkg/allocation/converters/converter.go
Expand Up @@ -16,7 +16,7 @@
package converters

import (
pb "agones.dev/agones/pkg/allocation/go/v1alpha1"
pb "agones.dev/agones/pkg/allocation/go"
"agones.dev/agones/pkg/apis"
agonesv1 "agones.dev/agones/pkg/apis/agones/v1"
allocationv1 "agones.dev/agones/pkg/apis/allocation/v1"
Expand All @@ -25,8 +25,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ConvertAllocationRequestV1Alpha1ToGSAV1 converts AllocationRequest to GameServerAllocation V1 (GSA)
func ConvertAllocationRequestV1Alpha1ToGSAV1(in *pb.AllocationRequest) *allocationv1.GameServerAllocation {
// ConvertAllocationRequestToGSA converts AllocationRequest to GameServerAllocation V1 (GSA)
func ConvertAllocationRequestToGSA(in *pb.AllocationRequest) *allocationv1.GameServerAllocation {
if in == nil {
return nil
}
Expand All @@ -37,7 +37,7 @@ func ConvertAllocationRequestV1Alpha1ToGSAV1(in *pb.AllocationRequest) *allocati
},
Spec: allocationv1.GameServerAllocationSpec{
Preferred: convertLabelSelectorsToInternalLabelSelectors(in.GetPreferredGameServerSelectors()),
Scheduling: convertAllocationSchedulingV1Alpha1ToSchedulingStrategyV1(in.GetScheduling()),
Scheduling: convertAllocationSchedulingToGSASchedulingStrategy(in.GetScheduling()),
},
}

Expand All @@ -63,16 +63,16 @@ func ConvertAllocationRequestV1Alpha1ToGSAV1(in *pb.AllocationRequest) *allocati
return gsa
}

// ConvertGSAV1ToAllocationRequestV1Alpha1 converts AllocationRequest to GameServerAllocation V1 (GSA)
func ConvertGSAV1ToAllocationRequestV1Alpha1(in *allocationv1.GameServerAllocation) *pb.AllocationRequest {
// ConvertGSAToAllocationRequest converts AllocationRequest to GameServerAllocation V1 (GSA)
func ConvertGSAToAllocationRequest(in *allocationv1.GameServerAllocation) *pb.AllocationRequest {
if in == nil {
return nil
}

out := &pb.AllocationRequest{
Namespace: in.GetNamespace(),
PreferredGameServerSelectors: convertInternalLabelSelectorsToLabelSelectors(in.Spec.Preferred),
Scheduling: convertSchedulingStrategyV1ToAllocationSchedulingV1Alpha1(in.Spec.Scheduling),
Scheduling: convertGSASchedulingStrategyToAllocationScheduling(in.Spec.Scheduling),
MultiClusterSetting: &pb.MultiClusterSetting{
Enabled: in.Spec.MultiClusterSetting.Enabled,
},
Expand All @@ -90,8 +90,8 @@ func ConvertGSAV1ToAllocationRequestV1Alpha1(in *allocationv1.GameServerAllocati
return out
}

// convertAllocationSchedulingV1Alpha1ToSchedulingStrategyV1 converts AllocationRequest_SchedulingStrategy to apis.SchedulingStrategy
func convertAllocationSchedulingV1Alpha1ToSchedulingStrategyV1(in pb.AllocationRequest_SchedulingStrategy) apis.SchedulingStrategy {
// convertAllocationSchedulingToGSASchedulingStrategy converts AllocationRequest_SchedulingStrategy to apis.SchedulingStrategy
func convertAllocationSchedulingToGSASchedulingStrategy(in pb.AllocationRequest_SchedulingStrategy) apis.SchedulingStrategy {
switch in {
case pb.AllocationRequest_Packed:
return apis.Packed
Expand All @@ -101,8 +101,8 @@ func convertAllocationSchedulingV1Alpha1ToSchedulingStrategyV1(in pb.AllocationR
return apis.Packed
}

// convertSchedulingStrategyV1ToAllocationSchedulingV1Alpha1 converts apis.SchedulingStrategy to pb.AllocationRequest_SchedulingStrategy
func convertSchedulingStrategyV1ToAllocationSchedulingV1Alpha1(in apis.SchedulingStrategy) pb.AllocationRequest_SchedulingStrategy {
// convertGSASchedulingStrategyToAllocationScheduling converts apis.SchedulingStrategy to pb.AllocationRequest_SchedulingStrategy
func convertGSASchedulingStrategyToAllocationScheduling(in apis.SchedulingStrategy) pb.AllocationRequest_SchedulingStrategy {
switch in {
case apis.Packed:
return pb.AllocationRequest_Packed
Expand Down Expand Up @@ -146,8 +146,8 @@ func convertLabelSelectorsToInternalLabelSelectors(in []*pb.LabelSelector) []met
return result
}

// ConvertGSAV1ToAllocationResponseV1Alpha1 converts GameServerAllocation V1 (GSA) to AllocationResponse
func ConvertGSAV1ToAllocationResponseV1Alpha1(in *allocationv1.GameServerAllocation) (*pb.AllocationResponse, error) {
// ConvertGSAToAllocationResponse converts GameServerAllocation V1 (GSA) to AllocationResponse
func ConvertGSAToAllocationResponse(in *allocationv1.GameServerAllocation) (*pb.AllocationResponse, error) {
if in == nil {
return nil, nil
}
Expand All @@ -160,12 +160,12 @@ func ConvertGSAV1ToAllocationResponseV1Alpha1(in *allocationv1.GameServerAllocat
GameServerName: in.Status.GameServerName,
Address: in.Status.Address,
NodeName: in.Status.NodeName,
Ports: convertAgonesPortsV1ToAllocationPortsV1Alpha1(in.Status.Ports),
Ports: convertGSAAgonesPortsToAllocationPorts(in.Status.Ports),
}, nil
}

// ConvertAllocationResponseV1Alpha1ToGSAV1 converts AllocationResponse to GameServerAllocation V1 (GSA)
func ConvertAllocationResponseV1Alpha1ToGSAV1(in *pb.AllocationResponse) *allocationv1.GameServerAllocation {
// ConvertAllocationResponseToGSA converts AllocationResponse to GameServerAllocation V1 (GSA)
func ConvertAllocationResponseToGSA(in *pb.AllocationResponse) *allocationv1.GameServerAllocation {
if in == nil {
return nil
}
Expand All @@ -176,15 +176,15 @@ func ConvertAllocationResponseV1Alpha1ToGSAV1(in *pb.AllocationResponse) *alloca
GameServerName: in.GameServerName,
Address: in.Address,
NodeName: in.NodeName,
Ports: convertAllocationPortsV1Alpha1ToAgonesPortsV1(in.Ports),
Ports: convertAllocationPortsToGSAAgonesPorts(in.Ports),
},
}

return out
}

// convertAgonesPortsV1ToAllocationPortsV1Alpha1 converts GameServerStatusPort V1 (GSA) to AllocationResponse_GameServerStatusPort
func convertAgonesPortsV1ToAllocationPortsV1Alpha1(in []agonesv1.GameServerStatusPort) []*pb.AllocationResponse_GameServerStatusPort {
// convertGSAAgonesPortsToAllocationPorts converts GameServerStatusPort V1 (GSA) to AllocationResponse_GameServerStatusPort
func convertGSAAgonesPortsToAllocationPorts(in []agonesv1.GameServerStatusPort) []*pb.AllocationResponse_GameServerStatusPort {
var pbPorts []*pb.AllocationResponse_GameServerStatusPort
for _, port := range in {
pbPort := &pb.AllocationResponse_GameServerStatusPort{
Expand All @@ -196,8 +196,8 @@ func convertAgonesPortsV1ToAllocationPortsV1Alpha1(in []agonesv1.GameServerStatu
return pbPorts
}

// convertAllocationPortsV1Alpha1ToAgonesPortsV1 converts AllocationResponse_GameServerStatusPort to GameServerStatusPort V1 (GSA)
func convertAllocationPortsV1Alpha1ToAgonesPortsV1(in []*pb.AllocationResponse_GameServerStatusPort) []agonesv1.GameServerStatusPort {
// convertAllocationPortsToGSAAgonesPorts converts AllocationResponse_GameServerStatusPort to GameServerStatusPort V1 (GSA)
func convertAllocationPortsToGSAAgonesPorts(in []*pb.AllocationResponse_GameServerStatusPort) []agonesv1.GameServerStatusPort {
var out []agonesv1.GameServerStatusPort
for _, port := range in {
p := &agonesv1.GameServerStatusPort{
Expand All @@ -209,7 +209,7 @@ func convertAllocationPortsV1Alpha1ToAgonesPortsV1(in []*pb.AllocationResponse_G
return out
}

// convertStateV1ToAllocationStateV1Alpha1 converts GameServerAllocationState V1 (GSA) to AllocationResponse_GameServerAllocationState
// convertStateV1ToError converts GameServerAllocationState V1 (GSA) to AllocationResponse_GameServerAllocationState
func convertStateV1ToError(in allocationv1.GameServerAllocationState) error {
switch in {
case allocationv1.GameServerAllocationAllocated:
Expand Down
20 changes: 10 additions & 10 deletions pkg/allocation/converters/converter_test.go
Expand Up @@ -17,7 +17,7 @@ package converters
import (
"testing"

pb "agones.dev/agones/pkg/allocation/go/v1alpha1"
pb "agones.dev/agones/pkg/allocation/go"
"agones.dev/agones/pkg/apis"
agonesv1 "agones.dev/agones/pkg/apis/agones/v1"
allocationv1 "agones.dev/agones/pkg/apis/allocation/v1"
Expand Down Expand Up @@ -153,13 +153,13 @@ func TestConvertAllocationRequestToGameServerAllocation(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

out := ConvertAllocationRequestV1Alpha1ToGSAV1(tc.in)
out := ConvertAllocationRequestToGSA(tc.in)
if !assert.Equal(t, tc.want, out) {
t.Errorf("mismatch with want after conversion: \"%s\"", tc.name)
}

if !tc.skipConvertFromGSA {
gsa := ConvertGSAV1ToAllocationRequestV1Alpha1(tc.want)
gsa := ConvertGSAToAllocationRequest(tc.want)
if !assert.Equal(t, tc.in, gsa) {
t.Errorf("mismatch with input after double conversion \"%s\"", tc.name)
}
Expand All @@ -168,7 +168,7 @@ func TestConvertAllocationRequestToGameServerAllocation(t *testing.T) {
}
}

func TestConvertGSAV1ToAllocationRequestV1Alpha1Empty(t *testing.T) {
func TestConvertGSAToAllocationRequestEmpty(t *testing.T) {
tests := []struct {
name string
in *allocationv1.GameServerAllocation
Expand Down Expand Up @@ -212,15 +212,15 @@ func TestConvertGSAV1ToAllocationRequestV1Alpha1Empty(t *testing.T) {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
gsa := ConvertGSAV1ToAllocationRequestV1Alpha1(tc.in)
gsa := ConvertGSAToAllocationRequest(tc.in)
if !assert.Equal(t, tc.want, gsa) {
t.Errorf("mismatch with want after conversion \"%s\"", tc.name)
}
})
}
}

func TestConvertGSAV1ToAllocationResponseV1Alpha1(t *testing.T) {
func TestConvertGSAToAllocationResponse(t *testing.T) {
tests := []struct {
name string
in *allocationv1.GameServerAllocation
Expand Down Expand Up @@ -321,7 +321,7 @@ func TestConvertGSAV1ToAllocationResponseV1Alpha1(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

out, err := ConvertGSAV1ToAllocationResponseV1Alpha1(tc.in)
out, err := ConvertGSAToAllocationResponse(tc.in)
if tc.wantErrCode != 0 {
st, ok := status.FromError(err)
if !assert.True(t, ok) {
Expand All @@ -334,7 +334,7 @@ func TestConvertGSAV1ToAllocationResponseV1Alpha1(t *testing.T) {
}

if !tc.skipConvertToGSA {
gsa := ConvertAllocationResponseV1Alpha1ToGSAV1(tc.want)
gsa := ConvertAllocationResponseToGSA(tc.want)
if !assert.Equal(t, tc.in, gsa) {
t.Errorf("mismatch with input after double conversion \"%s\"", tc.name)
}
Expand All @@ -343,7 +343,7 @@ func TestConvertGSAV1ToAllocationResponseV1Alpha1(t *testing.T) {
}
}

func TestConvertAllocationResponseV1Alpha1ToGSAV1(t *testing.T) {
func TestConvertAllocationResponseToGSA(t *testing.T) {
tests := []struct {
name string
in *pb.AllocationResponse
Expand All @@ -366,7 +366,7 @@ func TestConvertAllocationResponseV1Alpha1ToGSAV1(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

out := ConvertAllocationResponseV1Alpha1ToGSAV1(tc.in)
out := ConvertAllocationResponseToGSA(tc.in)
if !assert.Equal(t, tc.want, out) {
t.Errorf("mismatch with want after conversion: \"%s\"", tc.name)
}
Expand Down

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

0 comments on commit 415ee32

Please sign in to comment.