Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyih committed Nov 12, 2024
1 parent d7be493 commit 63eb7f6
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 22 deletions.
3 changes: 1 addition & 2 deletions apis/bigqueryconnection/v1alpha1/connection_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ type Parent struct {
type BigQueryConnectionConnectionSpec struct {
Parent `json:",inline"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="ResourceID field is immutable"
// Immutable. Optional.
// The BigQuery Connection ID used for resource creation or acquisition.
// For creation: If specified, this value is used as the connection ID. If not provided, a UUID is generated and stored in the `status.ExternalRef` field.
// For creation: If specified, this value is used as the connection ID. If not provided, a UUID will be generated and assigned as the connection ID.
// For acquisition: This field must be provided to identify the connection resource to acquire.
ResourceID *string `json:"resourceID,omitempty"`

Expand Down
9 changes: 5 additions & 4 deletions apis/bigqueryconnection/v1beta1/connection_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,16 @@ func (r *BigQueryConnectionConnectionRef) Parent() (string, error) {
return "", fmt.Errorf("BigQueryConnectionConnectionRef not normalized to External form or not created from `New()`")
}

func (r *BigQueryConnectionConnectionRef) ConnectionID() (string, error) {
// ConnectionID returns the connection ID, a boolean indicating whether the connection ID is specified by user (or generated by service), and an error.
func (r *BigQueryConnectionConnectionRef) ConnectionID() (string, bool, error) {
if r.External != "" {
_, _, id, err := parseExternal(r.External)
if err != nil {
return "", err
return "", false, err
}
return id, nil
return id, id != "", nil
}
return "", fmt.Errorf("BigQueryConnectionConnectionRef not normalized to External form or not created from `New()`")
return "", false, fmt.Errorf("BigQueryConnectionConnectionRef not normalized to External form or not created from `New()`")
}

// NormalizedExternal provision the "External" value.
Expand Down
3 changes: 1 addition & 2 deletions apis/bigqueryconnection/v1beta1/connection_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ type Parent struct {
type BigQueryConnectionConnectionSpec struct {
Parent `json:",inline"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="ResourceID field is immutable"
// Immutable. Optional.
// The BigQuery Connection ID used for resource creation or acquisition.
// For creation: If specified, this value is used as the connection ID. If not provided, a UUID is generated and stored in the `status.ExternalRef` field.
// For creation: If specified, this value is used as the connection ID. If not provided, a UUID will be generated and assigned as the connection ID.
// For acquisition: This field must be provided to identify the connection resource to acquire.
ResourceID *string `json:"resourceID,omitempty"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,10 @@ spec:
description: 'Immutable. Optional. The BigQuery Connection ID used
for resource creation or acquisition. For creation: If specified,
this value is used as the connection ID. If not provided, a UUID
is generated and stored in the `status.ExternalRef` field. For acquisition:
will be generated and assigned as the connection ID. For acquisition:
This field must be provided to identify the connection resource
to acquire.'
type: string
x-kubernetes-validations:
- message: ResourceID field is immutable
rule: self == oldSelf
spark:
description: Spark properties.
properties:
Expand Down Expand Up @@ -808,13 +805,10 @@ spec:
description: 'Immutable. Optional. The BigQuery Connection ID used
for resource creation or acquisition. For creation: If specified,
this value is used as the connection ID. If not provided, a UUID
is generated and stored in the `status.ExternalRef` field. For acquisition:
will be generated and assigned as the connection ID. For acquisition:
This field must be provided to identify the connection resource
to acquire.'
type: string
x-kubernetes-validations:
- message: ResourceID field is immutable
rule: self == oldSelf
spark:
description: Spark properties.
properties:
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ func (a *Adapter) Find(ctx context.Context) (bool, error) {

log.V(2).Info("getting BigQueryConnectionConnection", "name", a.id.External)

id, err := a.id.ConnectionID()
_, idIsSet, err := a.id.ConnectionID()
if err != nil {
return false, err
}
if id == "" { // resource is not yet created
if !idIsSet { // resource is not yet created
return false, nil
}
req := &bigqueryconnectionpb.GetConnectionRequest{Name: a.id.External}
Expand Down Expand Up @@ -220,11 +220,11 @@ func (a *Adapter) Create(ctx context.Context, createOp *directbase.CreateOperati
Parent: parent,
Connection: resource,
}
id, err := a.id.ConnectionID()
id, isIsSet, err := a.id.ConnectionID()
if err != nil {
return err
}
if id != "" { // this means user has specified connection ID in `spec.ResourceID` field.
if isIsSet { // during "Create", this means user has specified connection ID in `spec.ResourceID` field.
req = &bigqueryconnectionpb.CreateConnectionRequest{
Parent: parent,
ConnectionId: id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ spark:
</td>
<td>
<p><code class="apitype">string</code></p>
<p>{% verbatim %}Immutable. Optional. The BigQuery Connection ID used for resource creation or acquisition. For creation: If specified, this value is used as the connection ID. If not provided, a UUID is generated and stored in the `status.ExternalRef` field. For acquisition: This field must be provided to identify the connection resource to acquire.{% endverbatim %}</p>
<p>{% verbatim %}Immutable. Optional. The BigQuery Connection ID used for resource creation or acquisition. For creation: If specified, this value is used as the connection ID. If not provided, a UUID will be generated and assigned as the connection ID. For acquisition: This field must be provided to identify the connection resource to acquire.{% endverbatim %}</p>
</td>
</tr>
<tr>
Expand Down

0 comments on commit 63eb7f6

Please sign in to comment.