Skip to content

Commit

Permalink
making CrashesToMarkUnhealthy optional
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkanatsios committed Jul 11, 2022
1 parent 603aeb3 commit 0f30bd1
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 20 deletions.
16 changes: 7 additions & 9 deletions cmd/e2e/build_crashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,12 @@ var _ = Describe("Crashing Build", func() {
g.Expect(verifyGameServerBuildOverall(ctx, kubeClient, state)).To(Succeed())
}, 45*time.Second, interval).Should(Succeed()) // bigger timeout because of the time crashes take to occur and captured by the controller

// we are updating the GameServerBuild with a big CrashesToMarkUnhealthy to give time to the GameServerBuild to become Healthy
// Reasoning: At one point during running the e2e tests, we noticed that this test failed.
// This is because the GameServers crashed multiple (10) times so the GameServerBuild stayed Unhealthy,
// before having the chance to transition (temporarily) to Healthy. So, by setting it to 1000 we give it more chance to transition to Healthy,
// before decreasing it to 10 (in the next step) so that it can become Unhealthy again.
// we are updating the GameServerBuild with a nil CrashesToMarkUnhealthy so the GameServerBuild will become Healthy
gsb := &mpsv1alpha1.GameServerBuild{}
err = kubeClient.Get(ctx, client.ObjectKey{Name: testBuildCrashingName, Namespace: testNamespace}, gsb)
Expect(err).ToNot(HaveOccurred())
patch := client.MergeFrom(gsb.DeepCopy())
gsb.Spec.CrashesToMarkUnhealthy = 1000
gsb.Spec.CrashesToMarkUnhealthy = nil
err = kubeClient.Patch(ctx, gsb, patch)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -64,12 +60,13 @@ var _ = Describe("Crashing Build", func() {
g.Expect(gsb.Status.Health).To(Equal(mpsv1alpha1.BuildHealthy))
}, 10*time.Second, interval).Should(Succeed())

// we're decreasing the CrashesToMarkUnhealthy to 10 so that the
// we're setting the CrashesToMarkUnhealthy to 10 so that the
// GameServerBuild will eventually become Unhealthy
err = kubeClient.Get(ctx, client.ObjectKey{Name: testBuildCrashingName, Namespace: testNamespace}, gsb)
Expect(err).ToNot(HaveOccurred())
patch = client.MergeFrom(gsb.DeepCopy())
gsb.Spec.CrashesToMarkUnhealthy = 10
crashes := 10
gsb.Spec.CrashesToMarkUnhealthy = &crashes
err = kubeClient.Patch(ctx, gsb, patch)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -97,6 +94,7 @@ var _ = Describe("Crashing Build", func() {
func createCrashingBuild(buildName, buildID, img string) *mpsv1alpha1.GameServerBuild {
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
crashes := 5
gsb.Spec.CrashesToMarkUnhealthy = &crashes
return gsb
}
4 changes: 2 additions & 2 deletions cmd/e2e/build_unhealthy_gameservers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ var _ = Describe("GameServerBuild with GameServers without Gsdk", func() {
func createBuildWithoutGsdk(buildName, buildID, img string) *mpsv1alpha1.GameServerBuild {
gsb := createTestBuild(buildName, buildID, img)
gsb.Spec.Template.Spec.Containers[0].Command = []string{"/bin/sh", "-c", "sleep 3600"}
gsb.Spec.CrashesToMarkUnhealthy = 2

crashes := 2
gsb.Spec.CrashesToMarkUnhealthy = &crashes
return gsb
}
1 change: 0 additions & 1 deletion installfiles/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ spec:
type: object
type: array
crashesToMarkUnhealthy:
default: 5
description: CrashesToMarkUnhealthy is the number of crashes needed to mark the build unhealthy
minimum: 0
type: integer
Expand Down
1 change: 0 additions & 1 deletion installfiles/operator_with_monitoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ spec:
type: object
type: array
crashesToMarkUnhealthy:
default: 5
description: CrashesToMarkUnhealthy is the number of crashes needed to mark the build unhealthy
minimum: 0
type: integer
Expand Down
1 change: 0 additions & 1 deletion installfiles/operator_with_security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ spec:
type: object
type: array
crashesToMarkUnhealthy:
default: 5
description: CrashesToMarkUnhealthy is the number of crashes needed to mark the build unhealthy
minimum: 0
type: integer
Expand Down
1 change: 0 additions & 1 deletion installfiles/operator_with_security_and_monitoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ spec:
type: object
type: array
crashesToMarkUnhealthy:
default: 5
description: CrashesToMarkUnhealthy is the number of crashes needed to mark the build unhealthy
minimum: 0
type: integer
Expand Down
3 changes: 1 addition & 2 deletions pkg/operator/api/v1alpha1/gameserverbuild_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ type GameServerBuildSpec struct {
// PortsToExpose is an array of ports that will be exposed on the VM
PortsToExpose []int32 `json:"portsToExpose"`

//+kubebuilder:default=5
//+kubebuilder:validation:Minimum=0
// CrashesToMarkUnhealthy is the number of crashes needed to mark the build unhealthy
CrashesToMarkUnhealthy int `json:"crashesToMarkUnhealthy,omitempty"`
CrashesToMarkUnhealthy *int `json:"crashesToMarkUnhealthy,omitempty"`

// BuildMetadata is the metadata for this GameServerBuild
BuildMetadata []BuildMetadataItem `json:"buildMetadata,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/operator/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ spec:
type: object
type: array
crashesToMarkUnhealthy:
default: 5
description: CrashesToMarkUnhealthy is the number of crashes needed
to mark the build unhealthy
minimum: 0
Expand Down
7 changes: 5 additions & 2 deletions pkg/operator/controllers/gameserverbuild_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ func (r *GameServerBuildReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}

// if GameServerBuild is unhealthy and current crashes equal or more than CrashesToMarkUnhealthy, do nothing more
if gsb.Status.Health == mpsv1alpha1.BuildUnhealthy && gsb.Status.CrashesCount >= gsb.Spec.CrashesToMarkUnhealthy {
if gsb.Status.Health == mpsv1alpha1.BuildUnhealthy &&
gsb.Spec.CrashesToMarkUnhealthy != nil &&
gsb.Status.CrashesCount >= *gsb.Spec.CrashesToMarkUnhealthy {
log.Info("GameServerBuild is Unhealthy, do nothing")
r.Recorder.Event(&gsb, corev1.EventTypeNormal, "Unhealthy Build", "GameServerBuild is Unhealthy, stopping reconciliation")
return ctrl.Result{}, nil
Expand Down Expand Up @@ -256,7 +258,8 @@ func (r *GameServerBuildReconciler) updateStatus(ctx context.Context, gsb *mpsv1
gsb.Status.CrashesCount = existingCrashes + crashesCount
gsb.Status.CurrentStandingByReadyDesired = fmt.Sprintf("%d/%d", standingByCount, gsb.Spec.StandingBy)

if gsb.Status.CrashesCount >= gsb.Spec.CrashesToMarkUnhealthy {
// GameServerBuild can only be set as Unhealthy if CrashesToMarkUnhealthy has been explicitly been set by the user
if gsb.Spec.CrashesToMarkUnhealthy != nil && gsb.Status.CrashesCount >= *gsb.Spec.CrashesToMarkUnhealthy {
gsb.Status.Health = mpsv1alpha1.BuildUnhealthy
} else {
gsb.Status.Health = mpsv1alpha1.BuildHealthy
Expand Down
2 changes: 2 additions & 0 deletions pkg/operator/controllers/gameserverbuild_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ var _ = Describe("GameServerBuild controller tests", func() {
// create a Build with 6 standingBy
buildName, buildID := getNewBuildNameAndID()
gsb := testGenerateGameServerBuild(buildName, testnamespace, buildID, 6, 6, false)
crashes := 5
gsb.Spec.CrashesToMarkUnhealthy = &crashes
Expect(testk8sClient.Create(ctx, &gsb)).Should(Succeed())
testVerifyTotalGameServerCount(ctx, buildID, 6)
testUpdateInitializingGameServersToStandingBy(ctx, buildID)
Expand Down

0 comments on commit 0f30bd1

Please sign in to comment.