Skip to content

Commit

Permalink
Consolidate Autopilot clusters into one. (#65)
Browse files Browse the repository at this point in the history
Mostly this is consolidation of two clusters into one, but also some
general cleanup of naming and documentation as I reviewed what I was
working on.

* Move "spanner" and "open-match" clusters into a single "services"
  cluster
* Make a "services" pipeline, separate from the "open-match" one, since
  we'll have a single pipeline for all services.
* General cleanup of labels and annotations that didn't seem to be
  doing anything on clusters and deployment pipelines and targets.
* Some cleanup of redundancy in naming.
* Remove spanner deploy from README, as it doesn't exist.
* Semantic headers for README.md

Closes #36
  • Loading branch information
markmandel authored Feb 22, 2023
1 parent ba3f0cd commit 3db341f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 155 deletions.
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can also click on the following icon to open this repository in a 'batteries

[![Open in Cloud Shell](https://gstatic.com/cloudssh/images/open-btn.svg)](https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fgoogleforgames%2Fglobal-multiplayer-demo.git&cloudshell_git_branch=main&cloudshell_open_in_editor=README.md&cloudshell_workspace=.)

## Google Cloud Auth
### Google Cloud Auth

Once you have Google Cloud CLI installed, you will need to authenticate against Google Cloud:

Expand Down Expand Up @@ -56,7 +56,7 @@ Provision the infrastructure.
terraform apply
```

### Deploy Agones To GKE Clusters
#### Deploy Agones To Agones GKE Clusters

The Agones deployment is in two steps: The Initial Install and the Allocation Endpoint Patch.

Expand All @@ -80,7 +80,7 @@ Continue the promotion until Agones has been deployed to all clusters.

You can monitor the status of the deployment through the Cloud Logging URL returned by the `gcloud builds` command as well as the Kubernetes Engine/Worloads panel in the GCP Console. Once the Worloads have been marked as OK, you can proceed to apply the Allocation Endpoint Patch.

#### Allocation Endpoint Patch
##### Allocation Endpoint Patch
After the Agones install has completed and the GKE Workloads show complete, run the Allocation Endpoint Patch Cloud Deploy to apply the appropriate endpoint patches to each cluster:

```shell
Expand All @@ -94,7 +94,7 @@ You can monitor the status of the deployment through the Cloud Logging URL retur
nd as well as the Kubernetes Engine/Worloads panel in the GCP Console. Once the Worloads have been marked as O
K, Agones should be avaialable.

#### Deploy Open Match to GKE Cluster
#### Deploy Open Match to Game Services GKE Cluster

Replace the` _RELEASE_NAME` substitution with a unique build name. Cloudbuild will deploy Open Match using Cloud Deploy.

Expand All @@ -103,15 +103,9 @@ cd $GAME_DEMO_HOME/infrastructure/deploy/open-match
gcloud builds submit --config=cloudbuild.yaml --substitutions=_RELEASE_NAME=rel-1
```

### Deploy Spanner Applications to GKE Cluster
## Install Game Backend Services

#### Initial Deploy
Replace the` _RELEASE_NAME` substitution with a unique build name. Cloudbuild will deploy Spanner applications using Cloud Deploy.

```shell
cd $GAME_DEMO_HOME/infrastructure/deploy/spanner/install
gcloud builds submit --config=cloudbuild.yaml --substitutions=_RELEASE_NAME=rel-1
```
TODO: fill in once we have services.

## Game Client

Expand Down
2 changes: 1 addition & 1 deletion infrastructure/deploy/open-match/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ steps:
args:
[
"deploy", "releases", "create", "${_RELEASE_NAME}",
"--delivery-pipeline", "global-game-open-match-deploy-pipeline",
"--delivery-pipeline", "global-game-open-match",
"--region", "us-central1"
]
substitutions:
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/deploy/services/install/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ steps:
args:
[
"deploy", "releases", "create", "${_RELEASE_NAME}",
"--delivery-pipeline", "global-game-spanner-deploy-pipeline",
"--delivery-pipeline", "global-game-services",
"--region", "us-central1"
]

Expand Down
42 changes: 0 additions & 42 deletions infrastructure/open-match-gke.tf

This file was deleted.

82 changes: 16 additions & 66 deletions infrastructure/pipelines.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,13 @@

##### Spanner Pipelines #####

resource "google_clouddeploy_target" "spanner" {
location = var.spanner_gke_config.location
name = "global-game-spanner-deploy-target"

annotations = {
my_first_annotation = "spanner-annotation-1"

my_second_annotation = "spanner-annotation-2"
}

description = "Global Game: Spanner Deploy Target"
resource "google_clouddeploy_target" "services_deploy_target" {
location = var.services_gke_config.location
name = "global-game-services-target"
description = "Global Game: Backend Services Deploy Target"

gke {
cluster = data.google_container_cluster.game-demo-spanner-gke.id
}

labels = {
my_first_label = "global-game-demo"

my_second_label = "spanner"
cluster = data.google_container_cluster.services-gke.id
}

project = var.project
Expand All @@ -42,29 +29,17 @@ resource "google_clouddeploy_target" "spanner" {
depends_on = [google_project_service.project]
}

resource "google_clouddeploy_delivery_pipeline" "spanner" {
location = var.spanner_gke_config.location
name = "global-game-spanner-deploy-pipeline"
resource "google_clouddeploy_delivery_pipeline" "services_pipeline" {
location = var.services_gke_config.location
name = "global-game-services"

annotations = {
my_first_annotation = "spanner-annotation-1"

my_second_annotation = "spanner-annotation-2"
}

description = "Global Game: Spanner Deploy Pipeline"

labels = {
my_first_label = "global-game-demo"

my_second_label = "spanner"
}
description = "Global Game: Backend Services Pipeline"

project = var.project

serial_pipeline {
stages {
target_id = google_clouddeploy_target.spanner.target_id
target_id = google_clouddeploy_target.services_deploy_target.target_id
}
}
}
Expand Down Expand Up @@ -135,25 +110,13 @@ resource "google_clouddeploy_delivery_pipeline" "agones" {
##### Open Match Pipelines #####

resource "google_clouddeploy_target" "open-match-target" {
location = var.open-match_gke_config.location
name = "global-game-open-match-deploy-target"

annotations = {
my_first_annotation = "open-match-annotation-1"

my_second_annotation = "open-match-annotation-2"
}
location = var.services_gke_config.location
name = "global-game-open-match-target"

description = "Global Game: Open Match Deploy Target"

gke {
cluster = data.google_container_cluster.game-demo-open-match-gke.id
}

labels = {
my_first_label = "global-game-demo"

my_second_label = "open-match"
cluster = data.google_container_cluster.services-gke.id
}

project = var.project
Expand All @@ -163,24 +126,11 @@ resource "google_clouddeploy_target" "open-match-target" {
}

resource "google_clouddeploy_delivery_pipeline" "open-match" {
location = var.open-match_gke_config.location
name = "global-game-open-match-deploy-pipeline"

annotations = {
my_first_annotation = "open-match-annotation-1"

my_second_annotation = "open-match-annotation-2"
}
location = var.services_gke_config.location
name = "global-game-open-match"

description = "Global Game: Open Match Deploy Pipeline"

labels = {
my_first_label = "global-game-demo"

my_second_label = "open-match"
}

project = var.project
project = var.project

serial_pipeline {
stages {
Expand Down
18 changes: 9 additions & 9 deletions infrastructure/spanner-gke.tf → infrastructure/services-gke.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

resource "google_container_cluster" "game-demo-spanner-gke" {
name = var.spanner_gke_config.cluster_name
location = var.spanner_gke_config.location
resource "google_container_cluster" "services-gke" {
name = var.services_gke_config.cluster_name
location = var.services_gke_config.location

network = google_compute_network.vpc.name
subnetwork = google_compute_subnetwork.subnet[var.spanner_gke_config.location].name
subnetwork = google_compute_subnetwork.subnet[var.services_gke_config.location].name

# See issue: https://github.com/hashicorp/terraform-provider-google/issues/10782
ip_allocation_policy {}
Expand All @@ -34,11 +34,11 @@ resource "google_container_cluster" "game-demo-spanner-gke" {
depends_on = [google_compute_subnetwork.subnet, google_project_service.project]
}

data "google_container_cluster" "game-demo-spanner-gke" {
name = var.spanner_gke_config.cluster_name
location = var.spanner_gke_config.location
data "google_container_cluster" "services-gke" {
name = var.services_gke_config.cluster_name
location = var.services_gke_config.location

depends_on = [google_container_cluster.game-demo-spanner-gke]
depends_on = [google_container_cluster.services-gke]
}

resource "google_service_account" "app-service-account" {
Expand All @@ -63,5 +63,5 @@ resource "google_service_account_iam_policy" "app-service-account-iam" {
service_account_id = google_service_account.app-service-account.name
policy_data = data.google_iam_policy.workload-id-policy.policy_data

depends_on = [google_project_service.project, google_container_cluster.game-demo-spanner-gke]
depends_on = [google_project_service.project, google_container_cluster.services-gke]
}
15 changes: 3 additions & 12 deletions infrastructure/terraform.tfvars.sample
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,9 @@ spanner_config = {
num_nodes = 3
}

# Spanner GKE Config Values
spanner_gke_config = {
cluster_name = "global-game-gke-spanner"
location = "us-central1"
resource_labels = {
environment = "staging"
}
}

# Open Match GKE Config Values
open-match_gke_config = {
cluster_name = "global-game-gke-open-match"
# Services GKE Config Values
services_gke_config = {
cluster_name = "global-game-services"
location = "us-central1"
resource_labels = {
environment = "staging"
Expand Down
14 changes: 2 additions & 12 deletions infrastructure/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,14 @@ variable "spanner_config" {
description = "Configuration specs for Spanner"
}

variable "spanner_gke_config" {
variable "services_gke_config" {
type = object({
cluster_name = string
location = string
resource_labels = map(string)
})

description = "Configuration specs for Spanner GKE Autopilot cluster"
}

variable "open-match_gke_config" {
type = object({
cluster_name = string
location = string
resource_labels = map(string)
})

description = "Configuration specs for Open Match GKE Autopilot cluster"
description = "Configuration specs for GKE Autopilot cluster that hosts all backend services"
}

variable "app_service_account_config" {
Expand Down

0 comments on commit 3db341f

Please sign in to comment.