Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
maqiuyujoyce committed Dec 17, 2024
1 parent f4f99f1 commit 2a9b0dc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 92 deletions.
11 changes: 5 additions & 6 deletions apis/alloydb/v1alpha1/instance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions apis/alloydb/v1beta1/instance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 1 addition & 12 deletions pkg/controller/direct/alloydb/instance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,18 @@ 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
}

return false, fmt.Errorf("getting instance %q: %w", a.id, err)
}

fmt.Printf("retrieved instance: %+v\n", instancepb)
a.actual = instancepb
return true, nil
}
Expand All @@ -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()
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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) {
Expand Down
50 changes: 0 additions & 50 deletions pkg/controller/direct/alloydb/instance_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,12 @@ resourceID: string
</td>
<td>
<p><code class="apitype">string</code></p>
<p>{% verbatim %}Availability type of an Instance. Defaults to REGIONAL for both primary and read instances.
<p>{% 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 %}</p>
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 %}</p>
</td>
</tr>
<tr>
Expand Down

0 comments on commit 2a9b0dc

Please sign in to comment.