Skip to content

Commit

Permalink
Merge branch 'main' into AddGameServerStateDurationToGrafana
Browse files Browse the repository at this point in the history
  • Loading branch information
vicentefb authored Sep 30, 2024
2 parents b55fcfc + 98655de commit 1f66af1
Show file tree
Hide file tree
Showing 32 changed files with 862 additions and 413 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*.iml
bin
*.o
*.sln
tmp
terraform.tfvars
terraform.tfstate*
Expand Down
2 changes: 1 addition & 1 deletion build/terraform/e2e/gke-autopilot/module.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ module "gke_cluster" {
}

udpFirewall = false // firewall is created at the project module level
}
}
2 changes: 1 addition & 1 deletion build/terraform/e2e/gke-standard/module.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ module "gke_cluster" {
}

udpFirewall = false // firewall is created at the project module level
}
}
2 changes: 1 addition & 1 deletion build/terraform/e2e/state-bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// tfstate, delete your local .terraform and .tfstate files. You may need to run
// `sudo chown -R yourusername .` to be able to delete them. Then navigate to this directory and run
// `terraform init`. Pull in the tfstate file from gcloud with
// `terraform import google_storage_bucket.default agones-images-e2e-infra-bucket-tfstate`.
// `terraform import google_storage_bucket.default "<YOUR_GCP_ProjectID>"-e2e-infra-bucket-tfstate`.

// # GCS bucket for holding the Terraform state of the e2e Terraform config.

Expand Down
53 changes: 53 additions & 0 deletions build/terraform/upgrade/gke-autopilot/module.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2024 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.


// Run:
// terraform apply -var project="<YOUR_GCP_ProjectID>"

terraform {
required_version = ">= 1.0.0"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 4.25.0"
}
helm = {
source = "hashicorp/helm"
version = "~> 2.3"
}
}
}

variable "project" {}
variable "kubernetesVersion" {}
variable "location" {}
variable "releaseChannel" {}

module "gke_cluster" {
source = "../../../../install/terraform/modules/gke-autopilot"

cluster = {
"name" = format("gke-autopilot-upgrade-test-cluster-%s", replace(var.kubernetesVersion, ".", "-"))
"project" = var.project
"location" = var.location
"releaseChannel" = var.releaseChannel
"kubernetesVersion" = var.kubernetesVersion
"deletionProtection" = false
"maintenanceExclusionStartTime" = timestamp()
"maintenanceExclusionEndTime" = timeadd(timestamp(), "2640h") # 110 days
}

udpFirewall = false // firewall is created at the project module level
}
67 changes: 67 additions & 0 deletions build/terraform/upgrade/gke-standard/module.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2024 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.


// Run:
// terraform apply -var project="<YOUR_GCP_ProjectID>"

terraform {
required_version = ">= 1.0.0"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 4.25.0"
}
helm = {
source = "hashicorp/helm"
version = "~> 2.3"
}
}
}

variable "project" {}
variable "kubernetesVersion" {}
variable "location" {}
variable "releaseChannel" {}

variable "machineType" {
default = "e2-standard-4"
}

variable "initialNodeCount" {
default = 4
}

variable "overrideName" {
default = ""
}

module "gke_cluster" {
source = "../../../../install/terraform/modules/gke"

cluster = {
"name" = var.overrideName != "" ? var.overrideName : format("standard-upgrade-test-cluster-%s", replace(var.kubernetesVersion, ".", "-"))
"location" = var.location
"releaseChannel" = var.releaseChannel
"machineType" = var.machineType
"initialNodeCount" = var.initialNodeCount
"enableImageStreaming" = true
"project" = var.project
"kubernetesVersion" = var.kubernetesVersion
"maintenanceExclusionStartTime" = timestamp()
"maintenanceExclusionEndTime" = timeadd(timestamp(), "2640h") # 110 days
}

udpFirewall = false // firewall is created at the project module level
}
109 changes: 109 additions & 0 deletions build/terraform/upgrade/module.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright 2024 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.


// Run:
// terraform init -backend-config="bucket=<YOUR_GCP_ProjectID>-upgrade-infra-bucket-tfstate" -backend-config="prefix=terraform/state"
// terraform apply -var project="<YOUR_GCP_ProjectID>"

terraform {
required_version = ">= 1.0.0"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 4.25.0"
}
helm = {
source = "hashicorp/helm"
version = "~> 2.3"
}
}
backend "gcs" {
}
}

