From 928b95f19d120c884c3d8a72c106df6e1e01fd69 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 | 16 ++++++++++++++ pkg/clients/rds/rds.go | 21 +++++++++++++++++++ 4 files changed, 56 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..0521c39 100644 --- a/package/crds/database.alibaba.crossplane.io_rdsinstances.yaml +++ b/package/crds/database.alibaba.crossplane.io_rdsinstances.yaml @@ -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 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, } }