diff --git a/apis/bigqueryanalyticshub/v1alpha1/listing_types.go b/apis/bigqueryanalyticshub/v1alpha1/listing_types.go index 6bcedbcb21..cd5f72c925 100644 --- a/apis/bigqueryanalyticshub/v1alpha1/listing_types.go +++ b/apis/bigqueryanalyticshub/v1alpha1/listing_types.go @@ -37,7 +37,7 @@ type BigQueryDatasetSource struct { // +required // Resource name of the dataset source for this listing. // e.g. `projects/myproject/datasets/123` - Dataset *refv1beta1.BigQueryDatasetRef `json:"datasetRef,omitempty"` + DatasetRef *refv1beta1.BigQueryDatasetRef `json:"datasetRef,omitempty"` // Optional. Resources in this dataset that are selectively shared. // If this field is empty, then the entire dataset (all resources) are diff --git a/apis/bigqueryanalyticshub/v1alpha1/zz_generated.deepcopy.go b/apis/bigqueryanalyticshub/v1alpha1/zz_generated.deepcopy.go index aa552d85b9..e7ca76b60e 100644 --- a/apis/bigqueryanalyticshub/v1alpha1/zz_generated.deepcopy.go +++ b/apis/bigqueryanalyticshub/v1alpha1/zz_generated.deepcopy.go @@ -456,8 +456,8 @@ func (in *BigQueryAnalyticsHubListingStatus) DeepCopy() *BigQueryAnalyticsHubLis // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BigQueryDatasetSource) DeepCopyInto(out *BigQueryDatasetSource) { *out = *in - if in.Dataset != nil { - in, out := &in.Dataset, &out.Dataset + if in.DatasetRef != nil { + in, out := &in.DatasetRef, &out.DatasetRef *out = new(v1beta1.BigQueryDatasetRef) **out = **in } diff --git a/mockgcp/mockbigqueryanalyticshub/analyticshub.go b/mockgcp/mockbigqueryanalyticshub/analyticshub.go index 69786ef77a..f9a1c9f11a 100644 --- a/mockgcp/mockbigqueryanalyticshub/analyticshub.go +++ b/mockgcp/mockbigqueryanalyticshub/analyticshub.go @@ -167,6 +167,8 @@ func (a *analyticsHubServer) UpdateListing(ctx context.Context, request *pb.Upda for _, path := range request.GetUpdateMask().Paths { switch path { + case "displayName": + obj.DisplayName = request.Listing.GetDisplayName() default: return nil, status.Errorf(codes.InvalidArgument, "field %q is not yet handled in mock", path) } diff --git a/pkg/controller/direct/bigqueryanalyticshub/listing_controller.go b/pkg/controller/direct/bigqueryanalyticshub/listing_controller.go index 31bb2244e0..183bc69254 100644 --- a/pkg/controller/direct/bigqueryanalyticshub/listing_controller.go +++ b/pkg/controller/direct/bigqueryanalyticshub/listing_controller.go @@ -95,24 +95,21 @@ func (m *modelListing) AdapterForObject(ctx context.Context, reader client.Reade } func resolveOptionalReferences(ctx context.Context, reader client.Reader, obj *krm.BigQueryAnalyticsHubListing) error { - if ref := obj.Spec.DataExchangeRef; ref != nil { - _, err := ref.NormalizedExternal(ctx, reader, obj.GetNamespace()) - if err != nil { - return fmt.Errorf("failed to resolve optional DataExchangeRef: %w", err) - } - } - if obj.Spec.Source != nil && obj.Spec.Source.BigQueryDatasetSource != nil { - if ref := obj.Spec.Source.BigQueryDatasetSource.Dataset; ref != nil { - if _, err := refs.ResolveBigQueryDataset(ctx, reader, obj, ref); err != nil { + if ref := obj.Spec.Source.BigQueryDatasetSource.DatasetRef; ref != nil { + datasetID, err := refs.ResolveBigQueryDataset(ctx, reader, obj, ref) + if err != nil { return err } + obj.Spec.Source.BigQueryDatasetSource.DatasetRef.External = datasetID.String() for _, selectedResource := range obj.Spec.Source.BigQueryDatasetSource.SelectedResources { if ref := selectedResource.TableRef; ref != nil { - if _, err := refs.ResolveBigQueryTable(ctx, reader, obj, ref); err != nil { + tableID, err := refs.ResolveBigQueryTable(ctx, reader, obj, ref) + if err != nil { return err } + selectedResource.TableRef.External = tableID.String() } } } @@ -200,6 +197,8 @@ func (a *ListingAdapter) Update(ctx context.Context, updateOp *directbase.Update return mapCtx.Err() } + resource.Name = a.id.External + updateMask := &fieldmaskpb.FieldMask{} if a.desired.Spec.DisplayName != nil && !reflect.DeepEqual(a.desired.Spec.DisplayName, a.actual.DisplayName) { updateMask.Paths = append(updateMask.Paths, "display_name") diff --git a/pkg/controller/direct/bigqueryanalyticshub/mapper.go b/pkg/controller/direct/bigqueryanalyticshub/mapper.go index e3786945b9..6d56967378 100644 --- a/pkg/controller/direct/bigqueryanalyticshub/mapper.go +++ b/pkg/controller/direct/bigqueryanalyticshub/mapper.go @@ -111,8 +111,8 @@ func Listing_BigQueryDatasetSource_FromProto(mapCtx *direct.MapContext, in *pb.L return nil } out := &krmv1alpha1.BigQueryDatasetSource{} - if out.Dataset != nil { - out.Dataset = &refs.BigQueryDatasetRef{ + if out.DatasetRef != nil { + out.DatasetRef = &refs.BigQueryDatasetRef{ External: in.Dataset, } } @@ -254,9 +254,9 @@ func Listing_BigQueryDatasetSource_ToProto(mapCtx *direct.MapContext, in *krmv1a } out := &pb.Listing_BigqueryDataset{} - if in.Dataset != nil { + if in.DatasetRef != nil { out.BigqueryDataset = &pb.Listing_BigQueryDatasetSource{ - Dataset: in.Dataset.External, + Dataset: in.DatasetRef.External, } } diff --git a/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/_generated_object_bigqueryanalyticshublisting-base.golden.yaml b/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/_generated_object_bigqueryanalyticshublisting-base.golden.yaml index 73197a2031..b5d022ad35 100644 --- a/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/_generated_object_bigqueryanalyticshublisting-base.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/_generated_object_bigqueryanalyticshublisting-base.golden.yaml @@ -6,19 +6,19 @@ metadata: finalizers: - cnrm.cloud.google.com/finalizer - cnrm.cloud.google.com/deletion-defender - generation: 1 + generation: 2 labels: cnrm-test: "true" - name: bigqueryanalyticshublisting-${uniqueId} + name: bigqueryanalyticshublisting${uniqueId} namespace: ${uniqueId} spec: dataExchangeRef: name: bigqueryanalyticshubdataexchange${uniqueId} - displayName: my_data_exchange + displayName: updated_name location: US projectRef: external: ${projectId} - resourceID: bigqueryanalyticshublisting-${uniqueId} + resourceID: bigqueryanalyticshublisting${uniqueId} source: bigQueryDatasetSource: datasetRef: @@ -30,6 +30,6 @@ status: reason: UpToDate status: "True" type: Ready - externalRef: projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting-${uniqueId} - observedGeneration: 1 + externalRef: projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting${uniqueId} + observedGeneration: 2 observedState: {} diff --git a/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/_http.log b/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/_http.log index 6353eafba1..293f3c5a87 100644 --- a/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/_http.log @@ -197,10 +197,10 @@ Grpc-Metadata-Content-Type: application/grpc --- -GET https://analyticshub.googleapis.com/v1/projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting-${uniqueId} +GET https://analyticshub.googleapis.com/v1/projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting${uniqueId} Content-Type: application/json User-Agent: kcc/controller-manager -x-goog-request-params: name=projects%2F${projectId}%2Flocations%2FUS%2FdataExchanges%2Fbigqueryanalyticshubdataexchange${uniqueId}%2Flistings%2Fbigqueryanalyticshublisting-${uniqueId} +x-goog-request-params: name=projects%2F${projectId}%2Flocations%2FUS%2FdataExchanges%2Fbigqueryanalyticshubdataexchange${uniqueId}%2Flistings%2Fbigqueryanalyticshublisting${uniqueId} 404 Not Found Content-Type: application/json @@ -208,18 +208,20 @@ Content-Type: application/json { "code": 5, "details": [], - "message": "listing \"projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting-${uniqueId}\" not found" + "message": "listing \"projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting${uniqueId}\" not found" } --- -POST https://analyticshub.googleapis.com/v1/projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings?listingId=bigqueryanalyticshublisting-${uniqueId} +POST https://analyticshub.googleapis.com/v1/projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings?listingId=bigqueryanalyticshublisting${uniqueId} Content-Type: application/json User-Agent: kcc/controller-manager x-goog-request-params: parent=projects%2F${projectId}%2Flocations%2FUS%2FdataExchanges%2Fbigqueryanalyticshubdataexchange${uniqueId} { - "bigqueryDataset": {}, + "bigqueryDataset": { + "dataset": "projects/${projectId}/datasets/bigquerydataset${uniqueId}" + }, "discoveryType": 0, "displayName": "my_data_exchange" } @@ -230,7 +232,7 @@ Grpc-Metadata-Content-Type: application/grpc { "bigqueryDataset": { - "dataset": "", + "dataset": "projects/${projectId}/datasets/bigquerydataset${uniqueId}", "restrictedExportPolicy": null, "selectedResources": [] }, @@ -241,7 +243,7 @@ Grpc-Metadata-Content-Type: application/grpc "displayName": "my_data_exchange", "documentation": "", "icon": "", - "name": "projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting-${uniqueId}", + "name": "projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting${uniqueId}", "primaryContact": "", "publisher": null, "requestAccess": "", @@ -251,10 +253,10 @@ Grpc-Metadata-Content-Type: application/grpc --- -GET https://analyticshub.googleapis.com/v1/projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting-${uniqueId} +GET https://analyticshub.googleapis.com/v1/projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting${uniqueId} Content-Type: application/json User-Agent: kcc/controller-manager -x-goog-request-params: name=projects%2F${projectId}%2Flocations%2FUS%2FdataExchanges%2Fbigqueryanalyticshubdataexchange${uniqueId}%2Flistings%2Fbigqueryanalyticshublisting-${uniqueId} +x-goog-request-params: name=projects%2F${projectId}%2Flocations%2FUS%2FdataExchanges%2Fbigqueryanalyticshubdataexchange${uniqueId}%2Flistings%2Fbigqueryanalyticshublisting${uniqueId} 200 OK Content-Type: application/json @@ -262,7 +264,7 @@ Grpc-Metadata-Content-Type: application/grpc { "bigqueryDataset": { - "dataset": "", + "dataset": "projects/${projectId}/datasets/bigquerydataset${uniqueId}", "restrictedExportPolicy": null, "selectedResources": [] }, @@ -273,7 +275,80 @@ Grpc-Metadata-Content-Type: application/grpc "displayName": "my_data_exchange", "documentation": "", "icon": "", - "name": "projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting-${uniqueId}", + "name": "projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting${uniqueId}", + "primaryContact": "", + "publisher": null, + "requestAccess": "", + "restrictedExportConfig": null, + "state": "STATE_UNSPECIFIED" +} + +--- + +PATCH https://analyticshub.googleapis.com/v1/projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting${uniqueId}?updateMask=displayName +Content-Type: application/json +User-Agent: kcc/controller-manager +x-goog-request-params: listing.name=projects%2F${projectId}%2Flocations%2FUS%2FdataExchanges%2Fbigqueryanalyticshubdataexchange${uniqueId}%2Flistings%2Fbigqueryanalyticshublisting${uniqueId} + +{ + "bigqueryDataset": { + "dataset": "projects/${projectId}/datasets/bigquerydataset${uniqueId}" + }, + "discoveryType": 0, + "displayName": "updated_name", + "name": "projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting${uniqueId}" +} + +200 OK +Content-Type: application/json +Grpc-Metadata-Content-Type: application/grpc + +{ + "bigqueryDataset": { + "dataset": "projects/${projectId}/datasets/bigquerydataset${uniqueId}", + "restrictedExportPolicy": null, + "selectedResources": [] + }, + "categories": [], + "dataProvider": null, + "description": "", + "discoveryType": "DISCOVERY_TYPE_UNSPECIFIED", + "displayName": "updated_name", + "documentation": "", + "icon": "", + "name": "projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting${uniqueId}", + "primaryContact": "", + "publisher": null, + "requestAccess": "", + "restrictedExportConfig": null, + "state": "STATE_UNSPECIFIED" +} + +--- + +GET https://analyticshub.googleapis.com/v1/projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting${uniqueId} +Content-Type: application/json +User-Agent: kcc/controller-manager +x-goog-request-params: name=projects%2F${projectId}%2Flocations%2FUS%2FdataExchanges%2Fbigqueryanalyticshubdataexchange${uniqueId}%2Flistings%2Fbigqueryanalyticshublisting${uniqueId} + +200 OK +Content-Type: application/json +Grpc-Metadata-Content-Type: application/grpc + +{ + "bigqueryDataset": { + "dataset": "projects/${projectId}/datasets/bigquerydataset${uniqueId}", + "restrictedExportPolicy": null, + "selectedResources": [] + }, + "categories": [], + "dataProvider": null, + "description": "", + "discoveryType": "DISCOVERY_TYPE_UNSPECIFIED", + "displayName": "updated_name", + "documentation": "", + "icon": "", + "name": "projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting${uniqueId}", "primaryContact": "", "publisher": null, "requestAccess": "", @@ -283,10 +358,10 @@ Grpc-Metadata-Content-Type: application/grpc --- -DELETE https://analyticshub.googleapis.com/v1/projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting-${uniqueId} +DELETE https://analyticshub.googleapis.com/v1/projects/${projectId}/locations/US/dataExchanges/bigqueryanalyticshubdataexchange${uniqueId}/listings/bigqueryanalyticshublisting${uniqueId} Content-Type: application/json User-Agent: kcc/controller-manager -x-goog-request-params: name=projects%2F${projectId}%2Flocations%2FUS%2FdataExchanges%2Fbigqueryanalyticshubdataexchange${uniqueId}%2Flistings%2Fbigqueryanalyticshublisting-${uniqueId} +x-goog-request-params: name=projects%2F${projectId}%2Flocations%2FUS%2FdataExchanges%2Fbigqueryanalyticshubdataexchange${uniqueId}%2Flistings%2Fbigqueryanalyticshublisting${uniqueId} 200 OK Content-Type: application/json diff --git a/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/create.yaml b/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/create.yaml index 7e6ff4f592..aa269497cb 100644 --- a/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/create.yaml +++ b/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/create.yaml @@ -15,7 +15,7 @@ apiVersion: bigqueryanalyticshub.cnrm.cloud.google.com/v1alpha1 kind: BigQueryAnalyticsHubListing metadata: - name: bigqueryanalyticshublisting-${uniqueId} + name: bigqueryanalyticshublisting${uniqueId} spec: displayName: my_data_exchange location: US @@ -27,4 +27,4 @@ spec: name: bigqueryanalyticshubdataexchange${uniqueId} projectRef: external: ${projectId} - resourceID: bigqueryanalyticshublisting-${uniqueId} \ No newline at end of file + resourceID: bigqueryanalyticshublisting${uniqueId} \ No newline at end of file diff --git a/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/update.yaml b/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/update.yaml new file mode 100644 index 0000000000..db73571317 --- /dev/null +++ b/pkg/test/resourcefixture/testdata/basic/bigqueryanalyticshub/v1alpha1/bigqueryanalyticshublisting-base/update.yaml @@ -0,0 +1,30 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: bigqueryanalyticshub.cnrm.cloud.google.com/v1alpha1 +kind: BigQueryAnalyticsHubListing +metadata: + name: bigqueryanalyticshublisting${uniqueId} +spec: + displayName: updated_name + location: US + source: + bigQueryDatasetSource: + datasetRef: + name: bigquerydataset${uniqueId} + dataExchangeRef: + name: bigqueryanalyticshubdataexchange${uniqueId} + projectRef: + external: ${projectId} + resourceID: bigqueryanalyticshublisting${uniqueId} \ No newline at end of file