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

Add a simple helm test #1449

Merged
merged 3 commits into from Apr 24, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/crd-client/Makefile
Expand Up @@ -25,7 +25,7 @@

REPOSITORY ?= gcr.io/agones-images

server_tag = $(REPOSITORY)/crd-client:0.2
server_tag = $(REPOSITORY)/crd-client:0.3

# _____ _
# |_ _|_ _ _ __ __ _ ___| |_ ___
Expand Down
2 changes: 1 addition & 1 deletion examples/crd-client/create-gs.yaml
Expand Up @@ -24,7 +24,7 @@ spec:
serviceAccountName: agones-controller
containers:
- name: create-gameserver
image: gcr.io/agones-images/crd-client:0.2
image: gcr.io/agones-images/crd-client:0.3
imagePullPolicy: Always
env:
- name: GAMESERVER_IMAGE
Expand Down
12 changes: 5 additions & 7 deletions examples/crd-client/go.mod
Expand Up @@ -3,20 +3,18 @@ module agones.dev/agones/examples/crd-client
go 1.13

require (
agones.dev/agones v1.2.0
agones.dev/agones v1.5.0
github.com/gogo/protobuf v1.3.1 // indirect
github.com/googleapis/gnostic v0.3.1 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/json-iterator/go v1.1.8 // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/sirupsen/logrus v1.2.0
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.3.1
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
k8s.io/api v0.0.0-20191004102255-dacd7df5a50b // kubernetes-1.13.12
k8s.io/apimachinery v0.0.0-20191004074956-01f8b7d1121a // kubernetes-1.13.12
k8s.io/client-go v9.0.0+incompatible // kubernetes-1.13.12
k8s.io/klog v0.3.0 // indirect
k8s.io/api v0.0.0-20191004102349-159aefb8556b // kubernetes-1.14.10
k8s.io/apimachinery v0.0.0-20191004074956-c5d2f014d689 // kubernetes-1.14.10
k8s.io/client-go v11.0.1-0.20191029005444-8e4128053008+incompatible // kubernetes-1.14.10
)
56 changes: 36 additions & 20 deletions examples/crd-client/go.sum

Large diffs are not rendered by default.

76 changes: 65 additions & 11 deletions examples/crd-client/main.go
Expand Up @@ -15,34 +15,50 @@
package main

import (
"fmt"
"strings"
"time"

aLekSer marked this conversation as resolved.
Show resolved Hide resolved
agonesv1 "agones.dev/agones/pkg/apis/agones/v1"
"agones.dev/agones/pkg/client/clientset/versioned"
"agones.dev/agones/pkg/util/runtime"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/spf13/viper"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)

const (
gameServerImage = "GAMESERVER_IMAGE"
gameServerImage = "GAMESERVER_IMAGE"
isHelmTest = "IS_HELM_TEST"
gameserversNamespace = "GAMESERVERS_NAMESPACE"

defaultImage = "gcr.io/agones-images/udp-server:0.19"
defaultNs = "default"
)

func main() {
viper.AllowEmptyEnv(true)
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))

pflag.String(gameServerImage, viper.GetString(gameServerImage), "The Address to bind the server grpcPort to. Defaults to 'localhost'")
viper.SetDefault(gameServerImage, defaultImage)
pflag.String(gameServerImage, "", "The Address to bind the server grpcPort to. Defaults to 'localhost'")
viper.SetDefault(gameServerImage, "")
runtime.Must(viper.BindEnv(gameServerImage))
viper.GetString(gameServerImage)

pflag.Bool(isHelmTest, false,
"Is Helm test - defines whether GameServer should be shut down at the end of the test or not. Defaults to false")
viper.SetDefault(isHelmTest, false)
runtime.Must(viper.BindEnv(isHelmTest))

pflag.String(gameserversNamespace, defaultNs, "Namespace where GameServers are created. Defaults to default")
viper.SetDefault(gameserversNamespace, defaultNs)
runtime.Must(viper.BindEnv(gameserversNamespace))

pflag.Parse()
runtime.Must(viper.BindPFlags(pflag.CommandLine))

config, err := rest.InClusterConfig()
logger := runtime.NewLoggerWithSource("main")
if err != nil {
Expand All @@ -67,7 +83,11 @@ func main() {
}

// Create a GameServer
gs := &agonesv1.GameServer{ObjectMeta: metav1.ObjectMeta{GenerateName: "udp-server", Namespace: "default"},
gs := &agonesv1.GameServer{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "helm-test-server-",
Namespace: viper.GetString(gameserversNamespace),
},
Spec: agonesv1.GameServerSpec{
Container: "udp-server",
Ports: []agonesv1.GameServerPort{{
Expand All @@ -79,15 +99,49 @@ func main() {
}},
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{{Name: "udp-server", Image: viper.GetString(gameServerImage)}},
Containers: []corev1.Container{
{
Name: "udp-server",
Image: viper.GetString(gameServerImage),
},
},
},
},
},
}
newGS, err := agonesClient.AgonesV1().GameServers("default").Create(gs)
newGS, err := agonesClient.AgonesV1().GameServers(gs.Namespace).Create(gs)
if err != nil {
panic(err)
logrus.Fatal("Unable to create GameServer: %v", err)
}
logrus.Infof("New GameServer name is: %s", newGS.ObjectMeta.Name)

