Skip to content

Commit

Permalink
Add GameServer addresses to the allocation APIs (#3307)
Browse files Browse the repository at this point in the history
* Add `addresses` to allocation.proto

* make gen-allocation-grpc

* Add all GameServer addresses to allocation.addresses response

* make gen-crd-client gen-all-sdk-grpc gen-api-docs

* Add docs for 'addresses'
  • Loading branch information
zmerlynn authored Aug 3, 2023
1 parent 37aea03 commit d524a6c
Show file tree
Hide file tree
Showing 14 changed files with 910 additions and 606 deletions.
27 changes: 27 additions & 0 deletions pkg/allocation/converters/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"agones.dev/agones/pkg/util/runtime"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -299,6 +300,7 @@ func ConvertGSAToAllocationResponse(in *allocationv1.GameServerAllocation) (*pb.
return &pb.AllocationResponse{
GameServerName: in.Status.GameServerName,
Address: in.Status.Address,
Addresses: convertGSAAddressesToAllocationAddresses(in.Status.Addresses),
NodeName: in.Status.NodeName,
Ports: convertGSAAgonesPortsToAllocationPorts(in.Status.Ports),
Source: in.Status.Source,
Expand All @@ -317,6 +319,7 @@ func ConvertAllocationResponseToGSA(in *pb.AllocationResponse, rs string) *alloc
State: allocationv1.GameServerAllocationAllocated,
GameServerName: in.GameServerName,
Address: in.Address,
Addresses: convertAllocationAddressesToGSAAddresses(in.Addresses),
NodeName: in.NodeName,
Ports: convertAllocationPortsToGSAAgonesPorts(in.Ports),
Source: rs,
Expand All @@ -328,6 +331,30 @@ func ConvertAllocationResponseToGSA(in *pb.AllocationResponse, rs string) *alloc
return out
}

// convertGSAAddressesToAllocationAddresses converts corev1.NodeAddress to AllocationResponse_GameServerStatusAddress
func convertGSAAddressesToAllocationAddresses(in []corev1.NodeAddress) []*pb.AllocationResponse_GameServerStatusAddress {
var addresses []*pb.AllocationResponse_GameServerStatusAddress
for _, addr := range in {
addresses = append(addresses, &pb.AllocationResponse_GameServerStatusAddress{
Type: string(addr.Type),
Address: addr.Address,
})
}
return addresses
}

// convertAllocationAddressesToGSAAddresses converts AllocationResponse_GameServerStatusAddress to corev1.NodeAddress
func convertAllocationAddressesToGSAAddresses(in []*pb.AllocationResponse_GameServerStatusAddress) []corev1.NodeAddress {
var addresses []corev1.NodeAddress
for _, addr := range in {
addresses = append(addresses, corev1.NodeAddress{
Type: corev1.NodeAddressType(addr.Type),
Address: addr.Address,
})
}
return addresses
}

// convertGSAAgonesPortsToAllocationPorts converts GameServerStatusPort V1 (GSA) to AllocationResponse_GameServerStatusPort
func convertGSAAgonesPortsToAllocationPorts(in []agonesv1.GameServerStatusPort) []*pb.AllocationResponse_GameServerStatusPort {
var pbPorts []*pb.AllocationResponse_GameServerStatusPort
Expand Down
92 changes: 92 additions & 0 deletions pkg/allocation/converters/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -913,6 +914,72 @@ func TestConvertGSAToAllocationResponse(t *testing.T) {
},
},
},
{
name: "addresses convert",
in: &allocationv1.GameServerAllocation{
TypeMeta: metav1.TypeMeta{
Kind: "GameServerAllocation",
APIVersion: "allocation.agones.dev/v1",
},
Status: allocationv1.GameServerAllocationStatus{
State: allocationv1.GameServerAllocationAllocated,
GameServerName: "GSN",
Ports: []agonesv1.GameServerStatusPort{
{
Port: 123,
},
{
Name: "port-name",
},
},
Address: "address",
Addresses: []corev1.NodeAddress{
{Type: "SomeAddressType", Address: "123.123.123.123"},
{Type: "AnotherAddressType", Address: "321.321.321.321"},
},
NodeName: "node-name",
Source: "local",
Metadata: &allocationv1.GameServerMetadata{
Labels: map[string]string{
"label-key": "label-value",
"other-key": "other-value",
},
Annotations: map[string]string{
"annotation-key": "annotation-value",
"other-key": "other-value",
},
},
},
},
want: &pb.AllocationResponse{
GameServerName: "GSN",
Address: "address",
Addresses: []*pb.AllocationResponse_GameServerStatusAddress{
{Type: "SomeAddressType", Address: "123.123.123.123"},
{Type: "AnotherAddressType", Address: "321.321.321.321"},
},
NodeName: "node-name",
Ports: []*pb.AllocationResponse_GameServerStatusPort{
{
Port: 123,
},
{
Name: "port-name",
},
},
Source: "local",
Metadata: &pb.AllocationResponse_GameServerMetadata{
Labels: map[string]string{
"label-key": "label-value",
"other-key": "other-value",
},
Annotations: map[string]string{
"annotation-key": "annotation-value",
"other-key": "other-value",
},
},
},
},
}
for _, tc := range tests {
tc := tc
Expand Down Expand Up @@ -968,6 +1035,31 @@ func TestConvertAllocationResponseToGSA(t *testing.T) {
},
},
},
{
name: "Addresses convert",
in: &pb.AllocationResponse{
Ports: []*pb.AllocationResponse_GameServerStatusPort{},
Source: "33.188.237.156:443",
Addresses: []*pb.AllocationResponse_GameServerStatusAddress{
{Type: "SomeAddressType", Address: "123.123.123.123"},
{Type: "AnotherAddressType", Address: "321.321.321.321"},
},
},
want: &allocationv1.GameServerAllocation{
TypeMeta: metav1.TypeMeta{
Kind: "GameServerAllocation",
APIVersion: "allocation.agones.dev/v1",
},
Status: allocationv1.GameServerAllocationStatus{
State: allocationv1.GameServerAllocationAllocated,
Source: "33.188.237.156:443",
Addresses: []corev1.NodeAddress{
{Type: "SomeAddressType", Address: "123.123.123.123"},
{Type: "AnotherAddressType", Address: "321.321.321.321"},
},
},
},
},
}
for _, tc := range tests {
tc := tc
Expand Down
Loading

0 comments on commit d524a6c

Please sign in to comment.