Skip to content

Commit

Permalink
feat: add status/ready for aws resources (#29)
Browse files Browse the repository at this point in the history
* feat: add bump client workflow

* fix: health aws resource health

* chore: cleanup

* Apply suggestions from code review

---------

Co-authored-by: Moshe Immerman <moshe@flanksource.com>
  • Loading branch information
adityathebe and moshloop authored May 21, 2024
1 parent db628bf commit 0f8fbf3
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 67 deletions.
48 changes: 47 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Create Release
on:
push:
branches:
- master
- main
permissions:
contents: read
Expand All @@ -28,3 +27,50 @@ jobs:
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

bump-clients:
runs-on: ubuntu-latest
needs: [semantic-release]
if: needs.semantic-release.outputs.new-release-published == 'true'
strategy:
matrix:
repos: ['mission-control', 'canary-checker', 'commons', 'config-db', 'duty', 'gomplate']
steps:
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
with:
repository: flanksource/${{ matrix.repos }}
token: ${{ secrets.FLANKBOT }}

- name: Setup Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: v1.22.x

- name: Create commits
run: |
# Sleep to let index refresh
sleep 60
go get github.com/flanksource/duty@v${{ needs.semantic-release.outputs.release-version }}
go mod tidy
if [ -d "hack/generate-schemas" ]; then
cd hack/generate-schemas && go mod tidy
fi
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e # v6.0.5
with:
branch: 'bump-duty-auto-pr'
commit-message: 'chore: bump duty to v${{ needs.semantic-release.outputs.release-version }}'
title: 'chore: bump duty to v${{ needs.semantic-release.outputs.release-version }}'
token: ${{ secrets.FLANKBOT }}
labels: dependencies

- name: Enable Pull Request Automerge
if: steps.cpr.outputs.pull-request-operation == 'created'
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.FLANKBOT }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: squash
repository: flanksource/${{ matrix.repos }}
136 changes: 71 additions & 65 deletions pkg/health/health_aws.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package health

import "strings"
import (
"strings"
)

const (
AWSResourceTypeEBS string = "ebs"
Expand All @@ -12,94 +14,98 @@ const (
AWSResourceTypeSubnet string = "subnet"
)

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

return string(HealthStatusUnknown)
return HealthStatus{
Status: HealthStatusUnknown,
Health: HealthUnknown,
Ready: false,
}
}

