Skip to content

Commit

Permalink
Add docs, import cleanup.
Browse files Browse the repository at this point in the history
Described `helm test` command. Updated `crd-client` docs and version in
yaml of example Job which creates a GameServer and also used by the test.
  • Loading branch information
aLekSer committed Apr 22, 2020
1 parent e38d335 commit 308cb54
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/crd-client/create-gs.yaml
Original file line number Diff line number Diff line change
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
45 changes: 34 additions & 11 deletions examples/crd-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import (
"strings"
"time"

"github.com/sirupsen/logrus"

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"
)
Expand All @@ -48,14 +48,18 @@ func main() {
viper.SetDefault(gameServerImage, defaultImage)
runtime.Must(viper.BindEnv(gameServerImage))

pflag.Bool(isHelmTest, false, "Is helm test - shutdown GameServer at the end of test. Defaults to false")
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 Down Expand Up @@ -86,9 +90,6 @@ func main() {
ObjectMeta: metav1.ObjectMeta{
GenerateName: gsName,
Namespace: viper.GetString(gameserversNamespace),
Labels: map[string]string{
labelKey: labelValue,
},
},
Spec: agonesv1.GameServerSpec{
Container: "udp-server",
Expand All @@ -111,17 +112,39 @@ func main() {
},
},
}
newGS, err := agonesClient.AgonesV1().GameServers(defaultNs).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) {
time.Sleep(1 * time.Second)
err = agonesClient.AgonesV1().GameServers(defaultNs).Delete(newGS.ObjectMeta.Name, nil) // nolint: errcheck
err = wait.PollImmediate(1*time.Second, 60*time.Second, func() (bool, error) {
checkGs, err := agonesClient.AgonesV1().GameServers(gs.Namespace).Get(newGS.Name, metav1.GetOptions{})

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 {
panic(err)
logrus.Fatalf("Unable to delete GameServer: %v", err)
}
}
}
9 changes: 5 additions & 4 deletions site/content/en/docs/Guides/access-api.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 308cb54

Please sign in to comment.