Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding a test for hostnetwork #182

Merged
merged 4 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 5 additions & 35 deletions cmd/e2e/build_crashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -83,42 +81,14 @@ var _ = Describe("Crashing Build", func() {
gsbHealth: mpsv1alpha1.BuildUnhealthy,
}
g.Expect(verifyGameServerBuildOverall(ctx, kubeClient, state)).To(Succeed())
}, 30*time.Second, interval).Should(Succeed())
}, 40*time.Second, interval).Should(Succeed())
})
})

// createCrashingBuild creates a build which contains game servers that will crash on start
func createCrashingBuild(buildName, buildID, img string) *mpsv1alpha1.GameServerBuild {
return &mpsv1alpha1.GameServerBuild{
ObjectMeta: metav1.ObjectMeta{
Name: buildName,
Namespace: testNamespace,
},
Spec: mpsv1alpha1.GameServerBuildSpec{
BuildID: buildID,
TitleID: "1E03",
PortsToExpose: []mpsv1alpha1.PortToExpose{{ContainerName: containerName, PortName: portKey}},
StandingBy: 2,
Max: 4,
CrashesToMarkUnhealthy: 5,
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: img,
Name: containerName,
ImagePullPolicy: corev1.PullIfNotPresent,
Command: []string{"/bin/sh", "-c", "sleep 2 && command_that_does_not_exist"},
Ports: []corev1.ContainerPort{
{
Name: portKey,
ContainerPort: 80,
},
},
},
},
},
},
},
}
gsb := createTestBuild(buildName, buildID, img)
gsb.Spec.Template.Spec.Containers[0].Command = []string{"/bin/sh", "-c", "sleep 2 && command_that_does_not_exist"}
gsb.Spec.CrashesToMarkUnhealthy = 5
return gsb
}
115 changes: 115 additions & 0 deletions cmd/e2e/build_host_network_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package main

