From 237d76fc9578e70d7a8f80d8e75ac0bc99f4d7f2 Mon Sep 17 00:00:00 2001 From: rzrbld Date: Sun, 22 Mar 2020 14:06:46 +0300 Subject: [PATCH 1/2] add k8s probes add env ADMINIO_PROBES_ENABLE for enable or disable liveness and readiness probes --- .gitignore | 4 ++++ README.md | 18 ++++++++++++++---- src/config/config.go | 1 + src/handlers/probes.go | 16 ++++++++++++++++ src/main.go | 5 +++++ 5 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/handlers/probes.go diff --git a/.gitignore b/.gitignore index 95cf6da..30fb190 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out .DS_Store +main +run.sh +runc.sh +rung.sh diff --git a/README.md b/README.md index 0f92a9f..3a5d903 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,21 @@ it will bring up: after that you can go to `` http://localhost `` and try out ### Run with docker -`` docker run rzrbld/adminio-api:0.2 `` +``` +docker run -d \ + -p 8080:8080 \ + -e ADMINIO_HOST_PORT=":8080" \ + -e MINIO_HOST_PORT="localhost:9000" \ + -e MINIO_ACCESS="test" \ + -e MINIO_SECRET="testtest123" \ + rzrbld/adminio-api:latest + +``` ### Run manually - [start](https://docs.min.io/) minio server - set env variables - - run ./main form `dist` folder + - compile and run ./main form `src` folder ### Env variables | Variable | Description | Default | @@ -48,6 +57,7 @@ after that you can go to `` http://localhost `` and try out | `ADMINIO_COOKIE_NAME` | name for the session cookie | adminiosessionid | | `ADMINIO_AUDIT_LOG_ENABLE` | enable audit log, mae sense if oauth is enabled, othervise set to false | false | | `ADMINIO_METRICS_ENABLE` | enable default iris\golang metrics and bucket sizes metric on /metric/ uri path | false | +| `ADMINIO_PROBES_ENABLE` | enable liveness and readiness probes for k8s installations | false | ### Supported oauth providers @@ -66,5 +76,5 @@ after that you can go to `` http://localhost `` and try out - wso2 ### example config -prometheus config: `examples/prometheus.yml` -bucket policy: `examples/policy.xml` + - prometheus config for adminio metrics: `examples/prometheus.yml` + - bucket policy: `examples/policy.xml` diff --git a/src/config/config.go b/src/config/config.go index 47ea348..216302f 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -22,6 +22,7 @@ var ( OauthEnable, _ = strconv.ParseBool(getEnv("ADMINIO_OAUTH_ENABLE", "false")) AuditLogEnable, _ = strconv.ParseBool(getEnv("ADMINIO_AUDIT_LOG_ENABLE", "false")) MetricsEnable, _ = strconv.ParseBool(getEnv("ADMINIO_METRICS_ENABLE", "false")) + ProbesEnable, _ = strconv.ParseBool(getEnv("ADMINIO_PROBES_ENABLE", "false")) OauthProvider = getEnv("ADMINIO_OAUTH_PROVIDER", "github") OauthClientId = getEnv("ADMINIO_OAUTH_CLIENT_ID", "my-github-oauth-app-client-id") OauthClientSecret = getEnv("ADMINIO_OAUTH_CLIENT_SECRET", "my-github-oauth-app-secret") diff --git a/src/handlers/probes.go b/src/handlers/probes.go new file mode 100644 index 0000000..d3ee024 --- /dev/null +++ b/src/handlers/probes.go @@ -0,0 +1,16 @@ +package handlers + +import ( + iris "github.com/kataras/iris/v12" + resph "github.com/rzrbld/adminio-api/response" +) + +var Readiness = func(ctx iris.Context) { + var res = resph.DefaultResConstructor(ctx, nil) + ctx.JSON(res) +} + +var Liveness = func(ctx iris.Context) { + var res = resph.DefaultResConstructor(ctx, nil) + ctx.JSON(res) +} diff --git a/src/main.go b/src/main.go index 38251d7..d65a754 100644 --- a/src/main.go +++ b/src/main.go @@ -65,6 +65,11 @@ func main() { app.Get("/metrics", iris.FromStd(promhttp.Handler())) } + if cnf.ProbesEnable { + app.Get("/read", hdl.Readiness) + app.Get("/live", hdl.Liveness) + } + v1auth := app.Party("/auth/", crs).AllowMethods(iris.MethodOptions) { v1auth.Get("/logout/", hdl.AuthLogout) From e7d62d3fc81fff6f51c8f2503bb0d9958c7784d3 Mon Sep 17 00:00:00 2001 From: rzrbld Date: Mon, 23 Mar 2020 00:13:37 +0300 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a5d903..e65f492 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ docker run -d \ - set env variables - compile and run ./main form `src` folder -### Env variables +### Config Env variables | Variable | Description | Default | |--------------|:-----------------------:|-----------:| | `ADMINIO_HOST_PORT` | which host and port API should listening. This is Iris based API, so you will need to provide 0.0.0.0:8080 for listening on all interfaces | localhost:8080 |