Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve listing #3333

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/bigqueryanalyticshub/v1alpha1/listing_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apis/bigqueryanalyticshub/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions mockgcp/mockbigqueryanalyticshub/analyticshub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
19 changes: 9 additions & 10 deletions pkg/controller/direct/bigqueryanalyticshub/listing_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/direct/bigqueryanalyticshub/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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: {}
Original file line number Diff line number Diff line change
Expand Up @@ -197,29 +197,31 @@ 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

{
"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"
}
Expand All @@ -230,7 +232,7 @@ Grpc-Metadata-Content-Type: application/grpc

{
"bigqueryDataset": {
"dataset": "",
"dataset": "projects/${projectId}/datasets/bigquerydataset${uniqueId}",
"restrictedExportPolicy": null,
"selectedResources": []
},
Expand All @@ -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": "",
Expand All @@ -251,18 +253,18 @@ 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
Grpc-Metadata-Content-Type: application/grpc

{
"bigqueryDataset": {
"dataset": "",
"dataset": "projects/${projectId}/datasets/bigquerydataset${uniqueId}",
"restrictedExportPolicy": null,
"selectedResources": []
},
Expand All @@ -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": "",
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,4 +27,4 @@ spec:
name: bigqueryanalyticshubdataexchange${uniqueId}
projectRef:
external: ${projectId}
resourceID: bigqueryanalyticshublisting-${uniqueId}
resourceID: bigqueryanalyticshublisting${uniqueId}
Original file line number Diff line number Diff line change
@@ -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}
Loading