Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ jobs:
if: needs.semantic-release.outputs.new-release-published == 'true'
strategy:
matrix:
repos: ['mission-control', 'canary-checker', 'commons', 'config-db', 'gomplate']
repos: ["mission-control", "canary-checker", "commons", "config-db", "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
Expand All @@ -60,9 +60,9 @@ jobs:
id: cpr
uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e # v6.0.5
with:
branch: 'bump-is-healthy-auto-pr'
commit-message: 'chore: bump is-healthy to v${{ needs.semantic-release.outputs.release-version }}'
title: 'chore: bump is-healthy to v${{ needs.semantic-release.outputs.release-version }}'
branch: "bump-is-healthy-auto-pr"
commit-message: "chore: bump is-healthy to v${{ needs.semantic-release.outputs.release-version }}"
title: "chore: bump is-healthy to v${{ needs.semantic-release.outputs.release-version }}"
token: ${{ secrets.FLANKBOT }}
labels: dependencies

Expand All @@ -74,3 +74,23 @@ jobs:
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: squash
repository: flanksource/${{ matrix.repos }}
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

# Go workspace file
go.work
# Added by goreleaser init:
dist/
26 changes: 26 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: 2

before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

release:
footer: >-
74 changes: 66 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,81 @@

NAME=is-healthy
YQ=yq
OS ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH ?= $(shell uname -m | sed 's/x86_64/amd64/')
LD_FLAGS=-ldflags "-w -s -X \"main.version=$(VERSION_TAG)\""
ifeq ($(VERSION),)
VERSION_TAG=$(shell git describe --abbrev=0 --tags || echo latest)
else
VERSION_TAG=$(VERSION)
endif


# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

.PHONY: test
test:
go test ./... -v

.PHONY: tidy
tidy:
go mod tidy -go=1.20 -compat=1.20

.PHONY: lint
lint:
lint: fmt
golangci-lint run

golines -m 120 -w pkg/
golines -m 120 -w events/

gofumpt -w .

.PHONY:
sync:
git submodule update --init --recursive

update-submodules:
git submodule update --remote --merge && git submodule sync


tidy:
go mod tidy

fmt:
golines -m 120 -w pkg/
golines -m 120 -w events/
gofumpt -w .

.PHONY: compress
compress:
test -e ./$(RELEASE_DIR)/$(NAME)_linux_amd64 && upx -5 ./$(RELEASE_DIR)/$(NAME)_linux_amd64 || true
test -e ./$(RELEASE_DIR)/$(NAME)_linux_arm64 && upx -5 ./$(RELEASE_DIR)/$(NAME)_linux_arm64 || true

.PHONY: compress-build
compress-build:
upx -5 ./$(RELEASE_DIR)/$(NAME) ./$(RELEASE_DIR)/$(NAME).test

.PHONY: linux
linux:
GOOS=linux GOARCH=amd64 go build -o ./$(RELEASE_DIR)/$(NAME)_linux_amd64 $(LD_FLAGS) main.go
GOOS=linux GOARCH=arm64 go build -o ./$(RELEASE_DIR)/$(NAME)_linux_arm64 $(LD_FLAGS) main.go

.PHONY: darwin
darwin:
GOOS=darwin GOARCH=amd64 go build -o ./$(RELEASE_DIR)/$(NAME)_darwin_amd64 $(LD_FLAGS) main.go
GOOS=darwin GOARCH=arm64 go build -o ./$(RELEASE_DIR)/$(NAME)_darwin_arm64 $(LD_FLAGS) main.go

.PHONY: windows
windows:
GOOS=windows GOARCH=amd64 go build -o ./$(RELEASE_DIR)/$(NAME).exe $(LD_FLAGS) main.go

.PHONY: binaries
binaries: linux darwin windows compress


.PHONY: build
build:
GOOS=$(OS) GOARCH=$(ARCH) go build -o ./.bin/$(NAME) $(LD_FLAGS) main.go


.PHONY: install
install:
cp ./.bin/$(NAME) /usr/local/bin/
63 changes: 61 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
# is-healthy
<div align="center">
<p>
<a href="https://github.com/flanksource/is-healthy/actions"><img src="https://github.com/flanksource/is-healthy/workflows/Test/badge.svg"></a>
<a href="https://goreportcard.com/report/github.com/flanksource/is-healthy"><img src="https://goreportcard.com/badge/github.com/flanksource/is-healthy"></a>
<img src="https://img.shields.io/github/license/flanksource/is-healthy.svg?style=flat-square"/>
</p>
</div>
`is-healthy` is a heuristic library for checking the health of Kubernetes and Cloud resources, it supports basic, enhanced and heuristic mode.

`is-healthy` is a library and CLI to test the status of Kubernetes JSON objects, it is copied mostly from the Argocd project and modified to reduce the dependency tree

* **Basic Mode**: Wraps Argo health check functionality. Does not distinguish between `health` and `status`, `lastUpdated` and `ready` are not supported
* **health**: One of `healthy`, `unhealthy`, `warning`, `unknown`
* **message**: A reason for the status e.g. `Back-off pulling image "nginx:invalid"`
* **Enhanced Mode**: returns the following fields:

* ***ready***: Whether the resource is currently being reconciled / provisioned.
> `ready` is independent of `health`, e.g. A pod in a failure state can be ready if its state is terminal and will not change.
* **health**: One of `healthy`, `unhealthy`, `warning`, `unknown`,
> `health` can transition based on the age or last event time of a resource.
* **status**: A text description of the state of of resource e.g. `Running` or `ImagePullBackoff`
* **message**: A reason for the status e.g. `Back-off pulling image "nginx:invalid"`
* **lastUpdated**: The last time the resource was updated
* **Heuristic Mode**: Attempts to determine health using and fields named `state`, `status` etc..

|Object Type|Support Mode||
|---|---|---|
|Core Kubernetes Resources|Enhanced||
|Pod|Enhanced|Ignores pod restarts for the first `15m` <br />`warning` if restarted in in last 24h<br />`unhealthy` if restarted in last `1h`|
|Certificate|Enhanced|`unhealthy` if not issued with `1h`<br /> `warning` if not issued with `15m` <br/>`warning` if certificate expiry `< 2d`|
|CronJob|Enhanced||
|Flux CRD's|Enhanced||
|Argo CRD's|Enhanced||
|Cert-Manager CRD's|Enhanced|Marks|
|Kubernetes Resources using [Conditions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties)|Heuristic||




## Example

```shell
kubectl po -o json <pod-name> | is-healthy -j
```

Output:

```json
{
"ready": false,
"health": "unhealthy",
"status": "ImagePullBackOff",
"message": "Back-off pulling image \"nginx:invalid\"",
"lastUpdated": "2025-03-26T10:17:18Z"
}
```


## Attribution

This project builds upon the health check implementations from:
* [Argo CD](https://github.com/argoproj/argo-cd)
* [gitops-engine](https://github.com/argoproj/gitops-engine)
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ require (
github.com/go-logr/logr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/cobra v1.9.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/text v0.16.0 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down Expand Up @@ -308,6 +309,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
Expand Down Expand Up @@ -463,13 +466,17 @@ github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJ
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
github.com/spf13/cobra v1.2.1/go.mod h1:ExllRjgxM/piMAM+3tAZvg8fsklGAf3tPfi+i8t68Nk=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
Expand Down
Loading