-
Notifications
You must be signed in to change notification settings - Fork 820
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to pass
GameServer
yaml/json to local sdk server
To be able to work locally, you need to be able to specify your local `GameServer` configuration, as it likely will have application specific configuration in it -- or maybe you want to specify what state it's in. This commit allow you to specify the local resource as either yaml/json through a `-f` or `--file` flag. Closes #296
- Loading branch information
1 parent
d6d5d10
commit 8e1141a
Showing
8 changed files
with
265 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2018 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package gameservers | ||
|
||
import ( | ||
"agones.dev/agones/pkg/apis/stable/v1alpha1" | ||
"agones.dev/agones/pkg/sdk" | ||
) | ||
|
||
// convert converts a K8s GameServer object, into a gRPC SDK GameServer object | ||
func convert(gs *v1alpha1.GameServer) *sdk.GameServer { | ||
meta := gs.ObjectMeta | ||
status := gs.Status | ||
health := gs.Spec.Health | ||
result := &sdk.GameServer{ | ||
ObjectMeta: &sdk.GameServer_ObjectMeta{ | ||
Name: meta.Name, | ||
Namespace: meta.Namespace, | ||
Uid: string(meta.UID), | ||
ResourceVersion: meta.ResourceVersion, | ||
Generation: meta.Generation, | ||
CreationTimestamp: meta.CreationTimestamp.Unix(), | ||
Annotations: meta.Annotations, | ||
Labels: meta.Labels, | ||
}, | ||
Spec: &sdk.GameServer_Spec{ | ||
Health: &sdk.GameServer_Spec_Health{ | ||
Disabled: health.Disabled, | ||
PeriodSeconds: health.PeriodSeconds, | ||
FailureThreshold: health.FailureThreshold, | ||
InitialDelaySeconds: health.InitialDelaySeconds, | ||
}, | ||
}, | ||
Status: &sdk.GameServer_Status{ | ||
State: string(status.State), | ||
Address: status.Address, | ||
}, | ||
} | ||
if meta.DeletionTimestamp != nil { | ||
result.ObjectMeta.DeletionTimestamp = meta.DeletionTimestamp.Unix() | ||
} | ||
|
||
// loop around and add all the ports | ||
for _, p := range status.Ports { | ||
grpcPort := &sdk.GameServer_Status_Port{ | ||
Name: p.Name, | ||
Port: p.Port, | ||
} | ||
result.Status.Ports = append(result.Status.Ports, grpcPort) | ||
} | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2018 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package gameservers | ||
|
||
import ( | ||
"testing" | ||
|
||
"agones.dev/agones/pkg/apis/stable/v1alpha1" | ||
"agones.dev/agones/pkg/sdk" | ||
"github.com/stretchr/testify/assert" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestConvert(t *testing.T) { | ||
t.Parallel() | ||
|
||
fixture := &v1alpha1.GameServer{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
CreationTimestamp: v1.Now(), | ||
Namespace: "default", | ||
Name: "test", | ||
Labels: map[string]string{"foo": "bar"}, | ||
Annotations: map[string]string{"stuff": "things"}, | ||
UID: "1234", | ||
}, | ||
Spec: v1alpha1.GameServerSpec{ | ||
Health: v1alpha1.Health{ | ||
Disabled: false, | ||
InitialDelaySeconds: 10, | ||
FailureThreshold: 15, | ||
PeriodSeconds: 20, | ||
}, | ||
}, | ||
Status: v1alpha1.GameServerStatus{ | ||
NodeName: "george", | ||
Address: "127.0.0.1", | ||
State: "Ready", | ||
Ports: []v1alpha1.GameServerStatusPort{ | ||
{Name: "default", Port: 12345}, | ||
{Name: "beacon", Port: 123123}, | ||
}, | ||
}, | ||
} | ||
|
||
eq := func(t *testing.T, fixture *v1alpha1.GameServer, sdkGs *sdk.GameServer) { | ||
assert.Equal(t, fixture.ObjectMeta.Name, sdkGs.ObjectMeta.Name) | ||
assert.Equal(t, fixture.ObjectMeta.Namespace, sdkGs.ObjectMeta.Namespace) | ||
assert.Equal(t, fixture.ObjectMeta.CreationTimestamp.Unix(), sdkGs.ObjectMeta.CreationTimestamp) | ||
assert.Equal(t, string(fixture.ObjectMeta.UID), sdkGs.ObjectMeta.Uid) | ||
assert.Equal(t, fixture.ObjectMeta.Labels, sdkGs.ObjectMeta.Labels) | ||
assert.Equal(t, fixture.ObjectMeta.Annotations, sdkGs.ObjectMeta.Annotations) | ||
assert.Equal(t, fixture.Spec.Health.Disabled, sdkGs.Spec.Health.Disabled) | ||
assert.Equal(t, fixture.Spec.Health.InitialDelaySeconds, sdkGs.Spec.Health.InitialDelaySeconds) | ||
assert.Equal(t, fixture.Spec.Health.FailureThreshold, sdkGs.Spec.Health.FailureThreshold) | ||
assert.Equal(t, fixture.Spec.Health.PeriodSeconds, sdkGs.Spec.Health.PeriodSeconds) | ||
assert.Equal(t, fixture.Status.Address, sdkGs.Status.Address) | ||
assert.Equal(t, string(fixture.Status.State), sdkGs.Status.State) | ||
assert.Len(t, sdkGs.Status.Ports, len(fixture.Status.Ports)) | ||
for i, fp := range fixture.Status.Ports { | ||
p := sdkGs.Status.Ports[i] | ||
assert.Equal(t, fp.Name, p.Name) | ||
assert.Equal(t, fp.Port, p.Port) | ||
} | ||
} | ||
|
||
sdkGs := convert(fixture) | ||
eq(t, fixture, sdkGs) | ||
assert.Zero(t, sdkGs.ObjectMeta.DeletionTimestamp) | ||
|
||
now := v1.Now() | ||
fixture.DeletionTimestamp = &now | ||
sdkGs = convert(fixture) | ||
eq(t, fixture, sdkGs) | ||
assert.Equal(t, fixture.ObjectMeta.DeletionTimestamp.Unix(), sdkGs.ObjectMeta.DeletionTimestamp) | ||
} |
Oops, something went wrong.