Skip to content

Commit 97e4bdc

Browse files
adityathebemoshloop
authored andcommitted
map aws statuses by the resource type as well
1 parent 27dd8b5 commit 97e4bdc

File tree

3 files changed

+143
-76
lines changed

3 files changed

+143
-76
lines changed

pkg/health/health.go

+14-13
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@ const (
2424
// Indicates that resource is missing in the cluster.
2525
HealthStatusMissing HealthStatusCode = "Missing"
2626

27-
HealthStatusCreating = "Creating"
28-
HealthStatusDeleted = "Deleted"
29-
HealthStatusDeleting = "Deleting"
30-
HealthStatusError = "Error"
31-
HealthStatusInaccesible = "Inaccesible"
32-
HealthStatusInfo = "Info"
33-
HealthStatusPending = "Pending"
34-
HealthStatusMaintenance = "Maintenance"
35-
HealthStatusScaling = "Scaling"
36-
HealthStatusUnhealthy = "Unhealthy"
37-
HealthStatusUpdating = "Updating"
38-
HealthStatusWarning = "Warning"
39-
HealthStatusStopping = "Stopping"
27+
HealthStatusCreating HealthStatusCode = "Creating"
28+
HealthStatusDeleted HealthStatusCode = "Deleted"
29+
HealthStatusDeleting HealthStatusCode = "Deleting"
30+
HealthStatusError HealthStatusCode = "Error"
31+
HealthStatusInaccesible HealthStatusCode = "Inaccesible"
32+
HealthStatusInfo HealthStatusCode = "Info"
33+
HealthStatusPending HealthStatusCode = "Pending"
34+
HealthStatusMaintenance HealthStatusCode = "Maintenance"
35+
HealthStatusScaling HealthStatusCode = "Scaling"
36+
HealthStatusUnhealthy HealthStatusCode = "Unhealthy"
37+
HealthStatusUpdating HealthStatusCode = "Updating"
38+
HealthStatusWarning HealthStatusCode = "Warning"
39+
HealthStatusStopped HealthStatusCode = "Stopped"
40+
HealthStatusStopping HealthStatusCode = "Stopping"
4041
)
4142

4243
// Implements custom health assessment that overrides built-in assessment

pkg/health/health_aws.go

+90-63
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,104 @@ package health
22

33
import "strings"
44

