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

tool: add update-types sync command to synchronize go types with proto definitions #3401

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 25 additions & 6 deletions apis/bigquerydatatransfer/v1beta1/transferconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ type EncryptionConfiguration struct {
type Status struct {
// The status code, which should be an enum value of
// [google.rpc.Code][google.rpc.Code].
// +kcc:proto:field=google.rpc.Status.code
Code *int32 `json:"code,omitempty"`

// A developer-facing error message, which should be in English. Any
// user-facing error message should be localized and sent in the
// [google.rpc.Status.details][google.rpc.Status.details] field, or localized
// by the client.
// +kcc:proto:field=google.rpc.Status.message
Message *string `json:"message,omitempty"`

/* NOTYET
Expand All @@ -63,14 +65,16 @@ type BigQueryDataTransferConfigSpec struct {
// for just [today-1].
// Only valid if the data source supports the feature. Set the value to 0
// to use the default value.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.data_refresh_window_days
DataRefreshWindowDays *int32 `json:"dataRefreshWindowDays,omitempty"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="DataSourceID field is immutable"
// Immutable.
// +required
// Data source ID. This cannot be changed once data transfer is created. The
// full list of available data source IDs can be returned through an API call:
// https://cloud.google.com/bigquery-transfer/docs/reference/datatransfer/rest/v1/projects.locations.dataSources/list
// +required
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.data_source_id
DataSourceID *string `json:"dataSourceID,omitempty"`

// The BigQuery target dataset id.
Expand All @@ -79,31 +83,36 @@ type BigQueryDataTransferConfigSpec struct {

// Is this config disabled. When set to true, no runs will be scheduled for
// this transfer config.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.disabled
Disabled *bool `json:"disabled,omitempty"`

// User specified display name for the data transfer.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.display_name
DisplayName *string `json:"displayName,omitempty"`

// Email notifications will be sent according to these preferences
// to the email address of the user who owns this transfer config.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.email_preferences
EmailPreferences *EmailPreferences `json:"emailPreferences,omitempty"`

// The encryption configuration part. Currently, it is only used for the
// optional KMS key name. The BigQuery service account of your project must be
// granted permissions to use the key. Read methods will return the key name
// applied in effect. Write methods will apply the key if it is present, or
// otherwise try to apply project default keys if it is absent.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.encryption_configuration
EncryptionConfiguration *EncryptionConfiguration `json:"encryptionConfiguration,omitempty"`

// Pub/Sub topic where notifications will be sent after transfer runs
// associated with this transfer config finish.
PubSubTopicRef *refv1beta1.PubSubTopicRef `json:"pubSubTopicRef,omitempty"`

// +required
// Parameters specific to each data source. For more information see the
// bq tab in the 'Setting up a data transfer' section for each data source.
// For example the parameters for Cloud Storage transfers are listed here:
// https://cloud.google.com/bigquery-transfer/docs/cloud-storage-transfer#bq
// +required
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.params
Params map[string]string `json:"params,omitempty"`

Parent `json:",inline"`
Expand All @@ -125,9 +134,11 @@ type BigQueryDataTransferConfigSpec struct {
//
// NOTE: The minimum interval time between recurring transfers depends on the
// data source; refer to the documentation for your data source.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.schedule
Schedule *string `json:"schedule,omitempty"`

// Options customizing the data transfer schedule.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.schedule_options
ScheduleOptions *ScheduleOptions `json:"scheduleOptions,omitempty"`

// Service account email. If this field is set, the transfer config will be created with this service account's credentials.
Expand All @@ -136,10 +147,10 @@ type BigQueryDataTransferConfigSpec struct {
// For the latest list of data sources, please refer to https://cloud.google.com/bigquery/docs/use-service-accounts.
ServiceAccountRef *refv1beta1.IAMServiceAccountRef `json:"serviceAccountRef,omitempty"`

// V2 options customizing different types of data transfer schedule.
// This field supports existing time-based and manual transfer schedule. Also
// supports Event-Driven transfer schedule. ScheduleOptionsV2 cannot be used
// together with ScheduleOptions/Schedule.
// Options customizing different types of data transfer schedule.
// This field replaces "schedule" and "schedule_options" fields.
// ScheduleOptionsV2 cannot be used together with ScheduleOptions/Schedule.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.schedule_options_v2
ScheduleOptionsV2 *ScheduleOptionsV2 `json:"scheduleOptionsV2,omitempty"`
}

Expand Down Expand Up @@ -173,6 +184,7 @@ type BigQueryDataTransferConfigStatus struct {
// +kcc:proto=google.cloud.bigquery.datatransfer.v1.TransferConfig
type BigQueryDataTransferConfigObservedState struct {
// Output only. Region in which BigQuery dataset is located.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.dataset_region
DatasetRegion *string `json:"datasetRegion,omitempty"`

// Identifier. The resource name of the transfer config.
Expand All @@ -182,27 +194,34 @@ type BigQueryDataTransferConfigObservedState struct {
// where `config_id` is usually a UUID, even though it is not
// guaranteed or required. The name is ignored when creating a transfer
// config.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.name
Name *string `json:"name,omitempty"`

// Output only. Next time when data transfer will run.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.next_run_time
NextRunTime *string `json:"nextRunTime,omitempty"`

// Output only. Information about the user whose credentials are used to
// transfer data. Populated only for `transferConfigs.get` requests. In case
// the user information is not available, this field will not be populated.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.owner_info
OwnerInfo *UserInfo `json:"ownerInfo,omitempty"`

// Output only. State of the most recently updated transfer run.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.state
State *string `json:"state,omitempty"`

// Output only. Data transfer modification time. Ignored by server on input.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.update_time
UpdateTime *string `json:"updateTime,omitempty"`

// Deprecated. Unique ID of the user on whose behalf transfer is done.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.user_id
UserID *int64 `json:"userID,omitempty"`

// Output only. Error code with detailed information about reason of the
// latest config failure.
// +kcc:proto:field=google.cloud.bigquery.datatransfer.v1.TransferConfig.error
Error *Status `json:"error,omitempty"`
}

Expand Down
13 changes: 13 additions & 0 deletions apis/bigquerydatatransfer/v1beta1/types.generated.go

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 @@ -664,10 +664,9 @@ spec:
type: string
type: object
scheduleOptionsV2:
description: V2 options customizing different types of data transfer
schedule. This field supports existing time-based and manual transfer
schedule. Also supports Event-Driven transfer schedule. ScheduleOptionsV2
cannot be used together with ScheduleOptions/Schedule.
description: Options customizing different types of data transfer
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schedule. This field replaces "schedule" and "schedule_options"
fields. ScheduleOptionsV2 cannot be used together with ScheduleOptions/Schedule.
properties:
eventDrivenSchedule:
description: Event driven transfer schedule options. If set, the
Expand Down
52 changes: 52 additions & 0 deletions dev/tools/controllerbuilder/pkg/codegen/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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.

package codegen

import "strings"

const (
// KCCProtoMessageAnnotation is used for go structs that map to proto messages
KCCProtoMessageAnnotation = "+kcc:proto"

// KCCProtoFieldAnnotation is used for go struct fields that map to proto fields
KCCProtoFieldAnnotation = "+kcc:proto:field"

// KCCProtoIgnoreAnnotation is used for go struct fields that are ignored
KCCProtoIgnoreAnnotation = "+kcc:proto:ignore"
)

// special-case proto messages that are currently not mapped to KRM Go structs
var protoMessagesNotMappedToGoStruct = map[string]string{
"google.protobuf.Timestamp": "string",
"google.protobuf.Duration": "string",
"google.protobuf.Int64Value": "int64",
"google.protobuf.StringValue": "string",
"google.protobuf.Struct": "map[string]string",
}

var Acronyms = []string{
"ID", "HTML", "URL", "HTTP", "HTTPS", "SSH",
"IP", "GB", "FS", "PD", "KMS", "GCE", "VTPM",
}

// IsAcronym returns true if the given string is an acronym
func IsAcronym(s string) bool {
for _, acronym := range Acronyms {
if strings.EqualFold(s, acronym) {
return true
}
}
return false
}
Loading
Loading