Skip to content
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
40 changes: 29 additions & 11 deletions cmd/icinga-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/pkg/errors"
promapi "github.com/prometheus/client_golang/api"
promv1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/spf13/pflag"
"golang.org/x/sync/errgroup"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/informers"
Expand All @@ -35,24 +36,41 @@ import (
func main() {
runtime.ReallyCrash = true

kconfig, err := kclientcmd.NewNonInteractiveDeferredLoadingClientConfig(
kclientcmd.NewDefaultClientConfigLoadingRules(), &kclientcmd.ConfigOverrides{}).ClientConfig()
if err != nil {
klog.Fatal(err)
}

var configLocation string
var showVersion bool

klog.InitFlags(nil)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)

pflag.BoolVar(&showVersion, "version", false, "print version and exit")
pflag.StringVar(&configLocation, "config", "./config.yml", "path to the config file")

loadingRules := kclientcmd.NewDefaultClientConfigLoadingRules()
loadingRules.DefaultClientConfig = &kclientcmd.DefaultClientConfig
pflag.StringVar(&loadingRules.ExplicitPath, "kubeconfig", "", "Path to a kube config. Only required if out-of-cluster")

overrides := kclientcmd.ConfigOverrides{}
kflags := kclientcmd.RecommendedConfigOverrideFlags("")
kflags.ContextOverrideFlags.Namespace = kclientcmd.FlagInfo{}
kclientcmd.BindOverrideFlags(&overrides, pflag.CommandLine, kflags)

flag.BoolFunc("version", "print version and exit", func(_ string) error {
pflag.Parse()

if showVersion {
internal.Version.Print()
os.Exit(0)
}

return nil
})
flag.StringVar(&configLocation, "config", "./config.yml", "path to the config file")
flag.Parse()
kconfig, err := kclientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &overrides).ClientConfig()
if err != nil {
if kclientcmd.IsEmptyConfig(err) {
klog.Fatal(
"no configuration provided: set KUBECONFIG environment variable or --kubeconfig CLI flag to" +
" a kubeconfig file with cluster access configured")
}

klog.Fatal(errors.Wrap(err, "can't configure Kubernetes client"))
}

clientset, err := kubernetes.NewForConfig(kconfig)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions doc/02-Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,19 @@ All available settings can be found under [Configuration](03-Configuration.md).

## Running Icinga for Kubernetes

With locally accessible kubeconfig and `config.yml` files, `icinga-kubernetes` can be executed by running:
With locally accessible
[kubeconfig](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/)
and `config.yml` files, `icinga-kubernetes` can be executed by running:

```bash
icinga-kubernetes -config /path/to/config.yml
```

## Using a Container

With locally accessible kubeconfig and `config.yml` files,
With locally accessible
[kubeconfig](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/)
and `config.yml` files,
run the `icinga/icinga-kubernetes` image using a container runtime of you choice, e.g. Docker:

```bash
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/common v0.53.0
github.com/spf13/pflag v1.0.5
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
golang.org/x/sync v0.7.0
Expand Down Expand Up @@ -52,7 +53,6 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/ssgreg/journald v1.0.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
Expand Down