From 308cb547c032c48c59ea7f9a6bcb4a76648d4251 Mon Sep 17 00:00:00 2001 From: Alexander Apalikov Date: Tue, 21 Apr 2020 11:47:36 +0300 Subject: [PATCH] Add docs, import cleanup. 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. --- examples/crd-client/create-gs.yaml | 2 +- examples/crd-client/main.go | 45 ++++++++++++++----- site/content/en/docs/Guides/access-api.md | 9 ++-- .../docs/Installation/Install Agones/helm.md | 22 +++++++++ 4 files changed, 62 insertions(+), 16 deletions(-) diff --git a/examples/crd-client/create-gs.yaml b/examples/crd-client/create-gs.yaml index 3633a7cd4a..961c6b9e8e 100644 --- a/examples/crd-client/create-gs.yaml +++ b/examples/crd-client/create-gs.yaml @@ -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 diff --git a/examples/crd-client/main.go b/examples/crd-client/main.go index 65f613cba9..153f721ad4 100644 --- a/examples/crd-client/main.go +++ b/examples/crd-client/main.go @@ -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" ) @@ -48,7 +48,8 @@ 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)) @@ -56,6 +57,9 @@ func main() { 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 { @@ -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", @@ -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) } } } diff --git a/site/content/en/docs/Guides/access-api.md b/site/content/en/docs/Guides/access-api.md index 0ed1f13416..a885dc21a2 100644 --- a/site/content/en/docs/Guides/access-api.md +++ b/site/content/en/docs/Guides/access-api.md @@ -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. diff --git a/site/content/en/docs/Installation/Install Agones/helm.md b/site/content/en/docs/Installation/Install Agones/helm.md index 5c9933367d..4554544f54 100644 --- a/site/content/en/docs/Installation/Install Agones/helm.md +++ b/site/content/en/docs/Installation/Install Agones/helm.md @@ -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.