import (
"context"
"crypto/tls"

"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1"
"k8s.io/client-go/kubernetes"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var _ = Describe("Build with hostnetwork", func() {
testBuildWithHostNetworkName := "hostnetwork"
testBuildWithHostNetworkID := "8512e8da-c82f-4a35-86c5-9d2b5fabd6f6"
It("should scale as usual", func() {
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
Expect(err).ToNot(HaveOccurred())

ctx := context.Background()
kubeConfig := ctrl.GetConfigOrDie()
kubeClient, err := createKubeClient(kubeConfig)
Expect(err).ToNot(HaveOccurred())
err = kubeClient.Create(ctx, createBuildWithHostNetwork(testBuildWithHostNetworkName, testBuildWithHostNetworkID, img))
Expect(err).ToNot(HaveOccurred())

coreClient, err := kubernetes.NewForConfig(kubeConfig)
Expect(err).ToNot(HaveOccurred())

Eventually(func(g Gomega) {
state := buildState{
buildName: testBuildWithHostNetworkName,
buildID: testBuildWithHostNetworkID,
standingByCount: 2,
podRunningCount: 2,
gsbHealth: mpsv1alpha1.BuildHealthy,
}
g.Expect(verifyGameServerBuildOverall(ctx, kubeClient, state)).To(Succeed())

gsb := &mpsv1alpha1.GameServerBuild{}
err = kubeClient.Get(ctx, client.ObjectKey{Name: testBuildWithHostNetworkName, Namespace: testNamespace}, gsb)
g.Expect(verifyPodsInHostNetwork(ctx, kubeClient, gsb, state)).To(Succeed())
}, timeout, interval).Should(Succeed())

// update the standingBy to 3
gsb := &mpsv1alpha1.GameServerBuild{}
err = kubeClient.Get(ctx, client.ObjectKey{Name: testBuildWithHostNetworkName, Namespace: testNamespace}, gsb)
Expect(err).ToNot(HaveOccurred())
patch := client.MergeFrom(gsb.DeepCopy())
gsb.Spec.StandingBy = 3
err = kubeClient.Patch(ctx, gsb, patch)
Expect(err).ToNot(HaveOccurred())

Eventually(func(g Gomega) {
state := buildState{
buildName: testBuildWithHostNetworkName,
buildID: testBuildWithHostNetworkID,
standingByCount: 3,
podRunningCount: 3,
gsbHealth: mpsv1alpha1.BuildHealthy,
}
g.Expect(verifyGameServerBuildOverall(ctx, kubeClient, state)).To(Succeed())
g.Expect(verifyPodsInHostNetwork(ctx, kubeClient, gsb, state)).To(Succeed())
}, timeout, interval).Should(Succeed())

// allocate a game server
sessionID2 := uuid.New().String()
err = allocate(testBuildWithHostNetworkID, sessionID2, cert)
Expect(err).ToNot(HaveOccurred())

// so we now should have 1 active and 3 standingBy
Eventually(func(g Gomega) {
state := buildState{
buildName: testBuildWithHostNetworkName,
buildID: testBuildWithHostNetworkID,
standingByCount: 3,
activeCount: 1,
podRunningCount: 4,
gsbHealth: mpsv1alpha1.BuildHealthy,
}
g.Expect(verifyGameServerBuildOverall(ctx, kubeClient, state)).To(Succeed())
g.Expect(verifyPodsInHostNetwork(ctx, kubeClient, gsb, state)).To(Succeed())
}, timeout, interval).Should(Succeed())

Expect(validateThatAllocatedServersHaveReadyForPlayersUnblocked(ctx, kubeClient, coreClient, testBuildWithHostNetworkID, 1)).To(Succeed())

// killing an Active game server
err = stopActiveGameServer(ctx, kubeClient, coreClient, kubeConfig, testBuildWithHostNetworkID)
Expect(err).ToNot(HaveOccurred())

// so we now should have 3 standingBy
Eventually(func(g Gomega) {
state := buildState{
buildName: testBuildWithHostNetworkName,
buildID: testBuildWithHostNetworkID,
standingByCount: 3,
podRunningCount: 3,
gsbHealth: mpsv1alpha1.BuildHealthy,
}
g.Expect(verifyGameServerBuildOverall(ctx, kubeClient, state)).To(Succeed())
g.Expect(verifyPodsInHostNetwork(ctx, kubeClient, gsb, state)).To(Succeed())
}, timeout, interval).Should(Succeed())

})
})

// createBuildWithHostNetwork creates a GameServerBuild with hostnetwork enabled for its game server processes
func createBuildWithHostNetwork(buildName, buildID, img string) *mpsv1alpha1.GameServerBuild {
gsb := createTestBuild(buildName, buildID, img)
gsb.Spec.Template.Spec.HostNetwork = true
return gsb
}
42 changes: 6 additions & 36 deletions cmd/e2e/build_sleep_before_readyforplayers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
. "github.com/onsi/gomega"
mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -105,41 +104,12 @@ var _ = Describe("Build which sleeps before calling GSDK ReadyForPlayers", func(
// createBuildWithSleepBeforeReadyForPlayers creates a build which game server process will sleep for a while before it calls ReadyForPlayers
// useful to track the Initializing state of the GameServers
func createBuildWithSleepBeforeReadyForPlayers(buildName, buildID, img string) *mpsv1alpha1.GameServerBuild {
return &mpsv1alpha1.GameServerBuild{
ObjectMeta: metav1.ObjectMeta{
Name: buildName,
Namespace: testNamespace,
},
Spec: mpsv1alpha1.GameServerBuildSpec{
BuildID: buildID,
TitleID: "1E03",
PortsToExpose: []mpsv1alpha1.PortToExpose{{ContainerName: containerName, PortName: portKey}},
StandingBy: 2,
Max: 4,
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: img,
Name: containerName,
ImagePullPolicy: corev1.PullIfNotPresent,
Ports: []corev1.ContainerPort{
{
Name: portKey,
ContainerPort: 80,
},
},
Env: []corev1.EnvVar{
{
Name: "SLEEP_BEFORE_READY_FOR_PLAYERS",
Value: "true",
},
},
},
},
},
},
gsb := createTestBuild(buildName, buildID, img)
gsb.Spec.Template.Spec.Containers[0].Env = []corev1.EnvVar{
{
Name: "SLEEP_BEFORE_READY_FOR_PLAYERS",
Value: "true",
},
}

return gsb
}
42 changes: 6 additions & 36 deletions cmd/e2e/build_without_readyforplayers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
. "github.com/onsi/gomega"
mpsv1alpha1 "github.com/playfab/thundernetes/pkg/operator/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -114,41 +113,12 @@ var _ = Describe("Build without ReadyForPlayers GSDK call", func() {

// createBuildWithoutReadyForPlayers creates a GameServerBuild which game server process do not call ReadyForPlayers
func createBuildWithoutReadyForPlayers(buildName, buildID, img string) *mpsv1alpha1.GameServerBuild {
return &mpsv1alpha1.GameServerBuild{
ObjectMeta: metav1.ObjectMeta{
Name: buildName,
Namespace: testNamespace,
},
Spec: mpsv1alpha1.GameServerBuildSpec{
BuildID: buildID,
TitleID: "1E03",
PortsToExpose: []mpsv1alpha1.PortToExpose{{ContainerName: containerName, PortName: portKey}},
StandingBy: 2,
Max: 4,
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: img,
Name: containerName,
ImagePullPolicy: corev1.PullIfNotPresent,
Ports: []corev1.ContainerPort{
{
Name: portKey,
ContainerPort: 80,
},
},
Env: []corev1.EnvVar{
{
Name: "SKIP_READY_FOR_PLAYERS",
Value: "true",
},
},
},
},
},
},
gsb := createTestBuild(buildName, buildID, img)
gsb.Spec.Template.Spec.Containers[0].Env = []corev1.EnvVar{
{
Name: "SKIP_READY_FOR_PLAYERS",
Value: "true",
},
}

return gsb
}
Loading