Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't load kubernetes client until cli app starts #3

Merged
merged 1 commit into from
Aug 23, 2023
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: run-tests
name: test-and-build

on: [push]

jobs:
build:
name: run-tests
name: test-and-build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Is your Kubernetes cluster unhealthy? Do your workloads have symptoms? Then maybe it needs a checkup with `kube-doctor` 🏥

```shell
```console
$ kube-doctor --warning-symptoms --non-namespaced-resources
== Checking DaemonSet resources
👀 DaemonSet kube-system/efs-csi-node: efs-plugin no resources specified
Expand Down Expand Up @@ -93,66 +93,66 @@ This tool will check for the following symptoms:

By default `kube-doctor` will check all namespaces but it can also target a specific namespace:

```shell
```console
kube-doctor --namespace kube-system
```

Or label selector;:

```shell
```console
kube-doctor --label-selector app.kubernetes.io/name=prometheus
```

Or a combination of both:

```shell
```console
kube-doctor --label-selector app.kubernetes.io/name=prometheus --namespace monitoring
```

Non-namespaced resources like nodes can be checked with the `--non-namespaced-resources` flag:

```shell
```console
kube-doctor --non-namespaced-resources
```

To see other options, including debug logging, consult the help:

```shell
```console
kube-doctor --help
```

## Installation

Check out code and build:

```shell
```console
git clone [email protected]:max-rocket-internet/kube-doctor.git
cd kube-doctor
go build ./... && go install ./...
```

Run from `main` branch without `git`:

```shell
```console
go install github.com/max-rocket-internet/kube-doctor@latest
cd $GOPATH/pkg/mod/github.com/max-rocket-internet/kube-doctor*/
go run main.go
```

To get a binary, check [the releases](https://github.com/max-rocket-internet/kube-doctor/releases).
To download a binary, check [the releases](https://github.com/max-rocket-internet/kube-doctor/releases).

## Contributing

Pull requests welcome 💙

To run all tests:

```shell
```console
go test ./...
```

Or just a single package:

```shell
```console
go test ./.../checkup
```
2 changes: 2 additions & 0 deletions pkg/doctor/checkup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
)

func DoCheckUp(cCtx *cli.Context) {
kubernetes.Init()

log.Setup(cCtx.Bool("debug"), cCtx.Bool("warning-symptoms"))
log.Debug(fmt.Sprintf("Connected to cluster from context %s running version %s", kubernetes.ContextName, kubernetes.ServerVersion))

Expand Down
10 changes: 7 additions & 3 deletions pkg/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ import (
)

var (
client = createClient()
ContextName = ""
ServerVersion = ""
client *kubernetes.Clientset
ContextName string
ServerVersion string
)

func Init() {
client = createClient()
}

func createClient() *kubernetes.Clientset {
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
configOverrides := &clientcmd.ConfigOverrides{}
Expand Down