Skip to content

Commit

Permalink
feat(health): support for some rds.crossplane.io resources (#19076)
Browse files Browse the repository at this point in the history
Signed-off-by: Jellyfrog <[email protected]>
  • Loading branch information
Jellyfrog authored Jul 22, 2024
1 parent f9078f7 commit f26b76a
Show file tree
Hide file tree
Showing 11 changed files with 471 additions and 0 deletions.
41 changes: 41 additions & 0 deletions resource_customizations/rds.aws.crossplane.io/DBCluster/health.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
local hs = {}
if obj.status ~= nil then
if obj.status.conditions ~= nil then
local ready = false
local synced = false
local suspended = false
for i, condition in ipairs(obj.status.conditions) do

if condition.type == "Ready" then
ready = condition.status == "True"
ready_message = condition.reason
elseif condition.type == "Synced" then
synced = condition.status == "True"
if condition.reason == "ReconcileError" then
synced_message = condition.message
elseif condition.reason == "ReconcilePaused" then
suspended = true
suspended_message = condition.reason
end
end
end
if ready and synced then
hs.status = "Healthy"
hs.message = ready_message
elseif synced == false and suspended == true then
hs.status = "Suspended"
hs.message = suspended_message
elseif ready == false and synced == true and suspended == false then
hs.status = "Progressing"
hs.message = "Waiting for DBCluster to be available"
else
hs.status = "Degraded"
hs.message = synced_message
end
return hs
end
end

hs.status = "Progressing"
hs.message = "Waiting for DBCluster to be created"
return hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tests:
- healthStatus:
status: Progressing
message: Waiting for DBCluster to be available
inputPath: testdata/creating.yaml
- healthStatus:
status: Healthy
message: Available
inputPath: testdata/healthy.yaml
- healthStatus:
status: Degraded
message: "create failed: cannot create DBCluster in AWS: InvalidParameterValue:
Invalid DB engine\n\tstatus code: 400, request id: "
inputPath: testdata/degraded.yaml
- healthStatus:
status: Suspended
message: ReconcilePaused
inputPath: testdata/suspended.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: rds.aws.crossplane.io/v1alpha1
kind: DBCluster
metadata:
name: test-rds1
spec:
deletionPolicy: Delete
forProvider:
allowMajorVersionUpgrade: true
applyImmediately: true
autogeneratePassword: true
databaseName: app
dbSubnetGroupName: test-rds
engine: aurora-postgresql
engineVersion: '16.2'
masterUsername: root
skipFinalSnapshot: true
managementPolicies:
- '*'
providerConfigRef:
name: provider-aws
publishConnectionDetailsTo:
configRef:
name: store-config
name: test-rds1-rds
status:
atProvider:
activityStreamStatus: stopped
clusterCreateTime: '2024-07-15T14:23:42Z'
crossAccountClone: false
dbClusterARN: 'arn:aws:rds:abc123:cluster:test-rds1'
dbClusterIdentifier: test-rds1
dbClusterParameterGroup: default.aurora-postgresql16
dbClusterResourceID: cluster-abc123
dbSubnetGroup: test-rds
endpoint: test-rds1.cluster-abc.rds.amazonaws.com
status: creating
vpcSecurityGroups:
- status: active
vpcSecurityGroupID: sg-abc123
conditions:
- lastTransitionTime: '2024-07-15T14:23:42Z'
reason: Creating
status: 'False'
type: Ready
- lastTransitionTime: '2024-07-15T14:23:42Z'
reason: ReconcileSuccess
status: 'True'
type: Synced
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: rds.aws.crossplane.io/v1alpha1
kind: DBCluster
metadata:
name: test-rds1
spec:
deletionPolicy: Delete
forProvider:
allowMajorVersionUpgrade: true
applyImmediately: true
autogeneratePassword: true
databaseName: app
dbSubnetGroupName: test-rds
engine: foobar
engineVersion: '16.2'
masterUsername: root
skipFinalSnapshot: true
managementPolicies:
- '*'
providerConfigRef:
name: provider-aws
publishConnectionDetailsTo:
configRef:
name: store-config
name: test-rds1-rds
status:
atProvider: {}
conditions:
- lastTransitionTime: "2024-07-17T18:03:12Z"
reason: Creating
status: "False"
type: Ready
- lastTransitionTime: "2024-07-17T18:03:12Z"
message: "create failed: cannot create DBCluster in AWS: InvalidParameterValue:
Invalid DB engine\n\tstatus code: 400, request id: "
reason: ReconcileError
status: "False"
type: Synced
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
apiVersion: rds.aws.crossplane.io/v1alpha1
kind: DBCluster
metadata:
name: test-rds1
spec:
deletionPolicy: Delete
forProvider:
allowMajorVersionUpgrade: true
applyImmediately: true
autogeneratePassword: true
databaseName: app
dbSubnetGroupName: test-rds
engine: aurora-postgresql
engineVersion: '16.2'
masterUsername: root
skipFinalSnapshot: true
managementPolicies:
- '*'
providerConfigRef:
name: provider-aws
publishConnectionDetailsTo:
configRef:
name: store-config
name: test-rds1-rds
status:
atProvider:
activityStreamStatus: stopped
clusterCreateTime: "2024-07-15T14:23:42Z"
crossAccountClone: false
dbClusterARN: arn:aws:rds:abc123:cluster:test-rds1
dbClusterIdentifier: test-rds1
dbClusterMembers:
- dbClusterParameterGroupStatus: in-sync
dbInstanceIdentifier: test-rds1-0
isClusterWriter: true
promotionTier: 1
dbClusterParameterGroup: default.aurora-postgresql16
dbClusterResourceID: cluster-abc123
dbSubnetGroup: sandbox5-valhalla-rds
earliestRestorableTime: "2024-07-15T14:24:40Z"
endpoint: test-rds1.cluster-abc123.rds.amazonaws.com
engineVersion: "16.2"
hostedZoneID: abc123
httpEndpointEnabled: false
iamDatabaseAuthenticationEnabled: false
latestRestorableTime: "2024-07-15T14:46:08Z"
multiAZ: false
readerEndpoint: test-rds1.abc123.rds.amazonaws.com
status: available
vpcSecurityGroups:
- status: active
vpcSecurityGroupID: sg-abc123
conditions:
- lastTransitionTime: "2024-07-15T14:48:40Z"
reason: Available
status: "True"
type: Ready
- lastTransitionTime: "2024-07-15T14:23:42Z"
reason: ReconcileSuccess
status: "True"
type: Synced
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: rds.aws.crossplane.io/v1alpha1
kind: DBCluster
metadata:
name: test-rds1
annotations:
crossplane.io/paused: "true"
spec:
deletionPolicy: Delete
forProvider:
allowMajorVersionUpgrade: true
applyImmediately: true
autogeneratePassword: true
databaseName: app
dbSubnetGroupName: test-rds
engine: aurora-postgresql
engineVersion: '16.2'
masterUsername: root
skipFinalSnapshot: true
managementPolicies:
- '*'
providerConfigRef:
name: provider-aws
publishConnectionDetailsTo:
configRef:
name: store-config
name: test-rds1-rds
status:
atProvider: {}
conditions:
- lastTransitionTime: "2024-07-17T18:03:12Z"
reason: Creating
status: "False"
type: Ready
- lastTransitionTime: "2024-07-17T18:04:55Z"
reason: ReconcilePaused
status: "False"
type: Synced
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
local hs = {}
if obj.status ~= nil then
if obj.status.conditions ~= nil then
local ready = false
local synced = false
local suspended = false
for i, condition in ipairs(obj.status.conditions) do

if condition.type == "Ready" then
ready = condition.status == "True"
ready_message = condition.reason
elseif condition.type == "Synced" then
synced = condition.status == "True"
if condition.reason == "ReconcileError" then
synced_message = condition.message
elseif condition.reason == "ReconcilePaused" then
suspended = true
suspended_message = condition.reason
end
end
end
if ready and synced then
hs.status = "Healthy"
hs.message = ready_message
elseif synced == false and suspended == true then
hs.status = "Suspended"
hs.message = suspended_message
elseif ready == false and synced == true and suspended == false then
hs.status = "Progressing"
hs.message = "Waiting for DBInstance to be available"
else
hs.status = "Degraded"
hs.message = synced_message
end
return hs
end
end

hs.status = "Progressing"
hs.message = "Waiting for DBInstance to be created"
return hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests:
- healthStatus:
status: Progressing
message: Waiting for DBInstance to be available
inputPath: testdata/creating.yaml
- healthStatus:
status: Healthy
message: Available
inputPath: testdata/healthy.yaml
- healthStatus:
status: Degraded
message: "update failed: cannot update DBInstance in AWS: InvalidParameterValue:
Invalid DB Instance class: db.t4g.foobar\n\tstatus code: 400, request id: "
inputPath: testdata/degraded.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: rds.aws.crossplane.io/v1alpha1
kind: DBInstance
metadata:
name: test-rds1-0
spec:
deletionPolicy: Delete
forProvider:
autoMinorVersionUpgrade: true
caCertificateIdentifier: rds-ca-rsa2048-g1
dbClusterIdentifier: test-rds1
dbInstanceClass: db.t4g.medium
dbName: app
dbSubnetGroupName: test-rds
enablePerformanceInsights: false
engine: aurora-postgresql
licenseModel: postgresql-license
masterUsername: root
multiAZ: false
preferredMaintenanceWindow: 'tue:00:36-tue:01:06'
promotionTier: 1
publiclyAccessible: false
region: eu-north-1
storageThroughput: 0
managementPolicies:
- '*'
providerConfigRef:
name: provider-aws
status:
atProvider:
certificateDetails:
cAIdentifier: rds-ca-rsa2048-g1
customerOwnedIPEnabled: false
dbInstanceARN: 'arn:aws:rds:abc:db:test-rds1-0'
dbInstanceIdentifier: test-rds1-0
dbInstancePort: 0
dbInstanceStatus: creating
conditions:
- lastTransitionTime: '2024-07-15T14:25:07Z'
reason: Creating
status: 'False'
type: Ready
- lastTransitionTime: '2024-07-15T14:25:07Z'
reason: ReconcileSuccess
status: 'True'
type: Synced
Loading

0 comments on commit f26b76a

Please sign in to comment.