From dc80551ba183bcd103453aad7f8bb3b3738bc4ba Mon Sep 17 00:00:00 2001 From: "chenyu.jiang" Date: Wed, 3 Nov 2021 23:44:26 -0700 Subject: [PATCH] add rds networktype --- apis/database/v1alpha1/rds_types.go | 18 ++++++++++++++++ examples/database/rds.yaml | 1 + ...se.alibaba.crossplane.io_rdsinstances.yaml | 17 +++++++++++++++ pkg/clients/rds/rds.go | 21 +++++++++++++++++++ 4 files changed, 57 insertions(+) diff --git a/apis/database/v1alpha1/rds_types.go b/apis/database/v1alpha1/rds_types.go index a309cb9..4fb6c14 100644 --- a/apis/database/v1alpha1/rds_types.go +++ b/apis/database/v1alpha1/rds_types.go @@ -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. diff --git a/examples/database/rds.yaml b/examples/database/rds.yaml index 12b9190..f985116 100644 --- a/examples/database/rds.yaml +++ b/examples/database/rds.yaml @@ -14,6 +14,7 @@ spec: dbInstanceStorageInGB: 20 securityIPList: "0.0.0.0/0" masterUsername: "test123" + networkType: CLASSIC writeConnectionSecretToRef: namespace: crossplane-system name: example-rds diff --git a/package/crds/database.alibaba.crossplane.io_rdsinstances.yaml b/package/crds/database.alibaba.crossplane.io_rdsinstances.yaml index c67afd4..a2d305a 100644 --- a/package/crds/database.alibaba.crossplane.io_rdsinstances.yaml +++ b/package/crds/database.alibaba.crossplane.io_rdsinstances.yaml @@ -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. diff --git a/pkg/clients/rds/rds.go b/pkg/clients/rds/rds.go index 0ec1094..3fc7f74 100644 --- a/pkg/clients/rds/rds.go +++ b/pkg/clients/rds/rds.go @@ -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 @@ -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 { @@ -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 { @@ -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, } }