Skip to content

Commit

Permalink
Don't load kubernetes cliet until cli app starts (#3)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Williams <[email protected]>
  • Loading branch information
max-rocket-internet and max-rocket-internet authored Aug 23, 2023
1 parent 95e23b5 commit c70ba66
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
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

0 comments on commit c70ba66

Please sign in to comment.