Skip to content

Commit 22b401c

Browse files
committed
WIP
1 parent be4bf11 commit 22b401c

5 files changed

+139
-33
lines changed

Dockerfile

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ RUN go build -o /go/bin/icinga-kubernetes ./cmd/icinga-kubernetes/main.go
77

88
FROM scratch
99

10-
COPY --from=builder /go/bin/icinga-kubernetes /go/bin/icinga-kubernetes
11-
EXPOSE 8080
12-
ENTRYPOINT ["/go/bin/icinga-kubernetes"]
10+
WORKDIR /go/bin/
11+
COPY --from=alpine /tmp /tmp
12+
COPY --from=builder /go/bin/icinga-kubernetes ./icinga-kubernetes
13+
14+
ENTRYPOINT ["./icinga-kubernetes"]

cmd/icinga-kubernetes/main.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
kinformers "k8s.io/client-go/informers"
1616
"k8s.io/client-go/kubernetes"
1717
kclientcmd "k8s.io/client-go/tools/clientcmd"
18+
"os"
1819
)
1920

2021
func main() {
@@ -34,7 +35,29 @@ func main() {
3435
logging.Fatal(errors.Wrap(err, "can't parse flags"))
3536
}
3637

37-
cfg, err := config.FromYAMLFile[internal.Config](flags.Config)
38+
cfg := &internal.Config{}
39+
configFile := flags.Config
40+
41+
if ikConfig, inCluster := os.LookupEnv("ICINGA_KUBERNETES_CONFIG"); inCluster {
42+
file, err := os.CreateTemp("", "yaml-config-")
43+
if err != nil {
44+
logging.Fatal(errors.Wrap(err, "can't create temporary yaml config"))
45+
}
46+
defer func() {
47+
err := os.Remove(file.Name())
48+
if err != nil {
49+
logging.Fatal(errors.Wrap(err, "can't remove temporary yaml config"))
50+
}
51+
}()
52+
53+
if _, err = file.Write([]byte(ikConfig)); err != nil {
54+
logging.Fatal(errors.Wrap(err, "can't write to temporary yaml config"))
55+
}
56+
57+
configFile = file.Name()
58+
}
59+
60+
cfg, err = config.FromYAMLFile[internal.Config](configFile)
3861
if err != nil {
3962
logging.Fatal(errors.Wrap(err, "can't create configuration"))
4063
}

icinga-kubernetes-expose-8080.yml

-15
This file was deleted.

icinga-kubernetes.example.yml

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: icinga-kubernetes
5+
labels:
6+
app: icinga-kubernetes
7+
8+
---
9+
apiVersion: v1
10+
kind: ConfigMap
11+
metadata:
12+
name: icinga-kubernetes-config
13+
namespace: icinga-kubernetes
14+
data:
15+
config: |
16+
# This is the configuration file for Icinga Kubernetes.
17+
#
18+
# Connection configuration for the database to which Icinga Kubernetes synchronizes Kubernetes data.
19+
# This is also the database used in Icinga Kubernetes Web to view and work with the data.
20+
database:
21+
# Database type. Either 'mysql' for MySQL or 'pgsql' for PostgreSQL.
22+
# Defaults to 'mysql'.
23+
# type: mysql
24+
25+
# Database host or absolute Unix socket path.
26+
host: 10.96.0.2
27+
28+
# Database port. By default, the MySQL or PostgreSQL port, depending on the database type.
29+
# port:
30+
31+
# Database name.
32+
database: kubernetes
33+
34+
# Database user.
35+
user: kubernetes
36+
37+
# Database password.
38+
password: kubernetes
39+
40+
# Icinga Kubernetes logs its activities at various severity levels and any errors that occur either
41+
# on the console or in systemd's journal. The latter is used automatically when running under systemd.
42+
# In any case, the default log level is 'info'.
43+
logging:
44+
# Default logging level. Can be set to 'fatal', 'error', 'warn', 'info' or 'debug'.
45+
# If not set, defaults to 'info'.
46+
level: info
47+
48+
# Logging output. Can be set to 'console' (stderr) or 'systemd-journald'.
49+
# If not set, logs to systemd-journald when running under systemd, otherwise stderr.
50+
# output:
51+
52+
# Interval for periodic logging defined as duration string.
53+
# A duration string is a sequence of decimal numbers and a unit suffix, such as "20s".
54+
# Valid units are "ms", "s", "m", "h".
55+
# Defaults to "20s".
56+
# interval: 20s
57+
58+
---
59+
apiVersion: v1
60+
kind: ServiceAccount
61+
metadata:
62+
name: icinga-kubernetes
63+
namespace: icinga-kubernetes
64+
65+
---
66+
kind: ClusterRole
67+
apiVersion: rbac.authorization.k8s.io/v1
68+
metadata:
69+
namespace: icinga-kubernetes
70+
name: resource-reader
71+
rules:
72+
- apiGroups: [ "" ]
73+
resources: [ "*" ]
74+
verbs: [ "get", "watch", "list" ]
75+
76+
---
77+
apiVersion: rbac.authorization.k8s.io/v1
78+
kind: ClusterRoleBinding
79+
metadata:
80+
name: read-resources
81+
namespace: icinga-kubernetes
82+
subjects:
83+
- kind: ServiceAccount
84+
name: icinga-kubernetes
85+
namespace: icinga-kubernetes
86+
roleRef:
87+
kind: ClusterRole
88+
name: resource-reader
89+
apiGroup: "rbac.authorization.k8s.io"
90+
91+
---
92+
apiVersion: v1
93+
kind: Pod
94+
metadata:
95+
name: icinga-kubernetes
96+
labels:
97+
app: icinga-kubernetes
98+
namespace: icinga-kubernetes
99+
spec:
100+
serviceAccountName: icinga-kubernetes
101+
containers:
102+
- name: icinga-kubernetes
103+
image: icinga-kubernetes
104+
imagePullPolicy: Never
105+
env:
106+
- name: ICINGA_KUBERNETES_CONFIG
107+
valueFrom:
108+
configMapKeyRef:
109+
name: icinga-kubernetes-config
110+
key: config

icinga-kubernetes.yml

-14
This file was deleted.

0 commit comments

Comments
 (0)