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

Remove env namespace dependency from allocator service. #814

Merged
merged 3 commits into from
Jun 7, 2019
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
5 changes: 1 addition & 4 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 Down Expand Up @@ -53,7 +52,6 @@ func main() {

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

// TODO: add liveness probe
Expand Down Expand Up @@ -133,7 +131,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 +140,7 @@ func (h *httpHandler) allocateHandler(w http.ResponseWriter, r *http.Request) {
return
}

allocation := h.agonesClient.AllocationV1alpha1().GameServerAllocations(h.namespace)
allocation := h.agonesClient.AllocationV1alpha1().GameServerAllocations(gsa.ObjectMeta.Namespace)
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
17 changes: 6 additions & 11 deletions install/helm/agones/templates/service/allocation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,11 @@ 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
# Create a ClusterRole in that grants access to the agones allocation api
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
kind: ClusterRole
metadata:
name: gameserver-allocator
namespace: {{ .Release.Namespace }}
Expand Down Expand Up @@ -122,9 +117,9 @@ metadata:
heritage: {{ $.Release.Service }}

---
# Bind the gameserver-allocator ServiceAccount to the gameserver-allocator Role
# Bind the gameserver-allocator ServiceAccount to the gameserver-allocator ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
kind: ClusterRoleBinding
metadata:
name: gameserver-allocator
namespace: {{ .Release.Namespace }}
Expand All @@ -138,7 +133,7 @@ subjects:
name: gameserver-allocator
namespace: {{ .Release.Namespace }}
roleRef:
kind: Role
kind: ClusterRole
name: gameserver-allocator

{{- end }}
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 }}
16 changes: 6 additions & 10 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1077,16 +1077,11 @@ 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
# Create a ClusterRole in that grants access to the agones allocation api
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
kind: ClusterRole
metadata:
name: gameserver-allocator
namespace: agones-system
Expand Down Expand Up @@ -1114,9 +1109,9 @@ metadata:
heritage: Tiller

---
# Bind the gameserver-allocator ServiceAccount to the gameserver-allocator Role
# Bind the gameserver-allocator ServiceAccount to the gameserver-allocator ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
kind: ClusterRoleBinding
metadata:
name: gameserver-allocator
namespace: agones-system
Expand All @@ -1130,7 +1125,7 @@ subjects:
name: gameserver-allocator
namespace: agones-system
roleRef:
kind: Role
kind: ClusterRole
name: gameserver-allocator

---
Expand Down Expand Up @@ -1177,6 +1172,7 @@ metadata:
heritage: "Tiller"
data:
tls-ca.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUR5ekNDQXJPZ0F3SUJBZ0lVS2JaV1IwSmk2QlRxa2RiQjkwT200dUpIaTM4d0RRWUpLb1pJaHZjTkFRRUwKQlFBd2RURUxNQWtHQTFVRUJoTUNRVlV4RXpBUkJnTlZCQWdNQ2xOdmJXVXRVM1JoZEdVeElUQWZCZ05WQkFvTQpHRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSFI1SUV4MFpERXVNQ3dHQ1NxR1NJYjNEUUVKQVJZZllXZHZibVZ6CkxXUnBjMk4xYzNOQVoyOXZaMnhsWjNKdmRYQnpMbU52YlRBZUZ3MHhPVEExTVRReE9ETXhOVGxhRncweU9UQTEKTVRFeE9ETXhOVG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ZRVkgzVUI2TzMrRm00MFROb1RadDFHQkYzL0x0ZHdnZFJrbUZUaGlCL2ZJdHRUMFBHYUVmZQpBK3lleWhOYlZ5VWdPWUk3bks1UEs1czdnQlN5a0dMelhJaWVsb21tckE2SzI5L1pObGoraE53S1dISUJaL0NuCmNPa1ZnUEJrZUJrWStWclZjM24vSEJjbGorczdSNzVLcmhwTktPTWZ2M2pvcmhSQVE4ZVFvSWhIYmlxY2JNN3EKbHpwbDM5VXhzajJWMVlCYXl1OWlubXFKaUJmNFNNdW50elVwUHpLYWwwTytpZUtBMmJLU1NUbEdHbnIzUlJ2eQpNWGRnN1pYWmV3S3FiYlMvQnJIcQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==

---
# Source: agones/templates/controller.yaml
# Copyright 2018 Google LLC All Rights Reserved.
Expand Down
6 changes: 3 additions & 3 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 All @@ -78,13 +81,10 @@ func TestAllocator(t *testing.T) {
var response *http.Response
err = wait.PollImmediate(2*time.Second, 5*time.Minute, func() (bool, error) {
response, err = client.Post(requestURL, "application/json", bytes.NewBuffer(body))

if err != nil {
response.Body.Close() // nolint: errcheck
logrus.WithError(err).Infof("failing http request")
return false, nil
}

return true, nil
})

Expand Down