variable "project" {}
variable "kubernetes_versions" {
description = "Create upgrade test clusters with these k8s versions in these regions"
type = map(list(string))
default = {
"1.28" = ["us-west1", "RAPID"]
"1.29" = ["europe-west1", "RAPID"]
"1.30" = ["asia-east1", "RAPID"]
// "1.31" = ["us-east1", "RAPID"]
//
// Before merge: When adding Kubernetes version 1.{N}, first uncomment the line above, extending
// the infrastructure to 4 versions temporarily. Come back to these instructions after the
// update PR merges.
//
// After merge: After the Kubernetes update PR merges, and all active PRs are updated:
//
// * Move the 1.{N-3} line to the bottom and comment it out
// * Change the (commented out) 1.{N-3} to 1.{N+1}
// * You should now have 3 versions uncommented (versions 1.{N-2} .. 1.{N}),
// and 1.{N+1} commented out for the next update. The new, commented out 1.{N+1}
// should be using the region of the previous 1.{N-3} - this region will become
// unused.
//
// Rationale: We cycle the regions us-east1 -> us-west1 -> europe-west1 -> asia-east1 -> us-east1
// as versions are added, using 4 regions so that the PR adding 1.{N} is in a unique region to
// 1.{N-3} .. 1.{N-1}, meaning versions never need to share a region in CI.
}
}

module "gke_standard_cluster" {
for_each = var.kubernetes_versions
source = "./gke-standard"
project = var.project
kubernetesVersion = each.key
location = each.value[0]
releaseChannel = each.value[1]
}

module "gke_autopilot_cluster" {
for_each = var.kubernetes_versions
source = "./gke-autopilot"
project = var.project
kubernetesVersion = each.key
location = each.value[0]
releaseChannel = each.value[1]
}

resource "google_compute_firewall" "udp" {
name = "gke-game-server-firewall"
project = var.project
network = "default"

allow {
protocol = "udp"
ports = ["7000-8000"]
}

target_tags = ["game-server"]
source_ranges = ["0.0.0.0/0"]
}

resource "google_compute_firewall" "tcp" {
name = "gke-game-server-firewall-tcp"
project = var.project
network = "default"

allow {
protocol = "tcp"
ports = ["7000-8000"]
}

target_tags = ["game-server"]
source_ranges = ["0.0.0.0/0"]
}
43 changes: 43 additions & 0 deletions build/terraform/upgrade/state-bucket/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2024 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.


// Run:
// terraform apply -var project="<YOUR_GCP_ProjectID>"

// GCS bucket for holding the Terraform state of the upgrade test Terraform config.

terraform {
required_version = ">= 1.0.0"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 4.25.0"
}
}
}

variable "project" {}

resource "google_storage_bucket" "default" {
project = var.project
name = "${var.project}-upgrade-infra-bucket-tfstate"
force_destroy = false
uniform_bucket_level_access = true
location = "US"
storage_class = "STANDARD"
versioning {
enabled = true
}
}
31 changes: 21 additions & 10 deletions cmd/allocator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ import (
"sync"
"time"

"agones.dev/agones/pkg"
"agones.dev/agones/pkg/allocation/converters"
pb "agones.dev/agones/pkg/allocation/go"
allocationv1 "agones.dev/agones/pkg/apis/allocation/v1"
"agones.dev/agones/pkg/client/clientset/versioned"
"agones.dev/agones/pkg/client/informers/externalversions"
"agones.dev/agones/pkg/gameserverallocations"
"agones.dev/agones/pkg/gameservers"
"agones.dev/agones/pkg/metrics"
"agones.dev/agones/pkg/util/fswatch"
"github.com/heptiolabs/healthcheck"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand All @@ -45,15 +55,6 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"

"agones.dev/agones/pkg"
"agones.dev/agones/pkg/allocation/converters"
pb "agones.dev/agones/pkg/allocation/go"
allocationv1 "agones.dev/agones/pkg/apis/allocation/v1"
"agones.dev/agones/pkg/client/clientset/versioned"
"agones.dev/agones/pkg/client/informers/externalversions"
"agones.dev/agones/pkg/gameserverallocations"
"agones.dev/agones/pkg/gameservers"
"agones.dev/agones/pkg/util/fswatch"
"agones.dev/agones/pkg/util/httpserver"
"agones.dev/agones/pkg/util/runtime"
"agones.dev/agones/pkg/util/signals"
Expand Down Expand Up @@ -218,9 +219,19 @@ func main() {
logger.WithField("grpc-port", conf.GRPCPort).WithField("http-port", conf.HTTPPort).Fatal("Must specify a valid gRPC port or an HTTP port for the allocator service")
}
healthserver := &httpserver.Server{Logger: logger}
health, closer := setupMetricsRecorder(conf, healthserver)
var health healthcheck.Handler

metricsConf := metrics.Config{
Stackdriver: conf.Stackdriver,
PrometheusMetrics: conf.PrometheusMetrics,
GCPProjectID: conf.GCPProjectID,
StackdriverLabels: conf.StackdriverLabels,
}
health, closer := metrics.SetupMetrics(metricsConf, healthserver)
defer closer()

metrics.SetReportingPeriod(conf.PrometheusMetrics, conf.Stackdriver)

kubeClient, agonesClient, err := getClients(conf)
if err != nil {
logger.WithError(err).Fatal("could not create clients")
Expand Down
Loading

0 comments on commit 1f66af1

Please sign in to comment.