From 2a9b0dc206a9bac3568d0faba2c274095c6a9a83 Mon Sep 17 00:00:00 2001 From: Joyce Ma Date: Thu, 12 Dec 2024 18:20:59 +0000 Subject: [PATCH] Clean up --- apis/alloydb/v1alpha1/instance_types.go | 11 ++-- apis/alloydb/v1beta1/instance_types.go | 11 ++-- ...stances.alloydb.cnrm.cloud.google.com.yaml | 22 ++++---- .../direct/alloydb/instance_controller.go | 13 +---- .../direct/alloydb/instance_mappings.go | 50 ------------------- .../resource-docs/alloydb/alloydbinstance.md | 11 ++-- 6 files changed, 26 insertions(+), 92 deletions(-) diff --git a/apis/alloydb/v1alpha1/instance_types.go b/apis/alloydb/v1alpha1/instance_types.go index 5210a86ba33..41a70666fcb 100644 --- a/apis/alloydb/v1alpha1/instance_types.go +++ b/apis/alloydb/v1alpha1/instance_types.go @@ -39,13 +39,12 @@ type AlloyDBInstanceSpec struct { // of arbitrary data. This is distinct from labels. Annotations map[string]string `json:"annotations,omitempty"` - // Availability type of an Instance. Defaults to REGIONAL for both primary and read instances. + // Availability type of an Instance. If empty, defaults to REGIONAL for primary instances. // - // Note that primary and read instances can have different availability types. - // Only READ_POOL instance supports ZONAL type. Users can't specify the zone for READ_POOL instance. - // Zone is automatically chosen from the list of zones in the region specified. - // Read pool of size 1 can only have zonal availability. Read pools with node count of 2 or more - // can have regional availability (nodes are present in 2 or more zones in a region). Possible values: ["AVAILABILITY_TYPE_UNSPECIFIED", "ZONAL", "REGIONAL"]. + // For read pools, availabilityType is always UNSPECIFIED. Instances in the + // read pools are evenly distributed across available zones within the region + // (i.e. read pools with more than one node will have a node in at least two zones). + // Possible values: ["AVAILABILITY_TYPE_UNSPECIFIED", "ZONAL", "REGIONAL"]. AvailabilityType *string `json:"availabilityType,omitempty"` // Database flags. Set at instance level. * They are copied diff --git a/apis/alloydb/v1beta1/instance_types.go b/apis/alloydb/v1beta1/instance_types.go index 78ac8ad5333..2fe8fe57ce2 100644 --- a/apis/alloydb/v1beta1/instance_types.go +++ b/apis/alloydb/v1beta1/instance_types.go @@ -39,13 +39,12 @@ type AlloyDBInstanceSpec struct { // of arbitrary data. This is distinct from labels. Annotations map[string]string `json:"annotations,omitempty"` - // Availability type of an Instance. Defaults to REGIONAL for both primary and read instances. + // Availability type of an Instance. If empty, defaults to REGIONAL for primary instances. // - // Note that primary and read instances can have different availability types. - // Only READ_POOL instance supports ZONAL type. Users can't specify the zone for READ_POOL instance. - // Zone is automatically chosen from the list of zones in the region specified. - // Read pool of size 1 can only have zonal availability. Read pools with node count of 2 or more - // can have regional availability (nodes are present in 2 or more zones in a region). Possible values: ["AVAILABILITY_TYPE_UNSPECIFIED", "ZONAL", "REGIONAL"]. + // For read pools, availabilityType is always UNSPECIFIED. Instances in the + // read pools are evenly distributed across available zones within the region + // (i.e. read pools with more than one node will have a node in at least two zones). + // Possible values: ["AVAILABILITY_TYPE_UNSPECIFIED", "ZONAL", "REGIONAL"]. AvailabilityType *string `json:"availabilityType,omitempty"` // Database flags. Set at instance level. * They are copied diff --git a/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_alloydbinstances.alloydb.cnrm.cloud.google.com.yaml b/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_alloydbinstances.alloydb.cnrm.cloud.google.com.yaml index b32deca3614..72edcbdce04 100644 --- a/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_alloydbinstances.alloydb.cnrm.cloud.google.com.yaml +++ b/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_alloydbinstances.alloydb.cnrm.cloud.google.com.yaml @@ -69,13 +69,12 @@ spec: type: object availabilityType: description: |- - Availability type of an Instance. Defaults to REGIONAL for both primary and read instances. + Availability type of an Instance. If empty, defaults to REGIONAL for primary instances. - Note that primary and read instances can have different availability types. - Only READ_POOL instance supports ZONAL type. Users can't specify the zone for READ_POOL instance. - Zone is automatically chosen from the list of zones in the region specified. - Read pool of size 1 can only have zonal availability. Read pools with node count of 2 or more - can have regional availability (nodes are present in 2 or more zones in a region). Possible values: ["AVAILABILITY_TYPE_UNSPECIFIED", "ZONAL", "REGIONAL"]. + For read pools, availabilityType is always UNSPECIFIED. Instances in the + read pools are evenly distributed across available zones within the region + (i.e. read pools with more than one node will have a node in at least two zones). + Possible values: ["AVAILABILITY_TYPE_UNSPECIFIED", "ZONAL", "REGIONAL"]. type: string clusterRef: description: The AlloyDBInstance cluster that this resource belongs @@ -360,13 +359,12 @@ spec: type: object availabilityType: description: |- - Availability type of an Instance. Defaults to REGIONAL for both primary and read instances. + Availability type of an Instance. If empty, defaults to REGIONAL for primary instances. - Note that primary and read instances can have different availability types. - Only READ_POOL instance supports ZONAL type. Users can't specify the zone for READ_POOL instance. - Zone is automatically chosen from the list of zones in the region specified. - Read pool of size 1 can only have zonal availability. Read pools with node count of 2 or more - can have regional availability (nodes are present in 2 or more zones in a region). Possible values: ["AVAILABILITY_TYPE_UNSPECIFIED", "ZONAL", "REGIONAL"]. + For read pools, availabilityType is always UNSPECIFIED. Instances in the + read pools are evenly distributed across available zones within the region + (i.e. read pools with more than one node will have a node in at least two zones). + Possible values: ["AVAILABILITY_TYPE_UNSPECIFIED", "ZONAL", "REGIONAL"]. type: string clusterRef: description: The AlloyDBInstance cluster that this resource belongs diff --git a/pkg/controller/direct/alloydb/instance_controller.go b/pkg/controller/direct/alloydb/instance_controller.go index abb031d971c..61597895e88 100644 --- a/pkg/controller/direct/alloydb/instance_controller.go +++ b/pkg/controller/direct/alloydb/instance_controller.go @@ -132,13 +132,11 @@ var _ directbase.Adapter = &instanceAdapter{} func (a *instanceAdapter) Find(ctx context.Context) (bool, error) { log := klog.FromContext(ctx) log.V(2).Info("getting instance", "name", a.id) - fmt.Printf("getting instance: %v\n", a.id) req := &alloydbpb.GetInstanceRequest{Name: a.id.String()} instancepb, err := a.gcpClient.GetInstance(ctx, req) if err != nil { log.V(2).Info("error getting instance", "name", a.id, "error", err) - fmt.Printf("instance error: %+v\n", err) if direct.IsNotFound(err) { return false, nil } @@ -146,7 +144,6 @@ func (a *instanceAdapter) Find(ctx context.Context) (bool, error) { return false, fmt.Errorf("getting instance %q: %w", a.id, err) } - fmt.Printf("retrieved instance: %+v\n", instancepb) a.actual = instancepb return true, nil } @@ -155,7 +152,6 @@ func (a *instanceAdapter) Find(ctx context.Context) (bool, error) { func (a *instanceAdapter) Create(ctx context.Context, createOp *directbase.CreateOperation) error { log := klog.FromContext(ctx) log.V(2).Info("creating instance", "name", a.id) - fmt.Printf("creating instance: %v\n", a.id) mapCtx := &direct.MapContext{} desired := a.desired.DeepCopy() @@ -234,14 +230,13 @@ func (a *instanceAdapter) Update(ctx context.Context, updateOp *directbase.Updat desiredLabels["managed-by-cnrm"] = "true" if !reflect.DeepEqual(a.actual.GetLabels(), desiredLabels) { log.V(2).Info("'metadata.labels' field is updated (-old +new)", cmp.Diff(a.actual.GetLabels(), desiredLabels)) - updatePaths = append(updatePaths, "availability_type") + updatePaths = append(updatePaths, "labels") } if len(updatePaths) == 0 { log.V(2).Info("no field needs update", "name", a.id) return nil } - fmt.Printf("maqiuyu... updateMasks: %+v\n", updatePaths) updateMask := &fieldmaskpb.FieldMask{ Paths: updatePaths, } @@ -377,12 +372,6 @@ func (a *instanceAdapter) Delete(ctx context.Context, deleteOp *directbase.Delet req := &alloydbpb.DeleteInstanceRequest{Name: a.id.String()} op, err := a.gcpClient.DeleteInstance(ctx, req) - if op != nil { - opMetadata, opErr := op.Metadata() - fmt.Printf("maqiuyu... delete operation: %v\n%v\nMetadata:\n%+v\nErr while getting metadata\n%v\n", op.Name(), op.Done(), opMetadata, opErr) - } else { - fmt.Printf("maqiuyu... delete operation not triggered. Maybe there is an error? %+v\n", err) - } if err != nil { log.V(2).Info("error deleting instance", "name", a.id, "error", err) if direct.IsNotFound(err) { diff --git a/pkg/controller/direct/alloydb/instance_mappings.go b/pkg/controller/direct/alloydb/instance_mappings.go index c5b40b0e122..fe2087c0530 100644 --- a/pkg/controller/direct/alloydb/instance_mappings.go +++ b/pkg/controller/direct/alloydb/instance_mappings.go @@ -15,8 +15,6 @@ package alloydb import ( - "fmt" - pb "cloud.google.com/go/alloydb/apiv1beta/alloydbpb" krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/alloydb/v1beta1" @@ -29,39 +27,14 @@ func AlloyDBInstanceSpec_FromProto(mapCtx *direct.MapContext, in *pb.Instance) * } out := &krm.AlloyDBInstanceSpec{} out.Annotations = in.GetAnnotations() - //out.AvailabilityType = direct.LazyPtr(in.GetAvailabilityType().String()) out.AvailabilityType = direct.Enum_FromProto(mapCtx, in.GetAvailabilityType()) out.DatabaseFlags = in.GetDatabaseFlags() out.DisplayName = direct.LazyPtr(in.GetDisplayName()) out.GceZone = direct.LazyPtr(in.GetGceZone()) - //out.InstanceType = direct.LazyPtr(in.GetInstanceType().String()) out.InstanceType = direct.Enum_FromProto(mapCtx, in.GetInstanceType()) - // how to handle the labels? out.MachineConfig = Instance_MachineConfig_FromProto(mapCtx, in.GetMachineConfig()) out.NetworkConfig = Instance_InstanceNetworkConfig_FromProto(mapCtx, in.GetNetworkConfig()) out.ReadPoolConfig = Instance_ReadPoolConfig_FromProto(mapCtx, in.GetReadPoolConfig()) - - // MISSING: Uid - // MISSING: CreateTime - // MISSING: UpdateTime - // MISSING: DeleteTime - // MISSING: Labels??? - // MISSING: State - // MISSING: WritableNode - // MISSING: Nodes - // MISSING: QueryInsightsConfig - // MISSING: ObservabilityConfig - // MISSING: IpAddress - // MISSING: PublicIpAddress - // MISSING: Reconciling - // MISSING: Etag - // MISSING: UpdatePolicy - // MISSING: ClientConnectionConfig - // MISSING: SatisfiesPzs - // MISSING: PscInstanceConfig - // MISSING: GeminiConfig - // MISSING: OutboundPublicIpAddresses - fmt.Printf("maqiuyu...AlloyDBInstanceSpec_FromProto: %+v\n", out) return out } @@ -76,31 +49,9 @@ func AlloyDBInstanceSpec_ToProto(mapCtx *direct.MapContext, in *krm.AlloyDBInsta out.DisplayName = direct.ValueOf(in.DisplayName) out.GceZone = direct.ValueOf(in.GceZone) out.InstanceType = direct.Enum_ToProto[pb.Instance_InstanceType](mapCtx, in.InstanceType) - // how to handle the labels? out.MachineConfig = Instance_MachineConfig_ToProto(mapCtx, in.MachineConfig) out.NetworkConfig = Instance_InstanceNetworkConfig_ToProto(mapCtx, in.NetworkConfig) out.ReadPoolConfig = Instance_ReadPoolConfig_ToProto(mapCtx, in.ReadPoolConfig) - // MISSING: Uid - // MISSING: CreateTime - // MISSING: UpdateTime - // MISSING: DeleteTime - // MISSING: Labels should be an internal field for to map metadata.labels - // MISSING: State - // MISSING: WritableNode - // MISSING: Nodes - // MISSING: QueryInsightsConfig - // MISSING: ObservabilityConfig - // MISSING: IpAddress - // MISSING: PublicIpAddress - // MISSING: Reconciling - // MISSING: Etag - // MISSING: UpdatePolicy - // MISSING: ClientConnectionConfig - // MISSING: SatisfiesPzs - // MISSING: PscInstanceConfig - // MISSING: GeminiConfig - // MISSING: OutboundPublicIpAddresses - fmt.Printf("maqiuyu...AlloyDBInstanceSpec_ToProto: %+v\n", out) return out } @@ -119,6 +70,5 @@ func AlloyDBInstanceStatus_FromProto(mapCtx *direct.MapContext, in *pb.Instance) out.Uid = direct.LazyPtr(in.Uid) out.UpdateTime = direct.StringTimestamp_FromProto(mapCtx, in.GetUpdateTime()) - fmt.Printf("maqiuyu...AlloyDBInstanceStatus_FromProto: %+v", out) return out } diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/alloydb/alloydbinstance.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/alloydb/alloydbinstance.md index 3770dd32b68..f2bb9bac9d2 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/alloydb/alloydbinstance.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/alloydb/alloydbinstance.md @@ -119,13 +119,12 @@ resourceID: string

string

-

{% verbatim %}Availability type of an Instance. Defaults to REGIONAL for both primary and read instances. +

{% verbatim %}Availability type of an Instance. If empty, defaults to REGIONAL for primary instances. -Note that primary and read instances can have different availability types. -Only READ_POOL instance supports ZONAL type. Users can't specify the zone for READ_POOL instance. -Zone is automatically chosen from the list of zones in the region specified. -Read pool of size 1 can only have zonal availability. Read pools with node count of 2 or more -can have regional availability (nodes are present in 2 or more zones in a region). Possible values: ["AVAILABILITY_TYPE_UNSPECIFIED", "ZONAL", "REGIONAL"].{% endverbatim %}

+For read pools, availabilityType is always UNSPECIFIED. Instances in the +read pools are evenly distributed across available zones within the region +(i.e. read pools with more than one node will have a node in at least two zones). +Possible values: ["AVAILABILITY_TYPE_UNSPECIFIED", "ZONAL", "REGIONAL"].{% endverbatim %}