if viper.GetBool(isHelmTest) {
err = wait.PollImmediate(1*time.Second, 60*time.Second, func() (bool, error) {
checkGs, err := agonesClient.AgonesV1().GameServers(gs.Namespace).Get(newGS.Name, metav1.GetOptions{})

fmt.Printf("New game servers' name is: %s", newGS.ObjectMeta.Name)
if err != nil {
logrus.WithError(err).Warn("error retrieving gameserver")
return false, nil
}

state := agonesv1.GameServerStateReady
logger.WithField("gs", checkGs.ObjectMeta.Name).
WithField("currentState", checkGs.Status.State).
WithField("awaitingState", state).Info("Waiting for states to match")

if checkGs.Status.State == state {
return true, nil
}

return false, nil
})
if err != nil {
logrus.Fatalf("Wait GameServer to become Ready failed: %v", err)
}

err = agonesClient.AgonesV1().GameServers(gs.Namespace).Delete(newGS.ObjectMeta.Name, nil)
if err != nil {
logrus.Fatalf("Unable to delete GameServer: %v", err)
}
}
}
36 changes: 36 additions & 0 deletions install/helm/agones/templates/tests/test-runner.yaml
@@ -0,0 +1,36 @@
# Copyright 2020 Google LLC 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.

apiVersion: v1
kind: Pod
metadata:
name: "{{ .Release.Name }}-test"
namespace: agones-system
annotations:
"helm.sh/hook": test-success
"helm.sh/hook-delete-policy": hook-succeeded
spec:
serviceAccountName: agones-controller
containers:
- name: create-gameserver
image: gcr.io/agones-images/crd-client:0.3
imagePullPolicy: Always
env:
- name: GAMESERVER_IMAGE
value: "gcr.io/agones-images/udp-server:0.19"
- name: IS_HELM_TEST
value: "true"
- name: GAMESERVERS_NAMESPACE
value: "{{ index .Values.gameservers.namespaces 0 }}"
restartPolicy: Never
39 changes: 39 additions & 0 deletions install/yaml/install.yaml
Expand Up @@ -1321,6 +1321,45 @@ metadata:
data:
tls-ca.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM0akNDQWNxZ0F3SUJBZ0lSQU9lTWcwK1JKaFBJbks5ekFpMnpoUjR3RFFZSktvWklodmNOQVFFTEJRQXcKR0RFV01CUUdBMVVFQXhNTllXeHNiMk5oZEdsdmJpMWpZVEFlRncweE9UQTJNVGt4T0RRek5UVmFGdzB5T1RBMgpNVFl4T0RRek5UVmFNQUF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bXBpTmNyVElYREhPY2hhcFByWG53eDhxLzcrZERYYlhoUk84ClFDK2lZWVY0MVlTSGt1djNiYUtrYXlYamV0czc3Zz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K

---
# Source: agones/templates/tests/test-runner.yaml
# Copyright 2020 Google LLC 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.

apiVersion: v1
kind: Pod
metadata:
name: "agones-manual-test"
namespace: agones-system
annotations:
"helm.sh/hook": test-success
"helm.sh/hook-delete-policy": hook-succeeded
spec:
serviceAccountName: agones-controller
containers:
- name: create-gameserver
image: gcr.io/agones-images/crd-client:0.3
imagePullPolicy: Always
env:
- name: GAMESERVER_IMAGE
value: "gcr.io/agones-images/udp-server:0.19"
- name: IS_HELM_TEST
value: "true"
- name: GAMESERVERS_NAMESPACE
value: "default"
restartPolicy: Never

---
# Source: agones/templates/controller.yaml
# Copyright 2018 Google LLC All Rights Reserved.
Expand Down
9 changes: 5 additions & 4 deletions site/content/en/docs/Guides/access-api.md
Expand Up @@ -116,13 +116,14 @@ func main() {
}
```
In order to create GS using provided example, you can run it as a Kubernetes Job:
```
```bash
$ kubectl create -f https://raw.githubusercontent.com/googleforgames/agones/{{< release-branch >}}/examples/crd-client/create-gs.yaml --namespace agones-system
$ kubectl get pods --namespace agones-system
NAME READY STATUS RESTARTS AGE
pi-with-timeout-8qvfj 0/1 Completed 0 6s
$ kubectl logs pi-with-timeout-8qvfj --namespace agones-syste
{"message":"\u0026{0xc000243e00 default}","severity":"info","source":"main","time":"2019-12-06T14:36:54.265857671Z"}
create-gs-6wz86-7qsm5 0/1 Completed 0 6s
$ kubectl logs create-gs-6wz86-7qsm5 --namespace agones-system
{"message":"\u0026{0xc0001dde00 default}","severity":"info","source":"main","time":"2020-04-21T11:14:00.477576428Z"}
{"message":"New GameServer name is: helm-test-server-fxfgg","severity":"info","time":"2020-04-21T11:14:00.516024697Z"}
```
You have just created a GameServer using Kubernetes Go Client.

Expand Down
22 changes: 22 additions & 0 deletions site/content/en/docs/Installation/Install Agones/helm.md
Expand Up @@ -207,6 +207,28 @@ $ helm install --name my-release --namespace agones-system -f values.yaml agones
You can use the default {{< ghlink href="install/helm/agones/values.yaml" >}}values.yaml{{< /ghlink >}}
{{< /alert >}}

{{% feature publishVersion="1.6.0" %}}
Check the Agones installation by running the following command:
```bash
$ helm test my-release --cleanup
RUNNING: agones-test
PASSED: agones-test
```

This test would create a `GameServer` resource and delete it afterwards.

{{< alert title="Tip" color="info">}}
If you receive the following error:
```
RUNNING: agones-test
ERROR: pods "agones-test" already exists
Error: 1 test(s) failed
```
That mean that you skiped `--cleanup` flag and you should either delete `agones-test` pod manually or run with the same test `helm test my-release --cleanup` two more times.
{{< /alert >}}

{{% /feature %}}

## TLS Certificates

By default agones chart generates tls certificates used by the admission controller, while this is handy, it requires the agones controller to restart on each `helm upgrade` command.
Expand Down