diff --git a/examples/crd-client/Makefile b/examples/crd-client/Makefile index 8a0f37c2f4..b6b8a3c461 100644 --- a/examples/crd-client/Makefile +++ b/examples/crd-client/Makefile @@ -25,7 +25,7 @@ REPOSITORY ?= gcr.io/agones-images -server_tag = $(REPOSITORY)/crd-client:0.2 +server_tag = $(REPOSITORY)/crd-client:0.3 # _____ _ # |_ _|_ _ _ __ __ _ ___| |_ ___ diff --git a/examples/crd-client/go.mod b/examples/crd-client/go.mod index c4eba0ad62..3ee4f6c1dd 100644 --- a/examples/crd-client/go.mod +++ b/examples/crd-client/go.mod @@ -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 diff --git a/examples/crd-client/go.sum b/examples/crd-client/go.sum index 4f4560602b..2a3bee4283 100644 --- a/examples/crd-client/go.sum +++ b/examples/crd-client/go.sum @@ -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= diff --git a/examples/crd-client/main.go b/examples/crd-client/main.go index 2a73d97090..65f613cba9 100644 --- a/examples/crd-client/main.go +++ b/examples/crd-client/main.go @@ -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" @@ -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 { @@ -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{{ @@ -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) + } + } } diff --git a/install/helm/agones/templates/tests/test-runner.yaml b/install/helm/agones/templates/tests/test-runner.yaml new file mode 100644 index 0000000000..08c247c629 --- /dev/null +++ b/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 diff --git a/install/yaml/install.yaml b/install/yaml/install.yaml index 7be69f7905..3dbebfe232 100644 --- a/install/yaml/install.yaml +++ b/install/yaml/install.yaml @@ -1321,6 +1321,45 @@ metadata: data: tls-ca.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM0akNDQWNxZ0F3SUJBZ0lSQU9lTWcwK1JKaFBJbks5ekFpMnpoUjR3RFFZSktvWklodmNOQVFFTEJRQXcKR0RFV01CUUdBMVVFQXhNTllXeHNiMk5oZEdsdmJpMWpZVEFlRncweE9UQTJNVGt4T0RRek5UVmFGdzB5T1RBMgpNVFl4T0RRek5UVmFNQUF3Z2dFaU1BMEdDU3FHU0liM0RRRUJBUVVBQTRJQkR3QXdnZ0VLQW9JQkFRRDZMSm5DCmk5RmZnc0Z4MVQremNScm5FNEZRNUNQVUVQOEdrUHNxSE1ic21EelArMEIrVWtFK3k1cGpWbGcrdThxbHNkQ24KenRRVlU1OC9sejJTUDdBZnNIMTNISUpzaTZ4azc3M1hSRVE0NlhxSnBvblg3NjRSajJ5Zjd4T25KMDRidGxUSgp0M3E4U0IvUFk3c2tXdHlRTjJQRDN4QVN0REVXbnUvdzNHMUxNNzYyWGJ3a1o3VlJUY1hFdEpUaTY3dWlwdy96CmhVaU9NcFplT1YxV09neit4cjJQZTZmK0NObTNYUzNVblhjUzhKYmlxajhXQmM4bzdaS2VyRnJlNGFMRElldFkKK3g5M1lYWDZYNjNCZDNvZ3JlR3BmeFdRU3hBYTBHUEtLa1dvaHNESWZRREYwZ0pKcjZSc0prOVVOWEZyaHJqMApUSTRzTGRMbCthdlJMSjFQQWdNQkFBR2pQekE5TUE0R0ExVWREd0VCL3dRRUF3SUZvREFkQmdOVkhTVUVGakFVCkJnZ3JCZ0VGQlFjREFRWUlLd1lCQlFVSEF3SXdEQVlEVlIwVEFRSC9CQUl3QURBTkJna3Foa2lHOXcwQkFRc0YKQUFPQ0FRRUFKZ1ErVzZlYTdKZjhldmp0cWNmRC9EZUVMYzRLcFFwdk9NR0ZGVDkzQTM4bWFzeFNxVXluOGk4RgppaEplNDZFZnFkREQvcWRWSDh4TkJId2NIcjgyVDVLcFkzTWc1amJPWG1iMEoxZEdSTFRHSmdGd0ZpUXdsM3J3CmZ4dWhlYnZvaTJkcVhQbGc3L2ZZZmVqN2RkbTAxMTdhRCtwUExCN0NNUGVLdk5QSHF2N0VBRlowOU8rRjM3cjkKNTBPZEMrSk1VK0FNczRVMzVVeEZGZjRVRHVIbWM4U0l0bTJra1U3Vk1TcDFaV1VuRVZFUExaU09SZ3dZdWFNcQo3WTgzOVpXVmtyRGZMUEJrS09Ec1BVMDI3NGdmbXBpTmNyVElYREhPY2hhcFByWG53eDhxLzcrZERYYlhoUk84ClFDK2lZWVY0MVlTSGt1djNiYUtrYXlYamV0czc3Zz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K +--- +# 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.