Skip to content

Commit

Permalink
Merge branch 'master' into wait-for-fleet-cond-parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
markmandel authored Oct 1, 2019
2 parents e221a98 + 3caee5c commit 2871be4
Show file tree
Hide file tree
Showing 10,395 changed files with 187,172 additions and 204,265 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@ Clean leftover binary and package files after running SDK conformance tests.
#### `make test`
Run the linter and tests

#### `make build-examples`
Run `make build` for all `examples` subdirectories

#### `make site-server`
Generate `https://agones.dev` website locally and host on `http://localhost:1313`

Expand Down
2 changes: 1 addition & 1 deletion build/build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.s
# \_/\_/ \___|_.__/|___/_|\__\___|
#

ENV HUGO_VER 0.55.2
ENV HUGO_VER 0.58.3
RUN mkdir /tmp/hugo && \
wget -q -O /tmp/hugo/hugo.tar.gz https://github.com/gohugoio/hugo/releases/download/v${HUGO_VER}/hugo_extended_${HUGO_VER}_Linux-64bit.tar.gz && \
tar -zxvf /tmp/hugo/hugo.tar.gz -C /tmp/hugo/ && \
Expand Down
33 changes: 32 additions & 1 deletion build/includes/sdk.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ build_sdk_base_remote_tag = $(REGISTRY)/$(build_sdk_base_tag)
build_sdk_prefix = agones-build-sdk-
grpc_release_tag = v1.16.1
sdk_build_folder = build-sdk-images/
examples_folder = ../examples/
SDK_FOLDER ?= go
COMMAND ?= gen
SDK_IMAGE_TAG=$(build_sdk_prefix)$(SDK_FOLDER):$(build_sdk_version)

.PHONY: test-sdks test-sdk build-sdks build-sdk gen-all-sdk-grpc gen-sdk-grpc run-all-sdk-command run-sdk-command
.PHONY: test-sdks test-sdk build-sdks build-sdk gen-all-sdk-grpc gen-sdk-grpc run-all-sdk-command run-sdk-command build-example

# Tests all the sdks
test-sdks: COMMAND := test
Expand Down Expand Up @@ -148,3 +149,33 @@ run-sdk-conformance-tests:
# after building conformance tests for all SDKs supported
clean-sdk-conformance-tests:
$(MAKE) run-all-sdk-command COMMAND=clean

# Perform make build for all examples
build-examples: build-example-xonotic build-example-cpp-simple build-example-simple-udp build-example-autoscaler-webhook build-example-nodejs-simple

# Run "make build" command for one example directory
build-example:
cd $(examples_folder)/$(EXAMPLE); \
if [ -f Makefile ] ; then \
make build; \
else \
echo "Makefile was not found in "/examples/$(EXAMPLE)" directory - nothing to execute" ; \
fi

build-example-xonotic:
$(MAKE) build-example EXAMPLE=xonotic

build-example-cpp-simple:
$(MAKE) build-example EXAMPLE=cpp-simple

build-example-simple-udp:
$(MAKE) build-example EXAMPLE=simple-udp

build-example-rust-simple:
$(MAKE) build-example EXAMPLE=rust-simple

build-example-autoscaler-webhook:
$(MAKE) build-example EXAMPLE=autoscaler-webhook

