Skip to content

Commit 2867162

Browse files
author
Sam Naser
authored
fix: ASM module rewrite improvements (#1165)
* add guide for migrating from previous module * add options for fleet registration and feature enablement * fix test with membership name
1 parent 0d9c44e commit 2867162

File tree

7 files changed

+52
-13
lines changed

7 files changed

+52
-13
lines changed

docs/upgrading_to_v20.0.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,24 @@ release for the Anthos Service Mesh (ASM) module.
66
### ASM module rewrite
77

88
The [ASM submodule](https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/tree/master/modules/asm) has been rewritten to use the `ControlPlaneRevision` API to provision
9-
a managed control plane rather than using an installer script. Due to the drastic difference in implementation the module does not support an upgrade path
10-
from the previous version.
9+
a managed control plane rather than using an installer script. Due to implementation differences, there are migration steps required to safely move from
10+
an installation performed with the old module to using the new module. **NOTE:** these migration steps are best-effort and have not been tested against all possible ASM configurations.
11+
12+
1. Run `terraform state rm module.asm`
13+
2. Update the module version to v20.0
14+
3. Import the system namespace into the new module with `terraform import module.asm.kubernetes_namespace.system istio-system`
15+
4. Run `terraform apply`
16+
17+
There should be two ASM revisions present at this point (in-cluster or managed, depending on whether the previous installation was managed). Now,
18+
we must perform a canary upgrade to move workloads onto the new ASM revision. To do this:
19+
20+
1. Relabel namespaces to use the revision label from the managed revision (`asm-managed`, `asm-managed-stable`, or `asm-managed-rapid`)
21+
2. Rollout workloads in those namespaces to get them onto the new ASM version
22+
3. [Optional] Remove the previous revision with `istioctl x uninstall --revision ...` (if the previous installation was in-cluster)
23+
24+
25+
#### Migrating options
26+
27+
Another difference from the previous module is that the new ASM module does not provide variables for option configuration (e.g. `custom_overlay`, `options`). For the new version these should be managed separately
28+
outside the module. This is because those options were tightly coupled to pulling down an installer which the new module does not do. To use options specified in the previous module with the new module find the corresponding configuration [here](https://github.com/GoogleCloudPlatform/anthos-service-mesh-packages/tree/main/asm/istio/options) and move the
29+
config to the mesh configuration for the managed revision.

examples/simple_zonal_with_asm/main.tf

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ module "gke" {
5757
}
5858

5959
module "asm" {
60-
source = "../../modules/asm"
61-
project_id = var.project_id
62-
cluster_name = module.gke.name
63-
cluster_location = module.gke.location
64-
multicluster_mode = "connected"
65-
enable_cni = true
60+
source = "../../modules/asm"
61+
project_id = var.project_id
62+
cluster_name = module.gke.name
63+
cluster_location = module.gke.location
64+
multicluster_mode = "connected"
65+
enable_cni = true
66+
enable_fleet_registration = true
67+
enable_mesh_feature = true
6668
}

modules/asm/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ To deploy this config:
3535
| cluster\_location | The cluster location for this ASM installation. | `string` | n/a | yes |
3636
| cluster\_name | The unique name to identify the cluster in ASM. | `string` | n/a | yes |
3737
| enable\_cni | Determines whether to enable CNI for this ASM installation. Required to use Managed Data Plane (MDP). | `bool` | `false` | no |
38+
| enable\_fleet\_registration | Determines whether the module enables the mesh feature on the fleet. | `bool` | `false` | no |
39+
| enable\_mesh\_feature | Determines whether the module registers the cluster to the fleet. | `bool` | `false` | no |
3840
| enable\_vpc\_sc | Determines whether to enable VPC-SC for this ASM installation. For more information read https://cloud.google.com/service-mesh/docs/managed/vpc-sc | `bool` | `false` | no |
3941
| fleet\_id | The fleet to use for this ASM installation. | `string` | `""` | no |
4042
| multicluster\_mode | [Preview] Determines whether remote secrets should be autogenerated across fleet cluster. | `string` | `"manual"` | no |

examples/simple_zonal_with_asm/hub.tf renamed to modules/asm/hub.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2022 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,18 +14,20 @@
1414
* limitations under the License.
1515
*/
1616

17-
resource "google_gke_hub_membership" "cluster_membership" {
17+
resource "google_gke_hub_membership" "membership" {
18+
count = var.enable_fleet_registration ? 1 : 0
1819
provider = google-beta
1920
project = var.project_id
20-
membership_id = "gke-asm-membership"
21+
membership_id = "${data.google_container_cluster.asm.name}-membership"
2122
endpoint {
2223
gke_cluster {
23-
resource_link = "//container.googleapis.com/${module.gke.cluster_id}"
24+
resource_link = "//container.googleapis.com/${data.google_container_cluster.asm.id}"
2425
}
2526
}
2627
}
2728

2829
resource "google_gke_hub_feature" "mesh" {
30+
count = var.enable_mesh_feature ? 1 : 0
2931
name = "servicemesh"
3032
project = var.project_id
3133
location = "global"

modules/asm/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ resource "kubernetes_config_map" "asm_options" {
4646
data = {
4747
multicluster_mode = var.multicluster_mode
4848
}
49+
50+
depends_on = [google_gke_hub_membership.membership, google_gke_hub_feature.mesh]
4951
}
5052

5153
module "cpr" {

modules/asm/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,15 @@ variable "enable_vpc_sc" {
7474
type = bool
7575
default = false
7676
}
77+
78+
variable "enable_fleet_registration" {
79+
description = "Determines whether the module enables the mesh feature on the fleet."
80+
type = bool
81+
default = false
82+
}
83+
84+
variable "enable_mesh_feature" {
85+
description = "Determines whether the module registers the cluster to the fleet."
86+
type = bool
87+
default = false
88+
}

test/integration/simple_zonal_with_asm/controls/gcloud.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
end
4141
end
4242

43-
describe command("gcloud container hub memberships describe gke-asm-membership --project=#{project_id} --format=json") do
43+
describe command("gcloud container hub memberships describe #{cluster_name}-membership --project=#{project_id} --format=json") do
4444
its(:exit_status) { should eq 0 }
4545
its(:stderr) { should eq '' }
4646

0 commit comments

Comments
 (0)