5+
const (
6+
AWSResourceTypeEBS string = "ebs"
7+
AWSResourceTypeEC2 string = "ec2"
8+
AWSResourceTypeEKS string = "eks"
9+
AWSResourceTypeELB string = "elb"
10+
AWSResourceTypeRDS string = "rds"
11+
AWSResourceTypeVPC string = "vpc"
12+
AWSResourceTypeSubnet string = "subnet"
13+
)
14+
515
// MapAWSStatus maps an AWS resource's statuses to a Health Code
6-
func MapAWSStatus(status string) string {
7-
if s, found := awsStatusMap[strings.ToLower(status)]; found {
8-
return string(s)
16+
func MapAWSStatus(status string, resourceType string) string {
17+
if resourceStatuses, found := awsStatusMap[resourceType]; found {
18+
if v, found := resourceStatuses[strings.ToLower(status)]; found {
19+
return string(v)
20+
}
921
}
1022

1123
return string(HealthStatusUnknown)
1224
}
1325

14-
var awsStatusMap = map[string]HealthStatusCode{
15-
"available": HealthStatusHealthy,
16-
"pending": HealthStatusPending,
17-
"running": HealthStatusHealthy,
18-
"shutting-down": HealthStatusDeleting,
19-
"stopped": HealthStatusSuspended,
20-
"stopping": HealthStatusDeleting,
21-
"terminated": HealthStatusDeleted,
26+
var awsStatusMap = map[string]map[string]HealthStatusCode{
27+
AWSResourceTypeEC2: {
28+
"pending": HealthStatusPending,
29+
"running": HealthStatusHealthy,
30+
"shutting-down": HealthStatusDeleting,
31+
"stopped": HealthStatusStopped,
32+
"stopping": HealthStatusStopping,
33+
"terminated": HealthStatusDeleted,
34+
},
35+
36+
AWSResourceTypeEKS: {
37+
"creating": HealthStatusCreating,
38+
"active": HealthStatusHealthy,
39+
"deleting": HealthStatusDeleting,
40+
"failed": HealthStatusError,
41+
"updating": HealthStatusUpdating,
42+
"pending": HealthStatusPending,
43+
},
44+
45+
AWSResourceTypeEBS: {
46+
"creating": HealthStatusCreating,
47+
"available": HealthStatusStopped,
48+
"in-use": HealthStatusHealthy,
49+
"deleting": HealthStatusDeleting,
50+
"deleted": HealthStatusDeleted,
51+
"error": HealthStatusError,
52+
},
2253

23-
// EKS
24-
"creating": HealthStatusCreating,
25-
"active": HealthStatusHealthy,
26-
"deleting": HealthStatusDeleting,
27-
"failed": HealthStatusError,
28-
"updating": HealthStatusUpdating,
29-
// "pending": HealthStatusPending,
54+
AWSResourceTypeRDS: {
55+
"available": HealthStatusHealthy,
56+
"billed": HealthStatusHealthy,
57+
"backing-up": HealthStatusMaintenance,
58+
"configuring-enhanced-monitoring": HealthStatusMaintenance,
59+
"configuring-iam-database-auth": HealthStatusMaintenance,
60+
"configuring-log-exports": HealthStatusMaintenance,
61+
"converting-to-vpc": HealthStatusUpdating,
62+
"creating": HealthStatusCreating,
63+
"delete-precheck": HealthStatusMaintenance,
64+
"deleting": HealthStatusDeleting,
65+
"failed": HealthStatusUnhealthy,
66+
"inaccessible-encryption-credentials": HealthStatusInaccesible,
67+
"inaccessible-encryption-credentials-recoverable": HealthStatusInaccesible,
68+
"incompatible-network": HealthStatusUnhealthy,
69+
"incompatible-option-group": HealthStatusUnhealthy,
70+
"incompatible-parameters": HealthStatusUnhealthy,
71+
"incompatible-restore": HealthStatusUnhealthy,
72+
"insufficient-capacity": HealthStatusUnhealthy,
73+
"maintenance": HealthStatusMaintenance,
74+
"modifying": HealthStatusUpdating,
75+
"moving-to-vpc": HealthStatusMaintenance,
76+
"rebooting": HealthStatusStopping,
77+
"resetting-master-credentials": HealthStatusMaintenance,
78+
"renaming": HealthStatusMaintenance,
79+
"restore-error": HealthStatusError,
80+
"starting": HealthStatusProgressing,
81+
"stopped": HealthStatusStopped,
82+
"stopping": HealthStatusStopping,
83+
"storage-config-upgrade": HealthStatusUpdating,
84+
"storage-full": HealthStatusUnhealthy,
85+
"storage-optimization": HealthStatusMaintenance,
86+
"upgrading": HealthStatusUpdating,
87+
},
3088

31-
// EBS
32-
// "creating": HealthStatusCreating,
33-
// "available": HealthStatusUpdating,
34-
"in-use": HealthStatusHealthy,
35-
// "deleting": HealthStatusDeleting,
36-
"deleted": HealthStatusDeleted,
37-
"error": HealthStatusError,
89+
AWSResourceTypeELB: {
90+
"active": HealthStatusHealthy,
91+
"provisioning": HealthStatusProgressing,
92+
"active_impaired": HealthStatusWarning,
93+
"failed": HealthStatusError,
94+
},
3895

39-
// RDS Status
40-
// "available": HealthStatusHealthy,
41-
"billed": HealthStatusHealthy,
42-
"backing-up": HealthStatusMaintenance,
43-
"configuring-enhanced-monitoring": HealthStatusMaintenance,
44-
"configuring-iam-database-auth": HealthStatusMaintenance,
45-
"configuring-log-exports": HealthStatusMaintenance,
46-
"converting-to-vpc": HealthStatusUpdating,
47-
// "creating": HealthStatusCreating,
48-
"delete-precheck": HealthStatusMaintenance,
49-
// "deleting": HealthStatusDeleting,
50-
// "failed": HealthStatusUnhealthy,
51-
"inaccessible-encryption-credentials": HealthStatusInaccesible,
52-
"inaccessible-encryption-credentials-recoverable": HealthStatusInaccesible,
53-
"incompatible-network": HealthStatusUnhealthy,
54-
"incompatible-option-group": HealthStatusUnhealthy,
55-
"incompatible-parameters": HealthStatusUnhealthy,
56-
"incompatible-restore": HealthStatusUnhealthy,
57-
"insufficient-capacity": HealthStatusUnhealthy,
58-
"maintenance": HealthStatusMaintenance,
59-
"modifying": HealthStatusUpdating,
60-
"moving-to-vpc": HealthStatusMaintenance,
61-
"rebooting": HealthStatusStopping,
62-
"resetting-master-credentials": HealthStatusMaintenance,
63-
"renaming": HealthStatusMaintenance,
64-
"restore-error": HealthStatusError,
65-
"starting": HealthStatusProgressing,
66-
// "stopped": HealthStatusSuspended,
67-
// "stopping": HealthStatusStopping,
68-
"storage-config-upgrade": HealthStatusUpdating,
69-
"storage-full": HealthStatusUnhealthy,
70-
"storage-optimization": HealthStatusMaintenance,
71-
"upgrading": HealthStatusUpdating,
96+
AWSResourceTypeVPC: {
97+
"pending": HealthStatusPending,
98+
"available": HealthStatusHealthy,
99+
},
72100

73-
// ELB
74-
// "active": HealthStatusHealthy,
75-
"provisioning": HealthStatusProgressing,
76-
"active_impaired": HealthStatusWarning,
77-
// "failed": HealthStatusError,
101+
AWSResourceTypeSubnet: {
102+
"pending": HealthStatusPending,
103+
"available": HealthStatusHealthy,
104+
},
78105
}

pkg/health/health_aws_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package health
2+
3+
import "testing"
4+
5+
func TestMapAWSStatus(t *testing.T) {
6+
type args struct {
7+
status string
8+
resourceType string
9+
}
10+
tests := []struct {
11+
name string
12+
args args
13+
want HealthStatusCode
14+
}{
15+
{
16+
name: "ec2",
17+
args: args{status: "shutting-down", resourceType: AWSResourceTypeEC2},
18+
want: HealthStatusDeleting,
19+
},
20+
{
21+
name: "unknown resource",
22+
args: args{status: "shutting-down", resourceType: "blob"},
23+
want: HealthStatusUnknown,
24+
},
25+
{
26+
name: "unknown type",
27+
args: args{status: "wakingup", resourceType: AWSResourceTypeEC2},
28+
want: HealthStatusUnknown,
29+
},
30+
}
31+
32+
for _, tt := range tests {
33+
t.Run(tt.name, func(t *testing.T) {
34+
if got := MapAWSStatus(tt.args.status, tt.args.resourceType); got != string(tt.want) {
35+
t.Errorf("MapAWSStatus() = %v, want %v", got, tt.want)
36+
}
37+
})
38+
}
39+
}

0 commit comments

Comments
 (0)