build-example-nodejs-simple:
$(MAKE) build-example EXAMPLE=nodejs-simple
4 changes: 3 additions & 1 deletion cmd/allocator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,16 @@ func (h *httpHandler) allocateHandler(w http.ResponseWriter, r *http.Request) {
gsa := allocationv1.GameServerAllocation{}
if err := json.NewDecoder(r.Body).Decode(&gsa); err != nil {
http.Error(w, "invalid request", http.StatusBadRequest)
logger.WithError(err).Info("bad request")
return
}
logger.WithField("gsa", gsa).Infof("allocation request received")

allocation := h.agonesClient.AllocationV1().GameServerAllocations(gsa.ObjectMeta.Namespace)
allocatedGsa, err := allocation.Create(&gsa)
if err != nil {
http.Error(w, err.Error(), httpCode(err))
logger.Debug(err)
logger.WithField("gsa", gsa).WithError(err).Info("calling allocation extension API failed")
return
}
w.Header().Set("Content-Type", "application/json")
Expand Down
2 changes: 1 addition & 1 deletion examples/cpp-simple/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN cmake --version
COPY ./sdks/cpp sdk
RUN cd sdk && mkdir -p .build && \
cd .build && \
cmake .. -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" -Wno-dev && \
cmake .. -DCMAKE_BUILD_TYPE=Release -DAGONES_SILENT_OUTPUT=ON -G "Unix Makefiles" -Wno-dev && \
cmake --build . --target install

COPY ./examples/cpp-simple cpp-simple
Expand Down
4 changes: 2 additions & 2 deletions examples/xonotic/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ COPY examples/xonotic/main.go .
COPY . /go/src/agones.dev/agones
RUN go build -o wrapper .

RUN curl -o xonotic.zip http://dl.xonotic.org/xonotic-0.8.2.zip && \
unzip xonotic.zip && rm xonotic.zip
RUN curl -o xonotic.zip https://dl.xonotic.org/xonotic-0.8.2.zip && \
unzip -qq xonotic.zip && rm xonotic.zip

# final image
FROM debian:stretch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ spec:
type: string
required:
- clusterName
- allocationEndpoints
- secretName
- namespace
type: object
Expand Down
1 change: 0 additions & 1 deletion install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,6 @@ spec:
type: string
required:
- clusterName
- allocationEndpoints
- secretName
- namespace
type: object
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/multicluster/v1alpha1/gameserverallocationpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ type GameServerAllocationPolicySpec struct {
type ClusterConnectionInfo struct {
// Optional: the name of the targeted cluster
ClusterName string `json:"clusterName"`
// The endpoints for the allocator service in the targeted cluster
// There should be at least one endpoint or the policy is ineffective
// The endpoints for the allocator service in the targeted cluster.
// If the AllocationEndpoints is not set, the allocation happens on local cluster.
// If there are multiple endpoints any of the endpoints that can handle allocation request should suffice
AllocationEndpoints []string `json:"allocationEndpoints"`
AllocationEndpoints []string `json:"allocationEndpoints,omitempty"`
// The name of the secret that contains TLS client certificates to connect the allocator server in the targeted cluster
SecretName string `json:"secretName"`
// The cluster namespace from which to allocate gameservers
Expand Down
30 changes: 24 additions & 6 deletions pkg/gameserverallocations/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const (
// from the topNGameServerCount of Ready gameservers
// to reduce the contention while allocating gameservers.
topNGameServerDefaultCount = 100
allocatorRequestURLFmt = "https://%s/v1alpha1/gameserverallocation"
)

const (
Expand Down Expand Up @@ -177,6 +178,7 @@ func (c *Allocator) Allocate(gsa *allocationv1.GameServerAllocation, stop <-chan
if err != nil {
return nil, errors.Wrap(err, "could not find objectkinds for status")
}
c.loggerForGameServerAllocation(gsa).Info("GameServerAllocation is invalid")

status.TypeMeta = metav1.TypeMeta{Kind: gvks[0].Kind, APIVersion: gvks[0].Version}
return status, nil
Expand All @@ -192,6 +194,7 @@ func (c *Allocator) Allocate(gsa *allocationv1.GameServerAllocation, stop <-chan
}

if err != nil {
c.loggerForGameServerAllocation(gsa).WithError(err).Error("allocation failed")
return nil, err
}

Expand All @@ -216,6 +219,9 @@ func (c *Allocator) allocateFromLocalCluster(gsa *allocationv1.GameServerAllocat
err := Retry(allocationRetry, func() error {
var err error
gs, err = c.allocate(gsa, stop)
if err != nil {
c.loggerForGameServerAllocation(gsa).WithError(err).Warn("failed to allocate. Retrying... ")
}
return err
})

Expand Down Expand Up @@ -265,12 +271,22 @@ func (c *Allocator) applyMultiClusterAllocation(gsa *allocationv1.GameServerAllo
if connectionInfo == nil {
break
}
if connectionInfo.ClusterName == gsa.ObjectMeta.ClusterName {
result, err = c.allocateFromLocalCluster(gsa, stop)
c.baseLogger.Error(err)
if len(connectionInfo.AllocationEndpoints) == 0 {
// Change the naemspace to the policy namespace and allocate locally
gsaCopy := gsa
if gsa.Namespace != connectionInfo.Namespace {
gsaCopy = gsa.DeepCopy()
gsaCopy.Namespace = connectionInfo.Namespace
}
result, err = c.allocateFromLocalCluster(gsaCopy, stop)
if err != nil {
c.loggerForGameServerAllocation(gsaCopy).WithError(err).Error("self-allocation failed")
}
} else {
result, err = c.allocateFromRemoteCluster(*gsa, connectionInfo, gsa.ObjectMeta.Namespace)
c.baseLogger.Error(err)
if err != nil {
c.loggerForGameServerAllocation(gsa).WithField("allocConnInfo", connectionInfo).WithError(err).Error("remote-allocation failed")
}
}
if result != nil {
return result, nil
Expand Down Expand Up @@ -303,7 +319,9 @@ func (c *Allocator) allocateFromRemoteCluster(gsa allocationv1.GameServerAllocat

// TODO: Retry on transient error --> response.StatusCode >= 500
for i, endpoint := range connectionInfo.AllocationEndpoints {
response, err := client.Post(endpoint, "application/json", bytes.NewBuffer(body))
c.loggerForGameServerAllocation(&gsa).WithField("endpoint", endpoint).Info("forwarding allocation request")
requestURL := fmt.Sprintf(allocatorRequestURLFmt, endpoint)
response, err := client.Post(requestURL, "application/json", bytes.NewBuffer(body))
if err != nil {
return nil, err
}
Expand All @@ -317,7 +335,7 @@ func (c *Allocator) allocateFromRemoteCluster(gsa allocationv1.GameServerAllocat
// failing with 5xx http status, try the next endpoint. Otherwise, return the error response.
if response.StatusCode >= 500 && (i+1) < len(connectionInfo.AllocationEndpoints) {
// If there is a server error try a different endpoint
c.baseLogger.WithError(err).WithField("endpoint", endpoint).Warn("The request sent failed, trying next endpoint")
c.loggerForGameServerAllocation(&gsa).WithError(err).WithField("endpoint", endpoint).Warn("The request failed. Trying next endpoint")
continue
}
if response.StatusCode >= 400 {
Expand Down
34 changes: 23 additions & 11 deletions pkg/gameserverallocations/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -802,10 +803,9 @@ func TestMultiClusterAllocationFromLocal(t *testing.T) {
Priority: 1,
Weight: 200,
ConnectionInfo: multiclusterv1alpha1.ClusterConnectionInfo{
AllocationEndpoints: []string{"localhost"},
ClusterName: "multicluster",
SecretName: "localhostsecret",
Namespace: "ns1",
ClusterName: "multicluster",
SecretName: "localhostsecret",
Namespace: defaultNs,
},
},
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -831,9 +831,8 @@ func TestMultiClusterAllocationFromLocal(t *testing.T) {

gsa := &allocationv1.GameServerAllocation{
ObjectMeta: metav1.ObjectMeta{
Namespace: defaultNs,
Name: "alloc1",
ClusterName: "multicluster",
Namespace: defaultNs,
Name: "alloc1",
},
Spec: allocationv1.GameServerAllocationSpec{
MultiClusterSetting: allocationv1.MultiClusterSetting{
Expand All @@ -851,6 +850,7 @@ func TestMultiClusterAllocationFromLocal(t *testing.T) {
ret, err := executeAllocation(gsa, c)
assert.NoError(t, err)
assert.Equal(t, gsa.Spec.Required, ret.Spec.Required)
assert.Equal(t, gsa.Namespace, ret.Namespace)
expectedState := allocationv1.GameServerAllocationAllocated
assert.True(t, expectedState == ret.Status.State, "Failed: %s vs %s", expectedState, ret.Status.State)
})
Expand Down Expand Up @@ -920,6 +920,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) {
_, _ = w.Write(response)
}))
defer server.Close()
serverURL := parseURL(t, server.URL)

// Set client CA for server
certpool := x509.NewCertPool()
Expand All @@ -938,7 +939,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) {
Priority: 1,
Weight: 200,
ConnectionInfo: multiclusterv1alpha1.ClusterConnectionInfo{
AllocationEndpoints: []string{server.URL, "non-existing"},
AllocationEndpoints: []string{serverURL.Host, "non-existing"},
ClusterName: clusterName,
SecretName: secretName,
Namespace: targetedNamespace,
Expand Down Expand Up @@ -996,6 +997,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) {
http.Error(w, "test error message", 500)
}))
defer server.Close()
serverURL := parseURL(t, server.URL)

// Set client CA for server
certpool := x509.NewCertPool()
Expand All @@ -1013,7 +1015,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) {
Priority: 1,
Weight: 200,
ConnectionInfo: multiclusterv1alpha1.ClusterConnectionInfo{
AllocationEndpoints: []string{server.URL},
AllocationEndpoints: []string{serverURL.Host},
ClusterName: clusterName,
SecretName: secretName,
},
Expand Down Expand Up @@ -1069,6 +1071,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) {
http.Error(w, "test error message", 500)
}))
defer unhealthyServer.Close()
unhealthyServerURL := parseURL(t, unhealthyServer.URL)

// Set client CA for unhealthy server
certpool := x509.NewCertPool()
Expand All @@ -1088,6 +1091,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) {
_, _ = w.Write(response)
}))
defer healthyServer.Close()
healthyServerURL := parseURL(t, healthyServer.URL)
healthyServer.TLS = unhealthyServer.TLS

// Allocation policy reactor
Expand All @@ -1100,7 +1104,7 @@ func TestMultiClusterAllocationFromRemote(t *testing.T) {
Priority: 1,
Weight: 200,
ConnectionInfo: multiclusterv1alpha1.ClusterConnectionInfo{
AllocationEndpoints: []string{unhealthyServer.URL, healthyServer.URL},
AllocationEndpoints: []string{unhealthyServerURL.Host, healthyServerURL.Host},
ClusterName: clusterName,
SecretName: secretName,
},
Expand Down Expand Up @@ -1230,7 +1234,7 @@ func executeAllocation(gsa *allocationv1.GameServerAllocation, c *Controller) (*
return nil, err
}
rec := httptest.NewRecorder()
if err = c.processAllocationRequest(rec, r, defaultNs, stop); err != nil {
if err = c.processAllocationRequest(rec, r, gsa.Namespace, stop); err != nil {
return nil, err
}

Expand Down Expand Up @@ -1330,6 +1334,14 @@ func getPEMFromDER(der []byte) []byte {
return pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: der})
}

func parseURL(t *testing.T, rawURL string) *url.URL {
serverURL, err := url.Parse(rawURL)
if err != nil {
t.Fatalf("failed to parse URL %s: %s", rawURL, err)
}
return serverURL
}

var clientCert = []byte(`-----BEGIN CERTIFICATE-----
MIIDuzCCAqOgAwIBAgIUduDWtqpUsp3rZhCEfUrzI05laVIwDQYJKoZIhvcNAQEL
BQAwbTELMAkGA1UEBhMCR0IxDzANBgNVBAgMBkxvbmRvbjEPMA0GA1UEBwwGTG9u
Expand Down
2 changes: 0 additions & 2 deletions site/content/en/docs/Advanced/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ date: 2019-01-03T05:44:55Z
description: "Advanced Guides, Techniques and walk-throughs"
weight: 300
---

{{< pagelist >}}
2 changes: 0 additions & 2 deletions site/content/en/docs/Getting Started/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ date: 2017-01-05
description: >
Quickstarts for getting up and running with Agones
---

{{< pagelist >}}
2 changes: 0 additions & 2 deletions site/content/en/docs/Guides/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ date: 2019-01-02
description: >
Guides for deeper integrations with Agones
---

{{< pagelist >}}
2 changes: 0 additions & 2 deletions site/content/en/docs/Reference/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ description: >
Reference documentation for Agones Custom Resource Definitions
---

{{< pagelist >}}

2 changes: 0 additions & 2 deletions site/content/en/docs/Third Party Content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ description: >
Content created by our community
---

{{< pagelist >}}


2 changes: 0 additions & 2 deletions site/content/en/docs/Tutorials/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ date: 2019-01-03T03:15:21Z
description: "Agones Tutorials"
weight: 10
---

{{< pagelist >}}
8 changes: 2 additions & 6 deletions site/content/en/docs/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ menu:
description: >
Documentation and usage guides on how to develop and host dedicated game servers on top of Agones.
---
Release version: {{< release-version >}}

These pages show you how to get up and running as quickly as possible in Agones.

If you are new to Agones, start with [Installation]({{< relref "./Installation/_index.md" >}}), to get Agones
up and running.

The [Getting Started]({{< relref "./Getting Started/_index.md" >}}) section will have you
first `GameServer` up and running, and then have you spinning up `Fleets` after that.

{{< pagelist >}}

<br/>
Release version: {{< release-version >}}
first `GameServer` up and running, and then have you spinning up `Fleets` after that.
Loading

0 comments on commit 2871be4

Please sign in to comment.