diff --git a/apis/bigtable/v1alpha1/authorizedview_identity.go b/apis/bigtable/v1alpha1/authorizedview_identity.go new file mode 100644 index 00000000000..ab235b3a697 --- /dev/null +++ b/apis/bigtable/v1alpha1/authorizedview_identity.go @@ -0,0 +1,107 @@ +// 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" + + 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" + "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 *bigtablev1beta1.TableIdentity + id string +} + +func (i *AuthorizedViewIdentity) String() string { + return i.parent.String() + "/authorizedViews/" + i.id +} + +func (i *AuthorizedViewIdentity) ID() string { + return i.id +} + +// New builds a AuthorizedViewIdentity from the Config Connector AuthorizedView object. +func NewAuthorizedViewIdentity(ctx context.Context, reader client.Reader, obj *BigtableAuthorizedView) (*AuthorizedViewIdentity, error) { + + // Get Parent + tableExternal, err := obj.Spec.TableRef.NormalizedExternal(ctx, reader, obj.GetNamespace()) + if err != nil { + return nil, err + } + instanceIdentity, tableID, err := bigtablev1beta1.ParseTableExternal(tableExternal) + if err != nil { + return nil, err + } + + // 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.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", + resourceID, actualResourceID) + } + } + return &AuthorizedViewIdentity{ + parent: &bigtablev1beta1.TableIdentity{ + Parent: instanceIdentity, + Id: tableID, + }, + id: resourceID, + }, nil +} + +func ParseAuthorizedViewExternal(external string) (*bigtablev1beta1.TableIdentity, string, error) { + tokens := strings.Split(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) + } + p := &bigtablev1beta1.TableIdentity{ + Parent: &bigtablev1beta1.InstanceIdentity{ + Parent: &parent.ProjectParent{ + ProjectID: tokens[1], + }, + Id: tokens[3], + }, + Id: tokens[5], + } + resourceID := tokens[7] + return p, 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..464bf4ae3ee --- /dev/null +++ b/apis/bigtable/v1alpha1/authorizedview_types.go @@ -0,0 +1,115 @@ +// 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 ( + 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 +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 +// +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/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/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 +} 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 new file mode 100644 index 00000000000..6edfae2b954 --- /dev/null +++ b/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_bigtableauthorizedviews.bigtable.cnrm.cloud.google.com.yaml @@ -0,0 +1,239 @@ +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 + 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 + - 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_fuzzer.go b/pkg/controller/direct/bigtable/authorizedview_fuzzer.go new file mode 100644 index 00000000000..fa04ce45866 --- /dev/null +++ b/pkg/controller/direct/bigtable/authorizedview_fuzzer.go @@ -0,0 +1,43 @@ +// 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.RegisterKRMSpecFuzzer(bigtableAuthorizedViewFuzzer()) +} + +func bigtableAuthorizedViewFuzzer() fuzztesting.KRMFuzzer { + f := fuzztesting.NewKRMTypedSpecFuzzer(&pb.AuthorizedView{}, + BigtableAuthorizedViewSpec_FromProto, BigtableAuthorizedViewSpec_ToProto, + ) + + f.SpecFields.Insert(".subset_view") + f.SpecFields.Insert(".etag") + 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/bigtable/authorizedview_mapper.go b/pkg/controller/direct/bigtable/authorizedview_mapper.go new file mode 100644 index 00000000000..0e55de2ecf0 --- /dev/null +++ b/pkg/controller/direct/bigtable/authorizedview_mapper.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 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.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 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", 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) }