in pkg/controller/direct/bigqueryanalyticshub/listing_controller.go [188:283]
func (a *ListingAdapter) Update(ctx context.Context, updateOp *directbase.UpdateOperation) error {
log := klog.FromContext(ctx).WithName(listingCtrlName)
log.V(2).Info("updating Listing", "name", a.id.External)
mapCtx := &direct.MapContext{}
desired := a.desired.DeepCopy()
resource := BigQueryAnalyticsHubListingSpec_ToProto(mapCtx, &desired.Spec)
if mapCtx.Err() != nil {
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")
}
if a.desired.Spec.Description != nil && !reflect.DeepEqual(a.desired.Spec.Description, a.actual.Description) {
updateMask.Paths = append(updateMask.Paths, "description")
}
if a.desired.Spec.PrimaryContact != nil && !reflect.DeepEqual(a.desired.Spec.PrimaryContact, a.actual.PrimaryContact) {
updateMask.Paths = append(updateMask.Paths, "primary_contact")
}
if a.desired.Spec.Documentation != nil && !reflect.DeepEqual(a.desired.Spec.Documentation, a.actual.Documentation) {
updateMask.Paths = append(updateMask.Paths, "documentation")
}
if a.desired.Spec.DiscoveryType != nil && !reflect.DeepEqual(a.desired.Spec.DiscoveryType, a.actual.DiscoveryType.String()) {
updateMask.Paths = append(updateMask.Paths, "discovery_type")
}
if a.desired.Spec.RequestAccess != nil && reflect.DeepEqual(a.desired.Spec.RequestAccess, a.actual.RequestAccess) {
updateMask.Paths = append(updateMask.Paths, "request_access")
}
// NOT YET
// if a.desired.Spec.Icon != nil && !reflect.DeepEqual(a.desired.Spec.Icon, a.actual.Icon) {
// updateMask.Paths = append(updateMask.Paths, "icon")
// }
if a.desired.Spec.DataProvider != nil {
mapCtx := &direct.MapContext{}
toProto := DataProvider_ToProto(mapCtx, a.desired.Spec.DataProvider)
if mapCtx.Err() != nil {
return fmt.Errorf("converting data provider: %w", mapCtx.Err())
}
if !reflect.DeepEqual(toProto, a.actual.DataProvider) {
updateMask.Paths = append(updateMask.Paths, "data_provider")
}
}
if a.desired.Spec.Publisher != nil {
mapCtx := &direct.MapContext{}
toProto := Publisher_ToProto(mapCtx, a.desired.Spec.Publisher)
if mapCtx.Err() != nil {
return fmt.Errorf("converting publisher: %w", mapCtx.Err())
}
if !reflect.DeepEqual(toProto, a.actual.Publisher) {
updateMask.Paths = append(updateMask.Paths, "publisher")
}
}
if a.desired.Spec.Categories != nil {
mapCtx := &direct.MapContext{}
toProto := Categories_ToProto(mapCtx, a.desired.Spec.Categories)
if mapCtx.Err() != nil {
return fmt.Errorf("converting categories: %w", mapCtx.Err())
}
if !reflect.DeepEqual(toProto, a.actual.Categories) {
updateMask.Paths = append(updateMask.Paths, "categories")
}
}
if len(updateMask.Paths) == 0 {
log.V(2).Info("no field needs update", "name", a.id.External)
return nil
}
req := &bigqueryanalyticshubpb.UpdateListingRequest{
UpdateMask: updateMask,
Listing: resource,
}
updated, err := a.gcpClient.UpdateListing(ctx, req)
if err != nil {
return fmt.Errorf("updating Listing %s: %w", a.id.External, err)
}
log.V(2).Info("successfully updated Listing", "name", a.id.External)
status := &krm.BigQueryAnalyticsHubListingStatus{}
status.ObservedState = BigQueryAnalyticsHubListingObservedState_FromProto(mapCtx, updated)
if mapCtx.Err() != nil {
return mapCtx.Err()
}
return updateOp.UpdateStatus(ctx, status, nil)
}