Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ARM
k8s
Kured
Commits
1a6e814a
Commit
1a6e814a
authored
Aug 15, 2017
by
Adam Harrison
Browse files
Basic slack notification support
parent
55ba7797
Changes
4
Hide whitespace changes
Inline
Side-by-side
cmd/kured/Dockerfile
View file @
1a6e814a
FROM
ubuntu
RUN
apt-get update
&&
apt-get
install
-y
ca-certificates
&&
rm
-rf
/var/cache/apt
ADD
https://storage.googleapis.com/kubernetes-release/release/v1.4.8/bin/linux/amd64/kubectl /usr/bin/kubectl
RUN
chmod
0755 /usr/bin/kubectl
COPY
./kured /usr/bin/kured
...
...
cmd/kured/main.go
View file @
1a6e814a
...
...
@@ -16,6 +16,7 @@ import (
"github.com/weaveworks/kured/pkg/alerts"
"github.com/weaveworks/kured/pkg/daemonsetlock"
"github.com/weaveworks/kured/pkg/delaytick"
"github.com/weaveworks/kured/pkg/notifications/slack"
)
var
(
...
...
@@ -27,6 +28,8 @@ var (
prometheusURL
string
alertFilter
*
regexp
.
Regexp
rebootSentinel
string
slackHookURL
string
slackUsername
string
)
func
main
()
{
...
...
@@ -50,6 +53,11 @@ func main() {
rootCmd
.
PersistentFlags
()
.
StringVar
(
&
rebootSentinel
,
"reboot-sentinel"
,
"/var/run/reboot-required"
,
"path to file whose existence signals need to reboot"
)
rootCmd
.
PersistentFlags
()
.
StringVar
(
&
slackHookURL
,
"slack-hook-url"
,
""
,
"slack hook URL for reboot notfications"
)
rootCmd
.
PersistentFlags
()
.
StringVar
(
&
slackUsername
,
"slack-username"
,
"kured"
,
"slack username for reboot notfications"
)
if
err
:=
rootCmd
.
Execute
();
err
!=
nil
{
log
.
Fatal
(
err
)
}
...
...
@@ -169,8 +177,15 @@ func waitForDrain(client *kubernetes.Clientset, nodeID string) {
}
}
func
reboot
()
{
func
reboot
(
nodeID
string
)
{
log
.
Infof
(
"Commanding reboot"
)
if
slackHookURL
!=
""
{
if
err
:=
slack
.
NotifyReboot
(
slackHookURL
,
slackUsername
,
nodeID
);
err
!=
nil
{
log
.
Warnf
(
"Error notifying slack: %v"
,
err
)
}
}
// Relies on /var/run/dbus/system_bus_socket bind mount to talk to systemd
rebootCmd
:=
exec
.
Command
(
"/bin/systemctl"
,
"reboot"
)
if
err
:=
rebootCmd
.
Run
();
err
!=
nil
{
...
...
@@ -237,7 +252,7 @@ func root(cmd *cobra.Command, args []string) {
drain
(
nodeID
)
waitForDrain
(
client
,
nodeID
)
}
reboot
()
reboot
(
nodeID
)
break
}
}
...
...
kured-ds.yaml
View file @
1a6e814a
...
...
@@ -23,6 +23,7 @@ spec:
# - --period=60
# - --prometheus-url=http://prometheus.monitoring.svc.cluster.local
# - --reboot-sentinel=/var/run/reboot-required
# - --slack-hook-url=https://hooks.slack.com/...
env
:
# Pass in the name of the node on which this pod is scheduled
# for use with drain/uncordon operations and lock acquisition
...
...
pkg/notifications/slack/slack.go
0 → 100644
View file @
1a6e814a
package
slack
import
(
"bytes"
"encoding/json"
"fmt"
"net/http"
"time"
)
var
(
httpClient
=
&
http
.
Client
{
Timeout
:
5
*
time
.
Second
}
)
type
body
struct
{
Text
string
`json:"text,omitempty"`
Username
string
`json:"username,omitempty"`
}
func
NotifyReboot
(
hookURL
,
username
,
nodeID
string
)
error
{
msg
:=
body
{
Text
:
fmt
.
Sprintf
(
"Rebooting node %s"
,
nodeID
),
Username
:
username
,
}
var
buf
bytes
.
Buffer
if
err
:=
json
.
NewEncoder
(
&
buf
)
.
Encode
(
&
msg
);
err
!=
nil
{
return
err
}
resp
,
err
:=
httpClient
.
Post
(
hookURL
,
"application/json"
,
&
buf
)
defer
resp
.
Body
.
Close
()
if
err
!=
nil
{
return
err
}
if
resp
.
StatusCode
<
200
||
resp
.
StatusCode
>=
300
{
return
fmt
.
Errorf
(
resp
.
Status
)
}
return
nil
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment