-
Notifications
You must be signed in to change notification settings - Fork 813
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ading a more graceful termination for allocator
- Loading branch information
Showing
10 changed files
with
640 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2023 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. | ||
|
||
package allocator | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
helper "agones.dev/agones/test/e2e/allochelper" | ||
e2eframework "agones.dev/agones/test/e2e/framework" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var framework *e2eframework.Framework | ||
|
||
func TestMain(m *testing.M) { | ||
log.SetFormatter(&log.TextFormatter{ | ||
EnvironmentOverrideColors: true, | ||
FullTimestamp: true, | ||
TimestampFormat: "2006-01-02 15:04:05.000", | ||
}) | ||
|
||
var ( | ||
err error | ||
exitCode int | ||
) | ||
|
||
if err = e2eframework.ParseTestFlags(); err != nil { | ||
log.WithError(err).Error("failed to parse go test flags") | ||
os.Exit(1) | ||
} | ||
|
||
if framework, err = e2eframework.NewFromFlags(); err != nil { | ||
log.WithError(err).Error("failed to setup framework") | ||
os.Exit(1) | ||
} | ||
|
||
if err = helper.CleanupNamespaces(context.Background(), framework); err != nil { | ||
log.WithError(err).Error("failed to cleanup e2e namespaces") | ||
os.Exit(1) | ||
} | ||
|
||
if framework.Namespace == "" { | ||
// use a custom namespace - Unix timestamp | ||
framework.Namespace = strconv.Itoa(int(time.Now().Unix())) | ||
log.Infof("Custom namespace is set: %s", framework.Namespace) | ||
|
||
if err := framework.CreateNamespace(framework.Namespace); err != nil { | ||
log.WithError(err).Error("failed to create a custom namespace") | ||
os.Exit(1) | ||
} | ||
|
||
defer func() { | ||
if derr := framework.DeleteNamespace(framework.Namespace); derr != nil { | ||
log.Error(derr) | ||
} | ||
os.Exit(exitCode) | ||
}() | ||
} else { | ||
// use an already existing namespace | ||
// run cleanup before tests to ensure no resources from previous runs exist | ||
err = framework.CleanUp(framework.Namespace) | ||
if err != nil { | ||
log.WithError(err).Error("failed to cleanup resources") | ||
} | ||
|
||
defer func() { | ||
err = framework.CleanUp(framework.Namespace) | ||
if err != nil { | ||
log.WithError(err).Error("failed to cleanup resources") | ||
} | ||
os.Exit(exitCode) | ||
}() | ||
} | ||
|
||
exitCode = m.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2023 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. | ||
|
||
package allocator | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
pb "agones.dev/agones/pkg/allocation/go" | ||
agonesv1 "agones.dev/agones/pkg/apis/agones/v1" | ||
helper "agones.dev/agones/test/e2e/allochelper" | ||
e2e "agones.dev/agones/test/e2e/framework" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
) | ||
|
||
const ( | ||
retryInterval = 5 * time.Second | ||
retryTimeout = 45 * time.Second | ||
) | ||
|
||
func TestAllocatorAfterDeleteReplica(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
// get allocator pods | ||
list, err := helper.GetAgonesAllocatorPods(ctx, framework) | ||
assert.NoError(t, err) | ||
|
||
grpcClient, err := helper.GetAllocatorClient(ctx, t, framework) | ||
require.NoError(t, err, "Could not initialize rpc client") | ||
|
||
// create fleet | ||
flt, err := helper.CreateFleet(ctx, framework.Namespace, framework) | ||
if !assert.Nil(t, err) { | ||
return | ||
} | ||
framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas)) | ||
|
||
var response *pb.AllocationResponse | ||
request := &pb.AllocationRequest{ | ||
Namespace: framework.Namespace, | ||
PreferredGameServerSelectors: []*pb.GameServerSelector{{MatchLabels: map[string]string{agonesv1.FleetNameLabel: flt.ObjectMeta.Name}}}, | ||
Scheduling: pb.AllocationRequest_Packed, | ||
Metadata: &pb.MetaPatch{Labels: map[string]string{"gslabel": "allocatedbytest"}}, | ||
} | ||
|
||
// delete 2 of the allocators | ||
for _, pod := range list.Items[1:] { | ||
err = helper.DeleteAgonesAllocatorPod(ctx, pod.ObjectMeta.Name, framework) | ||
require.NoError(t, err, "Could not delete allocator pod") | ||
} | ||
|
||
// Wait and keep making calls till we know the draining time has passed | ||
_ = wait.PollImmediate(retryInterval, retryTimeout, func() (bool, error) { | ||
response, err = grpcClient.Allocate(context.Background(), request) | ||
logrus.Info(response) | ||
helper.ValidateAllocatorResponse(t, response) | ||
require.NoError(t, err, "Failed grpc allocation request") | ||
helper.DeleteAgonesPod(ctx, response.GameServerName, framework.Namespace, framework) | ||
return false, nil | ||
}) | ||
} |
Oops, something went wrong.