From 84014d5b7d0189a59fc20078b561fc823ed6efb1 Mon Sep 17 00:00:00 2001 From: justinsb Date: Thu, 31 Oct 2024 07:50:04 -0400 Subject: [PATCH 1/2] tests: rename tests with same name The IAMPolicy samples and IAMPartialPolicy samples had the same name, causing our test results to be ambiguous. Rename to deduplicate. --- .../iam_v1beta1_iampartialpolicy.yaml | 0 .../iam_v1beta1_iamserviceaccount.yaml | 0 .../resourcemanager_v1beta1_project.yaml | 0 .../iam_v1beta1_iampartialpolicy.yaml | 0 .../iam_v1beta1_iamserviceaccount.yaml | 0 .../pubsub_v1beta1_pubsubtopic.yaml | 0 pkg/snippet/snippetgeneration/snippetgeneration.go | 2 +- 7 files changed, 1 insertion(+), 1 deletion(-) rename config/samples/resources/iampartialpolicy/{project-level-policy => project-level-iampartialpolicy}/iam_v1beta1_iampartialpolicy.yaml (100%) rename config/samples/resources/iampartialpolicy/{project-level-policy => project-level-iampartialpolicy}/iam_v1beta1_iamserviceaccount.yaml (100%) rename config/samples/resources/iampartialpolicy/{project-level-policy => project-level-iampartialpolicy}/resourcemanager_v1beta1_project.yaml (100%) rename config/samples/resources/iampartialpolicy/{pubsub-admin-policy => pubsub-admin-iampartialpolicy}/iam_v1beta1_iampartialpolicy.yaml (100%) rename config/samples/resources/iampartialpolicy/{pubsub-admin-policy => pubsub-admin-iampartialpolicy}/iam_v1beta1_iamserviceaccount.yaml (100%) rename config/samples/resources/iampartialpolicy/{pubsub-admin-policy => pubsub-admin-iampartialpolicy}/pubsub_v1beta1_pubsubtopic.yaml (100%) diff --git a/config/samples/resources/iampartialpolicy/project-level-policy/iam_v1beta1_iampartialpolicy.yaml b/config/samples/resources/iampartialpolicy/project-level-iampartialpolicy/iam_v1beta1_iampartialpolicy.yaml similarity index 100% rename from config/samples/resources/iampartialpolicy/project-level-policy/iam_v1beta1_iampartialpolicy.yaml rename to config/samples/resources/iampartialpolicy/project-level-iampartialpolicy/iam_v1beta1_iampartialpolicy.yaml diff --git a/config/samples/resources/iampartialpolicy/project-level-policy/iam_v1beta1_iamserviceaccount.yaml b/config/samples/resources/iampartialpolicy/project-level-iampartialpolicy/iam_v1beta1_iamserviceaccount.yaml similarity index 100% rename from config/samples/resources/iampartialpolicy/project-level-policy/iam_v1beta1_iamserviceaccount.yaml rename to config/samples/resources/iampartialpolicy/project-level-iampartialpolicy/iam_v1beta1_iamserviceaccount.yaml diff --git a/config/samples/resources/iampartialpolicy/project-level-policy/resourcemanager_v1beta1_project.yaml b/config/samples/resources/iampartialpolicy/project-level-iampartialpolicy/resourcemanager_v1beta1_project.yaml similarity index 100% rename from config/samples/resources/iampartialpolicy/project-level-policy/resourcemanager_v1beta1_project.yaml rename to config/samples/resources/iampartialpolicy/project-level-iampartialpolicy/resourcemanager_v1beta1_project.yaml diff --git a/config/samples/resources/iampartialpolicy/pubsub-admin-policy/iam_v1beta1_iampartialpolicy.yaml b/config/samples/resources/iampartialpolicy/pubsub-admin-iampartialpolicy/iam_v1beta1_iampartialpolicy.yaml similarity index 100% rename from config/samples/resources/iampartialpolicy/pubsub-admin-policy/iam_v1beta1_iampartialpolicy.yaml rename to config/samples/resources/iampartialpolicy/pubsub-admin-iampartialpolicy/iam_v1beta1_iampartialpolicy.yaml diff --git a/config/samples/resources/iampartialpolicy/pubsub-admin-policy/iam_v1beta1_iamserviceaccount.yaml b/config/samples/resources/iampartialpolicy/pubsub-admin-iampartialpolicy/iam_v1beta1_iamserviceaccount.yaml similarity index 100% rename from config/samples/resources/iampartialpolicy/pubsub-admin-policy/iam_v1beta1_iamserviceaccount.yaml rename to config/samples/resources/iampartialpolicy/pubsub-admin-iampartialpolicy/iam_v1beta1_iamserviceaccount.yaml diff --git a/config/samples/resources/iampartialpolicy/pubsub-admin-policy/pubsub_v1beta1_pubsubtopic.yaml b/config/samples/resources/iampartialpolicy/pubsub-admin-iampartialpolicy/pubsub_v1beta1_pubsubtopic.yaml similarity index 100% rename from config/samples/resources/iampartialpolicy/pubsub-admin-policy/pubsub_v1beta1_pubsubtopic.yaml rename to config/samples/resources/iampartialpolicy/pubsub-admin-iampartialpolicy/pubsub_v1beta1_pubsubtopic.yaml diff --git a/pkg/snippet/snippetgeneration/snippetgeneration.go b/pkg/snippet/snippetgeneration/snippetgeneration.go index 7dbf245319..6a8891aaa0 100644 --- a/pkg/snippet/snippetgeneration/snippetgeneration.go +++ b/pkg/snippet/snippetgeneration/snippetgeneration.go @@ -86,7 +86,7 @@ var preferredSampleForResource = map[string]string{ "iamauditconfig": "project-level-audit-config", "iamcustomrole": "project-role", "iampolicy": "external-project-level-policy", - "iampartialpolicy": "project-level-policy", + "iampartialpolicy": "project-level-iampartialpolicy", "iampolicymember": "external-project-level-policy-member", "iamworkforcepoolprovider": "oidc-workforce-pool-provider", "iamworkloadidentitypoolprovider": "oidc-workload-identity-pool-provider", From a8dca2c0526eb71412f088ca55805cb814b2a8fb Mon Sep 17 00:00:00 2001 From: justinsb Date: Thu, 31 Oct 2024 16:45:39 -0400 Subject: [PATCH 2/2] docs: Generate better titles for samples We probably should have an override capability, but .... this works. --- .../bigquerydatatransferconfig.md | 4 +- .../cloudfunctions/cloudfunctionsfunction.md | 4 +- .../cloudscheduler/cloudschedulerjob.md | 2 +- .../edgecontainer/edgecontainercluster.md | 4 +- .../resource-docs/iam/iampartialpolicy.md | 4 +- .../generated/resource-docs/iam/iampolicy.md | 2 +- .../resource-docs/iam/iampolicymember.md | 2 +- .../monitoringnotificationchannel.md | 2 +- .../pubsub/pubsubsubscription.md | 4 +- .../generated/resource-docs/run/runjob.md | 6 +-- .../generated/resource-docs/run/runservice.md | 2 +- .../resource-docs/vertexai/vertexaidataset.md | 4 +- .../vertexai/vertexaiendpoint.md | 4 +- .../resource-reference/main.go | 45 +++++++++++-------- 14 files changed, 48 insertions(+), 41 deletions(-) diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/bigquerydatatransfer/bigquerydatatransferconfig.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/bigquerydatatransfer/bigquerydatatransferconfig.md index 4833cabaa3..d52eca762c 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/bigquerydatatransfer/bigquerydatatransferconfig.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/bigquerydatatransfer/bigquerydatatransferconfig.md @@ -646,7 +646,7 @@ observedState: ## Sample YAML(s) -### Bigquerydatatransferconfig Salesforce +### BigQueryDataTransferConfig Salesforce ```yaml # Copyright 2024 Google LLC # @@ -690,7 +690,7 @@ spec: location: us-central1 ``` -### Bigquerydatatransferconfig Scheduledquery +### BigQueryDataTransferConfig Scheduledquery ```yaml # Copyright 2024 Google LLC # diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/cloudfunctions/cloudfunctionsfunction.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/cloudfunctions/cloudfunctionsfunction.md index 92b1296922..da96476f52 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/cloudfunctions/cloudfunctionsfunction.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/cloudfunctions/cloudfunctionsfunction.md @@ -724,7 +724,7 @@ results in a new version of a function being created.{% endverbatim %}

## Sample YAML(s) -### Eventtrigger With Pubsubtopic +### Eventtrigger With PubSubTopic ```yaml # Copyright 2022 Google LLC # @@ -804,7 +804,7 @@ spec: external: "projects/${PROJECT_ID?}" ``` -### Eventtrigger With Storagebucket +### Eventtrigger With StorageBucket ```yaml # Copyright 2022 Google LLC # diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/cloudscheduler/cloudschedulerjob.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/cloudscheduler/cloudschedulerjob.md index 0a34ed840b..ee49d6373c 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/cloudscheduler/cloudschedulerjob.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/cloudscheduler/cloudschedulerjob.md @@ -873,7 +873,7 @@ spec: displayName: Example Service Account ``` -### Scheduler Job Pubsub +### Scheduler Job PubSub ```yaml # Copyright 2020 Google LLC # diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/edgecontainer/edgecontainercluster.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/edgecontainer/edgecontainercluster.md index 212ebb9f87..59569fcfa3 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/edgecontainer/edgecontainercluster.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/edgecontainer/edgecontainercluster.md @@ -1056,7 +1056,7 @@ if the cluster does not have any worker nodes.{% endverbatim %}

## Sample YAML(s) -### Edgecontainercluster Local Control Plane +### EdgeContainerCluster Local Control Plane ```yaml # Copyright 2023 Google LLC # @@ -1106,7 +1106,7 @@ spec: - ${EXTERNAL_LOAD_BALANCER_IPV4_CIDR?} ``` -### Edgecontainercluster Remote Control Plane +### EdgeContainerCluster Remote Control Plane ```yaml # Copyright 2023 Google LLC # diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/iam/iampartialpolicy.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/iam/iampartialpolicy.md index 06195f6a1d..ff67f9fea1 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/iam/iampartialpolicy.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/iam/iampartialpolicy.md @@ -1064,7 +1064,7 @@ observedGeneration: integer ## Sample YAML(s) -### Project Level Policy +### Project Level Iampartialpolicy ```yaml # Copyright 2020 Google LLC # @@ -1120,7 +1120,7 @@ spec: external: "${ORG_ID?}" ``` -### Pubsub Admin Policy +### PubSub Admin Iampartialpolicy ```yaml # Copyright 2020 Google LLC # diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/iam/iampolicy.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/iam/iampolicy.md index 5ed7ddec09..0abad17507 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/iam/iampolicy.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/iam/iampolicy.md @@ -1080,7 +1080,7 @@ spec: external: "${ORG_ID?}" ``` -### Pubsub Admin Policy +### PubSub Admin Policy ```yaml # Copyright 2020 Google LLC # diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/iam/iampolicymember.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/iam/iampolicymember.md index 651922b4f9..de6f9340c9 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/iam/iampolicymember.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/iam/iampolicymember.md @@ -1087,7 +1087,7 @@ metadata: name: iampolicymember-dep-memberref ``` -### Pubsub Admin Policy Member +### PubSub Admin Policy Member ```yaml # Copyright 2020 Google LLC # diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/monitoring/monitoringnotificationchannel.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/monitoring/monitoringnotificationchannel.md index 4f5c24a53e..96f0f2f71d 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/monitoring/monitoringnotificationchannel.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/monitoring/monitoringnotificationchannel.md @@ -560,7 +560,7 @@ spec: enabled: false ``` -### Pubsub Monitoring Notification Channel +### PubSub Monitoring Notification Channel ```yaml # Copyright 2022 Google LLC # diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/pubsub/pubsubsubscription.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/pubsub/pubsubsubscription.md index 72326628cc..ca88e19e48 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/pubsub/pubsubsubscription.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/pubsub/pubsubsubscription.md @@ -863,7 +863,7 @@ observedGeneration: integer ## Sample YAML(s) -### Basic Pubsub Subscription +### Basic PubSub Subscription ```yaml # Copyright 2020 Google LLC # @@ -906,7 +906,7 @@ metadata: name: pubsubsubscription-dep2-basic ``` -### BigQuery Pubsub Subscription +### BigQuery PubSub Subscription ```yaml # Copyright 2022 Google LLC # diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/run/runjob.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/run/runjob.md index 173bcbc84a..b02d2d8f4a 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/run/runjob.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/run/runjob.md @@ -1890,7 +1890,7 @@ spec: - launch_stage ``` -### Job With Iamserviceaccount +### Job With IAMServiceAccount ```yaml # Copyright 2023 Google LLC # @@ -1930,7 +1930,7 @@ spec: displayName: runjob-dep-iamserviceaccount ``` -### Job With Kmscryptokey +### Job With KMSCryptoKey ```yaml # Copyright 2023 Google LLC # @@ -2043,7 +2043,7 @@ spec: tier: db-n1-standard-1 ``` -### Job With Secretmanagersecret +### Job With SecretManagerSecret ```yaml # Copyright 2023 Google LLC # diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/run/runservice.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/run/runservice.md index f931f6f53c..d83fcda178 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/run/runservice.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/run/runservice.md @@ -2487,7 +2487,7 @@ spec: name: runservice-dep-serviceaccount ``` -### Run Service Vpcaccess +### Run Service VPCAccess ```yaml # Copyright 2022 Google LLC # diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/vertexai/vertexaidataset.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/vertexai/vertexaidataset.md index 4d1f9e6880..34003b686a 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/vertexai/vertexaidataset.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/vertexai/vertexaidataset.md @@ -326,7 +326,7 @@ observedState: ## Sample YAML(s) -### Vertexai Dataset Basic +### VertexAI Dataset Basic ```yaml # Copyright 2024 Google LLC # @@ -355,7 +355,7 @@ spec: external: ${PROJECT_ID?} ``` -### Vertexai Dataset Encryptionkey +### VertexAI Dataset Encryptionkey ```yaml # Copyright 2024 Google LLC # diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/vertexai/vertexaiendpoint.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/vertexai/vertexaiendpoint.md index c5d5b64b94..d92529ec9c 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/vertexai/vertexaiendpoint.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/vertexai/vertexaiendpoint.md @@ -375,7 +375,7 @@ observedState: ## Sample YAML(s) -### Vertexai Endpoint Encryptionkey +### VertexAI Endpoint Encryptionkey ```yaml # Copyright 2024 Google LLC # @@ -453,7 +453,7 @@ spec: resourceID: aiplatform.googleapis.com ``` -### Vertexai Endpoint Network +### VertexAI Endpoint Network ```yaml # Copyright 2024 Google LLC # diff --git a/scripts/generate-google3-docs/resource-reference/main.go b/scripts/generate-google3-docs/resource-reference/main.go index 3b225dc390..90e75e5e1b 100644 --- a/scripts/generate-google3-docs/resource-reference/main.go +++ b/scripts/generate-google3-docs/resource-reference/main.go @@ -16,6 +16,7 @@ package main import ( "fmt" + "io/fs" "io/ioutil" "log" "os" @@ -487,7 +488,7 @@ func buildSamples(kind, sampleDirPath string, smLoader *servicemappingloader.Ser if err != nil { return nil, fmt.Errorf("error building sample at %v: %w", subDirPath, err) } - name := formatDirectoryName(subDir.Name(), smLoader.GetServiceMappings()) + name := titleForSample(subDir, smLoader.GetServiceMappings()) sampleYAMLs[name] = sample } } else { @@ -766,31 +767,37 @@ func referencesSupportedByIAMAuditConfig(smLoader *servicemappingloader.ServiceM return refs, nil } -func formatDirectoryName(s string, serviceMappings []v1alpha1.ServiceMapping) string { - nameToSm := make(map[string]v1alpha1.ServiceMapping) +// titleForSample returns the title that should be used for the sample +func titleForSample(dir fs.FileInfo, serviceMappings []v1alpha1.ServiceMapping) string { + serviceMappingNames := make(map[string]v1alpha1.ServiceMapping) + resourceKinds := make(map[string]v1alpha1.ResourceConfig) for _, sm := range serviceMappings { - nameToSm[sm.Spec.Name] = sm + serviceMappingNames[strings.ToLower(sm.Spec.Name)] = sm + + for _, resource := range sm.Spec.Resources { + resourceKinds[strings.ToLower(resource.Kind)] = resource + } } - split := strings.Split(s, "-") - ret := "" - for i, v := range split { - title := strings.Title(v) - if _, ok := nameToSm[strings.ToUpper(title)]; ok { - // value is IAM, KMS, etc, don't use strings.Title(v) as it will result in Kms or Iam - title = strings.ToUpper(title) + split := strings.Split(dir.Name(), "-") + var words []string + for _, v := range split { + word := strings.Title(v) + if serviceMapping, ok := serviceMappingNames[strings.ToLower(word)]; ok { + // If it's a well-known service, use its correctly capitalized name (PubSub, VertexAI etc) + word = serviceMapping.Spec.Name + } + if resource, ok := resourceKinds[strings.ToLower(word)]; ok { + // If it's a well-known kind, use the correct capitalization + word = resource.Kind } for _, s := range allowedSpellings { - if strings.ToLower(s) == strings.ToLower(title) { - title = s + if strings.EqualFold(s, word) { + word = s } } - if i != len(split)-1 { - ret += title + " " - } else { - ret += title - } + words = append(words, word) } - return ret + return strings.Join(words, " ") } func resourceSupportsIAMPolicyAndPolicyMember(rc *v1alpha1.ResourceConfig) bool {