Skip to content

Commit 37280c9

Browse files
authored
Merge pull request #2250 from swisscom/feature/add-rds-instance-db-read-replica
feat(rds): add db-instance read replica
2 parents 16704fd + 5ecc518 commit 37280c9

File tree

10 files changed

+948
-83
lines changed

10 files changed

+948
-83
lines changed

apis/rds/v1alpha1/custom_types.go

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,72 @@ type CustomDBInstanceParameters struct {
676676
// +optional
677677
SkipFinalSnapshot bool `json:"skipFinalSnapshot,omitempty"`
678678

679+
// The identifier of the Multi-AZ DB cluster that will act as the source for
680+
// the read replica. Each DB cluster can have up to 15 read replicas.
681+
//
682+
// Constraints:
683+
//
684+
// * Must be the identifier of an existing Multi-AZ DB cluster.
685+
//
686+
// * Can't be specified if the SourceDBInstanceIdentifier parameter is also
687+
// specified.
688+
//
689+
// * The specified DB cluster must have automatic backups enabled, that is,
690+
// its backup retention period must be greater than 0.
691+
//
692+
// * The source DB cluster must be in the same Amazon Web Services Region
693+
// as the read replica. Cross-Region replication isn't supported.
694+
// +immutable
695+
// +crossplane:generate:reference:type=github.com/crossplane-contrib/provider-aws/apis/rds/v1alpha1.DBCluster
696+
SourceDBClusterID *string `json:"sourceDBClusterID,omitempty"`
697+
698+
// SourceDBClusterIDRef is a reference to a DBCluster used to set
699+
// SourceDBClusterID.
700+
// +optional
701+
SourceDBClusterIDRef *xpv1.Reference `json:"sourceDBClusterIDRef,omitempty"`
702+
703+
// SourceDBClusterIDSelector selects a reference to a DBCluster used to
704+
// set SourceDBClusterID.
705+
// +optional
706+
SourceDBClusterIDSelector *xpv1.Selector `json:"sourceDBClusterIDSelector,omitempty"`
707+
708+
// The identifier of the DB instance that will act as the source for the read
709+
// replica. Each DB instance can have up to 15 read replicas, with the exception of
710+
// Oracle and SQL Server, which can have up to five.
711+
//
712+
// Constraints:
713+
//
714+
// - Must be the identifier of an existing Db2, MariaDB, MySQL, Oracle,
715+
// PostgreSQL, or SQL Server DB instance.
716+
//
717+
// * Can't be specified if the SourceDBClusterIdentifier parameter is also
718+
// specified.
719+
//
720+
// - For the limitations of Oracle read replicas, see [Version and licensing considerations for RDS for Oracle replicas]in the Amazon RDS User
721+
// Guide.
722+
//
723+
// - For the limitations of SQL Server read replicas, see [Read replica limitations with SQL Server]in the Amazon RDS User
724+
// Guide.
725+
//
726+
// - The specified DB instance must have automatic backups enabled, that is, its
727+
// backup retention period must be greater than 0.
728+
//
729+
// [Read replica limitations with SQL Server]: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.ReadReplicas.html#SQLServer.ReadReplicas.Limitations
730+
// [Version and licensing considerations for RDS for Oracle replicas]: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/oracle-read-replicas.limitations.html#oracle-read-replicas.limitations.versions-and-licenses
731+
// +immutable
732+
// +crossplane:generate:reference:type=github.com/crossplane-contrib/provider-aws/apis/rds/v1alpha1.DBInstance
733+
SourceDBInstanceID *string `json:"sourceDBInstanceID,omitempty"`
734+
735+
// SourceDBInstanceIDRef is a reference to a DBInstance used to set
736+
// SourceDBInstanceID.
737+
// +optional
738+
SourceDBInstanceIDRef *xpv1.Reference `json:"sourceDBInstanceIDRef,omitempty"`
739+
740+
// SourceDBInstanceIDSelector selects a reference to a DBInstance used to
741+
// set SourceDBInstanceID.
742+
// +optional
743+
SourceDBInstanceIDSelector *xpv1.Selector `json:"sourceDBInstanceIDSelector,omitempty"`
744+
679745
// A list of Amazon EC2 VPC security groups to authorize on this DB instance.
680746
// This change is asynchronously applied as soon as possible.
681747
//
@@ -744,7 +810,13 @@ type CustomDBInstanceParameters struct {
744810
}
745811

746812
// CustomDBInstanceObservation includes the custom status fields of DBInstance.
747-
type CustomDBInstanceObservation struct{}
813+
type CustomDBInstanceObservation struct {
814+
// AWS API calls don't return any field which explicitly indicates the role of database, which would be really convenient.
815+
// DatabaseRole works on the similar principle as the Role field in AWS UI("Aurora and RDS" > "Databases").
816+
817+
// The database role may be Standalone, Primary or Replica.
818+
DatabaseRole *string `json:"databaseRole,omitempty"`
819+
}
748820

749821
// CustomDBInstanceRoleAssociationParameters are custom parameters for the DBInstanceRoleAssociation
750822
type CustomDBInstanceRoleAssociationParameters struct {

apis/rds/v1alpha1/zz_generated.deepcopy.go

Lines changed: 36 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
apiVersion: rds.aws.crossplane.io/v1alpha1
3+
kind: DBInstance
4+
metadata:
5+
name: example-read-replica-1
6+
spec:
7+
forProvider:
8+
region: eu-central-1
9+
sourceDBInstanceID: example-dbinstance
10+
engine: postgres
11+
dbInstanceClass: db.t3.micro
12+
autoMinorVersionUpgrade: true
13+
allowMajorVersionUpgrade: true # unset per default (Note: supported dbInstanceClass and dbParameterGroup with correct dbParameterGroupFamily needed, before majorVersion upgrade possible; applyImmediately matters)
14+
applyImmediately: true
15+
skipFinalSnapshot: true
16+
# masterUserPasswordSecretRef:
17+
# key: password
18+
# name: replica-test
19+
# namespace: default
20+
writeConnectionSecretToRef:
21+
name: example-read-replica-1
22+
namespace: default
23+
providerConfigRef:
24+
name: provider-aws
25+
26+
# By default, the read replica has the master user credentials as the source database.
27+
#---
28+
#apiVersion: v1
29+
#kind: Secret
30+
#metadata:
31+
# name: replica-test
32+
# namespace: default
33+
#type: Opaque
34+
#data:
35+
# password: dGVzdFBhc3N3b3JkITEyMw== # testPassword!123

package/crds/rds.aws.crossplane.io_dbinstances.yaml

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,206 @@ spec:
17381738
You must specify a FinalDBSnapshotIdentifier parameter if SkipFinalSnapshot
17391739
is disabled.
17401740
type: boolean
1741+
sourceDBClusterID:
1742+
description: |-
1743+
The identifier of the Multi-AZ DB cluster that will act as the source for
1744+
the read replica. Each DB cluster can have up to 15 read replicas.
1745+
1746+
Constraints:
1747+
1748+
* Must be the identifier of an existing Multi-AZ DB cluster.
1749+
1750+
* Can't be specified if the SourceDBInstanceIdentifier parameter is also
1751+
specified.
1752+
1753+
* The specified DB cluster must have automatic backups enabled, that is,
1754+
its backup retention period must be greater than 0.
1755+
1756+
* The source DB cluster must be in the same Amazon Web Services Region
1757+
as the read replica. Cross-Region replication isn't supported.
1758+
type: string
1759+
sourceDBClusterIDRef:
1760+
description: |-
1761+
SourceDBClusterIDRef is a reference to a DBCluster used to set
1762+
SourceDBClusterID.
1763+
properties:
1764+
name:
1765+
description: Name of the referenced object.
1766+
type: string
1767+
policy:
1768+
description: Policies for referencing.
1769+
properties:
1770+
resolution:
1771+
default: Required
1772+
description: |-
1773+
Resolution specifies whether resolution of this reference is required.
1774+
The default is 'Required', which means the reconcile will fail if the
1775+
reference cannot be resolved. 'Optional' means this reference will be
1776+
a no-op if it cannot be resolved.
1777+
enum:
1778+
- Required
1779+
- Optional
1780+
type: string
1781+
resolve:
1782+
description: |-
1783+
Resolve specifies when this reference should be resolved. The default
1784+
is 'IfNotPresent', which will attempt to resolve the reference only when
1785+
the corresponding field is not present. Use 'Always' to resolve the
1786+
reference on every reconcile.
1787+
enum:
1788+
- Always
1789+
- IfNotPresent
1790+
type: string
1791+
type: object
1792+
required:
1793+
- name
1794+
type: object
1795+
sourceDBClusterIDSelector:
1796+
description: |-
1797+
SourceDBClusterIDSelector selects a reference to a DBCluster used to
1798+
set SourceDBClusterID.
1799+
properties:
1800+
matchControllerRef:
1801+
description: |-
1802+
MatchControllerRef ensures an object with the same controller reference
1803+
as the selecting object is selected.
1804+
type: boolean
1805+
matchLabels:
1806+
additionalProperties:
1807+
type: string
1808+
description: MatchLabels ensures an object with matching labels
1809+
is selected.
1810+
type: object
1811+
policy:
1812+
description: Policies for selection.
1813+
properties:
1814+
resolution:
1815+
default: Required
1816+
description: |-
1817+
Resolution specifies whether resolution of this reference is required.
1818+
The default is 'Required', which means the reconcile will fail if the
1819+
reference cannot be resolved. 'Optional' means this reference will be
1820+
a no-op if it cannot be resolved.
1821+
enum:
1822+
- Required
1823+
- Optional
1824+
type: string
1825+
resolve:
1826+
description: |-
1827+
Resolve specifies when this reference should be resolved. The default
1828+
is 'IfNotPresent', which will attempt to resolve the reference only when
1829+
the corresponding field is not present. Use 'Always' to resolve the
1830+
reference on every reconcile.
1831+
enum:
1832+
- Always
1833+
- IfNotPresent
1834+
type: string
1835+
type: object
1836+
type: object
1837+
sourceDBInstanceID:
1838+
description: |-
1839+
The identifier of the DB instance that will act as the source for the read
1840+
replica. Each DB instance can have up to 15 read replicas, with the exception of
1841+
Oracle and SQL Server, which can have up to five.
1842+
1843+
Constraints:
1844+
1845+
- Must be the identifier of an existing Db2, MariaDB, MySQL, Oracle,
1846+
PostgreSQL, or SQL Server DB instance.
1847+
1848+
* Can't be specified if the SourceDBClusterIdentifier parameter is also
1849+
specified.
1850+
1851+
- For the limitations of Oracle read replicas, see [Version and licensing considerations for RDS for Oracle replicas]in the Amazon RDS User
1852+
Guide.
1853+
1854+
- For the limitations of SQL Server read replicas, see [Read replica limitations with SQL Server]in the Amazon RDS User
1855+
Guide.
1856+
1857+
- The specified DB instance must have automatic backups enabled, that is, its
1858+
backup retention period must be greater than 0.
1859+
1860+
[Read replica limitations with SQL Server]: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.ReadReplicas.html#SQLServer.ReadReplicas.Limitations
1861+
[Version and licensing considerations for RDS for Oracle replicas]: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/oracle-read-replicas.limitations.html#oracle-read-replicas.limitations.versions-and-licenses
1862+
type: string
1863+
sourceDBInstanceIDRef:
1864+
description: |-
1865+
SourceDBInstanceIDRef is a reference to a DBInstance used to set
1866+
SourceDBInstanceID.
1867+
properties:
1868+
name:
1869+
description: Name of the referenced object.
1870+
type: string
1871+
policy:
1872+
description: Policies for referencing.
1873+
properties:
1874+
resolution:
1875+
default: Required
1876+
description: |-
1877+
Resolution specifies whether resolution of this reference is required.
1878+
The default is 'Required', which means the reconcile will fail if the
1879+
reference cannot be resolved. 'Optional' means this reference will be
1880+
a no-op if it cannot be resolved.
1881+
enum:
1882+
- Required
1883+
- Optional
1884+
type: string
1885+
resolve:
1886+
description: |-
1887+
Resolve specifies when this reference should be resolved. The default
1888+
is 'IfNotPresent', which will attempt to resolve the reference only when
1889+
the corresponding field is not present. Use 'Always' to resolve the
1890+
reference on every reconcile.
1891+
enum:
1892+
- Always
1893+
- IfNotPresent
1894+
type: string
1895+
type: object
1896+
required:
1897+
- name
1898+
type: object
1899+
sourceDBInstanceIDSelector:
1900+
description: |-
1901+
SourceDBInstanceIDSelector selects a reference to a DBInstance used to
1902+
set SourceDBInstanceID.
1903+
properties:
1904+
matchControllerRef:
1905+
description: |-
1906+
MatchControllerRef ensures an object with the same controller reference
1907+
as the selecting object is selected.
1908+
type: boolean
1909+
matchLabels:
1910+
additionalProperties:
1911+
type: string
1912+
description: MatchLabels ensures an object with matching labels
1913+
is selected.
1914+
type: object
1915+
policy:
1916+
description: Policies for selection.
1917+
properties:
1918+
resolution:
1919+
default: Required
1920+
description: |-
1921+
Resolution specifies whether resolution of this reference is required.
1922+
The default is 'Required', which means the reconcile will fail if the
1923+
reference cannot be resolved. 'Optional' means this reference will be
1924+
a no-op if it cannot be resolved.
1925+
enum:
1926+
- Required
1927+
- Optional
1928+
type: string
1929+
resolve:
1930+
description: |-
1931+
Resolve specifies when this reference should be resolved. The default
1932+
is 'IfNotPresent', which will attempt to resolve the reference only when
1933+
the corresponding field is not present. Use 'Always' to resolve the
1934+
reference on every reconcile.
1935+
enum:
1936+
- Always
1937+
- IfNotPresent
1938+
type: string
1939+
type: object
1940+
type: object
17411941
storageEncrypted:
17421942
description: |-
17431943
Specifes whether the DB instance is encrypted. By default, it isn't encrypted.
@@ -2157,6 +2357,9 @@ spec:
21572357
For more information about CoIPs, see Customer-owned IP addresses (https://docs.aws.amazon.com/outposts/latest/userguide/routing.html#ip-addressing)
21582358
in the Amazon Web Services Outposts User Guide.
21592359
type: boolean
2360+
databaseRole:
2361+
description: The database role may be Standalone, Primary or Replica.
2362+
type: string
21602363
dbClusterIdentifier:
21612364
description: |-
21622365
If the DB instance is a member of a DB cluster, indicates the name of the

0 commit comments

Comments
 (0)