From 170cabc447e9797ab094925e68bfbe26958944b4 Mon Sep 17 00:00:00 2001 From: Hossein Golestani Date: Mon, 29 Jan 2024 21:24:15 +0000 Subject: [PATCH 1/4] initial commit for scope-level namespace labels --- mmv1/products/gkehub2/Scope.yaml | 8 ++++++++ mmv1/products/pubsub/Topic.yaml | 2 +- .../terraform/examples/gkehub_scope_basic.tf.erb | 5 +++++ .../services/gkehub2/resource_gke_hub_scope_test.go | 10 ++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mmv1/products/gkehub2/Scope.yaml b/mmv1/products/gkehub2/Scope.yaml index 7c12b64c03b4..dffb33cea188 100644 --- a/mmv1/products/gkehub2/Scope.yaml +++ b/mmv1/products/gkehub2/Scope.yaml @@ -117,6 +117,14 @@ properties: - :READY - :DELETING - :UPDATING + - !ruby/object:Api::Type::KeyValueLabels + name: 'namespaceLabels' + description: | + Scope-level cluster namespace labels. For the member clusters bound + to the Scope, these labels are applied to each namespace under the + Scope. Scope-level labels take precedence over Namespace-level + labels (`namespace_labels` in the Fleet Namespace resource) if they + share a key. Keys and values must be Kubernetes-conformant. - !ruby/object:Api::Type::KeyValueLabels name: 'labels' description: | diff --git a/mmv1/products/pubsub/Topic.yaml b/mmv1/products/pubsub/Topic.yaml index 95bb9563576f..44f9f3a77c2e 100644 --- a/mmv1/products/pubsub/Topic.yaml +++ b/mmv1/products/pubsub/Topic.yaml @@ -119,7 +119,7 @@ properties: - !ruby/object:Api::Type::NestedObject name: 'schemaSettings' description: | - Settings for validating messages published against a schema. + UPDATED_DESCRIPTION default_from_api: true properties: - !ruby/object:Api::Type::String diff --git a/mmv1/templates/terraform/examples/gkehub_scope_basic.tf.erb b/mmv1/templates/terraform/examples/gkehub_scope_basic.tf.erb index 107fa956c82d..63efb8be3c78 100644 --- a/mmv1/templates/terraform/examples/gkehub_scope_basic.tf.erb +++ b/mmv1/templates/terraform/examples/gkehub_scope_basic.tf.erb @@ -1,5 +1,10 @@ resource "google_gke_hub_scope" "<%= ctx[:primary_resource_id] %>" { scope_id = "<%= ctx[:vars]['resource_name'] %>" + namespace_labels = { + keyb = "valueb" + keya = "valuea" + keyc = "valuec" + } labels = { keyb = "valueb" keya = "valuea" diff --git a/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_scope_test.go b/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_scope_test.go index 967fe08c4bc2..be00b628a7c6 100644 --- a/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_scope_test.go +++ b/mmv1/third_party/terraform/services/gkehub2/resource_gke_hub_scope_test.go @@ -47,6 +47,11 @@ func testAccGKEHub2Scope_gkehubScopeBasicExample_basic(context map[string]interf return acctest.Nprintf(` resource "google_gke_hub_scope" "scope" { scope_id = "tf-test-scope%{random_suffix}" + namespace_labels = { + keyb = "valueb" + keya = "valuea" + keyc = "valuec" + } labels = { keyb = "valueb" keya = "valuea" @@ -60,6 +65,11 @@ func testAccGKEHub2Scope_gkehubScopeBasicExample_update(context map[string]inter return acctest.Nprintf(` resource "google_gke_hub_scope" "scope" { scope_id = "tf-test-scope%{random_suffix}" + namespace_labels = { + updated_keyb = "updated_valueb" + updated_keya = "updated_valuea" + updated_keyc = "updated_valuec" + } labels = { updated_keyb = "updated_valueb" updated_keya = "updated_valuea" From 71c4adaa0b53d1a1ff88aed371cf8fe4291c73de Mon Sep 17 00:00:00 2001 From: Hossein Golestani Date: Thu, 8 Feb 2024 16:02:07 +0000 Subject: [PATCH 2/4] Add validation exceptions for the field of the GKEHub Scope and Namespace resources to be of type --- mmv1/api/type.rb | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/mmv1/api/type.rb b/mmv1/api/type.rb index 291c03053af0..7d6f347eb304 100644 --- a/mmv1/api/type.rb +++ b/mmv1/api/type.rb @@ -806,7 +806,12 @@ def validate raise "Please use type KeyValueLabels for field #{lineage} " \ "in resource #{product_name}/#{resource_name}" end - elsif is_a? Api::Type::KeyValueLabels + elsif (is_a? Api::Type::KeyValueLabels) && + # "namespaceLabels" is distinct from "labels", so skip the resource + !(product_name == 'GKEHub2' && resource_name == 'Namespace') && + + # "namespaceLabels" is distinct from "labels", so skip the resource + !(product_name == 'GKEHub2' && resource_name == 'Scope') raise "Please don't use type KeyValueLabels for field #{lineage} " \ "in resource #{product_name}/#{resource_name}" end @@ -834,9 +839,21 @@ def field_min_version class KeyValueLabels < KeyValuePairs def validate super - return unless @name != 'labels' - raise "The field #{name} has the type KeyValueLabels, but the field name is not 'labels'!" + return if @__resource.__product.nil? + + product_name = @__resource.__product.name + resource_name = @__resource.name + + if (@name != 'labels') && + # "namespaceLabels" is distinct from "labels", so skip the resource + !(product_name == 'GKEHub2' && resource_name == 'Namespace') && + + # "namespaceLabels" is distinct from "labels", so skip the resource + !(product_name == 'GKEHub2' && resource_name == 'Scope') + + raise "The field #{name} has the type KeyValueLabels, but the field name is not 'labels'!" + end end end From fc9d73dfa12ef4958a4a9ea1c77427de5919a483 Mon Sep 17 00:00:00 2001 From: Hossein Golestani Date: Mon, 12 Feb 2024 22:19:49 +0000 Subject: [PATCH 3/4] Undoing unnecessary changes --- mmv1/api/type.rb | 23 +++-------------------- mmv1/products/pubsub/Topic.yaml | 2 +- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/mmv1/api/type.rb b/mmv1/api/type.rb index 7d6f347eb304..291c03053af0 100644 --- a/mmv1/api/type.rb +++ b/mmv1/api/type.rb @@ -806,12 +806,7 @@ def validate raise "Please use type KeyValueLabels for field #{lineage} " \ "in resource #{product_name}/#{resource_name}" end - elsif (is_a? Api::Type::KeyValueLabels) && - # "namespaceLabels" is distinct from "labels", so skip the resource - !(product_name == 'GKEHub2' && resource_name == 'Namespace') && - - # "namespaceLabels" is distinct from "labels", so skip the resource - !(product_name == 'GKEHub2' && resource_name == 'Scope') + elsif is_a? Api::Type::KeyValueLabels raise "Please don't use type KeyValueLabels for field #{lineage} " \ "in resource #{product_name}/#{resource_name}" end @@ -839,21 +834,9 @@ def field_min_version class KeyValueLabels < KeyValuePairs def validate super + return unless @name != 'labels' - return if @__resource.__product.nil? - - product_name = @__resource.__product.name - resource_name = @__resource.name - - if (@name != 'labels') && - # "namespaceLabels" is distinct from "labels", so skip the resource - !(product_name == 'GKEHub2' && resource_name == 'Namespace') && - - # "namespaceLabels" is distinct from "labels", so skip the resource - !(product_name == 'GKEHub2' && resource_name == 'Scope') - - raise "The field #{name} has the type KeyValueLabels, but the field name is not 'labels'!" - end + raise "The field #{name} has the type KeyValueLabels, but the field name is not 'labels'!" end end diff --git a/mmv1/products/pubsub/Topic.yaml b/mmv1/products/pubsub/Topic.yaml index 44f9f3a77c2e..95bb9563576f 100644 --- a/mmv1/products/pubsub/Topic.yaml +++ b/mmv1/products/pubsub/Topic.yaml @@ -119,7 +119,7 @@ properties: - !ruby/object:Api::Type::NestedObject name: 'schemaSettings' description: | - UPDATED_DESCRIPTION + Settings for validating messages published against a schema. default_from_api: true properties: - !ruby/object:Api::Type::String From 3c39295c6528b386e2b9b09c9b83cef8b77fc44c Mon Sep 17 00:00:00 2001 From: Hossein Golestani Date: Mon, 12 Feb 2024 22:58:06 +0000 Subject: [PATCH 4/4] Fixing the type of Scope namespace_labels field --- mmv1/products/gkehub2/Scope.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/products/gkehub2/Scope.yaml b/mmv1/products/gkehub2/Scope.yaml index dffb33cea188..ff73465a443e 100644 --- a/mmv1/products/gkehub2/Scope.yaml +++ b/mmv1/products/gkehub2/Scope.yaml @@ -117,7 +117,7 @@ properties: - :READY - :DELETING - :UPDATING - - !ruby/object:Api::Type::KeyValueLabels + - !ruby/object:Api::Type::KeyValuePairs name: 'namespaceLabels' description: | Scope-level cluster namespace labels. For the member clusters bound