From cc1c58de4b8ab36d3d7fb99edcc9331f76169c5d Mon Sep 17 00:00:00 2001 From: Gemma Hou Date: Thu, 13 Mar 2025 23:08:23 +0000 Subject: [PATCH 1/7] conductor: "Generated types and mapper for BigtableAuthorizedView" --- .../v1alpha1/authorizedview_identity.go | 118 ++++++++++++++++++ .../v1alpha1/authorizedview_reference.go | 83 ++++++++++++ .../bigtable/v1alpha1/authorizedview_types.go | 84 +++++++++++++ apis/bigtable/v1alpha1/types.generated.go | 50 ++++++++ 4 files changed, 335 insertions(+) create mode 100644 apis/bigtable/v1alpha1/authorizedview_identity.go create mode 100644 apis/bigtable/v1alpha1/authorizedview_reference.go create mode 100644 apis/bigtable/v1alpha1/authorizedview_types.go diff --git a/apis/bigtable/v1alpha1/authorizedview_identity.go b/apis/bigtable/v1alpha1/authorizedview_identity.go new file mode 100644 index 00000000000..94d675d7b56 --- /dev/null +++ b/apis/bigtable/v1alpha1/authorizedview_identity.go @@ -0,0 +1,118 @@ +// Copyright 2025 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 v1alpha1 + +import ( + "context" + "fmt" + "strings" + + "github.com/GoogleCloudPlatform/k8s-config-connector/apis/common" + refsv1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +// AuthorizedViewIdentity defines the resource reference to BigtableAuthorizedView, which "External" field +// holds the GCP identifier for the KRM object. +type AuthorizedViewIdentity struct { + parent *AuthorizedViewParent + id string +} + +func (i *AuthorizedViewIdentity) String() string { + return i.parent.String() + "/authorizedviews/" + i.id +} + +func (i *AuthorizedViewIdentity) ID() string { + return i.id +} + +func (i *AuthorizedViewIdentity) Parent() *AuthorizedViewParent { + return i.parent +} + +type AuthorizedViewParent struct { + ProjectID string + Location string +} + +func (p *AuthorizedViewParent) String() string { + return "projects/" + p.ProjectID + "/locations/" + p.Location +} + + +// New builds a AuthorizedViewIdentity from the Config Connector AuthorizedView object. +func NewAuthorizedViewIdentity(ctx context.Context, reader client.Reader, obj *BigtableAuthorizedView) (*AuthorizedViewIdentity, error) { + + // Get Parent + projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef) + if err != nil { + return nil, err + } + projectID := projectRef.ProjectID + if projectID == "" { + return nil, fmt.Errorf("cannot resolve project") + } + location := obj.Spec.Location + + // Get desired ID + resourceID := common.ValueOf(obj.Spec.ResourceID) + if resourceID == "" { + resourceID = obj.GetName() + } + if resourceID == "" { + return nil, fmt.Errorf("cannot resolve resource ID") + } + + // Use approved External + externalRef := common.ValueOf(obj.Status.ExternalRef) + if externalRef != "" { + // Validate desired with actual + actualParent, actualResourceID, err := ParseAuthorizedViewExternal(externalRef) + if err != nil { + return nil, err + } + if actualParent.ProjectID != projectID { + return nil, fmt.Errorf("spec.projectRef changed, expect %s, got %s", actualParent.ProjectID, projectID) + } + if actualParent.Location != location { + return nil, fmt.Errorf("spec.location changed, expect %s, got %s", actualParent.Location, location) + } + if actualResourceID != resourceID { + return nil, fmt.Errorf("cannot reset `metadata.name` or `spec.resourceID` to %s, since it has already assigned to %s", + resourceID, actualResourceID) + } + } + return &AuthorizedViewIdentity{ + parent: &AuthorizedViewParent{ + ProjectID: projectID, + Location: location, + }, + id: resourceID, + }, nil +} + +func ParseAuthorizedViewExternal(external string) (parent *AuthorizedViewParent, resourceID string, err error) { + tokens := strings.Split(external, "/") + if len(tokens) != 6 || tokens[0] != "projects" || tokens[2] != "locations" || tokens[4] != "authorizedviews" { + return nil, "", fmt.Errorf("format of BigtableAuthorizedView external=%q was not known (use projects/{{projectID}}/locations/{{location}}/authorizedviews/{{authorizedviewID}})", external) + } + parent = &AuthorizedViewParent{ + ProjectID: tokens[1], + Location: tokens[3], + } + resourceID = tokens[5] + return parent, resourceID, nil +} diff --git a/apis/bigtable/v1alpha1/authorizedview_reference.go b/apis/bigtable/v1alpha1/authorizedview_reference.go new file mode 100644 index 00000000000..61005865a17 --- /dev/null +++ b/apis/bigtable/v1alpha1/authorizedview_reference.go @@ -0,0 +1,83 @@ +// Copyright 2025 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 v1alpha1 + +import ( + "context" + "fmt" + + refsv1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s" + apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +var _ refsv1beta1.ExternalNormalizer = &AuthorizedViewRef{} + +// AuthorizedViewRef defines the resource reference to BigtableAuthorizedView, which "External" field +// holds the GCP identifier for the KRM object. +type AuthorizedViewRef struct { + // A reference to an externally managed BigtableAuthorizedView resource. + // Should be in the format "projects/{{projectID}}/locations/{{location}}/authorizedviews/{{authorizedviewID}}". + External string `json:"external,omitempty"` + + // The name of a BigtableAuthorizedView resource. + Name string `json:"name,omitempty"` + + // The namespace of a BigtableAuthorizedView resource. + Namespace string `json:"namespace,omitempty"` +} + +// NormalizedExternal provision the "External" value for other resource that depends on BigtableAuthorizedView. +// If the "External" is given in the other resource's spec.BigtableAuthorizedViewRef, the given value will be used. +// Otherwise, the "Name" and "Namespace" will be used to query the actual BigtableAuthorizedView object from the cluster. +func (r *AuthorizedViewRef) NormalizedExternal(ctx context.Context, reader client.Reader, otherNamespace string) (string, error) { + if r.External != "" && r.Name != "" { + return "", fmt.Errorf("cannot specify both name and external on %s reference", BigtableAuthorizedViewGVK.Kind) + } + // From given External + if r.External != "" { + if _, _, err := ParseAuthorizedViewExternal(r.External); err != nil { + return "", err + } + return r.External, nil + } + + // From the Config Connector object + if r.Namespace == "" { + r.Namespace = otherNamespace + } + key := types.NamespacedName{Name: r.Name, Namespace: r.Namespace} + u := &unstructured.Unstructured{} + u.SetGroupVersionKind(BigtableAuthorizedViewGVK) + if err := reader.Get(ctx, key, u); err != nil { + if apierrors.IsNotFound(err) { + return "", k8s.NewReferenceNotFoundError(u.GroupVersionKind(), key) + } + return "", fmt.Errorf("reading referenced %s %s: %w", BigtableAuthorizedViewGVK, key, err) + } + // Get external from status.externalRef. This is the most trustworthy place. + actualExternalRef, _, err := unstructured.NestedString(u.Object, "status", "externalRef") + if err != nil { + return "", fmt.Errorf("reading status.externalRef: %w", err) + } + if actualExternalRef == "" { + return "", k8s.NewReferenceNotReadyError(u.GroupVersionKind(), key) + } + r.External = actualExternalRef + return r.External, nil +} diff --git a/apis/bigtable/v1alpha1/authorizedview_types.go b/apis/bigtable/v1alpha1/authorizedview_types.go new file mode 100644 index 00000000000..5c4fe2fb8e3 --- /dev/null +++ b/apis/bigtable/v1alpha1/authorizedview_types.go @@ -0,0 +1,84 @@ +// Copyright 2025 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 v1alpha1 + +import ( + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/k8s/v1alpha1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +var BigtableAuthorizedViewGVK = GroupVersion.WithKind("BigtableAuthorizedView") + +// BigtableAuthorizedViewSpec defines the desired state of BigtableAuthorizedView +// +kcc:proto=google.bigtable.admin.v2.AuthorizedView +type BigtableAuthorizedViewSpec struct { + // The BigtableAuthorizedView name. If not given, the metadata.name will be used. + ResourceID *string `json:"resourceID,omitempty"` +} + +// BigtableAuthorizedViewStatus defines the config connector machine state of BigtableAuthorizedView +type BigtableAuthorizedViewStatus struct { + /* Conditions represent the latest available observations of the + object's current state. */ + Conditions []v1alpha1.Condition `json:"conditions,omitempty"` + + // ObservedGeneration is the generation of the resource that was most recently observed by the Config Connector controller. If this is equal to metadata.generation, then that means that the current reported status reflects the most recent desired state of the resource. + ObservedGeneration *int64 `json:"observedGeneration,omitempty"` + + // A unique specifier for the BigtableAuthorizedView resource in GCP. + ExternalRef *string `json:"externalRef,omitempty"` + + // ObservedState is the state of the resource as most recently observed in GCP. + ObservedState *BigtableAuthorizedViewObservedState `json:"observedState,omitempty"` +} + +// BigtableAuthorizedViewObservedState is the state of the BigtableAuthorizedView resource as most recently observed in GCP. +// +kcc:proto=google.bigtable.admin.v2.AuthorizedView +type BigtableAuthorizedViewObservedState struct { +} + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// TODO(user): make sure the pluralizaiton below is correct +// +kubebuilder:resource:categories=gcp,shortName=gcpbigtableauthorizedview;gcpbigtableauthorizedviews +// +kubebuilder:subresource:status +// +kubebuilder:metadata:labels="cnrm.cloud.google.com/managed-by-kcc=true";"cnrm.cloud.google.com/system=true" +// +kubebuilder:printcolumn:name="Age",JSONPath=".metadata.creationTimestamp",type="date" +// +kubebuilder:printcolumn:name="Ready",JSONPath=".status.conditions[?(@.type=='Ready')].status",type="string",description="When 'True', the most recent reconcile of the resource succeeded" +// +kubebuilder:printcolumn:name="Status",JSONPath=".status.conditions[?(@.type=='Ready')].reason",type="string",description="The reason for the value in 'Ready'" +// +kubebuilder:printcolumn:name="Status Age",JSONPath=".status.conditions[?(@.type=='Ready')].lastTransitionTime",type="date",description="The last transition time for the value in 'Status'" + +// BigtableAuthorizedView is the Schema for the BigtableAuthorizedView API +// +k8s:openapi-gen=true +type BigtableAuthorizedView struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // +required + Spec BigtableAuthorizedViewSpec `json:"spec,omitempty"` + Status BigtableAuthorizedViewStatus `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// BigtableAuthorizedViewList contains a list of BigtableAuthorizedView +type BigtableAuthorizedViewList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []BigtableAuthorizedView `json:"items"` +} + +func init() { + SchemeBuilder.Register(&BigtableAuthorizedView{}, &BigtableAuthorizedViewList{}) +} diff --git a/apis/bigtable/v1alpha1/types.generated.go b/apis/bigtable/v1alpha1/types.generated.go index de52aa41621..e9cb4e52462 100644 --- a/apis/bigtable/v1alpha1/types.generated.go +++ b/apis/bigtable/v1alpha1/types.generated.go @@ -81,3 +81,53 @@ type Cluster_EncryptionConfig struct { // +kcc:proto:field=google.bigtable.admin.v2.Cluster.EncryptionConfig.kms_key_name KMSKeyRef *refs.KMSCryptoKeyRef `json:"kmsKeyRef,omitempty"` } + +// +kcc:proto=google.bigtable.admin.v2.AuthorizedView +type AuthorizedView struct { + // Identifier. The name of this AuthorizedView. + // Values are of the form + // `projects/{project}/instances/{instance}/tables/{table}/authorizedViews/{authorized_view}` + // +kcc:proto:field=google.bigtable.admin.v2.AuthorizedView.name + Name *string `json:"name,omitempty"` + + // An AuthorizedView permitting access to an explicit subset of a Table. + // +kcc:proto:field=google.bigtable.admin.v2.AuthorizedView.subset_view + SubsetView *AuthorizedView_SubsetView `json:"subsetView,omitempty"` + + // The etag for this AuthorizedView. + // If this is provided on update, it must match the server's etag. The server + // returns ABORTED error on a mismatched etag. + // +kcc:proto:field=google.bigtable.admin.v2.AuthorizedView.etag + Etag *string `json:"etag,omitempty"` + + // Set to true to make the AuthorizedView protected against deletion. + // The parent Table and containing Instance cannot be deleted if an + // AuthorizedView has this bit set. + // +kcc:proto:field=google.bigtable.admin.v2.AuthorizedView.deletion_protection + DeletionProtection *bool `json:"deletionProtection,omitempty"` +} + +// +kcc:proto=google.bigtable.admin.v2.AuthorizedView.FamilySubsets +type AuthorizedView_FamilySubsets struct { + // Individual exact column qualifiers to be included in the AuthorizedView. + // +kcc:proto:field=google.bigtable.admin.v2.AuthorizedView.FamilySubsets.qualifiers + Qualifiers [][]byte `json:"qualifiers,omitempty"` + + // Prefixes for qualifiers to be included in the AuthorizedView. Every + // qualifier starting with one of these prefixes is included in the + // AuthorizedView. To provide access to all qualifiers, include the empty + // string as a prefix + // (""). + // +kcc:proto:field=google.bigtable.admin.v2.AuthorizedView.FamilySubsets.qualifier_prefixes + QualifierPrefixes [][]byte `json:"qualifierPrefixes,omitempty"` +} + +// +kcc:proto=google.bigtable.admin.v2.AuthorizedView.SubsetView +type AuthorizedView_SubsetView struct { + // Row prefixes to be included in the AuthorizedView. + // To provide access to all rows, include the empty string as a prefix (""). + // +kcc:proto:field=google.bigtable.admin.v2.AuthorizedView.SubsetView.row_prefixes + RowPrefixes [][]byte `json:"rowPrefixes,omitempty"` + + // TODO: unsupported map type with key string and value message +} From 7935757d1078d187ab50fc89bfc06dabf5d09fbc Mon Sep 17 00:00:00 2001 From: Gemma Hou Date: Fri, 14 Mar 2025 02:54:11 +0000 Subject: [PATCH 2/7] conductor: "Generated CRD for BigtableAuthorizedView" --- ...dviews.bigtable.cnrm.cloud.google.com.yaml | 242 ++++++++++++++++++ .../direct/bigtable/authorizedview_mapper.go | 1 + .../{mapper.go => instance_mapper.go} | 0 3 files changed, 243 insertions(+) create mode 100644 config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_bigtableauthorizedviews.bigtable.cnrm.cloud.google.com.yaml create mode 100644 pkg/controller/direct/bigtable/authorizedview_mapper.go rename pkg/controller/direct/bigtable/{mapper.go => instance_mapper.go} (100%) diff --git a/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_bigtableauthorizedviews.bigtable.cnrm.cloud.google.com.yaml b/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_bigtableauthorizedviews.bigtable.cnrm.cloud.google.com.yaml new file mode 100644 index 00000000000..70a3d0e133b --- /dev/null +++ b/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_bigtableauthorizedviews.bigtable.cnrm.cloud.google.com.yaml @@ -0,0 +1,242 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + cnrm.cloud.google.com/version: 0.0.0-dev + creationTimestamp: null + labels: + cnrm.cloud.google.com/managed-by-kcc: "true" + cnrm.cloud.google.com/system: "true" + name: bigtableauthorizedviews.bigtable.cnrm.cloud.google.com +spec: + group: bigtable.cnrm.cloud.google.com + names: + categories: + - gcp + kind: BigtableAuthorizedView + listKind: BigtableAuthorizedViewList + plural: bigtableauthorizedviews + shortNames: + - gcpbigtableauthorizedview + - gcpbigtableauthorizedviews + singular: bigtableauthorizedview + preserveUnknownFields: false + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + - description: When 'True', the most recent reconcile of the resource succeeded + jsonPath: .status.conditions[?(@.type=='Ready')].status + name: Ready + type: string + - description: The reason for the value in 'Ready' + jsonPath: .status.conditions[?(@.type=='Ready')].reason + name: Status + type: string + - description: The last transition time for the value in 'Status' + jsonPath: .status.conditions[?(@.type=='Ready')].lastTransitionTime + name: Status Age + type: date + name: v1alpha1 + schema: + openAPIV3Schema: + description: BigtableAuthorizedView is the Schema for the BigtableAuthorizedView + API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: BigtableAuthorizedViewSpec defines the desired state of BigtableAuthorizedView + properties: + deletionProtection: + description: Set to true to make the AuthorizedView protected against + deletion. The parent Table and containing Instance cannot be deleted + if an AuthorizedView has this bit set. + type: boolean + etag: + description: The etag for this AuthorizedView. If this is provided + on update, it must match the server's etag. The server returns ABORTED + error on a mismatched etag. + type: string + instanceRef: + description: InstanceRef defines the resource reference to BigtableInstance, + which "External" field holds the GCP identifier for the KRM object. + oneOf: + - not: + required: + - external + required: + - name + - not: + anyOf: + - required: + - name + - required: + - namespace + required: + - external + properties: + external: + description: A reference to an externally managed BigtableInstance + resource. + type: string + name: + description: The name of a BigtableInstance resource. + type: string + namespace: + description: The namespace of a BigtableInstance resource. + type: string + type: object + location: + type: string + projectRef: + description: The Project that this resource belongs to. + oneOf: + - not: + required: + - external + required: + - name + - not: + anyOf: + - required: + - name + - required: + - namespace + required: + - external + properties: + external: + description: The `projectID` field of a project, when not managed + by Config Connector. + type: string + kind: + description: The kind of the Project resource; optional but must + be `Project` if provided. + type: string + name: + description: The `name` field of a `Project` resource. + type: string + namespace: + description: The `namespace` field of a `Project` resource. + type: string + type: object + resourceID: + description: The BigtableAuthorizedView name. If not given, the metadata.name + will be used. + type: string + subsetView: + description: An AuthorizedView permitting access to an explicit subset + of a Table. + properties: + rowPrefixes: + description: Row prefixes to be included in the AuthorizedView. + To provide access to all rows, include the empty string as a + prefix (""). + items: + format: byte + type: string + type: array + type: object + tableRef: + description: TableRef defines the resource reference to BigtableTable, + which "External" field holds the GCP identifier for the KRM object. + oneOf: + - not: + required: + - external + required: + - name + - not: + anyOf: + - required: + - name + - required: + - namespace + required: + - external + properties: + external: + description: A reference to an externally managed BigtableTable + resource. + type: string + name: + description: The name of a BigtableInstance resource. + type: string + namespace: + description: The namespace of a BigtableInstance resource. + type: string + type: object + required: + - "" + - instanceRef + - location + - projectRef + - tableRef + type: object + status: + description: BigtableAuthorizedViewStatus defines the config connector + machine state of BigtableAuthorizedView + properties: + conditions: + description: Conditions represent the latest available observations + of the object's current state. + items: + properties: + lastTransitionTime: + description: Last time the condition transitioned from one status + to another. + type: string + message: + description: Human-readable message indicating details about + last transition. + type: string + reason: + description: Unique, one-word, CamelCase reason for the condition's + last transition. + type: string + status: + description: Status is the status of the condition. Can be True, + False, Unknown. + type: string + type: + description: Type is the type of the condition. + type: string + type: object + type: array + externalRef: + description: A unique specifier for the BigtableAuthorizedView resource + in GCP. + type: string + observedGeneration: + description: ObservedGeneration is the generation of the resource + that was most recently observed by the Config Connector controller. + If this is equal to metadata.generation, then that means that the + current reported status reflects the most recent desired state of + the resource. + format: int64 + type: integer + observedState: + description: ObservedState is the state of the resource as most recently + observed in GCP. + type: object + type: object + required: + - spec + type: object + served: true + storage: true + subresources: + status: {} diff --git a/pkg/controller/direct/bigtable/authorizedview_mapper.go b/pkg/controller/direct/bigtable/authorizedview_mapper.go new file mode 100644 index 00000000000..1c0ec0e5407 --- /dev/null +++ b/pkg/controller/direct/bigtable/authorizedview_mapper.go @@ -0,0 +1 @@ +package bigtable diff --git a/pkg/controller/direct/bigtable/mapper.go b/pkg/controller/direct/bigtable/instance_mapper.go similarity index 100% rename from pkg/controller/direct/bigtable/mapper.go rename to pkg/controller/direct/bigtable/instance_mapper.go From a6992bb4de4a2f7fd420e92c52e0766fed61da18 Mon Sep 17 00:00:00 2001 From: Gemma Hou Date: Fri, 14 Mar 2025 02:56:05 +0000 Subject: [PATCH 3/7] Manual update --- .../v1alpha1/authorizedview_identity.go | 67 ++-- .../bigtable/v1alpha1/authorizedview_types.go | 33 +- apis/bigtable/v1alpha1/cluster_types.go | 4 +- .../v1alpha1/zz_generated.deepcopy.go | 349 ++++++++++++++++-- apis/bigtable/v1beta1/instance_identity.go | 34 ++ apis/bigtable/v1beta1/table_identity.go | 52 +++ apis/bigtable/v1beta1/table_reference.go | 92 +++++ .../bigtable/v1beta1/zz_generated.deepcopy.go | 56 +++ ...dviews.bigtable.cnrm.cloud.google.com.yaml | 3 - .../direct/bigtable/authorizedview_mapper.go | 82 ++++ .../direct/bigtable/mapper.generated.go | 60 --- pkg/gvks/supportedgvks/gvks_generated.go | 10 + 12 files changed, 713 insertions(+), 129 deletions(-) create mode 100644 apis/bigtable/v1beta1/instance_identity.go create mode 100644 apis/bigtable/v1beta1/table_identity.go create mode 100644 apis/bigtable/v1beta1/table_reference.go diff --git a/apis/bigtable/v1alpha1/authorizedview_identity.go b/apis/bigtable/v1alpha1/authorizedview_identity.go index 94d675d7b56..ab235b3a697 100644 --- a/apis/bigtable/v1alpha1/authorizedview_identity.go +++ b/apis/bigtable/v1alpha1/authorizedview_identity.go @@ -19,53 +19,40 @@ import ( "fmt" "strings" + bigtablev1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/bigtable/v1beta1" + "github.com/GoogleCloudPlatform/k8s-config-connector/apis/common/parent" + "github.com/GoogleCloudPlatform/k8s-config-connector/apis/common" - refsv1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" "sigs.k8s.io/controller-runtime/pkg/client" ) // AuthorizedViewIdentity defines the resource reference to BigtableAuthorizedView, which "External" field // holds the GCP identifier for the KRM object. type AuthorizedViewIdentity struct { - parent *AuthorizedViewParent - id string + parent *bigtablev1beta1.TableIdentity + id string } func (i *AuthorizedViewIdentity) String() string { - return i.parent.String() + "/authorizedviews/" + i.id + return i.parent.String() + "/authorizedViews/" + i.id } func (i *AuthorizedViewIdentity) ID() string { return i.id } -func (i *AuthorizedViewIdentity) Parent() *AuthorizedViewParent { - return i.parent -} - -type AuthorizedViewParent struct { - ProjectID string - Location string -} - -func (p *AuthorizedViewParent) String() string { - return "projects/" + p.ProjectID + "/locations/" + p.Location -} - - // New builds a AuthorizedViewIdentity from the Config Connector AuthorizedView object. func NewAuthorizedViewIdentity(ctx context.Context, reader client.Reader, obj *BigtableAuthorizedView) (*AuthorizedViewIdentity, error) { // Get Parent - projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef) + tableExternal, err := obj.Spec.TableRef.NormalizedExternal(ctx, reader, obj.GetNamespace()) if err != nil { return nil, err } - projectID := projectRef.ProjectID - if projectID == "" { - return nil, fmt.Errorf("cannot resolve project") + instanceIdentity, tableID, err := bigtablev1beta1.ParseTableExternal(tableExternal) + if err != nil { + return nil, err } - location := obj.Spec.Location // Get desired ID resourceID := common.ValueOf(obj.Spec.ResourceID) @@ -84,11 +71,8 @@ func NewAuthorizedViewIdentity(ctx context.Context, reader client.Reader, obj *B if err != nil { return nil, err } - if actualParent.ProjectID != projectID { - return nil, fmt.Errorf("spec.projectRef changed, expect %s, got %s", actualParent.ProjectID, projectID) - } - if actualParent.Location != location { - return nil, fmt.Errorf("spec.location changed, expect %s, got %s", actualParent.Location, location) + if actualParent.Id != tableID { + return nil, fmt.Errorf("spec.groupRef changed, expect %s, got %s", actualParent.Id, tableID) } if actualResourceID != resourceID { return nil, fmt.Errorf("cannot reset `metadata.name` or `spec.resourceID` to %s, since it has already assigned to %s", @@ -96,23 +80,28 @@ func NewAuthorizedViewIdentity(ctx context.Context, reader client.Reader, obj *B } } return &AuthorizedViewIdentity{ - parent: &AuthorizedViewParent{ - ProjectID: projectID, - Location: location, + parent: &bigtablev1beta1.TableIdentity{ + Parent: instanceIdentity, + Id: tableID, }, id: resourceID, }, nil } -func ParseAuthorizedViewExternal(external string) (parent *AuthorizedViewParent, resourceID string, err error) { +func ParseAuthorizedViewExternal(external string) (*bigtablev1beta1.TableIdentity, string, error) { tokens := strings.Split(external, "/") - if len(tokens) != 6 || tokens[0] != "projects" || tokens[2] != "locations" || tokens[4] != "authorizedviews" { - return nil, "", fmt.Errorf("format of BigtableAuthorizedView external=%q was not known (use projects/{{projectID}}/locations/{{location}}/authorizedviews/{{authorizedviewID}})", external) + if len(tokens) != 8 || tokens[0] != "projects" || tokens[2] != "instances" || tokens[4] != "tables" || tokens[6] != "authorizedViews" { + return nil, "", fmt.Errorf("format of BigtableAuthorizedView external=%q was not known (use projects/{{projectID}}/instances/{{instanceID}}/tables/{{tableID}}/authorizedViews/{{authorizedViewID}})", external) } - parent = &AuthorizedViewParent{ - ProjectID: tokens[1], - Location: tokens[3], + p := &bigtablev1beta1.TableIdentity{ + Parent: &bigtablev1beta1.InstanceIdentity{ + Parent: &parent.ProjectParent{ + ProjectID: tokens[1], + }, + Id: tokens[3], + }, + Id: tokens[5], } - resourceID = tokens[5] - return parent, resourceID, nil + resourceID := tokens[7] + return p, resourceID, nil } diff --git a/apis/bigtable/v1alpha1/authorizedview_types.go b/apis/bigtable/v1alpha1/authorizedview_types.go index 5c4fe2fb8e3..464bf4ae3ee 100644 --- a/apis/bigtable/v1alpha1/authorizedview_types.go +++ b/apis/bigtable/v1alpha1/authorizedview_types.go @@ -15,17 +15,49 @@ package v1alpha1 import ( + bigtablev1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/bigtable/v1beta1" + refv1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/k8s/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) var BigtableAuthorizedViewGVK = GroupVersion.WithKind("BigtableAuthorizedView") +type BigtableAuthorizedViewParent struct { + // +required + ProjectRef *refv1beta1.ProjectRef `json:"projectRef"` + + // +required + InstanceRef bigtablev1beta1.InstanceRef `json:"instanceRef"` + + // +required + TableRef bigtablev1beta1.TableRef `json:"tableRef"` +} + // BigtableAuthorizedViewSpec defines the desired state of BigtableAuthorizedView // +kcc:proto=google.bigtable.admin.v2.AuthorizedView type BigtableAuthorizedViewSpec struct { // The BigtableAuthorizedView name. If not given, the metadata.name will be used. ResourceID *string `json:"resourceID,omitempty"` + + // +required + BigtableAuthorizedViewParent `json:",inline"` + + // An AuthorizedView permitting access to an explicit subset of a Table. + // +kcc:proto:field=google.bigtable.admin.v2.AuthorizedView.subset_view + SubsetView *AuthorizedView_SubsetView `json:"subsetView,omitempty"` + + // The etag for this AuthorizedView. + // If this is provided on update, it must match the server's etag. The server + // returns ABORTED error on a mismatched etag. + // +kcc:proto:field=google.bigtable.admin.v2.AuthorizedView.etag + Etag *string `json:"etag,omitempty"` + + // Set to true to make the AuthorizedView protected against deletion. + // The parent Table and containing Instance cannot be deleted if an + // AuthorizedView has this bit set. + // +kcc:proto:field=google.bigtable.admin.v2.AuthorizedView.deletion_protection + DeletionProtection *bool `json:"deletionProtection,omitempty"` } // BigtableAuthorizedViewStatus defines the config connector machine state of BigtableAuthorizedView @@ -51,7 +83,6 @@ type BigtableAuthorizedViewObservedState struct { // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// TODO(user): make sure the pluralizaiton below is correct // +kubebuilder:resource:categories=gcp,shortName=gcpbigtableauthorizedview;gcpbigtableauthorizedviews // +kubebuilder:subresource:status // +kubebuilder:metadata:labels="cnrm.cloud.google.com/managed-by-kcc=true";"cnrm.cloud.google.com/system=true" diff --git a/apis/bigtable/v1alpha1/cluster_types.go b/apis/bigtable/v1alpha1/cluster_types.go index eff347b87da..96720a17cf1 100644 --- a/apis/bigtable/v1alpha1/cluster_types.go +++ b/apis/bigtable/v1alpha1/cluster_types.go @@ -25,7 +25,7 @@ import ( var BigtableClusterGVK = GroupVersion.WithKind("BigtableCluster") -type Parent struct { +type BigtableClusterParent struct { // +required ProjectRef *refv1beta1.ProjectRef `json:"projectRef"` // +required @@ -35,7 +35,7 @@ type Parent struct { // BigtableClusterSpec defines the desired state of BigtableCluster // +kcc:proto=google.bigtable.admin.v2.Cluster type BigtableClusterSpec struct { - Parent `json:",inline"` + BigtableClusterParent `json:",inline"` // The BigtableCluster name. If not given, the metadata.name will be used. ResourceID *string `json:"resourceID,omitempty"` diff --git a/apis/bigtable/v1alpha1/zz_generated.deepcopy.go b/apis/bigtable/v1alpha1/zz_generated.deepcopy.go index 15e99eae0e0..7585cc37cc4 100644 --- a/apis/bigtable/v1alpha1/zz_generated.deepcopy.go +++ b/apis/bigtable/v1alpha1/zz_generated.deepcopy.go @@ -19,11 +19,145 @@ package v1alpha1 import ( - "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" + "github.com/GoogleCloudPlatform/k8s-config-connector/apis/bigtable/v1beta1" + refsv1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" k8sv1alpha1 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/k8s/v1alpha1" runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AuthorizedView) DeepCopyInto(out *AuthorizedView) { + *out = *in + if in.Name != nil { + in, out := &in.Name, &out.Name + *out = new(string) + **out = **in + } + if in.SubsetView != nil { + in, out := &in.SubsetView, &out.SubsetView + *out = new(AuthorizedView_SubsetView) + (*in).DeepCopyInto(*out) + } + if in.Etag != nil { + in, out := &in.Etag, &out.Etag + *out = new(string) + **out = **in + } + if in.DeletionProtection != nil { + in, out := &in.DeletionProtection, &out.DeletionProtection + *out = new(bool) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AuthorizedView. +func (in *AuthorizedView) DeepCopy() *AuthorizedView { + if in == nil { + return nil + } + out := new(AuthorizedView) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AuthorizedViewIdentity) DeepCopyInto(out *AuthorizedViewIdentity) { + *out = *in + if in.parent != nil { + in, out := &in.parent, &out.parent + *out = new(v1beta1.TableIdentity) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AuthorizedViewIdentity. +func (in *AuthorizedViewIdentity) DeepCopy() *AuthorizedViewIdentity { + if in == nil { + return nil + } + out := new(AuthorizedViewIdentity) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AuthorizedViewRef) DeepCopyInto(out *AuthorizedViewRef) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AuthorizedViewRef. +func (in *AuthorizedViewRef) DeepCopy() *AuthorizedViewRef { + if in == nil { + return nil + } + out := new(AuthorizedViewRef) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AuthorizedView_FamilySubsets) DeepCopyInto(out *AuthorizedView_FamilySubsets) { + *out = *in + if in.Qualifiers != nil { + in, out := &in.Qualifiers, &out.Qualifiers + *out = make([][]byte, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = make([]byte, len(*in)) + copy(*out, *in) + } + } + } + if in.QualifierPrefixes != nil { + in, out := &in.QualifierPrefixes, &out.QualifierPrefixes + *out = make([][]byte, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = make([]byte, len(*in)) + copy(*out, *in) + } + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AuthorizedView_FamilySubsets. +func (in *AuthorizedView_FamilySubsets) DeepCopy() *AuthorizedView_FamilySubsets { + if in == nil { + return nil + } + out := new(AuthorizedView_FamilySubsets) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AuthorizedView_SubsetView) DeepCopyInto(out *AuthorizedView_SubsetView) { + *out = *in + if in.RowPrefixes != nil { + in, out := &in.RowPrefixes, &out.RowPrefixes + *out = make([][]byte, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = make([]byte, len(*in)) + copy(*out, *in) + } + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AuthorizedView_SubsetView. +func (in *AuthorizedView_SubsetView) DeepCopy() *AuthorizedView_SubsetView { + if in == nil { + return nil + } + out := new(AuthorizedView_SubsetView) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AutoscalingLimits) DeepCopyInto(out *AutoscalingLimits) { *out = *in @@ -74,6 +208,173 @@ func (in *AutoscalingTargets) DeepCopy() *AutoscalingTargets { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BigtableAuthorizedView) DeepCopyInto(out *BigtableAuthorizedView) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BigtableAuthorizedView. +func (in *BigtableAuthorizedView) DeepCopy() *BigtableAuthorizedView { + if in == nil { + return nil + } + out := new(BigtableAuthorizedView) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BigtableAuthorizedView) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BigtableAuthorizedViewList) DeepCopyInto(out *BigtableAuthorizedViewList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]BigtableAuthorizedView, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BigtableAuthorizedViewList. +func (in *BigtableAuthorizedViewList) DeepCopy() *BigtableAuthorizedViewList { + if in == nil { + return nil + } + out := new(BigtableAuthorizedViewList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BigtableAuthorizedViewList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BigtableAuthorizedViewObservedState) DeepCopyInto(out *BigtableAuthorizedViewObservedState) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BigtableAuthorizedViewObservedState. +func (in *BigtableAuthorizedViewObservedState) DeepCopy() *BigtableAuthorizedViewObservedState { + if in == nil { + return nil + } + out := new(BigtableAuthorizedViewObservedState) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BigtableAuthorizedViewParent) DeepCopyInto(out *BigtableAuthorizedViewParent) { + *out = *in + if in.ProjectRef != nil { + in, out := &in.ProjectRef, &out.ProjectRef + *out = new(refsv1beta1.ProjectRef) + **out = **in + } + out.InstanceRef = in.InstanceRef + out.TableRef = in.TableRef +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BigtableAuthorizedViewParent. +func (in *BigtableAuthorizedViewParent) DeepCopy() *BigtableAuthorizedViewParent { + if in == nil { + return nil + } + out := new(BigtableAuthorizedViewParent) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BigtableAuthorizedViewSpec) DeepCopyInto(out *BigtableAuthorizedViewSpec) { + *out = *in + if in.ResourceID != nil { + in, out := &in.ResourceID, &out.ResourceID + *out = new(string) + **out = **in + } + in.BigtableAuthorizedViewParent.DeepCopyInto(&out.BigtableAuthorizedViewParent) + if in.SubsetView != nil { + in, out := &in.SubsetView, &out.SubsetView + *out = new(AuthorizedView_SubsetView) + (*in).DeepCopyInto(*out) + } + if in.Etag != nil { + in, out := &in.Etag, &out.Etag + *out = new(string) + **out = **in + } + if in.DeletionProtection != nil { + in, out := &in.DeletionProtection, &out.DeletionProtection + *out = new(bool) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BigtableAuthorizedViewSpec. +func (in *BigtableAuthorizedViewSpec) DeepCopy() *BigtableAuthorizedViewSpec { + if in == nil { + return nil + } + out := new(BigtableAuthorizedViewSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BigtableAuthorizedViewStatus) DeepCopyInto(out *BigtableAuthorizedViewStatus) { + *out = *in + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]k8sv1alpha1.Condition, len(*in)) + copy(*out, *in) + } + if in.ObservedGeneration != nil { + in, out := &in.ObservedGeneration, &out.ObservedGeneration + *out = new(int64) + **out = **in + } + if in.ExternalRef != nil { + in, out := &in.ExternalRef, &out.ExternalRef + *out = new(string) + **out = **in + } + if in.ObservedState != nil { + in, out := &in.ObservedState, &out.ObservedState + *out = new(BigtableAuthorizedViewObservedState) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BigtableAuthorizedViewStatus. +func (in *BigtableAuthorizedViewStatus) DeepCopy() *BigtableAuthorizedViewStatus { + if in == nil { + return nil + } + out := new(BigtableAuthorizedViewStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BigtableCluster) DeepCopyInto(out *BigtableCluster) { *out = *in @@ -153,10 +454,31 @@ func (in *BigtableClusterObservedState) DeepCopy() *BigtableClusterObservedState return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BigtableClusterParent) DeepCopyInto(out *BigtableClusterParent) { + *out = *in + if in.ProjectRef != nil { + in, out := &in.ProjectRef, &out.ProjectRef + *out = new(refsv1beta1.ProjectRef) + **out = **in + } + out.InstanceRef = in.InstanceRef +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BigtableClusterParent. +func (in *BigtableClusterParent) DeepCopy() *BigtableClusterParent { + if in == nil { + return nil + } + out := new(BigtableClusterParent) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BigtableClusterSpec) DeepCopyInto(out *BigtableClusterSpec) { *out = *in - in.Parent.DeepCopyInto(&out.Parent) + in.BigtableClusterParent.DeepCopyInto(&out.BigtableClusterParent) if in.ResourceID != nil { in, out := &in.ResourceID, &out.ResourceID *out = new(string) @@ -339,7 +661,7 @@ func (in *Cluster_EncryptionConfig) DeepCopyInto(out *Cluster_EncryptionConfig) *out = *in if in.KMSKeyRef != nil { in, out := &in.KMSKeyRef, &out.KMSKeyRef - *out = new(v1beta1.KMSCryptoKeyRef) + *out = new(refsv1beta1.KMSCryptoKeyRef) **out = **in } } @@ -353,24 +675,3 @@ func (in *Cluster_EncryptionConfig) DeepCopy() *Cluster_EncryptionConfig { in.DeepCopyInto(out) return out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Parent) DeepCopyInto(out *Parent) { - *out = *in - if in.ProjectRef != nil { - in, out := &in.ProjectRef, &out.ProjectRef - *out = new(v1beta1.ProjectRef) - **out = **in - } - out.InstanceRef = in.InstanceRef -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Parent. -func (in *Parent) DeepCopy() *Parent { - if in == nil { - return nil - } - out := new(Parent) - in.DeepCopyInto(out) - return out -} diff --git a/apis/bigtable/v1beta1/instance_identity.go b/apis/bigtable/v1beta1/instance_identity.go new file mode 100644 index 00000000000..b8200a256c7 --- /dev/null +++ b/apis/bigtable/v1beta1/instance_identity.go @@ -0,0 +1,34 @@ +// Copyright 2025 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 v1beta1 + +import ( + "github.com/GoogleCloudPlatform/k8s-config-connector/apis/common/parent" +) + +// InstanceIdentity defines the resource reference to BigtableInstance, which "External" field +// holds the GCP identifier for the KRM object. +type InstanceIdentity struct { + Parent *parent.ProjectParent + Id string +} + +func (i *InstanceIdentity) String() string { + return i.Parent.String() + "/instances/" + i.Id +} + +func (i *InstanceIdentity) ID() string { + return i.Id +} diff --git a/apis/bigtable/v1beta1/table_identity.go b/apis/bigtable/v1beta1/table_identity.go new file mode 100644 index 00000000000..94c65f0fe18 --- /dev/null +++ b/apis/bigtable/v1beta1/table_identity.go @@ -0,0 +1,52 @@ +// Copyright 2025 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 v1beta1 + +import ( + "fmt" + "strings" + + "github.com/GoogleCloudPlatform/k8s-config-connector/apis/common/parent" +) + +// TableIdentity defines the resource reference to BigtableTable, which "External" field +// holds the GCP identifier for the KRM object. +type TableIdentity struct { + Parent *InstanceIdentity + Id string +} + +func (i *TableIdentity) String() string { + return i.Parent.String() + "/tables/" + i.Id +} + +func (i *TableIdentity) ID() string { + return i.Id +} + +func ParseTableExternal(external string) (*InstanceIdentity, string, error) { + tokens := strings.Split(external, "/") + if len(tokens) != 6 || tokens[0] != "projects" || tokens[2] != "instances" || tokens[4] != "tables" { + return nil, "", fmt.Errorf("format of BigtableTable external=%q was not known (use projects/{{projectID}}/instances/{{instanceID}}/tables/{{tableID}})", external) + } + p := &InstanceIdentity{ + Parent: &parent.ProjectParent{ + ProjectID: tokens[1], + }, + Id: tokens[3], + } + resourceID := tokens[5] + return p, resourceID, nil +} diff --git a/apis/bigtable/v1beta1/table_reference.go b/apis/bigtable/v1beta1/table_reference.go new file mode 100644 index 00000000000..759a5ae396e --- /dev/null +++ b/apis/bigtable/v1beta1/table_reference.go @@ -0,0 +1,92 @@ +// Copyright 2025 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 v1beta1 + +import ( + "context" + "fmt" + + refsv1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s" + apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +var _ refsv1beta1.ExternalNormalizer = &TableRef{} +var ( + BigtableTableGVK = GroupVersion.WithKind("BigtableTable") +) + +// TableRef defines the resource reference to BigtableTable, which "External" field +// holds the GCP identifier for the KRM object. +type TableRef struct { + // A reference to an externally managed BigtableTable resource. + External string `json:"external,omitempty"` + + // The name of a BigtableInstance resource. + Name string `json:"name,omitempty"` + + // The namespace of a BigtableInstance resource. + Namespace string `json:"namespace,omitempty"` +} + +// NormalizedExternal provision the "External" value for other resource that depends on BigtableTable. +// If the "External" is given in the other resource's spec.BigtableTableRef, the given value will be used. +// Otherwise, the "Name" and "Namespace" will be used to query the actual BigtableTable object from the cluster. +func (r *TableRef) NormalizedExternal(ctx context.Context, reader client.Reader, otherNamespace string) (string, error) { + if r.External != "" && r.Name != "" { + return "", fmt.Errorf("cannot specify both name and external on %s reference", BigtableTableGVK.Kind) + } + // From given External + // For backward compatibility, we are not validating the external format. + // todo: validate external when it's referenced by a pure direct resource + if r.External != "" { + return r.External, nil + } + + // From the Config Connector object + if r.Namespace == "" { + r.Namespace = otherNamespace + } + key := types.NamespacedName{Name: r.Name, Namespace: r.Namespace} + u := &unstructured.Unstructured{} + u.SetGroupVersionKind(BigtableTableGVK) + if err := reader.Get(ctx, key, u); err != nil { + if apierrors.IsNotFound(err) { + return "", k8s.NewReferenceNotFoundError(u.GroupVersionKind(), key) + } + return "", fmt.Errorf("reading referenced %s %s: %w", BigtableTableGVK, key, err) + } + + // todo: use externalRef for resource that managed by direct controller + resourceID, _, err := unstructured.NestedString(u.Object, "spec", "resourceID") + if err != nil { + return "", fmt.Errorf("reading spec.resourceID: %w", err) + } + if resourceID == "" { + metadataName, _, err := unstructured.NestedString(u.Object, "metadata", "name") + if err != nil { + return "", fmt.Errorf("reading metadata.name: %w", err) + } + resourceID = metadataName + } + if resourceID == "" { + return "", k8s.NewReferenceNotReadyError(u.GroupVersionKind(), key) + } + r.External = resourceID + return r.External, nil +} diff --git a/apis/bigtable/v1beta1/zz_generated.deepcopy.go b/apis/bigtable/v1beta1/zz_generated.deepcopy.go index 9c7d6bb7418..96f9560c7bf 100644 --- a/apis/bigtable/v1beta1/zz_generated.deepcopy.go +++ b/apis/bigtable/v1beta1/zz_generated.deepcopy.go @@ -19,6 +19,7 @@ package v1beta1 import ( + "github.com/GoogleCloudPlatform/k8s-config-connector/apis/common/parent" refsv1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/k8s/v1alpha1" runtime "k8s.io/apimachinery/pkg/runtime" @@ -974,6 +975,26 @@ func (in *InstanceCluster) DeepCopy() *InstanceCluster { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *InstanceIdentity) DeepCopyInto(out *InstanceIdentity) { + *out = *in + if in.Parent != nil { + in, out := &in.Parent, &out.Parent + *out = new(parent.ProjectParent) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InstanceIdentity. +func (in *InstanceIdentity) DeepCopy() *InstanceIdentity { + if in == nil { + return nil + } + out := new(InstanceIdentity) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *InstanceRef) DeepCopyInto(out *InstanceRef) { *out = *in @@ -1154,6 +1175,41 @@ func (in *Table) DeepCopy() *Table { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TableIdentity) DeepCopyInto(out *TableIdentity) { + *out = *in + if in.Parent != nil { + in, out := &in.Parent, &out.Parent + *out = new(InstanceIdentity) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TableIdentity. +func (in *TableIdentity) DeepCopy() *TableIdentity { + if in == nil { + return nil + } + out := new(TableIdentity) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TableRef) DeepCopyInto(out *TableRef) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TableRef. +func (in *TableRef) DeepCopy() *TableRef { + if in == nil { + return nil + } + out := new(TableRef) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Table_AutomatedBackupPolicy) DeepCopyInto(out *Table_AutomatedBackupPolicy) { *out = *in diff --git a/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_bigtableauthorizedviews.bigtable.cnrm.cloud.google.com.yaml b/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_bigtableauthorizedviews.bigtable.cnrm.cloud.google.com.yaml index 70a3d0e133b..6edfae2b954 100644 --- a/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_bigtableauthorizedviews.bigtable.cnrm.cloud.google.com.yaml +++ b/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_bigtableauthorizedviews.bigtable.cnrm.cloud.google.com.yaml @@ -99,8 +99,6 @@ spec: description: The namespace of a BigtableInstance resource. type: string type: object - location: - type: string projectRef: description: The Project that this resource belongs to. oneOf: @@ -182,7 +180,6 @@ spec: required: - "" - instanceRef - - location - projectRef - tableRef type: object diff --git a/pkg/controller/direct/bigtable/authorizedview_mapper.go b/pkg/controller/direct/bigtable/authorizedview_mapper.go index 1c0ec0e5407..0e55de2ecf0 100644 --- a/pkg/controller/direct/bigtable/authorizedview_mapper.go +++ b/pkg/controller/direct/bigtable/authorizedview_mapper.go @@ -1 +1,83 @@ +// Copyright 2025 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 bigtable + +import ( + krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/bigtable/v1alpha1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" + pb "google.golang.org/genproto/googleapis/bigtable/admin/v2" +) + +func AuthorizedView_FamilySubsets_FromProto(mapCtx *direct.MapContext, in *pb.AuthorizedView_FamilySubsets) *krm.AuthorizedView_FamilySubsets { + if in == nil { + return nil + } + out := &krm.AuthorizedView_FamilySubsets{} + out.Qualifiers = in.Qualifiers + out.QualifierPrefixes = in.QualifierPrefixes + return out +} +func AuthorizedView_FamilySubsets_ToProto(mapCtx *direct.MapContext, in *krm.AuthorizedView_FamilySubsets) *pb.AuthorizedView_FamilySubsets { + if in == nil { + return nil + } + out := &pb.AuthorizedView_FamilySubsets{} + out.Qualifiers = in.Qualifiers + out.QualifierPrefixes = in.QualifierPrefixes + return out +} +func AuthorizedView_SubsetView_FromProto(mapCtx *direct.MapContext, in *pb.AuthorizedView_SubsetView) *krm.AuthorizedView_SubsetView { + if in == nil { + return nil + } + out := &krm.AuthorizedView_SubsetView{} + out.RowPrefixes = in.RowPrefixes + // MISSING: FamilySubsets + return out +} +func AuthorizedView_SubsetView_ToProto(mapCtx *direct.MapContext, in *krm.AuthorizedView_SubsetView) *pb.AuthorizedView_SubsetView { + if in == nil { + return nil + } + out := &pb.AuthorizedView_SubsetView{} + out.RowPrefixes = in.RowPrefixes + // MISSING: FamilySubsets + return out +} + +func BigtableAuthorizedViewSpec_FromProto(mapCtx *direct.MapContext, in *pb.AuthorizedView) *krm.BigtableAuthorizedViewSpec { + if in == nil { + return nil + } + out := &krm.BigtableAuthorizedViewSpec{} + // MISSING: Name + out.SubsetView = AuthorizedView_SubsetView_FromProto(mapCtx, in.GetSubsetView()) + out.Etag = direct.LazyPtr(in.GetEtag()) + out.DeletionProtection = direct.LazyPtr(in.GetDeletionProtection()) + return out +} +func BigtableAuthorizedViewSpec_ToProto(mapCtx *direct.MapContext, in *krm.BigtableAuthorizedViewSpec) *pb.AuthorizedView { + if in == nil { + return nil + } + out := &pb.AuthorizedView{} + // MISSING: Name + if oneof := AuthorizedView_SubsetView_ToProto(mapCtx, in.SubsetView); oneof != nil { + out.AuthorizedView = &pb.AuthorizedView_SubsetView_{SubsetView: oneof} + } + out.Etag = direct.ValueOf(in.Etag) + out.DeletionProtection = direct.ValueOf(in.DeletionProtection) + return out +} diff --git a/pkg/controller/direct/bigtable/mapper.generated.go b/pkg/controller/direct/bigtable/mapper.generated.go index 3a825727fb8..6281bca396c 100644 --- a/pkg/controller/direct/bigtable/mapper.generated.go +++ b/pkg/controller/direct/bigtable/mapper.generated.go @@ -128,66 +128,6 @@ func AppProfile_StandardIsolation_ToProto(mapCtx *direct.MapContext, in *krm.App out.Priority = direct.Enum_ToProto[pb.AppProfile_Priority](mapCtx, in.Priority) return out } -func AuthorizedView_FromProto(mapCtx *direct.MapContext, in *pb.AuthorizedView) *krm.AuthorizedView { - if in == nil { - return nil - } - out := &krm.AuthorizedView{} - out.Name = direct.LazyPtr(in.GetName()) - out.SubsetView = AuthorizedView_SubsetView_FromProto(mapCtx, in.GetSubsetView()) - out.Etag = direct.LazyPtr(in.GetEtag()) - out.DeletionProtection = direct.LazyPtr(in.GetDeletionProtection()) - return out -} -func AuthorizedView_ToProto(mapCtx *direct.MapContext, in *krm.AuthorizedView) *pb.AuthorizedView { - if in == nil { - return nil - } - out := &pb.AuthorizedView{} - out.Name = direct.ValueOf(in.Name) - if oneof := AuthorizedView_SubsetView_ToProto(mapCtx, in.SubsetView); oneof != nil { - out.AuthorizedView = &pb.AuthorizedView_SubsetView_{SubsetView: oneof} - } - out.Etag = direct.ValueOf(in.Etag) - out.DeletionProtection = direct.ValueOf(in.DeletionProtection) - return out -} -func AuthorizedView_FamilySubsets_FromProto(mapCtx *direct.MapContext, in *pb.AuthorizedView_FamilySubsets) *krm.AuthorizedView_FamilySubsets { - if in == nil { - return nil - } - out := &krm.AuthorizedView_FamilySubsets{} - out.Qualifiers = in.Qualifiers - out.QualifierPrefixes = in.QualifierPrefixes - return out -} -func AuthorizedView_FamilySubsets_ToProto(mapCtx *direct.MapContext, in *krm.AuthorizedView_FamilySubsets) *pb.AuthorizedView_FamilySubsets { - if in == nil { - return nil - } - out := &pb.AuthorizedView_FamilySubsets{} - out.Qualifiers = in.Qualifiers - out.QualifierPrefixes = in.QualifierPrefixes - return out -} -func AuthorizedView_SubsetView_FromProto(mapCtx *direct.MapContext, in *pb.AuthorizedView_SubsetView) *krm.AuthorizedView_SubsetView { - if in == nil { - return nil - } - out := &krm.AuthorizedView_SubsetView{} - out.RowPrefixes = in.RowPrefixes - // MISSING: FamilySubsets - return out -} -func AuthorizedView_SubsetView_ToProto(mapCtx *direct.MapContext, in *krm.AuthorizedView_SubsetView) *pb.AuthorizedView_SubsetView { - if in == nil { - return nil - } - out := &pb.AuthorizedView_SubsetView{} - out.RowPrefixes = in.RowPrefixes - // MISSING: FamilySubsets - return out -} func Backup_FromProto(mapCtx *direct.MapContext, in *pb.Backup) *krm.Backup { if in == nil { return nil diff --git a/pkg/gvks/supportedgvks/gvks_generated.go b/pkg/gvks/supportedgvks/gvks_generated.go index 581ee5c8fe8..9f35e8b6a57 100644 --- a/pkg/gvks/supportedgvks/gvks_generated.go +++ b/pkg/gvks/supportedgvks/gvks_generated.go @@ -772,6 +772,16 @@ var SupportedGVKs = map[schema.GroupVersionKind]GVKMetadata{ "cnrm.cloud.google.com/tf2crd": "true", }, }, + { + Group: "bigtable.cnrm.cloud.google.com", + Version: "v1alpha1", + Kind: "BigtableAuthorizedView", + }: { + Labels: map[string]string{ + "cnrm.cloud.google.com/managed-by-kcc": "true", + "cnrm.cloud.google.com/system": "true", + }, + }, { Group: "bigtable.cnrm.cloud.google.com", Version: "v1alpha1", From 7927a5d6692b29ad8a929acac1e8844dc153cd46 Mon Sep 17 00:00:00 2001 From: Gemma Hou Date: Fri, 14 Mar 2025 02:57:56 +0000 Subject: [PATCH 4/7] conductor: "BigtableAuthorizedView: Create fuzz test" --- .../direct/bigtable/authorizedview_fuzzer.go | 45 +++++++++++++++++++ pkg/controller/direct/register/register.go | 1 + 2 files changed, 46 insertions(+) create mode 100644 pkg/controller/direct/bigtable/authorizedview_fuzzer.go diff --git a/pkg/controller/direct/bigtable/authorizedview_fuzzer.go b/pkg/controller/direct/bigtable/authorizedview_fuzzer.go new file mode 100644 index 00000000000..0cb696790b4 --- /dev/null +++ b/pkg/controller/direct/bigtable/authorizedview_fuzzer.go @@ -0,0 +1,45 @@ +// 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. + +// +tool:fuzz-gen +// proto.message: google.bigtable.admin.v2.AuthorizedView +// api.group: bigtable.cnrm.cloud.google.com + +package bigtable + +import ( + pb "cloud.google.com/go/bigtable/admin/apiv2/adminpb" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/fuzztesting" +) + +func init() { + fuzztesting.RegisterKRMFuzzer(bigtableAuthorizedViewFuzzer()) +} + +func bigtableAuthorizedViewFuzzer() fuzztesting.KRMFuzzer { + f := fuzztesting.NewKRMTypedFuzzer(&pb.AuthorizedView{}, + BigtableAuthorizedViewSpec_FromProto, BigtableAuthorizedViewSpec_ToProto, + BigtableAuthorizedViewObservedState_FromProto, BigtableAuthorizedViewObservedState_ToProto, + ) + + f.SpecFields.Insert(".subset_view") + f.SpecFields.Insert(".etag") + f.SpecFields.Insert(".deletion_protection") + + f.UnimplementedFields.Insert(".name") // special field + + return f +} + + diff --git a/pkg/controller/direct/register/register.go b/pkg/controller/direct/register/register.go index 64d4c520e1b..0ebf83b7d6c 100644 --- a/pkg/controller/direct/register/register.go +++ b/pkg/controller/direct/register/register.go @@ -70,4 +70,5 @@ import ( _ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/vmwareengine" _ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/workflows" _ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/workstations" + _ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/bigtable" ) From 41d1acfd82feb405b2a9deb322d1485ed2b93fbc Mon Sep 17 00:00:00 2001 From: Gemma Hou Date: Fri, 14 Mar 2025 02:59:35 +0000 Subject: [PATCH 5/7] Manual update --- pkg/controller/direct/bigtable/authorizedview_fuzzer.go | 6 ++---- .../direct/{cloudtasks => tasks}/mapper.generated.go | 0 .../direct/{cloudtasks => tasks}/queue_controller.go | 0 pkg/controller/direct/{cloudtasks => tasks}/queue_fuzzer.go | 0 4 files changed, 2 insertions(+), 4 deletions(-) rename pkg/controller/direct/{cloudtasks => tasks}/mapper.generated.go (100%) rename pkg/controller/direct/{cloudtasks => tasks}/queue_controller.go (100%) rename pkg/controller/direct/{cloudtasks => tasks}/queue_fuzzer.go (100%) diff --git a/pkg/controller/direct/bigtable/authorizedview_fuzzer.go b/pkg/controller/direct/bigtable/authorizedview_fuzzer.go index 0cb696790b4..fb16e3f791a 100644 --- a/pkg/controller/direct/bigtable/authorizedview_fuzzer.go +++ b/pkg/controller/direct/bigtable/authorizedview_fuzzer.go @@ -28,9 +28,8 @@ func init() { } func bigtableAuthorizedViewFuzzer() fuzztesting.KRMFuzzer { - f := fuzztesting.NewKRMTypedFuzzer(&pb.AuthorizedView{}, + f := fuzztesting.NewKRMTypedSpecFuzzer(&pb.AuthorizedView{}, BigtableAuthorizedViewSpec_FromProto, BigtableAuthorizedViewSpec_ToProto, - BigtableAuthorizedViewObservedState_FromProto, BigtableAuthorizedViewObservedState_ToProto, ) f.SpecFields.Insert(".subset_view") @@ -38,8 +37,7 @@ func bigtableAuthorizedViewFuzzer() fuzztesting.KRMFuzzer { f.SpecFields.Insert(".deletion_protection") f.UnimplementedFields.Insert(".name") // special field + f.UnimplementedFields.Insert(".subset_view.family_subsets") return f } - - diff --git a/pkg/controller/direct/cloudtasks/mapper.generated.go b/pkg/controller/direct/tasks/mapper.generated.go similarity index 100% rename from pkg/controller/direct/cloudtasks/mapper.generated.go rename to pkg/controller/direct/tasks/mapper.generated.go diff --git a/pkg/controller/direct/cloudtasks/queue_controller.go b/pkg/controller/direct/tasks/queue_controller.go similarity index 100% rename from pkg/controller/direct/cloudtasks/queue_controller.go rename to pkg/controller/direct/tasks/queue_controller.go diff --git a/pkg/controller/direct/cloudtasks/queue_fuzzer.go b/pkg/controller/direct/tasks/queue_fuzzer.go similarity index 100% rename from pkg/controller/direct/cloudtasks/queue_fuzzer.go rename to pkg/controller/direct/tasks/queue_fuzzer.go From 00292f5ac7a544f9e3a2f224dc71cccce6067927 Mon Sep 17 00:00:00 2001 From: Gemma Hou Date: Mon, 17 Mar 2025 22:44:25 +0000 Subject: [PATCH 6/7] fix spec fuzzer --- .../direct/bigtable/authorizedview_fuzzer.go | 2 +- pkg/controller/direct/register/register.go | 1 - pkg/test/fuzz/generate.go | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/controller/direct/bigtable/authorizedview_fuzzer.go b/pkg/controller/direct/bigtable/authorizedview_fuzzer.go index fb16e3f791a..fa04ce45866 100644 --- a/pkg/controller/direct/bigtable/authorizedview_fuzzer.go +++ b/pkg/controller/direct/bigtable/authorizedview_fuzzer.go @@ -24,7 +24,7 @@ import ( ) func init() { - fuzztesting.RegisterKRMFuzzer(bigtableAuthorizedViewFuzzer()) + fuzztesting.RegisterKRMSpecFuzzer(bigtableAuthorizedViewFuzzer()) } func bigtableAuthorizedViewFuzzer() fuzztesting.KRMFuzzer { diff --git a/pkg/controller/direct/register/register.go b/pkg/controller/direct/register/register.go index 0ebf83b7d6c..64d4c520e1b 100644 --- a/pkg/controller/direct/register/register.go +++ b/pkg/controller/direct/register/register.go @@ -70,5 +70,4 @@ import ( _ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/vmwareengine" _ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/workflows" _ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/workstations" - _ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/bigtable" ) diff --git a/pkg/test/fuzz/generate.go b/pkg/test/fuzz/generate.go index 8b79807c22d..bbddff51fe1 100644 --- a/pkg/test/fuzz/generate.go +++ b/pkg/test/fuzz/generate.go @@ -100,6 +100,13 @@ func fillWithRandom0(t *testing.T, randStream *rand.Rand, msg protoreflect.Messa case protoreflect.Uint32Kind: // TODO: handle []uint32 + case protoreflect.BytesKind: + listVal := msg.Mutable(field).List() + for j := 0; j < count; j++ { + b := randomBytes(randStream) + listVal.Append(protoreflect.ValueOf(b)) + } + default: t.Fatalf("unhandled field kind %v: %v", field.Kind(), field) } @@ -312,6 +319,15 @@ func Visit(msgPath string, msg protoreflect.Message, setter func(v protoreflect. visitor.VisitPrimitive(path+"[]", el, setter) } + case protoreflect.BytesKind: + for j := 0; j < count; j++ { + el := listVal.Get(j) + setter := func(v protoreflect.Value) { + listVal.Set(j, v) + } + visitor.VisitPrimitive(path+"[]", el, setter) + } + default: klog.Fatalf("unhandled field kind %v: %v", field.Kind(), field) } From 27bb8a0d5311957c6ee01851bb96aec5e3df5d6d Mon Sep 17 00:00:00 2001 From: Gemma Hou Date: Thu, 20 Mar 2025 20:48:56 +0000 Subject: [PATCH 7/7] manual update --- pkg/controller/direct/{tasks => cloudtasks}/mapper.generated.go | 0 pkg/controller/direct/{tasks => cloudtasks}/queue_controller.go | 0 pkg/controller/direct/{tasks => cloudtasks}/queue_fuzzer.go | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename pkg/controller/direct/{tasks => cloudtasks}/mapper.generated.go (100%) rename pkg/controller/direct/{tasks => cloudtasks}/queue_controller.go (100%) rename pkg/controller/direct/{tasks => cloudtasks}/queue_fuzzer.go (100%) diff --git a/pkg/controller/direct/tasks/mapper.generated.go b/pkg/controller/direct/cloudtasks/mapper.generated.go similarity index 100% rename from pkg/controller/direct/tasks/mapper.generated.go rename to pkg/controller/direct/cloudtasks/mapper.generated.go diff --git a/pkg/controller/direct/tasks/queue_controller.go b/pkg/controller/direct/cloudtasks/queue_controller.go similarity index 100% rename from pkg/controller/direct/tasks/queue_controller.go rename to pkg/controller/direct/cloudtasks/queue_controller.go diff --git a/pkg/controller/direct/tasks/queue_fuzzer.go b/pkg/controller/direct/cloudtasks/queue_fuzzer.go similarity index 100% rename from pkg/controller/direct/tasks/queue_fuzzer.go rename to pkg/controller/direct/cloudtasks/queue_fuzzer.go