Skip to content

Commit

Permalink
add rds networktype
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyu.jiang committed Nov 4, 2021
1 parent 6a555ef commit 928b95f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
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
16 changes: 16 additions & 0 deletions package/crds/database.alibaba.crossplane.io_rdsinstances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ spec:
securityIPList:
description: SecurityIPList is the IP whitelist for RDS instances
type: string
networkType:
default: CLASSIC
description: NetworkType is indicates service network type NetworkType:CLASSIC/VPC
type: string
vSwitchId:
description: VSwitchId is indicates VSwitch ID
type: string
vpcId:
description: VpcId is indicates VPC ID
type: string
zoneId:
description: zoneId is the region for use
type: string
zoneIdSlave1:
description: zoneIdSlave1 is the region for use1
type: string
required:
- dbInstanceClass
- dbInstanceStorageInGB
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

0 comments on commit 928b95f

Please sign in to comment.