Skip to content

Commit

Permalink
Add labels and annotations to allocation response (#3197)
Browse files Browse the repository at this point in the history
* Return labels and annotations with allocation responses
* regen all sdk and crd files
* add comment to satisfy the linter overlords
* regen deepcopy
* regen api docs
* introduce new e2e test for allocations
* sacrifices to the linter
* fix up test conditions
* add docs
* merge in main and regenerate site docs
* Update test/e2e/gameserverallocation_test.go
* Update site/content/en/docs/Reference/gameserverallocation.md
* Add check for label in allocator test
* fix indentation

---------

Co-authored-by: Mark Mandel <markmandel@google.com>
  • Loading branch information
austin-space and markmandel committed Jun 22, 2023
1 parent 6d8923e commit e287cc3
Show file tree
Hide file tree
Showing 20 changed files with 425 additions and 57 deletions.
22 changes: 22 additions & 0 deletions pkg/allocation/converters/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ func ConvertGSAToAllocationResponse(in *allocationv1.GameServerAllocation) (*pb.
NodeName: in.Status.NodeName,
Ports: convertGSAAgonesPortsToAllocationPorts(in.Status.Ports),
Source: in.Status.Source,
Metadata: convertGSAMetadataToAllocationMetadata(in.Status.Metadata),
}, nil
}

Expand All @@ -319,6 +320,7 @@ func ConvertAllocationResponseToGSA(in *pb.AllocationResponse, rs string) *alloc
NodeName: in.NodeName,
Ports: convertAllocationPortsToGSAAgonesPorts(in.Ports),
Source: rs,
Metadata: convertAllocationMetadataToGSAMetadata(in.Metadata),
},
}
out.SetGroupVersionKind(allocationv1.SchemeGroupVersion.WithKind("GameServerAllocation"))
Expand Down Expand Up @@ -352,6 +354,26 @@ func convertAllocationPortsToGSAAgonesPorts(in []*pb.AllocationResponse_GameServ
return out
}

func convertGSAMetadataToAllocationMetadata(in *allocationv1.GameServerMetadata) *pb.AllocationResponse_GameServerMetadata {
if in == nil {
return nil
}
metadata := &pb.AllocationResponse_GameServerMetadata{}
metadata.Labels = in.Labels
metadata.Annotations = in.Annotations
return metadata
}

func convertAllocationMetadataToGSAMetadata(in *pb.AllocationResponse_GameServerMetadata) *allocationv1.GameServerMetadata {
if in == nil {
return nil
}
metadata := &allocationv1.GameServerMetadata{}
metadata.Labels = in.Labels
metadata.Annotations = in.Annotations
return metadata
}

// convertStateV1ToError converts GameServerAllocationState V1 (GSA) to AllocationResponse_GameServerAllocationState
func convertStateV1ToError(in allocationv1.GameServerAllocationState) error {
switch in {
Expand Down
58 changes: 58 additions & 0 deletions pkg/allocation/converters/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,64 @@ func TestConvertGSAToAllocationResponse(t *testing.T) {
in: nil,
want: nil,
},
{
name: "status metadata contains labels and annotations",
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",
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",
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
175 changes: 142 additions & 33 deletions pkg/allocation/go/allocation.pb.go

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

20 changes: 20 additions & 0 deletions pkg/allocation/go/allocation.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@
],
"default": "Packed"
},
"AllocationResponseGameServerMetadata": {
"type": "object",
"properties": {
"labels": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"annotations": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
},
"AllocationResponseGameServerStatusPort": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -150,6 +167,9 @@
},
"source": {
"type": "string"
},
"metadata": {
"$ref": "#/definitions/AllocationResponseGameServerMetadata"
}
}
},
Expand Down

0 comments on commit e287cc3

Please sign in to comment.