Skip to content

Commit

Permalink
Adding labels and namespace labels to the GKEHub namespace resource (G…
Browse files Browse the repository at this point in the history
…oogleCloudPlatform#8832)

* Adding Terraform resources for Tenancy APIs in GKEHub

* Segregating MembershipBinding and MembershipRBACRoleBinding to keep things simpler in the review

* Fixing the docu URIs

* Adding TF support for Tenancy API for Membership Binding

* Adding dependent membership binding to the same commit chain

* Making Scope un-updatable and replacing hard coded project number with the one from test env

* Making Scope RRBAC updatable

* Making Namespace immutable

* Adding update test cases

* Removing all memberships field from Scope since it is no longer supported

* Removing all_memberships field for Scope from all test cases

* Enhancing namespace resource with the labels fields

* Adding more keys to test out the sorted comparison of keys in the map of labels

* Adding more keys to test out the sorted comparison of keys in the update map
  • Loading branch information
sahsagar-google authored and RileyHYZ committed Sep 15, 2023
1 parent 26be40b commit 3719625
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 1 deletion.
16 changes: 15 additions & 1 deletion mmv1/products/gkehub2/Namespace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
name: 'Namespace'
base_url: 'projects/{{project}}/locations/global/scopes/{{scope_id}}/namespaces'
create_url: 'projects/{{project}}/locations/global/scopes/{{scope_id}}/namespaces/?scope_namespace_id={{scope_namespace_id}}'
update_url: 'projects/{{project}}/locations/global/scopes/{{scope_id}}/namespaces/{{scope_namespace_id}}'
self_link: 'projects/{{project}}/locations/global/scopes/{{scope_id}}/namespaces/{{scope_namespace_id}}'
immutable: true
update_verb: :PATCH
update_mask: true
description: |
Namespace represents a namespace across the Fleet.
references: !ruby/object:Api::Resource::ReferenceLinks
Expand Down Expand Up @@ -123,3 +125,15 @@ properties:
- :READY
- :DELETING
- :UPDATING
- !ruby/object:Api::Type::KeyValuePairs
name: 'namespaceLabels'
description: |
Namespace-level cluster namespace labels. These labels are applied
to the related namespace of the member clusters bound to the parent
Scope. Scope-level labels (`namespace_labels` in the Fleet Scope
resource) take precedence over Namespace-level labels if they share
a key. Keys and values must be Kubernetes-conformant.
- !ruby/object:Api::Type::KeyValuePairs
name: 'labels'
description: |
Labels for this Namespace.
10 changes: 10 additions & 0 deletions mmv1/templates/terraform/examples/gkehub_namespace_basic.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,15 @@ resource "google_gke_hub_namespace" "<%= ctx[:primary_resource_id] %>" {
scope_namespace_id = "tf-test-namespace%{random_suffix}"
scope_id = "tf-test-scope%{random_suffix}"
scope = "${google_gke_hub_scope.<%= ctx[:primary_resource_id] %>.name}"
namespace_labels = {
keyb = "valueb"
keya = "valuea"
keyc = "valuec"
}
labels = {
keyb = "valueb"
keya = "valuea"
keyc = "valuec"
}
depends_on = [google_gke_hub_scope.<%= ctx[:primary_resource_id] %>]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package gkehub2_test

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
)

func TestAccGKEHub2Namespace_gkehubNamespaceBasicExample_update(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"project": envvar.GetTestProjectFromEnv(),
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccGKEHub2Namespace_gkehubNamespaceBasicExample_basic(context),
},
{
ResourceName: "google_gke_hub_namespace.namespace",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"scope_namespace_id", "scope", "scope_id", "scope"},
},
{
Config: testAccGKEHub2Namespace_gkehubNamespaceBasicExample_update(context),
},
{
ResourceName: "google_gke_hub_namespace.namespace",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"scope_namespace_id", "scope", "scope_id", "scope"},
},
},
})
}

func testAccGKEHub2Namespace_gkehubNamespaceBasicExample_basic(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_gke_hub_scope" "namespace" {
scope_id = "tf-test-scope%{random_suffix}"
}
resource "google_gke_hub_namespace" "namespace" {
scope_namespace_id = "tf-test-namespace%{random_suffix}"
scope_id = "tf-test-scope%{random_suffix}"
scope = "${google_gke_hub_scope.namespace.name}"
namespace_labels = {
keyb = "valueb"
keya = "valuea"
keyc = "valuec"
}
labels = {
keyb = "valueb"
keya = "valuea"
keyc = "valuec"
}
depends_on = [google_gke_hub_scope.namespace]
}
`, context)
}

func testAccGKEHub2Namespace_gkehubNamespaceBasicExample_update(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_gke_hub_scope" "namespace" {
scope_id = "tf-test-scope%{random_suffix}"
}
resource "google_gke_hub_namespace" "namespace" {
scope_namespace_id = "tf-test-namespace%{random_suffix}"
scope_id = "tf-test-scope%{random_suffix}"
scope = "${google_gke_hub_scope.namespace.name}"
namespace_labels = {
updated_keyb = "updated_valueb"
updated_keya = "updated_valuea"
updated_keyc = "updated_valuec"
}
labels = {
updated_keyb = "updated_valueb"
updated_keya = "updated_valuea"
updated_keyc = "updated_valuec"
}
depends_on = [google_gke_hub_scope.namespace]
}
`, context)
}

0 comments on commit 3719625

Please sign in to comment.