Skip to content

Commit

Permalink
Add docs, import cleanup.
Browse files Browse the repository at this point in the history
Described `helm test` command.
  • Loading branch information
aLekSer committed Apr 21, 2020
1 parent fb5c975 commit 9442ad9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 11 deletions.
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)
}
}
}
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 `--cleanup` the test 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 9442ad9

Please sign in to comment.