Skip to content

Commit

Permalink
map aws statuses by the resource type as well
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored and moshloop committed Jan 30, 2024
1 parent 27dd8b5 commit 97e4bdc
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 76 deletions.
27 changes: 14 additions & 13 deletions pkg/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ const (
// Indicates that resource is missing in the cluster.
HealthStatusMissing HealthStatusCode = "Missing"

HealthStatusCreating = "Creating"
HealthStatusDeleted = "Deleted"
HealthStatusDeleting = "Deleting"
HealthStatusError = "Error"
HealthStatusInaccesible = "Inaccesible"
HealthStatusInfo = "Info"
HealthStatusPending = "Pending"
HealthStatusMaintenance = "Maintenance"
HealthStatusScaling = "Scaling"
HealthStatusUnhealthy = "Unhealthy"
HealthStatusUpdating = "Updating"
HealthStatusWarning = "Warning"
HealthStatusStopping = "Stopping"
HealthStatusCreating HealthStatusCode = "Creating"
HealthStatusDeleted HealthStatusCode = "Deleted"
HealthStatusDeleting HealthStatusCode = "Deleting"
HealthStatusError HealthStatusCode = "Error"
HealthStatusInaccesible HealthStatusCode = "Inaccesible"
HealthStatusInfo HealthStatusCode = "Info"
HealthStatusPending HealthStatusCode = "Pending"
HealthStatusMaintenance HealthStatusCode = "Maintenance"
HealthStatusScaling HealthStatusCode = "Scaling"
HealthStatusUnhealthy HealthStatusCode = "Unhealthy"
HealthStatusUpdating HealthStatusCode = "Updating"
HealthStatusWarning HealthStatusCode = "Warning"
HealthStatusStopped HealthStatusCode = "Stopped"
HealthStatusStopping HealthStatusCode = "Stopping"
)

// Implements custom health assessment that overrides built-in assessment
Expand Down
153 changes: 90 additions & 63 deletions pkg/health/health_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,104 @@ package health

import "strings"

const (
AWSResourceTypeEBS string = "ebs"
AWSResourceTypeEC2 string = "ec2"
AWSResourceTypeEKS string = "eks"
AWSResourceTypeELB string = "elb"
AWSResourceTypeRDS string = "rds"
AWSResourceTypeVPC string = "vpc"
AWSResourceTypeSubnet string = "subnet"
)

