Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jrauh01 committed Dec 12, 2023
1 parent be4bf11 commit 7031590
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 21 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ FROM golang:alpine AS builder
RUN apk update && apk add --no-cache git
WORKDIR $GOPATH/src/icinga-kubernetes/
COPY . .
#COPY ./config.yml /go/bin/config.yml
RUN go build -o /go/bin/icinga-kubernetes ./cmd/icinga-kubernetes/main.go

FROM scratch

COPY --from=builder /go/bin/icinga-kubernetes /go/bin/icinga-kubernetes
WORKDIR /go/bin/
COPY --from=alpine /tmp /tmp
COPY --from=builder /go/bin/icinga-kubernetes ./icinga-kubernetes
EXPOSE 8080
ENTRYPOINT ["/go/bin/icinga-kubernetes"]
ENTRYPOINT ["./icinga-kubernetes"]
35 changes: 34 additions & 1 deletion cmd/icinga-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@ import (
"github.com/okzk/sdnotify"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
kclientcmd "k8s.io/client-go/tools/clientcmd"
"os"
)

func main() {
inCluster := false

if kconfig, err := rest.InClusterConfig(); err == nil {
if _, err := kubernetes.NewForConfig(kconfig); err == nil {
inCluster = true
}
}

kconfig, err := kclientcmd.NewNonInteractiveDeferredLoadingClientConfig(
kclientcmd.NewDefaultClientConfigLoadingRules(), &kclientcmd.ConfigOverrides{}).ClientConfig()
if err != nil {
Expand All @@ -34,7 +45,29 @@ func main() {
logging.Fatal(errors.Wrap(err, "can't parse flags"))
}

cfg, err := config.FromYAMLFile[internal.Config](flags.Config)
cfg := &internal.Config{}
configFile := flags.Config

if inCluster {
cm, err := k.CoreV1().ConfigMaps("default").Get(context.Background(), "icinga-kubernetes-config", kmetav1.GetOptions{})
if err != nil {
logging.Fatal(errors.Wrap(err, "can't load ConfigMap"))
}

file, err := os.CreateTemp("", "yaml-config-")
if err != nil {
logging.Fatal(errors.Wrap(err, "can't create temporary yaml config"))
}
defer os.Remove(file.Name())

if _, err = file.Write([]byte(cm.Data["config"])); err != nil {
logging.Fatal(errors.Wrap(err, "can't write to temporary yaml config"))
}

configFile = file.Name()
}

cfg, err = config.FromYAMLFile[internal.Config](configFile)
if err != nil {
logging.Fatal(errors.Wrap(err, "can't create configuration"))
}
Expand Down
47 changes: 47 additions & 0 deletions icinga-kubernetes-configmap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: icinga-kubernetes-config
data:
config: |
# This is the configuration file for Icinga Kubernetes.
#
# Connection configuration for the database to which Icinga Kubernetes synchronizes Kubernetes data.
# This is also the database used in Icinga Kubernetes Web to view and work with the data.
database:
# Database type. Either 'mysql' for MySQL or 'pgsql' for PostgreSQL.
# Defaults to 'mysql'.
# type: mysql
# Database host or absolute Unix socket path.
host: 10.96.0.2
# Database port. By default, the MySQL or PostgreSQL port, depending on the database type.
# port:
# Database name.
database: kubernetes
# Database user.
user: kubernetes
# Database password.
password: kubernetes
# Icinga Kubernetes logs its activities at various severity levels and any errors that occur either
# on the console or in systemd's journal. The latter is used automatically when running under systemd.
# In any case, the default log level is 'info'.
logging:
# Default logging level. Can be set to 'fatal', 'error', 'warn', 'info' or 'debug'.
# If not set, defaults to 'info'.
level: info

# Logging output. Can be set to 'console' (stderr) or 'systemd-journald'.
# If not set, logs to systemd-journald when running under systemd, otherwise stderr.
# output:

# Interval for periodic logging defined as duration string.
# A duration string is a sequence of decimal numbers and a unit suffix, such as "20s".
# Valid units are "ms", "s", "m", "h".
# Defaults to "20s".
# interval: 20s
15 changes: 0 additions & 15 deletions icinga-kubernetes-expose-8080.yml

This file was deleted.

38 changes: 35 additions & 3 deletions icinga-kubernetes.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
---
apiVersion: v1
kind: Pod
metadata:
name: icinga-kubernetes
labels:
app: icinga-kubernetes
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- minikube
containers:
- name: icinga-kubernetes
image: icinga-kubernetes
imagePullPolicy: Never
ports:
- containerPort: 8080

---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: default
name: pod-reader
rules:
- apiGroups: [ "" ] # "" indicates the core API group
resources: [ "*" ]
verbs: [ "get", "watch", "list" ]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: read-pods
namespace: default
subjects:
- kind: ServiceAccount
name: default
namespace: default
roleRef:
kind: ClusterRole
name: pod-reader
apiGroup: ""
10 changes: 10 additions & 0 deletions schema/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM mysql:latest

ENV MYSQL_USER=kubernetes
ENV MYSQL_PASSWORD=kubernetes
ENV MYSQL_DATABASE=kubernetes
ENV MYSQL_ROOT_PASSWORD=kubernetes

COPY schema.sql /docker-entrypoint-initdb.d

EXPOSE 3306

0 comments on commit 7031590

Please sign in to comment.