var awsStatusMap = map[string]map[string]HealthStatusCode{
var awsResourceHealthmap = map[string]map[string]HealthStatus{
AWSResourceTypeEC2: {
"pending": HealthStatusPending,
"running": HealthStatusHealthy,
"shutting-down": HealthStatusDeleting,
"stopped": HealthStatusStopped,
"stopping": HealthStatusStopping,
"terminated": HealthStatusDeleted,
"pending": HealthStatus{Status: HealthStatusPending, Health: HealthUnknown},
"running": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
"shutting-down": HealthStatus{Status: HealthStatusDeleting, Health: HealthUnknown},
"stopped": HealthStatus{Status: HealthStatusStopped, Health: HealthUnknown},
"stopping": HealthStatus{Status: HealthStatusStopping, Health: HealthUnknown},
"terminated": HealthStatus{Status: HealthStatusDeleted, Health: HealthUnknown},
},

AWSResourceTypeEKS: {
"creating": HealthStatusCreating,
"active": HealthStatusHealthy,
"deleting": HealthStatusDeleting,
"failed": HealthStatusError,
"updating": HealthStatusUpdating,
"pending": HealthStatusPending,
"creating": HealthStatus{Status: HealthStatusCreating, Health: HealthUnknown},
"active": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
"deleting": HealthStatus{Status: HealthStatusDeleting, Health: HealthUnknown},
"failed": HealthStatus{Status: HealthStatusError, Health: HealthUnhealthy},
"updating": HealthStatus{Status: HealthStatusUpdating, Health: HealthUnknown},
"pending": HealthStatus{Status: HealthStatusPending, Health: HealthUnknown},
},

AWSResourceTypeEBS: {
"creating": HealthStatusCreating,
"available": HealthStatusStopped,
"in-use": HealthStatusHealthy,
"deleting": HealthStatusDeleting,
"deleted": HealthStatusDeleted,
"error": HealthStatusError,
"creating": HealthStatus{Status: HealthStatusCreating, Health: HealthUnknown},
"available": HealthStatus{Status: HealthStatusStopped, Health: HealthHealthy, Ready: true},
"in-use": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
"deleting": HealthStatus{Status: HealthStatusDeleting, Health: HealthUnknown},
"deleted": HealthStatus{Status: HealthStatusDeleted, Health: HealthUnknown},
"error": HealthStatus{Status: HealthStatusError, Health: HealthUnhealthy},
},

// https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/accessing-monitoring.html
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": HealthStatusRestart,
"resetting-master-credentials": HealthStatusMaintenance,
"renaming": HealthStatusMaintenance,
"restore-error": HealthStatusError,
"starting": HealthStatusStarting,
"stopped": HealthStatusStopped,
"stopping": HealthStatusStopping,
"storage-config-upgrade": HealthStatusUpdating,
"storage-full": HealthStatusUnhealthy,
"storage-optimization": HealthStatusMaintenance,
"upgrading": HealthStatusUpdating,
"available": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
"billed": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
"backing-up": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy},
"configuring-enhanced-monitoring": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy},
"configuring-iam-database-auth": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy},
"configuring-log-exports": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy},
"converting-to-vpc": HealthStatus{Status: HealthStatusUpdating, Health: HealthHealthy, Ready: true},
"creating": HealthStatus{Status: HealthStatusCreating, Health: HealthUnknown},
"delete-precheck": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy, Ready: true},
"deleting": HealthStatus{Status: HealthStatusDeleting, Health: HealthUnknown},
"failed": HealthStatus{Status: HealthStatusUnhealthy, Health: HealthUnhealthy},
"inaccessible-encryption-credentials": HealthStatus{Status: HealthStatusInaccesible, Health: HealthUnhealthy},
"inaccessible-encryption-credentials-recoverable": HealthStatus{Status: HealthStatusInaccesible, Health: HealthWarning},
"incompatible-network": HealthStatus{Status: HealthStatusUnhealthy, Health: HealthUnhealthy},
"incompatible-option-group": HealthStatus{Status: HealthStatusUnhealthy, Health: HealthUnhealthy},
"incompatible-parameters": HealthStatus{Status: HealthStatusUnhealthy, Health: HealthUnhealthy},
"incompatible-restore": HealthStatus{Status: HealthStatusUnhealthy, Health: HealthUnhealthy},
"insufficient-capacity": HealthStatus{Status: HealthStatusUnhealthy, Health: HealthUnhealthy},
"maintenance": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy},
"modifying": HealthStatus{Status: HealthStatusUpdating, Health: HealthHealthy, Ready: true},
"moving-to-vpc": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy},
"rebooting": HealthStatus{Status: HealthStatusRestart, Health: HealthHealthy},
"resetting-master-credentials": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy, Ready: true},
"renaming": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy, Ready: true},
"restore-error": HealthStatus{Status: HealthStatusError, Health: HealthUnhealthy},
"starting": HealthStatus{Status: HealthStatusStarting, Health: HealthUnknown},
"stopped": HealthStatus{Status: HealthStatusStopped, Health: HealthHealthy},
"stopping": HealthStatus{Status: HealthStatusStopping, Health: HealthUnknown},
"storage-config-upgrade": HealthStatus{Status: HealthStatusUpdating, Health: HealthHealthy, Ready: true},
"storage-full": HealthStatus{Status: HealthStatusUnhealthy, Health: HealthUnhealthy},
"storage-optimization": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy, Ready: true},
"upgrading": HealthStatus{Status: HealthStatusUpdating, Health: HealthHealthy},
},

AWSResourceTypeELB: {
"active": HealthStatusHealthy,
"provisioning": HealthStatusCreating,
"active_impaired": HealthStatusWarning,
"failed": HealthStatusError,
"active": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
"provisioning": HealthStatus{Status: HealthStatusCreating, Health: HealthUnknown},
"active_impaired": HealthStatus{Status: HealthStatusWarning, Health: HealthWarning, Ready: true},
"failed": HealthStatus{Status: HealthStatusError, Health: HealthUnhealthy},
},

AWSResourceTypeVPC: {
"pending": HealthStatusPending,
"available": HealthStatusHealthy,
"pending": HealthStatus{Status: HealthStatusPending, Health: HealthUnknown},
"available": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
},

AWSResourceTypeSubnet: {
"pending": HealthStatusPending,
"available": HealthStatusHealthy,
"pending": HealthStatus{Status: HealthStatusPending, Health: HealthUnknown},
"available": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
},
}
2 changes: 1 addition & 1 deletion pkg/health/health_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestMapAWSStatus(t *testing.T) {

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) {
if got := GetAWSResourceHealth(tt.args.resourceType, tt.args.status); got.Status != tt.want {
t.Errorf("MapAWSStatus() = %v, want %v", got, tt.want)
}
})
Expand Down

0 comments on commit 0f8fbf3

Please sign in to comment.