From df8cf4052d3787f3cb798066bef726cf5bed490d Mon Sep 17 00:00:00 2001 From: Moshe Immermam Date: Sun, 17 Nov 2024 16:11:44 +0200 Subject: [PATCH] chore: improve fixture based testing --- go.mod | 1 + go.sum | 4 + pkg/health/health.go | 13 + pkg/health/health_aws_ecs_test.go | 18 - pkg/health/health_cnrm_test.go | 18 - pkg/health/health_fixtures_test.go | 21 + pkg/health/health_test.go | 69 +++- .../AWS/Cloudformation/Stack/healthy.yaml | 8 + .../AWS/Cloudformation/Stack/unhealthy.yaml | 10 + .../testdata/AWS/ECS/Cluster/healthy.yaml | 13 + .../testdata/AWS/ECS/Service/healthy.yaml | 376 ++++++++++++++++++ .../ECS/Task/{failed.yaml => unhealthy.yaml} | 3 + .../LoadBalancer/unknown.yaml | 54 +++ .../{degraded.yaml => unhealthy.yaml} | 0 .../{failed.yaml => unhealthy.yaml} | 3 + 15 files changed, 560 insertions(+), 51 deletions(-) delete mode 100644 pkg/health/health_aws_ecs_test.go delete mode 100644 pkg/health/health_cnrm_test.go create mode 100644 pkg/health/health_fixtures_test.go create mode 100644 pkg/health/testdata/AWS/Cloudformation/Stack/healthy.yaml create mode 100644 pkg/health/testdata/AWS/Cloudformation/Stack/unhealthy.yaml create mode 100644 pkg/health/testdata/AWS/ECS/Cluster/healthy.yaml create mode 100644 pkg/health/testdata/AWS/ECS/Service/healthy.yaml rename pkg/health/testdata/AWS/ECS/Task/{failed.yaml => unhealthy.yaml} (90%) create mode 100644 pkg/health/testdata/AWS/ElasticLoadbalancing/LoadBalancer/unknown.yaml rename pkg/health/testdata/Kubernetes/Application/{degraded.yaml => unhealthy.yaml} (100%) rename pkg/health/testdata/Kubernetes/ContainerCluster/{failed.yaml => unhealthy.yaml} (79%) diff --git a/go.mod b/go.mod index e2fcfdc..d60500c 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( ) require ( + github.com/bmatcuk/doublestar/v4 v4.7.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-logr/logr v1.2.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect diff --git a/go.sum b/go.sum index 34ae432..53f9c69 100644 --- a/go.sum +++ b/go.sum @@ -79,6 +79,10 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= +github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0= +github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE= +github.com/bmatcuk/doublestar/v4 v4.7.1 h1:fdDeAqgT47acgwd9bd9HxJRDmc9UAmPpc+2m0CXv75Q= +github.com/bmatcuk/doublestar/v4 v4.7.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cert-manager/cert-manager v1.9.0 h1:b8kfA8dOxDQyJtFJLH6dkT6WivRuAHR21PxnywJjuGk= github.com/cert-manager/cert-manager v1.9.0/go.mod h1:Bs3WsNX1LPKTs3boh//p7jLOn6ZRGEPz99ITeZU0g3c= diff --git a/pkg/health/health.go b/pkg/health/health.go index 30e19c0..5951778 100644 --- a/pkg/health/health.go +++ b/pkg/health/health.go @@ -22,6 +22,10 @@ const ( HealthWarning Health = "warning" ) +func IsValidHealth(s string) bool { + return s == string(HealthHealthy) || s == string(HealthUnhealthy) || s == string(HealthUnknown) || s == string(HealthWarning) +} + // Represents resource health status type HealthStatusCode string @@ -132,6 +136,15 @@ func GetHealthByConfigType(configType string, obj map[string]any, states ...stri if len(states) > 0 { return GetHealthFromStatusName(states[0]) + } else { + for k, v := range obj { + _k := strings.ToLower(k) + _v := fmt.Sprintf("%s", v) + if _k == "status" || _k == "state" || + strings.HasSuffix(_k, "status") { + return GetHealthFromStatusName(_v) + } + } } return HealthStatus{ Health: HealthUnknown, diff --git a/pkg/health/health_aws_ecs_test.go b/pkg/health/health_aws_ecs_test.go deleted file mode 100644 index 7a03f82..0000000 --- a/pkg/health/health_aws_ecs_test.go +++ /dev/null @@ -1,18 +0,0 @@ -package health_test - -import ( - "testing" - - "github.com/flanksource/is-healthy/pkg/health" -) - -func TestECSTask(t *testing.T) { - assertAppHealthMsg( - t, - "AWS::ECS::Task/failed.yaml", - "CannotPullContainerError", - health.HealthUnhealthy, - false, - "pull image manifest has been retried 5 time(s): failed to resolve ref docker.com/iiab-processing-fargate:dev: failed to do request: Head \"https://docker.com/v2/iiab-processing-fargate/manifests/dev\": dial tcp 10.0.0.1:443: connect: connection refused", - ) -} diff --git a/pkg/health/health_cnrm_test.go b/pkg/health/health_cnrm_test.go deleted file mode 100644 index 032febc..0000000 --- a/pkg/health/health_cnrm_test.go +++ /dev/null @@ -1,18 +0,0 @@ -package health_test - -import ( - "testing" - - "github.com/flanksource/is-healthy/pkg/health" -) - -func TestCnrmContainer(t *testing.T) { - assertAppHealthMsg( - t, - "Kubernetes::ContainerCluster/failed.yaml", - "UpdateFailed", - health.HealthUnhealthy, - true, - "Update call failed: error applying desired state: summary: googleapi: Error 403: Google Compute Engine: Required 'compute.networks.get' permission for 'projects/flanksource-prod/global/networks/flanksource-workload'.\nDetails:\n[\n {\n \"@type\": \"type.googleapis.com/google.rpc.RequestInfo\",\n \"requestId\": \"0xf1e9e3ca2797eb18\"\n },\n {\n \"@type\": \"type.googleapis.com/google.rpc.ErrorInfo\",\n \"domain\": \"container.googleapis.com\",\n \"reason\": \"GCE_PERMISSION_DENIED\"\n }\n]\n, forbidden", - ) -} diff --git a/pkg/health/health_fixtures_test.go b/pkg/health/health_fixtures_test.go new file mode 100644 index 0000000..4af0951 --- /dev/null +++ b/pkg/health/health_fixtures_test.go @@ -0,0 +1,21 @@ +package health_test + +import ( + "testing" + + "github.com/bmatcuk/doublestar/v4" +) + +func TestFixtures(t *testing.T) { + files, err := doublestar.FilepathGlob("testdata/*/**/*.yaml") + if err != nil { + t.Fatal(err) + } + if len(files) == 0 { + t.Fatal("no test files found") + } + + for _, file := range files { + testFixture(t, file) + } +} diff --git a/pkg/health/health_test.go b/pkg/health/health_test.go index 6eb9dba..798ab17 100644 --- a/pkg/health/health_test.go +++ b/pkg/health/health_test.go @@ -5,7 +5,9 @@ Package provides functionality that allows assessing the health state of a Kuber package health_test import ( + "fmt" "os" + "path/filepath" "sort" "strings" "testing" @@ -16,6 +18,7 @@ import ( "github.com/samber/lo" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + goyaml "gopkg.in/yaml.v3" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/util/yaml" ) @@ -48,6 +51,32 @@ var ( } ) +func testFixture(t *testing.T, yamlPath string) { + t.Run(yamlPath, func(t *testing.T) { + hr, obj := getHealthStatus(yamlPath, t, make(map[string]string)) + + expectedHealth := health.Health(strings.ReplaceAll(filepath.Base(yamlPath), ".yaml", "")) + if health.IsValidHealth(string(expectedHealth)) { + assert.Equal(t, expectedHealth, hr.Health) + } + + if v, ok := obj.GetAnnotations()["expected-health"]; ok { + assert.Equal(t, v, hr.Health) + } + + if v, ok := obj.GetAnnotations()["expected-message"]; ok { + assert.Equal(t, v, hr.Message) + } + if v, ok := obj.GetAnnotations()["expected-status"]; ok { + assert.Equal(t, health.HealthStatusCode(v), hr.Status) + } + + if v, ok := obj.GetAnnotations()["expected-ready"]; ok { + assert.Equal(t, v == "true", hr.Ready) + } + }) +} + func assertAppHealthMsg( t *testing.T, yamlPath string, @@ -69,7 +98,7 @@ func assertAppHealthMsg( } } t.Run(yamlPath, func(t *testing.T) { - health := getHealthStatus(yamlPath, t, m) + health, _ := getHealthStatus(yamlPath, t, m) assert.NotNil(t, health) assert.Equal(t, expectedHealth, health.Health) assert.Equal(t, expectedReady, health.Ready) @@ -96,7 +125,7 @@ func assertAppHealth( for i := 0; i < len(overrides); i += 2 { m[overrides[i]] = overrides[i+1] } - health := getHealthStatus(yamlPath, t, m) + health, _ := getHealthStatus(yamlPath, t, m) assert.NotNil(t, health) assert.Equal(t, expectedHealth, health.Health) assert.Equal(t, expectedReady, health.Ready) @@ -112,7 +141,8 @@ func assertAppHealthWithOverwriteMsg( expectedReady bool, expectedMsg string, ) { - health := getHealthStatus(yamlPath, t, overwrites) + health, _ := getHealthStatus(yamlPath, t, overwrites) + assert.NotNil(t, health) assert.Equal(t, expectedHealth, health.Health) assert.Equal(t, expectedReady, health.Ready) @@ -128,15 +158,15 @@ func assertAppHealthWithOverwrite( expectedHealth health.Health, expectedReady bool, ) { - health := getHealthStatus(yamlPath, t, overwrites) + health, _ := getHealthStatus(yamlPath, t, overwrites) assert.NotNil(t, health) assert.Equal(t, expectedHealth, health.Health) assert.Equal(t, expectedReady, health.Ready) assert.Equal(t, expectedStatus, health.Status) } -func getHealthStatus(yamlPath string, t *testing.T, overwrites map[string]string) *health.HealthStatus { - if !strings.HasPrefix(yamlPath, "./testdata/") && !strings.HasPrefix(yamlPath, "../resource_customizations") { +func getHealthStatus(yamlPath string, t *testing.T, overwrites map[string]string) (*health.HealthStatus, unstructured.Unstructured) { + if !strings.HasPrefix(yamlPath, "./testdata/") && !strings.HasPrefix(yamlPath, "testdata/") && !strings.HasPrefix(yamlPath, "../resource_customizations") { yamlPath = "./testdata/" + yamlPath } var yamlBytes []byte @@ -166,21 +196,30 @@ func getHealthStatus(yamlPath string, t *testing.T, overwrites map[string]string yamlString = strings.ReplaceAll(yamlString, k, v) } - if strings.Contains(yamlPath, "::") { - configType := strings.Split(yamlPath, "/")[2] - var obj map[string]any - err = yaml.Unmarshal([]byte(yamlString), &obj) + var obj unstructured.Unstructured + if !strings.Contains(yamlString, "apiVersion:") && !strings.Contains(yamlString, "kind:") { + configType := strings.Join(strings.Split(strings.ReplaceAll(filepath.Dir(yamlPath), "testdata/", ""), "/"), "::") + var m map[string]any + err = goyaml.Unmarshal([]byte(yamlString), &m) require.NoError(t, err) - return lo.ToPtr(health.GetHealthByConfigType(configType, obj)) + obj = unstructured.Unstructured{Object: m} + if v, ok := m["annotations"]; ok { + var a = make(map[string]string) + for k, v := range v.(map[string]any) { + a[k] = fmt.Sprintf("%s", v) + } + + obj.SetAnnotations(a) + } + return lo.ToPtr(health.GetHealthByConfigType(configType, m)), obj } - var obj unstructured.Unstructured err = yaml.Unmarshal([]byte(yamlString), &obj) require.NoError(t, err) health, err := health.GetResourceHealth(&obj, health.DefaultOverrides) require.NoError(t, err) - return health + return health, obj } func TestCrossplane(t *testing.T) { @@ -732,7 +771,7 @@ func TestFluxResources(t *testing.T) { ) assertAppHealth(t, "./testdata/flux-kustomization-unhealthy.yaml", "Progressing", health.HealthUnknown, false) assertAppHealth(t, "./testdata/flux-kustomization-failed.yaml", "BuildFailed", health.HealthUnhealthy, false) - status := getHealthStatus("./testdata/flux-kustomization-failed.yaml", t, nil) + status, _ := getHealthStatus("./testdata/flux-kustomization-failed.yaml", t, nil) assert.Contains(t, status.Message, "err='accumulating resources from 'kubernetes_resource_ingress_fail.yaml'") assertAppHealth( @@ -744,7 +783,7 @@ func TestFluxResources(t *testing.T) { ) assertAppHealth(t, "./testdata/flux-helmrelease-unhealthy.yaml", "UpgradeFailed", health.HealthUnhealthy, true) assertAppHealth(t, "./testdata/flux-helmrelease-upgradefailed.yaml", "UpgradeFailed", health.HealthUnhealthy, true) - helmreleaseStatus := getHealthStatus("./testdata/flux-helmrelease-upgradefailed.yaml", t, nil) + helmreleaseStatus, _ := getHealthStatus("./testdata/flux-helmrelease-upgradefailed.yaml", t, nil) assert.Contains( t, helmreleaseStatus.Message, diff --git a/pkg/health/testdata/AWS/Cloudformation/Stack/healthy.yaml b/pkg/health/testdata/AWS/Cloudformation/Stack/healthy.yaml new file mode 100644 index 0000000..58faa73 --- /dev/null +++ b/pkg/health/testdata/AWS/Cloudformation/Stack/healthy.yaml @@ -0,0 +1,8 @@ +CreationTime: "2023-05-09T03:59:08.629Z" +DriftInformation: + StackDriftStatus: NOT_CHECKED +StackId: arn:aws:cloudformation:eu-west-1:765618022540:stack/eksctl-mission-control-demo-cluster-addon-iamserviceaccount-kube-system-cluster-autoscaler/d94c1e20-ee1d-11ed-857e-0a810473a089 +StackName: eksctl-mission-control-demo-cluster-addon-iamserviceaccount-kube-system-cluster-autoscaler +StackStatus: CREATE_COMPLETE +TemplateDescription: IAM role for serviceaccount + "kube-system/cluster-autoscaler" [created and managed by eksctl] diff --git a/pkg/health/testdata/AWS/Cloudformation/Stack/unhealthy.yaml b/pkg/health/testdata/AWS/Cloudformation/Stack/unhealthy.yaml new file mode 100644 index 0000000..69d7361 --- /dev/null +++ b/pkg/health/testdata/AWS/Cloudformation/Stack/unhealthy.yaml @@ -0,0 +1,10 @@ +annotations: + message: 'The following resource(s) failed to create: [ECSCluster].' +CreationTime: 2024-06-27T14:23:12.654Z +DriftInformation: + StackDriftStatus: NOT_CHECKED +StackId: arn:aws:cloudformation:eu-west-1:765618022540:stack/Infra-ECS-Cluster-test-aditya-d2231163/c91bc4f0-3490-11ef-ba04-0267adf9bc1d +StackName: Infra-ECS-Cluster-test-aditya-d2231163 +StackStatus: CREATE_FAILED +StackStatusReason: "The following resource(s) failed to create: [ECSCluster]. " +TemplateDescription: The template used to create an ECS Cluster from the ECS Console. diff --git a/pkg/health/testdata/AWS/ECS/Cluster/healthy.yaml b/pkg/health/testdata/AWS/ECS/Cluster/healthy.yaml new file mode 100644 index 0000000..31f055c --- /dev/null +++ b/pkg/health/testdata/AWS/ECS/Cluster/healthy.yaml @@ -0,0 +1,13 @@ +ActiveServicesCount: 1 +Attachments: [] +CapacityProviders: [] +ClusterArn: arn:aws:ecs:eu-west-1:765618022540:cluster/demo-dev-cluster +ClusterName: demo-dev-cluster +DefaultCapacityProviderStrategy: [] +PendingTasksCount: 0 +RegisteredContainerInstancesCount: 0 +RunningTasksCount: 1 +Settings: [] +Statistics: [] +Status: ACTIVE +Tags: [] diff --git a/pkg/health/testdata/AWS/ECS/Service/healthy.yaml b/pkg/health/testdata/AWS/ECS/Service/healthy.yaml new file mode 100644 index 0000000..e06ef3b --- /dev/null +++ b/pkg/health/testdata/AWS/ECS/Service/healthy.yaml @@ -0,0 +1,376 @@ +CapacityProviderStrategy: [] +ClusterArn: arn:aws:ecs:eu-west-1:765618022540:cluster/demo-dev-cluster +CreatedAt: 2024-07-08T12:47:59.027Z +CreatedBy: arn:aws:iam::765618022540:user/Engineering/AdityaThebe +DeploymentConfiguration: + Alarms: + Enable: false + Rollback: false + AlarmNames: [] + MaximumPercent: 200 + MinimumHealthyPercent: 100 + DeploymentCircuitBreaker: + Enable: true + Rollback: true +DeploymentController: + Type: ECS +Deployments: + - Id: ecs-svc/4462357315744281090 + Status: PRIMARY + CreatedAt: 2024-07-08T12:47:59.027Z + UpdatedAt: 2024-11-01T17:53:00.891Z + LaunchType: FARGATE + FailedTasks: 0 + DesiredCount: 1 + PendingCount: 0 + RolloutState: COMPLETED + RunningCount: 1 + PlatformFamily: Linux + TaskDefinition: arn:aws:ecs:eu-west-1:765618022540:task-definition/demo-httpd-task:1 + PlatformVersion: 1.4.0 + RolloutStateReason: ECS deployment ecs-svc/4462357315744281090 completed. + NetworkConfiguration: + AwsvpcConfiguration: + Subnets: + - subnet-0aae33c66aa26d2b4 + - subnet-099e59970db9eeb65 + - subnet-07aef0e5d67ba44d6 + AssignPublicIp: ENABLED + SecurityGroups: + - sg-0125e9b77d363491f + VolumeConfigurations: [] + ServiceConnectResources: [] + CapacityProviderStrategy: [] +DesiredCount: 1 +EnableECSManagedTags: true +EnableExecuteCommand: false +Events: + - Id: 657fbf71-4d5c-4be8-94dd-2584878da629 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-17T12:09:18.664Z + - Id: 2972ff81-b736-4b7a-b543-118a3750af0b + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-17T06:09:15.02Z + - Id: 71fbef37-208c-424c-a340-45e881c3a027 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-17T00:09:13.599Z + - Id: 2cc25963-d60f-4909-9dd6-d9cf174b40e5 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-16T18:08:49.313Z + - Id: 5fd2af4d-6c9f-49f6-89d4-ec07dae85658 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-16T12:08:20.86Z + - Id: fd0849c6-deaa-4751-9af0-90f5555b1a1d + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-16T06:08:20.188Z + - Id: 4144f1d8-0064-42c4-9bfb-31ed545b018c + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-16T00:08:06.595Z + - Id: 771eb6e1-14d2-4951-bb67-78bf57c838f9 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-15T18:07:45.628Z + - Id: 7be6115c-883d-4367-a577-6a083a85941a + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-15T12:07:22.605Z + - Id: 0c949e17-8603-4c16-883c-2bcd98eaac35 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-15T06:07:16.635Z + - Id: 9d747124-4426-4419-ac24-3385f9877fbe + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-15T00:06:59.978Z + - Id: 8870ff9d-5c8e-44df-b638-90f9c04f4891 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-14T18:06:34.528Z + - Id: 9ac55fb7-3216-410c-b1f1-32c3a4e315b7 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-14T12:06:02.628Z + - Id: 2a5afc97-8e1a-46be-9afa-ecd89617f8c3 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-14T06:05:43.114Z + - Id: ee3828bb-f2a8-4a48-9406-eebccefe2932 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-14T00:05:27.945Z + - Id: 4d2afe39-6e59-4fe9-9228-2913903248dc + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-13T18:05:10.387Z + - Id: 742b7418-349a-40c3-8700-71a187dea02c + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-13T12:04:41.06Z + - Id: 74357d00-d239-4d76-a5b9-3f1338e57738 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-13T06:04:26.167Z + - Id: aa141a11-3094-4989-80e1-8246d833d573 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-13T00:04:12.381Z + - Id: c19f9eff-dfe8-40b0-b479-c17837dbf764 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-12T18:04:11.524Z + - Id: 63e09c32-3ca4-40c4-a8ee-443c33dfc00e + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-12T12:04:11.268Z + - Id: 33463c92-2c4d-471a-bd4e-922eb84d3a42 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-12T06:04:00.812Z + - Id: 4deeb1fe-e068-448d-9b88-d440d4b4164d + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-12T00:03:32.801Z + - Id: e1e7c3c7-76ba-4404-ad93-972063441661 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-11T18:03:24.033Z + - Id: bd536fed-ed5f-40b6-b2ee-4b19890e05c8 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-11T12:03:03.54Z + - Id: 635925aa-2f8e-47f7-b76f-5abccf5e82f9 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-11T06:02:47.003Z + - Id: 6d4dc7cd-28f4-481a-b7e8-dc6d906c48a5 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-11T00:02:38.718Z + - Id: b8b1214c-68fb-44e2-888d-c58b3584e872 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-10T18:02:33.838Z + - Id: 8766073e-fd7b-4c0c-b32d-0d8e8c056fe0 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-10T12:02:19.274Z + - Id: 8a33d0a6-99fa-499f-a829-5021cc159d73 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-10T06:02:02.354Z + - Id: 9c853a3b-fb25-44dd-82f8-2b928ad4032d + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-10T00:01:36.953Z + - Id: 3fbe3463-2cc0-4912-86f7-abfd8731b86d + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-09T18:01:16.268Z + - Id: 8680132f-7389-41e7-a145-9055eda60a6f + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-09T12:00:51.172Z + - Id: bf493cbd-5c67-498d-911a-e2169a6fa851 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-09T06:00:37.513Z + - Id: b465bfb6-f852-44c1-b3f0-9f2ec0cc80f4 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-09T00:00:31.442Z + - Id: a8f4b6c7-35a3-4f7e-bc26-eb1c25c140e6 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-08T18:00:26.252Z + - Id: f7b83cf9-37dd-4cb9-954d-31c257f8a6d1 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-08T11:59:57.392Z + - Id: 127837a4-09ec-4477-bb5b-a45541ba693f + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-08T05:59:31.164Z + - Id: b99a43be-c3e8-4484-b7d0-0e50c25d1b65 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-07T23:59:20.796Z + - Id: 74934105-0f63-4169-b7ee-15c4a03b8b55 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-07T17:59:11.827Z + - Id: eb1991bf-9693-45f2-b05b-907e7bf19395 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-07T11:58:59.376Z + - Id: 47cb92af-bf36-4fe5-adb0-d9eb08ba2151 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-07T05:58:29.619Z + - Id: d6a509a9-db65-4e24-b17f-d24bccdfc6b3 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-06T23:58:19.069Z + - Id: 6754f279-95ca-4083-8de0-241f58225010 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-06T17:58:18.894Z + - Id: 85eac415-977b-4be0-b8dc-7ff2a41276c1 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-06T11:58:05.962Z + - Id: fb975bc9-5485-4606-bf21-d2dfdfe6874b + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-06T05:57:48.804Z + - Id: c14438e7-3f19-4782-ba4d-45f053a8eb65 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-05T23:57:25.302Z + - Id: a684ad43-4339-4071-b158-6bbcf7fa4110 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-05T17:57:20.465Z + - Id: 0238592e-be51-4334-be85-7fd47f0b719a + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-05T11:56:49.722Z + - Id: d74dbbdd-348e-491b-8b08-b57cc4abb993 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-05T05:56:27.746Z + - Id: e924895b-4bb1-4034-8e09-9d7c46c12522 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-04T23:56:16.322Z + - Id: daaa424e-7e60-46ae-ae09-b7b97f715417 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-04T17:56:12.187Z + - Id: d73d33f9-1be6-47f5-a26b-4e1d936f8560 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-04T11:55:48.336Z + - Id: 976686b7-0a25-4cb4-957b-b944fdc9a304 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-04T05:55:32.489Z + - Id: 4c609c24-2664-442f-ba33-513b0cec833f + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-03T23:55:16.165Z + - Id: 449ae2b4-5950-4367-9c37-cd5e03cafc9a + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-03T17:55:09.452Z + - Id: 73fc698c-fca3-43bc-8cb7-89090e8ab1a2 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-03T11:54:49.903Z + - Id: bf37d937-2e66-4802-b46d-876a306070b5 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-03T05:54:29.81Z + - Id: 1e8536cc-d44b-4722-9d8a-010231db8530 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-02T23:54:24.207Z + - Id: 563bb710-e75a-4e7e-ab11-5f7e9101674d + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-02T17:54:00.558Z + - Id: d541433f-e28a-4818-ba6f-f3b12006a596 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-02T11:53:43.37Z + - Id: eee74091-8646-4237-8928-9377473e71e5 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-02T05:53:28.798Z + - Id: 0d08c75b-7a4e-461b-bdfe-78d953d88009 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-01T23:53:01.523Z + - Id: 4754b156-e766-467f-b752-2c110a333224 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-01T17:53:00.897Z + - Id: d2f2ecf4-c5f9-4923-babc-804f053b4a5b + Message: "(service httpd-service) has stopped 1 running tasks: (task + 9aafa604454947a8810f6791f07cd3b0)." + CreatedAt: 2024-11-01T17:51:50.837Z + - Id: b464128f-bffa-4616-84bd-1f170f8f6b13 + Message: "(service httpd-service) has started 1 tasks: (task + d8f8db0d67e34774935b2fbbc82961a3)." + CreatedAt: 2024-11-01T17:50:27.171Z + - Id: 5e854f0c-de80-43a9-b0cb-211365c44206 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-01T15:13:15.01Z + - Id: 70ec0ffe-346b-484e-8c73-03d44a25faf8 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-01T09:12:47.637Z + - Id: 22d7079d-a5af-438b-b642-d4b8dac1862d + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-11-01T03:12:40.841Z + - Id: 6d5fff48-ec22-4161-b6e1-a520dfb65731 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-31T21:12:36.15Z + - Id: e439bc63-b328-4ae6-a1ef-6d813439d7cd + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-31T15:12:19.535Z + - Id: 582c033c-2b58-4565-a023-c3ea68cb811a + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-31T09:11:48.89Z + - Id: ff07eca2-bc8a-457b-8b04-7db7d651b9bc + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-31T03:11:18.192Z + - Id: bccf4a45-7060-4f2e-933b-7d1fcd115c03 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-30T21:11:00.843Z + - Id: 6808232e-f13b-4919-be75-b2bc6085fb8b + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-30T15:10:33.363Z + - Id: eecec8c0-aa18-4bb7-8938-02d67ecc2519 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-30T09:10:18.951Z + - Id: f4957dc8-7b72-4971-983f-780d1fd5e592 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-30T03:09:55.534Z + - Id: 46754b35-2629-4a35-b66c-11a07a03ac8d + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-29T21:09:48.266Z + - Id: fc86261b-a1ad-4404-b17c-e1e3fecf66d4 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-29T15:09:22.487Z + - Id: 7dde9d8c-3cfd-46de-8869-64bbe1aa7e9d + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-29T09:09:10.6Z + - Id: 42a4220c-45e8-45f0-bbfe-667760ec5e5b + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-29T03:08:57.5Z + - Id: 2e4bfa54-c30e-4882-94cb-49efc5123a0c + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-28T21:08:52.854Z + - Id: 3a825b1b-ac2a-4f75-98fe-46dc685775eb + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-28T15:08:31.698Z + - Id: dab0e976-7b8b-4af1-b00d-85c32ac01f44 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-28T09:08:12.969Z + - Id: 823b9950-1036-46c2-ab2d-2d4e188b1af6 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-28T03:07:57.438Z + - Id: f2901bfd-dc64-4108-bca4-a457932c28b2 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-27T21:07:56.504Z + - Id: b5ef4384-16c0-48b7-ac9c-38207723f996 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-27T15:07:45.869Z + - Id: 289da137-562b-4223-8f2a-eee6b5f2543c + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-27T09:07:39.484Z + - Id: b84fbace-a638-42ba-89ec-74404ece497f + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-27T03:07:24.402Z + - Id: f9f36c3d-859a-4399-9691-0aea37b92dff + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-26T21:06:55.408Z + - Id: c0989436-31f8-4731-948a-c1063de3f434 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-26T15:06:34.549Z + - Id: 5bfdb77f-d6ce-4a41-800f-46f3cd87353d + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-26T09:06:15.829Z + - Id: c904b302-fe37-4f4f-b166-8b7b86e091b5 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-26T03:06:12.201Z + - Id: 2132ee3d-290e-4bf7-9d1a-f05c6ea206e0 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-25T21:05:48.204Z + - Id: e8ef0a08-56a1-4f66-a0aa-85c06dfbc41f + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-25T15:05:20.866Z + - Id: 48c7a36b-ea3d-4ea2-a6f0-1985e4136408 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-25T09:04:57.66Z + - Id: c0ed1466-e00d-46e5-9513-ce6f6e2c4cdc + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-25T03:04:54.536Z + - Id: cc63e08f-a0f5-4afc-85d2-73a98831ed6d + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-24T21:04:25.15Z + - Id: cffbd4c1-4029-4e48-820b-01cca03996a7 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-24T15:04:22.849Z + - Id: 854afc1b-0bdb-4aee-9391-3258081bf273 + Message: (service httpd-service) has reached a steady state. + CreatedAt: 2024-10-24T09:04:14.97Z +LaunchType: FARGATE +LoadBalancers: [] +NetworkConfiguration: + AwsvpcConfiguration: + Subnets: + - subnet-0aae33c66aa26d2b4 + - subnet-099e59970db9eeb65 + - subnet-07aef0e5d67ba44d6 + AssignPublicIp: ENABLED + SecurityGroups: + - sg-0125e9b77d363491f +PendingCount: 0 +PlacementConstraints: [] +PlacementStrategy: [] +PlatformFamily: Linux +PlatformVersion: LATEST +PropagateTags: NONE +RoleArn: arn:aws:iam::765618022540:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS +RunningCount: 1 +SchedulingStrategy: REPLICA +ServiceArn: arn:aws:ecs:eu-west-1:765618022540:service/demo-dev-cluster/httpd-service +ServiceName: httpd-service +ServiceRegistries: [] +Status: ACTIVE +Tags: [] +TaskDefinition: arn:aws:ecs:eu-west-1:765618022540:task-definition/demo-httpd-task:1 +TaskSets: [] diff --git a/pkg/health/testdata/AWS/ECS/Task/failed.yaml b/pkg/health/testdata/AWS/ECS/Task/unhealthy.yaml similarity index 90% rename from pkg/health/testdata/AWS/ECS/Task/failed.yaml rename to pkg/health/testdata/AWS/ECS/Task/unhealthy.yaml index 5190cc0..44a7410 100644 --- a/pkg/health/testdata/AWS/ECS/Task/failed.yaml +++ b/pkg/health/testdata/AWS/ECS/Task/unhealthy.yaml @@ -1,3 +1,6 @@ +annotations: + expected-status: CannotPullContainerError + expected-message: 'pull image manifest has been retried 5 time(s): failed to resolve ref docker.com/iiab-processing-fargate:dev: failed to do request: Head "https://docker.com/v2/iiab-processing-fargate/manifests/dev": dial tcp 10.0.0.1:443: connect: connection refused' Attachments: - Id: 8a9b2c3d-1e2f-4a5b-6c7d-8e9f0a1b2c3d Type: ElasticNetworkInterface diff --git a/pkg/health/testdata/AWS/ElasticLoadbalancing/LoadBalancer/unknown.yaml b/pkg/health/testdata/AWS/ElasticLoadbalancing/LoadBalancer/unknown.yaml new file mode 100644 index 0000000..83a086e --- /dev/null +++ b/pkg/health/testdata/AWS/ElasticLoadbalancing/LoadBalancer/unknown.yaml @@ -0,0 +1,54 @@ +AvailabilityZones: + - eu-west-1b + - eu-west-1c + - eu-west-1a +BackendServerDescriptions: [] +CanonicalHostedZoneName: ac389ee355c474d20a567c65c12f9d8c-15962110.eu-west-1.elb.amazonaws.com +CanonicalHostedZoneNameID: Z32O12XQLNTSW2 +CreatedTime: 2023-05-10T15:41:50.79Z +DNSName: ac389ee355c474d20a567c65c12f9d8c-15962110.eu-west-1.elb.amazonaws.com +HealthCheck: + Target: TCP:32258 + Timeout: 5 + Interval: 10 + HealthyThreshold: 2 + UnhealthyThreshold: 6 +Instances: + - InstanceId: i-0c0187ae2594844e6 + - InstanceId: i-09b6cd25d7fe29a88 + - InstanceId: i-070cd36b3b5b5fbe4 +ListenerDescriptions: + - Listener: + Protocol: TCP + InstancePort: 32634 + InstanceProtocol: TCP + LoadBalancerPort: 10254 + PolicyNames: [] + - Listener: + Protocol: TCP + InstancePort: 31478 + InstanceProtocol: TCP + LoadBalancerPort: 443 + PolicyNames: [] + - Listener: + Protocol: TCP + InstancePort: 32258 + InstanceProtocol: TCP + LoadBalancerPort: 80 + PolicyNames: [] +LoadBalancerName: ac389ee355c474d20a567c65c12f9d8c +Policies: + OtherPolicies: [] + LBCookieStickinessPolicies: [] + AppCookieStickinessPolicies: [] +Scheme: internet-facing +SecurityGroups: + - sg-0d02d5df08e81e5e0 +SourceSecurityGroup: + GroupName: k8s-elb-ac389ee355c474d20a567c65c12f9d8c + OwnerAlias: "765618022540" +Subnets: + - subnet-017dfefe7e6f269f2 + - subnet-09cba264d3549e8c0 + - subnet-0e33965610ced8995 +VPCId: vpc-09c963a9231399689 diff --git a/pkg/health/testdata/Kubernetes/Application/degraded.yaml b/pkg/health/testdata/Kubernetes/Application/unhealthy.yaml similarity index 100% rename from pkg/health/testdata/Kubernetes/Application/degraded.yaml rename to pkg/health/testdata/Kubernetes/Application/unhealthy.yaml diff --git a/pkg/health/testdata/Kubernetes/ContainerCluster/failed.yaml b/pkg/health/testdata/Kubernetes/ContainerCluster/unhealthy.yaml similarity index 79% rename from pkg/health/testdata/Kubernetes/ContainerCluster/failed.yaml rename to pkg/health/testdata/Kubernetes/ContainerCluster/unhealthy.yaml index b5a5f15..1769edf 100644 --- a/pkg/health/testdata/Kubernetes/ContainerCluster/failed.yaml +++ b/pkg/health/testdata/Kubernetes/ContainerCluster/unhealthy.yaml @@ -14,6 +14,9 @@ metadata: cnrm.cloud.google.com/project-id: workload-prod-eu-02 cnrm.cloud.google.com/state-into-spec: merge cnrm.cloud.google.com/management-conflict-prevention-policy: none + expected-status: UpdateFailed + expected-ready: "true" + expected-message: "Update call failed: error applying desired state: summary: googleapi: Error 403: Google Compute Engine: Required 'compute.networks.get' permission for 'projects/flanksource-prod/global/networks/flanksource-workload'.\nDetails:\n[\n {\n \"@type\": \"type.googleapis.com/google.rpc.RequestInfo\",\n \"requestId\": \"0xf1e9e3ca2797eb18\"\n },\n {\n \"@type\": \"type.googleapis.com/google.rpc.ErrorInfo\",\n \"domain\": \"container.googleapis.com\",\n \"reason\": \"GCE_PERMISSION_DENIED\"\n }\n]\n, forbidden" creationTimestamp: 2024-11-13T09:26:00Z spec: location: europe-west1