Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the clusterupgrade feature config for the fleet Feature resource. #9614

Merged
60 changes: 60 additions & 0 deletions mmv1/products/gkehub2/Feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ examples:
skip_test: true
primary_resource_name: 'fmt.Sprintf("policycontroller")'
primary_resource_id: 'feature'
- !ruby/object:Provider::Terraform::Examples
name: 'gkehub_feature_clusterupgrade'
skip_test: true
primary_resource_name: 'fmt.Sprint("clusterupgrade")'
primary_resource_id: 'feature'
autogen_async: true
# Skip sweeper gen since this is a child resource.
skip_sweeper: true
Expand Down Expand Up @@ -195,6 +200,61 @@ properties:
- :MODE_UNSPECIFIED
- :COPY
- :MOVE
- !ruby/object:Api::Type::NestedObject
name: clusterupgrade
description: Clusterupgrade feature spec.
properties:
- !ruby/object:Api::Type::Array
name: 'upstreamFleets'
description: |
Specified if other fleet should be considered as a source of upgrades. Currently, at most one upstream fleet is allowed. The fleet name should be either fleet project number or id.
required: true
item_type: Api::Type::String
- !ruby/object:Api::Type::NestedObject
name: 'postConditions'
description: |
Post conditions to override for the specified upgrade.
required: true
default_from_api: true
properties:
- !ruby/object:Api::Type::String
name: 'soaking'
description: |
Amount of time to "soak" after a rollout has been finished before marking it COMPLETE. Cannot exceed 30 days.
required: true
- !ruby/object:Api::Type::Array
name: 'gkeUpgradeOverrides'
description: |
Configuration overrides for individual upgrades.
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::NestedObject
name: 'upgrade'
description: |
Which upgrade to override.
required: true
properties:
- !ruby/object:Api::Type::String
name: 'name'
description: |
Name of the upgrade, e.g., "k8s_control_plane". It should be a valid upgrade name. It must not exceet 99 characters.
required: true
- !ruby/object:Api::Type::String
name: 'version'
description: |
Version of the upgrade, e.g., "1.22.1-gke.100". It should be a valid version. It must not exceet 99 characters.
required: true
- !ruby/object:Api::Type::NestedObject
name: 'postConditions'
description: |
Post conditions to override for the specified upgrade.
required: true
properties:
- !ruby/object:Api::Type::String
name: 'soaking'
description: |
Amount of time to "soak" after a rollout has been finished before marking it COMPLETE. Cannot exceed 30 days.
required: true
- !ruby/object:Api::Type::NestedObject
name: fleetDefaultMemberConfig
description: Optional. Fleet Default Membership Configuration.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resource "google_gke_hub_feature" "feature" {
name = "clusterupgrade"
location = "global"
spec {
clusterupgrade {
upstream_fleets = []
post_conditions {
soaking = "60s"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,120 @@ resource "google_gke_hub_feature" "feature" {
`, context)
}

func TestAccGKEHubFeature_Clusterupgrade(t *testing.T) {
// VCR fails to handle batched project services
acctest.SkipIfVcr(t)
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
"org_id": envvar.GetTestOrgFromEnv(t),
"billing_account": envvar.GetTestBillingAccountFromEnv(t),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckGKEHubFeatureDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccGKEHubFeature_Clusterupgrade(context),
},
{
ResourceName: "google_gke_hub_feature.feature",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"project", "update_time"},
},
{
Config: testAccGKEHubFeature_ClusterupgradeUpdate(context),
},
{
ResourceName: "google_gke_hub_feature.feature",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"update_time"},
},
},
})
}

func testAccGKEHubFeature_Clusterupgrade(context map[string]interface{}) string {
return gkeHubFeatureProjectSetupForGA(context) + acctest.Nprintf(`
resource "google_gke_hub_feature" "feature" {
name = "clusterupgrade"
location = "global"
spec {
clusterupgrade {
upstream_fleets = []
post_conditions {
soaking = "60s"
}
}
}
depends_on = [google_project_service.gkehub]
project = google_project.project.project_id
}

resource "google_gke_hub_feature" "feature_2" {
name = "clusterupgrade"
location = "global"
spec {
clusterupgrade {
upstream_fleets = []
post_conditions {
soaking = "60s"
}
}
}
depends_on = [google_project_service.gkehub_2]
project = google_project.project_2.project_id
}
`, context)
}

func testAccGKEHubFeature_ClusterupgradeUpdate(context map[string]interface{}) string {
return gkeHubFeatureProjectSetupForGA(context) + acctest.Nprintf(`
resource "google_gke_hub_feature" "feature" {
name = "clusterupgrade"
location = "global"
spec {
clusterupgrade {
upstream_fleets = [google_project.project_2.number]
post_conditions {
soaking = "120s"
}
gke_upgrade_overrides {
upgrade {
name = "k8s_control_plane"
version = "1.22.1-gke.100"
}
post_conditions {
soaking = "240s"
}
}
}
}
project = google_project.project.project_id
}

resource "google_gke_hub_feature" "feature_2" {
name = "clusterupgrade"
location = "global"
spec {
clusterupgrade {
upstream_fleets = []
post_conditions {
soaking = "60s"
}
}
}
depends_on = [google_project_service.gkehub_2]
project = google_project.project_2.project_id
}
`, context)
}

func TestAccGKEHubFeature_FleetDefaultMemberConfigPolicyController(t *testing.T) {
// VCR fails to handle batched project services
acctest.SkipIfVcr(t)
Expand Down Expand Up @@ -792,6 +906,31 @@ resource "google_project_service" "gkehub" {
service = "gkehub.googleapis.com"
disable_on_destroy = false
}

resource "google_project" "project_2" {
name = "tf-test-gkehub%{random_suffix}-2"
project_id = "tf-test-gkehub%{random_suffix}-2"
org_id = "%{org_id}"
billing_account = "%{billing_account}"
}

resource "google_project_service" "compute_2" {
project = google_project.project_2.project_id
service = "compute.googleapis.com"
disable_on_destroy = false
}

resource "google_project_service" "container_2" {
project = google_project.project_2.project_id
service = "container.googleapis.com"
disable_on_destroy = false
}

resource "google_project_service" "gkehub_2" {
project = google_project.project_2.project_id
service = "gkehub.googleapis.com"
disable_on_destroy = false
}
`, context)
}

Expand Down