// MapAWSStatus maps an AWS resource's statuses to a Health Code
func MapAWSStatus(status string) string {
if s, found := awsStatusMap[strings.ToLower(status)]; found {
return string(s)
func MapAWSStatus(status string, resourceType string) string {
if resourceStatuses, found := awsStatusMap[resourceType]; found {
if v, found := resourceStatuses[strings.ToLower(status)]; found {
return string(v)
}
}

return string(HealthStatusUnknown)
}

var awsStatusMap = map[string]HealthStatusCode{
"available": HealthStatusHealthy,
"pending": HealthStatusPending,
"running": HealthStatusHealthy,
"shutting-down": HealthStatusDeleting,
"stopped": HealthStatusSuspended,
"stopping": HealthStatusDeleting,
"terminated": HealthStatusDeleted,
var awsStatusMap = map[string]map[string]HealthStatusCode{
AWSResourceTypeEC2: {
"pending": HealthStatusPending,
"running": HealthStatusHealthy,
"shutting-down": HealthStatusDeleting,
"stopped": HealthStatusStopped,
"stopping": HealthStatusStopping,
"terminated": HealthStatusDeleted,
},

AWSResourceTypeEKS: {
"creating": HealthStatusCreating,
"active": HealthStatusHealthy,
"deleting": HealthStatusDeleting,
"failed": HealthStatusError,
"updating": HealthStatusUpdating,
"pending": HealthStatusPending,
},

AWSResourceTypeEBS: {
"creating": HealthStatusCreating,
"available": HealthStatusStopped,
"in-use": HealthStatusHealthy,
"deleting": HealthStatusDeleting,
"deleted": HealthStatusDeleted,
"error": HealthStatusError,
},

// EKS
"creating": HealthStatusCreating,
"active": HealthStatusHealthy,
"deleting": HealthStatusDeleting,
"failed": HealthStatusError,
"updating": HealthStatusUpdating,
// "pending": HealthStatusPending,
AWSResourceTypeRDS: {
"available": HealthStatusHealthy,
"billed": HealthStatusHealthy,
"backing-up": HealthStatusMaintenance,
"configuring-enhanced-monitoring": HealthStatusMaintenance,
"configuring-iam-database-auth": HealthStatusMaintenance,
"configuring-log-exports": HealthStatusMaintenance,
"converting-to-vpc": HealthStatusUpdating,
"creating": HealthStatusCreating,
"delete-precheck": HealthStatusMaintenance,
"deleting": HealthStatusDeleting,
"failed": HealthStatusUnhealthy,
"inaccessible-encryption-credentials": HealthStatusInaccesible,
"inaccessible-encryption-credentials-recoverable": HealthStatusInaccesible,
"incompatible-network": HealthStatusUnhealthy,
"incompatible-option-group": HealthStatusUnhealthy,
"incompatible-parameters": HealthStatusUnhealthy,
"incompatible-restore": HealthStatusUnhealthy,
"insufficient-capacity": HealthStatusUnhealthy,
"maintenance": HealthStatusMaintenance,
"modifying": HealthStatusUpdating,
"moving-to-vpc": HealthStatusMaintenance,
"rebooting": HealthStatusStopping,
"resetting-master-credentials": HealthStatusMaintenance,
"renaming": HealthStatusMaintenance,
"restore-error": HealthStatusError,
"starting": HealthStatusProgressing,
"stopped": HealthStatusStopped,
"stopping": HealthStatusStopping,
"storage-config-upgrade": HealthStatusUpdating,
"storage-full": HealthStatusUnhealthy,
"storage-optimization": HealthStatusMaintenance,
"upgrading": HealthStatusUpdating,
},

// EBS
// "creating": HealthStatusCreating,
// "available": HealthStatusUpdating,
"in-use": HealthStatusHealthy,
// "deleting": HealthStatusDeleting,
"deleted": HealthStatusDeleted,
"error": HealthStatusError,
AWSResourceTypeELB: {
"active": HealthStatusHealthy,
"provisioning": HealthStatusProgressing,
"active_impaired": HealthStatusWarning,
"failed": HealthStatusError,
},

// RDS Status
// "available": HealthStatusHealthy,
"billed": HealthStatusHealthy,
"backing-up": HealthStatusMaintenance,
"configuring-enhanced-monitoring": HealthStatusMaintenance,
"configuring-iam-database-auth": HealthStatusMaintenance,
"configuring-log-exports": HealthStatusMaintenance,
"converting-to-vpc": HealthStatusUpdating,
// "creating": HealthStatusCreating,
"delete-precheck": HealthStatusMaintenance,
// "deleting": HealthStatusDeleting,
// "failed": HealthStatusUnhealthy,
"inaccessible-encryption-credentials": HealthStatusInaccesible,
"inaccessible-encryption-credentials-recoverable": HealthStatusInaccesible,
"incompatible-network": HealthStatusUnhealthy,
"incompatible-option-group": HealthStatusUnhealthy,
"incompatible-parameters": HealthStatusUnhealthy,
"incompatible-restore": HealthStatusUnhealthy,
"insufficient-capacity": HealthStatusUnhealthy,
"maintenance": HealthStatusMaintenance,
"modifying": HealthStatusUpdating,
"moving-to-vpc": HealthStatusMaintenance,
"rebooting": HealthStatusStopping,
"resetting-master-credentials": HealthStatusMaintenance,
"renaming": HealthStatusMaintenance,
"restore-error": HealthStatusError,
"starting": HealthStatusProgressing,
// "stopped": HealthStatusSuspended,
// "stopping": HealthStatusStopping,
"storage-config-upgrade": HealthStatusUpdating,
"storage-full": HealthStatusUnhealthy,
"storage-optimization": HealthStatusMaintenance,
"upgrading": HealthStatusUpdating,
AWSResourceTypeVPC: {
"pending": HealthStatusPending,
"available": HealthStatusHealthy,
},

// ELB
// "active": HealthStatusHealthy,
"provisioning": HealthStatusProgressing,
"active_impaired": HealthStatusWarning,
// "failed": HealthStatusError,
AWSResourceTypeSubnet: {
"pending": HealthStatusPending,
"available": HealthStatusHealthy,
},
}
39 changes: 39 additions & 0 deletions pkg/health/health_aws_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package health

import "testing"

func TestMapAWSStatus(t *testing.T) {
type args struct {
status string
resourceType string
}
tests := []struct {
name string
args args
want HealthStatusCode
}{
{
name: "ec2",
args: args{status: "shutting-down", resourceType: AWSResourceTypeEC2},
want: HealthStatusDeleting,
},
{
name: "unknown resource",
args: args{status: "shutting-down", resourceType: "blob"},
want: HealthStatusUnknown,
},
{
name: "unknown type",
args: args{status: "wakingup", resourceType: AWSResourceTypeEC2},
want: HealthStatusUnknown,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := MapAWSStatus(tt.args.status, tt.args.resourceType); got != string(tt.want) {
t.Errorf("MapAWSStatus() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 97e4bdc

Please sign in to comment.