Skip to content

Commit

Permalink
Add a simple helm test
Browse files Browse the repository at this point in the history
This could be useful for Terraform configs check that installation
was completed, for example after switching to a new cluster.
  • Loading branch information
aLekSer committed Apr 7, 2020
1 parent a8ffcb8 commit 0e84668
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 9 deletions.
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
1 change: 1 addition & 0 deletions examples/crd-client/go.mod
Expand Up @@ -9,6 +9,7 @@ require (
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/sirupsen/logrus v1.2.0
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.3.1
Expand Down
1 change: 1 addition & 0 deletions examples/crd-client/go.sum
Expand Up @@ -224,6 +224,7 @@ google.golang.org/appengine v1.0.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9Ywl
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.3.0 h1:FBSsiFRMz3LBeXIomRnVzrQwSDj4ibvcRexLG0LZGQk=
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180601223552-81158efcc9f2/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
Expand Down
50 changes: 42 additions & 8 deletions examples/crd-client/main.go
Expand Up @@ -15,8 +15,10 @@
package main

import (
"fmt"
"strings"
"time"

"github.com/sirupsen/logrus"

agonesv1 "agones.dev/agones/pkg/apis/agones/v1"
"agones.dev/agones/pkg/client/clientset/versioned"
Expand All @@ -30,19 +32,30 @@ import (
)

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'")
pflag.String(gameServerImage, defaultImage, "The Address to bind the server grpcPort to. Defaults to 'localhost'")
viper.SetDefault(gameServerImage, defaultImage)
runtime.Must(viper.BindEnv(gameServerImage))
viper.GetString(gameServerImage)

pflag.Bool(isHelmTest, false, "Is helm test - shutdown GameServer at the end of test. 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))

config, err := rest.InClusterConfig()
logger := runtime.NewLoggerWithSource("main")
if err != nil {
Expand All @@ -66,8 +79,17 @@ func main() {
logger.WithError(err).Fatal("Could not create the agones api clientset")
}

gsName := "helm-test-server-"

// Create a GameServer
gs := &agonesv1.GameServer{ObjectMeta: metav1.ObjectMeta{GenerateName: "udp-server", Namespace: "default"},
gs := &agonesv1.GameServer{
ObjectMeta: metav1.ObjectMeta{
GenerateName: gsName,
Namespace: viper.GetString(gameserversNamespace),
Labels: map[string]string{
labelKey: labelValue,
},
},
Spec: agonesv1.GameServerSpec{
Container: "udp-server",
Ports: []agonesv1.GameServerPort{{
Expand All @@ -79,15 +101,27 @@ 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(defaultNs).Create(gs)
if err != nil {
panic(err)
}
logrus.Infof("New GameServer name is: %s", newGS.ObjectMeta.Name)

fmt.Printf("New game servers' 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
if err != nil {
panic(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-{{ randAlphaNum 5 | lower }}"
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

0 comments on commit 0e84668

Please sign in to comment.