Skip to content

Commit

Permalink
chore: Compare sqlinstance-replica mockgcp
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvigil committed Sep 11, 2024
1 parent 8429bbd commit b76b205
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 753 deletions.
9 changes: 7 additions & 2 deletions mockgcp/mocksql/operations_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ func (s *operations) startLRO(ctx context.Context, op *pb.Operation, obj proto.M

switch obj := obj.(type) {
case *pb.DatabaseInstance:
op.TargetId = obj.Name
op.TargetLink = fmt.Sprintf("https://sqladmin.googleapis.com/sql/v1beta4/projects/%s/instances/%s", op.TargetProject, op.TargetId)
if op.OperationType == pb.Operation_CREATE_REPLICA {
op.TargetId = obj.MasterInstanceName
op.TargetLink = fmt.Sprintf("https://sqladmin.googleapis.com/sql/v1beta4/projects/%s/instances/%s", op.TargetProject, op.TargetId)
} else {
op.TargetId = obj.Name
op.TargetLink = fmt.Sprintf("https://sqladmin.googleapis.com/sql/v1beta4/projects/%s/instances/%s", op.TargetProject, op.TargetId)
}
case *pb.User:
op.TargetId = obj.Instance
op.TargetLink = fmt.Sprintf("https://sqladmin.googleapis.com/sql/v1beta4/projects/%s/instances/%s", obj.Project, obj.Instance)
Expand Down
12 changes: 11 additions & 1 deletion mockgcp/mocksql/sqlinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/fields"
"github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/projects"
pb "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/generated/mockgcp/cloud/sql/v1beta4"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -249,6 +250,9 @@ func (s *sqlInstancesService) Insert(ctx context.Context, req *pb.SqlInstancesIn
TargetProject: name.Project.ID,
OperationType: pb.Operation_CREATE,
}
if obj.InstanceType == pb.SqlInstanceType_READ_REPLICA_INSTANCE {
op.OperationType = pb.Operation_CREATE_REPLICA
}

return s.operations.startLRO(ctx, op, obj, func() (proto.Message, error) {
return obj, nil
Expand Down Expand Up @@ -581,13 +585,19 @@ func populateDefaults(obj *pb.DatabaseInstance) {
backupConfiguration := settings.BackupConfiguration
if backupConfiguration == nil {
backupConfiguration = &pb.BackupConfiguration{}
settings.BackupConfiguration = backupConfiguration
} else {
if isPostgres(obj) {
setDefaultBool(&backupConfiguration.ReplicationLogArchivingEnabled, false)
}

if backupConfiguration.BinaryLogEnabled != nil && backupConfiguration.BinaryLogEnabled.Value {
if isPostgres(obj) || isMysql(obj) {
backupConfiguration.TransactionalLogStorageState = direct.PtrTo(pb.BackupConfiguration_CLOUD_STORAGE)
}
}
}
backupConfiguration.Kind = "sql#backupConfiguration"
settings.BackupConfiguration = backupConfiguration

backupRetentionSettings := backupConfiguration.BackupRetentionSettings
if backupRetentionSettings == nil {
Expand Down
Loading

0 comments on commit b76b205

Please sign in to comment.