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

feat: allocation response with counters and lists data #3681

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
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
68 changes: 66 additions & 2 deletions pkg/allocation/converters/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,49 @@ func ConvertGSAToAllocationResponse(in *allocationv1.GameServerAllocation) (*pb.
return nil, err
}

return &pb.AllocationResponse{
res := &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,
Metadata: convertGSAMetadataToAllocationMetadata(in.Status.Metadata),
}, nil
}
if runtime.FeatureEnabled(runtime.FeatureCountsAndLists) {
if in.Status.Counters != nil {
res.Counters = convertGSACountersToAllocationCounters(in.Status.Counters)
}
if in.Status.Lists != nil {
res.Lists = convertGSAListsToAllocationLists(in.Status.Lists)
}
}

return res, nil
}

// convertGSACountersToAllocationCounters converts a map of GameServerStatusCounter to AllocationResponse_CounterStatus
func convertGSACountersToAllocationCounters(in map[string]agonesv1.CounterStatus) map[string]*pb.AllocationResponse_CounterStatus {
out := map[string]*pb.AllocationResponse_CounterStatus{}
for k, v := range in {
out[k] = &pb.AllocationResponse_CounterStatus{
Count: wrapperspb.Int64(v.Count),
Capacity: wrapperspb.Int64(v.Capacity),
}
}
return out
}

// convertGSAListsToAllocationLists converts a map of GameServerStatusList to AllocationResponse_ListStatus
func convertGSAListsToAllocationLists(in map[string]agonesv1.ListStatus) map[string]*pb.AllocationResponse_ListStatus {
out := map[string]*pb.AllocationResponse_ListStatus{}
for k, v := range in {
out[k] = &pb.AllocationResponse_ListStatus{
Values: v.Values,
Capacity: wrapperspb.Int64(v.Capacity),
}
}
return out
}

// ConvertAllocationResponseToGSA converts AllocationResponse to GameServerAllocation V1 (GSA)
Expand All @@ -341,6 +375,14 @@ func ConvertAllocationResponseToGSA(in *pb.AllocationResponse, rs string) *alloc
Metadata: convertAllocationMetadataToGSAMetadata(in.Metadata),
},
}
if runtime.FeatureEnabled(runtime.FeatureCountsAndLists) {
if in.Counters != nil {
out.Status.Counters = convertAllocationCountersToGSACounters(in.Counters)
}
if in.Lists != nil {
out.Status.Lists = convertAllocationListsToGSALists(in.Lists)
}
}
out.SetGroupVersionKind(allocationv1.SchemeGroupVersion.WithKind("GameServerAllocation"))

return out
Expand Down Expand Up @@ -416,6 +458,28 @@ func convertAllocationMetadataToGSAMetadata(in *pb.AllocationResponse_GameServer
return metadata
}

func convertAllocationCountersToGSACounters(in map[string]*pb.AllocationResponse_CounterStatus) map[string]agonesv1.CounterStatus {
out := map[string]agonesv1.CounterStatus{}
for k, v := range in {
out[k] = agonesv1.CounterStatus{
Count: v.Count.GetValue(),
Capacity: v.Capacity.GetValue(),
}
}
return out
}

func convertAllocationListsToGSALists(in map[string]*pb.AllocationResponse_ListStatus) map[string]agonesv1.ListStatus {
out := map[string]agonesv1.ListStatus{}
for k, v := range in {
out[k] = agonesv1.ListStatus{
Values: v.Values,
Capacity: v.Capacity.GetValue(),
}
}
return out
}

// convertStateV1ToError converts GameServerAllocationState V1 (GSA) to AllocationResponse_GameServerAllocationState
func convertStateV1ToError(in allocationv1.GameServerAllocationState) error {
switch in {
Expand Down
Loading
Loading