Skip to content

Commit

Permalink
Remove env namespace dependency from allocator service.
Browse files Browse the repository at this point in the history
  • Loading branch information
pooneh-m committed Jun 6, 2019
1 parent 84bf6c1 commit 7072852
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
12 changes: 5 additions & 7 deletions cmd/allocator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"

Expand All @@ -37,9 +36,10 @@ var (
)

const (
certDir = "/home/allocator/client-ca/"
tlsDir = "/home/allocator/tls/"
port = "8443"
certDir = "/home/allocator/client-ca/"
tlsDir = "/home/allocator/tls/"
port = "8443"
agonesSystemNamespace = "agones-system"
)

// A handler for the web server
Expand All @@ -53,7 +53,6 @@ func main() {

h := httpHandler{
agonesClient: agonesClient,
namespace: os.Getenv("NAMESPACE"),
}

// TODO: add liveness probe
Expand Down Expand Up @@ -133,7 +132,6 @@ func (h *httpHandler) postOnly(in handler) handler {

type httpHandler struct {
agonesClient versioned.Interface
namespace string
}

func (h *httpHandler) allocateHandler(w http.ResponseWriter, r *http.Request) {
Expand All @@ -143,7 +141,7 @@ func (h *httpHandler) allocateHandler(w http.ResponseWriter, r *http.Request) {
return
}

allocation := h.agonesClient.AllocationV1alpha1().GameServerAllocations(h.namespace)
allocation := h.agonesClient.AllocationV1alpha1().GameServerAllocations(agonesSystemNamespace)
allocatedGsa, err := allocation.Create(&gsa)
if err != nil {
http.Error(w, err.Error(), httpCode(err))
Expand Down
6 changes: 4 additions & 2 deletions cmd/allocator/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
agonesfake "agones.dev/agones/pkg/client/clientset/versioned/fake"
"github.com/stretchr/testify/assert"
k8serror "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
k8stesting "k8s.io/client-go/testing"
)
Expand All @@ -36,11 +37,13 @@ func TestAllocateHandler(t *testing.T) {
fakeAgones := &agonesfake.Clientset{}
h := httpHandler{
agonesClient: fakeAgones,
namespace: "default",
}

fakeAgones.AddReactor("create", "gameserverallocations", func(action k8stesting.Action) (bool, k8sruntime.Object, error) {
return true, &v1alpha1.GameServerAllocation{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
},
Status: v1alpha1.GameServerAllocationStatus{
State: v1alpha1.GameServerAllocationContention,
},
Expand Down Expand Up @@ -72,7 +75,6 @@ func TestAllocateHandlerReturnsError(t *testing.T) {
fakeAgones := &agonesfake.Clientset{}
h := httpHandler{
agonesClient: fakeAgones,
namespace: "default",
}

fakeAgones.AddReactor("create", "gameserverallocations", func(action k8stesting.Action) (bool, k8sruntime.Object, error) {
Expand Down
7 changes: 1 addition & 6 deletions install/helm/agones/templates/service/allocation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ spec:
- mountPath: /home/allocator/client-ca
name: client-ca
readOnly: true
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace

---
# Create a Role in the default namespace that grants access to the agones api
Expand Down Expand Up @@ -200,4 +195,4 @@ data:
tls-ca.crt: {{ b64enc $ca.Cert }}
{{- else }}
tls-ca.crt: {{ .Files.Get "certs/allocator/server.crt" | b64enc }}
{{- end }}
{{- end }}
6 changes: 1 addition & 5 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1077,11 +1077,6 @@ spec:
- mountPath: /home/allocator/client-ca
name: client-ca
readOnly: true
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace

---
# Create a Role in the default namespace that grants access to the agones api
Expand Down Expand Up @@ -1177,6 +1172,7 @@ metadata:
heritage: "Tiller"
data:
tls-ca.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUR5ekNDQXJPZ0F3SUJBZ0lVS2JaV1IwSmk2QlRxa2RiQjkwT200dUpIaTM4d0R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JSTUIwR0ExVWQKRGdRV0JCUXhqcnJ0S3BOcE02TUg5ODY4cTY1ZHE0NzcwVEFmQmdOVkhTTUVHREFXZ0JReGpycnRLcE5wTTZNSAo5ODY4cTY1ZHE0NzcwVEFQQmdOVkhSTUJBZjhFQlRBREFRSC9NQTBHQ1NxR1NJYjNEUUVCQ3dVQUE0SUJBUUNvCmNGc3hzY0ZOajh3VGt1aHZtRUcyODV6Q3M5OFFqR3FzT1RCNC9Ha3JUbWJOUW9xT2JuYzZpTkM0YnM5QUM2SE8KYWJOUkM2bTVVYVZRVkgzVUI2TzMrRm00MFROb1RadDFHQkYzL0x0ZHdnZFJrbUZUaGlCL2ZJdHRUMFBHYUVmZQpBK3lleWhOYlZ5VWdPWUk3bks1UEs1czdnQlN5a0dMelhJaWVsb21tckE2SzI5L1pObGoraE53S1dISUJaL0NuCmNPa1ZnUEJrZUJrWStWclZjM24vSEJjbGorczdSNzVLcmhwTktPTWZ2M2pvcmhSQVE4ZVFvSWhIYmlxY2JNN3EKbHpwbDM5VXhzajJWMVlCYXl1OWlubXFKaUJmNFNNdW50elVwUHpLYWwwTytpZUtBMmJLU1NUbEdHbnIzUlJ2eQpNWGRnN1pYWmV3S3FiYlMvQnJIcQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==

---
# Source: agones/templates/controller.yaml
# Copyright 2018 Google LLC All Rights Reserved.
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func TestAllocator(t *testing.T) {
}
framework.WaitForFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))
gsa := &v1alpha1.GameServerAllocation{
ObjectMeta: metav1.ObjectMeta{
Namespace: defaultNs,
},
Spec: v1alpha1.GameServerAllocationSpec{
Required: metav1.LabelSelector{MatchLabels: map[string]string{stablev1alpha1.FleetNameLabel: flt.ObjectMeta.Name}},
}}
Expand Down

0 comments on commit 7072852

Please sign in to comment.