Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rds networktype #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apis/database/v1alpha1/rds_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ type RDSInstanceParameters struct {
// +immutable
// +optional
MasterUsername string `json:"masterUsername"`

// NetworkType is indicates service network type
// NetworkType:CLASSIC/VPC
// +optional
// +kubebuilder:default="CLASSIC"
NetworkType string `json:"networkType"`

// VpcId is indicates VPC ID
// +optional
VpcID string `json:"vpcId"`

// VSwitchId is indicates VSwitch ID
// +optional
VSwitchID string `json:"vSwitchId"`

// ZoneId and ZoneIdSlave is the available region
ZoneID string `json:"zoneId"`
ZoneIDSlave1 string `json:"zoneIdSlave1"`
}

// RDS instance states.
Expand Down
1 change: 1 addition & 0 deletions examples/database/rds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
dbInstanceStorageInGB: 20
securityIPList: "0.0.0.0/0"
masterUsername: "test123"
networkType: CLASSIC
writeConnectionSecretToRef:
namespace: crossplane-system
name: example-rds
Expand Down
17 changes: 17 additions & 0 deletions package/crds/database.alibaba.crossplane.io_rdsinstances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,32 @@ spec:
masterUsername:
description: 'MasterUsername is the name for the master user. MySQL Constraints: * Required for MySQL. * Must be 1 to 16 letters or numbers. * First character must be a letter. * Cannot be a reserved word for the chosen database engine. PostgreSQL Constraints: * Required for PostgreSQL. * Must be 1 to 63 letters or numbers. * First character must be a letter. * Cannot be a reserved word for the chosen database engine.'
type: string
networkType:
default: CLASSIC
description: NetworkType is indicates service network type NetworkType:CLASSIC/VPC
type: string
securityIPList:
description: SecurityIPList is the IP whitelist for RDS instances
type: string
vSwitchId:
description: VSwitchId is indicates VSwitch ID
type: string
vpcId:
description: VpcId is indicates VPC ID
type: string
zoneId:
description: ZoneId and ZoneIdSlave is the available region
type: string
zoneIdSlave1:
type: string
required:
- dbInstanceClass
- dbInstanceStorageInGB
- engine
- engineVersion
- securityIPList
- zoneId
- zoneIdSlave1
type: object
providerConfigRef:
description: ProviderConfigReference specifies how the provider that will be used to create, observe, update, and delete this managed resource should be configured.
Expand Down
21 changes: 21 additions & 0 deletions pkg/clients/rds/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ var (
)

const (
// HTTPSScheme indicates request scheme
httpsScheme = "https"
// VPCNetworkType indicates network type by vpc
VPCNetworkType = "VPC"
)

// Client defines RDS client operations
Expand Down Expand Up @@ -70,6 +73,11 @@ type CreateDBInstanceRequest struct {
SecurityIPList string
DBInstanceClass string
DBInstanceStorageInGB int
NetworkType string
VpcID string
VSwitchID string
ZoneID string
ZoneIDSlave1 string
}

type client struct {
Expand Down Expand Up @@ -132,6 +140,14 @@ func (c *client) CreateDBInstance(req *CreateDBInstanceRequest) (*DBInstance, er
request.PayType = "Postpaid"
request.ReadTimeout = 60 * time.Second
request.ClientToken = req.Name
request.InstanceNetworkType = req.NetworkType

if req.NetworkType == VPCNetworkType {
request.ZoneId = req.ZoneID
request.ZoneIdSlave1 = req.ZoneIDSlave1
request.VPCId = req.VpcID
request.VSwitchId = req.VSwitchID
}

resp, err := c.rdsCli.CreateDBInstance(request)
if err != nil {
Expand Down Expand Up @@ -193,6 +209,11 @@ func MakeCreateDBInstanceRequest(name string, p *v1alpha1.RDSInstanceParameters)
SecurityIPList: p.SecurityIPList,
DBInstanceClass: p.DBInstanceClass,
DBInstanceStorageInGB: p.DBInstanceStorageInGB,
NetworkType: p.NetworkType,
VpcID: p.VpcID,
VSwitchID: p.VSwitchID,
ZoneID: p.ZoneID,
ZoneIDSlave1: p.ZoneIDSlave1,
}
}

Expand Down