Skip to content

Commit

Permalink
Merge pull request #2244 from jingyih/fix_vertexai_skeleton_test
Browse files Browse the repository at this point in the history
Fix skeleton test for Vertex AI resources
  • Loading branch information
google-oss-prow[bot] authored Jul 17, 2024
2 parents 9d22e19 + c4539cc commit 120cc63
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/servicemappings/vertexai.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ spec:
- name: google_vertex_ai_endpoint
kind: VertexAIEndpoint
idTemplate: "projects/{{project}}/locations/{{region}}/endpoints/{{name}}"
idTemplateCanBeUsedToMatchResourceName: false
idTemplateCanBeUsedToMatchResourceName: true
resourceAvailableInAssetInventory: true
v1alpha1ToV1beta1: true
storageVersion: v1alpha1
Expand Down
9 changes: 8 additions & 1 deletion pkg/resourceskeleton/resourceskeleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func NewFromURI(uri string, smLoader *servicemappingloader.ServiceMappingLoader,
if err != nil {
return nil, fmt.Errorf("error parsing '%v' as url: %w", uri, err)
}
sm, rc, err := uri2.GetServiceMappingAndResourceConfig(smLoader, parsedURL.Host, parsedURL.Path)
canonicalHost := trimRegionPrefix(parsedURL.Host) // e.g. "us-central1-aiplatform.googleapis.com" -> "aiplatform.googleapis.com"
sm, rc, err := uri2.GetServiceMappingAndResourceConfig(smLoader, canonicalHost, parsedURL.Path)
if err != nil {
return nil, fmt.Errorf("error getting service mapping and resource config for url '%v': %w", uri, err)
}
Expand Down Expand Up @@ -230,3 +231,9 @@ func parseIAMCustomRoleID(id string) (*iamCustomRoleID, error) {
}
return &value, nil
}

func trimRegionPrefix(host string) string {
// e.g. "us-central1-aiplatform.googleapis.com" -> "aiplatform.googleapis.com"
parts := strings.Split(host, "-")
return parts[len(parts)-1]
}
16 changes: 12 additions & 4 deletions pkg/resourceskeleton/testdata/uri-skeleton.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1030,13 +1030,21 @@
- ExpectedSkeleton: null
ResourceConfigId: EdgeContainerVpnConnection
URI: "https://edgecontainer.googleapis.com/v1/projects/kcc-test/locations/us-central1/vpnConnections/edgecontainervpnconnection-test"
- ExpectedSkeleton: null
- ExpectedSkeleton: null # VertexAIDataset does not support import
ResourceConfigId: VertexAIDataset
URI: "https://us-central1-aiplatform.googleapis.com/v1beta1/projects/kcc-test/locations/us-central1/datasets/1234567890?alt=json"
- ExpectedSkeleton: null
URI: ""
- ExpectedSkeleton:
apiVersion: vertexai.cnrm.cloud.google.com/v1beta1
kind: VertexAIEndpoint
metadata:
name: vertexaiendpoint-test
spec:
projectRef:
external: kcc-test
region: us-central1
ResourceConfigId: VertexAIEndpoint
URI: "https://us-central1-aiplatform.googleapis.com/v1beta1/projects/kcc-test/locations/us-central1/endpoints/vertexaiendpoint-test"
- ExpectedSkeleton: null
- ExpectedSkeleton: null # https://github.com/GoogleCloudPlatform/k8s-config-connector/pull/2244/files#r1674798837
ResourceConfigId: VertexAIIndex
URI: "https://us-central1-aiplatform.googleapis.com/v1beta1/projects/kcc-test/locations/us-central1/indexes/vertexaiindex-test"
- ExpectedSkeleton: null
Expand Down

0 comments on commit 120cc63

Please sign in to comment.