Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass communication settings as a k8s secret #233

Merged
merged 12 commits into from
Dec 22, 2019
35 changes: 35 additions & 0 deletions comm_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Channels configuration
communications:
# Settings for Slack
slack:
enabled: false
channel: 'SLACK_CHANNEL'
token: 'SLACK_API_TOKEN'
notiftype: short # Change notification type short/long you want to receive. notiftype is optional and Default notification type is short (if not specified)

# Settings for Mattermost
mattermost:
enabled: false
url: 'MATTERMOST_SERVER_URL' # URL where Mattermost is running. e.g https://example.com:9243
token: 'MATTERMOST_TOKEN' # Personal Access token generated by BotKube user
team: 'MATTERMOST_TEAM' # Mattermost Team to configure with BotKube
channel: 'MATTERMOST_CHANNEL' # Mattermost Channel for receiving BotKube alerts
notiftype: short # Change notification type short/long you want to receive. notiftype is optional and Default notification type is short (if not specified)

# Settings for ELS
elasticsearch:
enabled: false
server: 'ELASTICSEARCH_ADDRESS' # e.g https://example.com:9243
username: 'ELASTICSEARCH_USERNAME'
password: 'ELASTICSEARCH_PASSWORD'
# ELS index settings
index:
name: botkube
type: botkube-event
shards: 1
replicas: 0

# Settings for Webhook
webhook:
enabled: false
url: 'WEBHOOK_URL' # e.g https://example.com:80
47 changes: 30 additions & 17 deletions deploy-all-in-one-tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,28 @@ data:
# about the best practices for the created resource
recommendations: true

# Channels configuration
# Setting to support multiple clusters
settings:
# Cluster name to differentiate incoming messages
clustername: not-configured
# Set true to enable kubectl commands execution
allowkubectl: false
# Set true to enable config watcher
configwatcher: true
# Set false to disable upgrade notification
upgradeNotifier: true
---
# secret
apiVersion: v1
kind: Secret
metadata:
name: botkube-communication-secret
labels:
app: botkube
type: Opaque
stringData:
comm_config.yaml: |
# Communication settings
communications:
# Settings for Slack
slack:
Expand Down Expand Up @@ -213,18 +234,6 @@ data:
webhook:
enabled: false
url: 'WEBHOOK_URL' # e.g https://example.com:80


# Setting to support multiple clusters
settings:
# Cluster name to differentiate incoming messages
clustername: not-configured
# Set true to enable kubectl commands execution
allowkubectl: false
# Set true to enable config watcher
configwatcher: true
# Set false to disable upgrade notification
upgradeNotifier: true
---
# serviceaccount
apiVersion: v1
Expand Down Expand Up @@ -266,7 +275,7 @@ subjects:
apiVersion: v1
kind: Secret
metadata:
name: botkube-secret
name: botkube-certificate-secret
labels:
app: botkube
data:
Expand Down Expand Up @@ -313,11 +322,15 @@ spec:
value: v0.9.1
volumes:
- name: config-volume
configMap:
name: botkube-configmap
projected:
sources:
- configMap:
name: botkube-configmap
- secret:
name: botkube-communication-secret
- name: certs
secret:
secretName: botkube-secret
secretName: botkube-certificate-secret
# run as non privilaged user
securityContext:
runAsUser: 101
Expand Down
42 changes: 28 additions & 14 deletions deploy-all-in-one.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,28 @@ data:
# about the best practices for the created resource
recommendations: true

# Channels configuration
# Setting to support multiple clusters
settings:
# Cluster name to differentiate incoming messages
clustername: not-configured
# Set true to enable kubectl commands execution
allowkubectl: false
# Set true to enable config watcher
configwatcher: true
# Set false to disable upgrade notification
upgradeNotifier: true
---
# secret
apiVersion: v1
kind: Secret
metadata:
name: botkube-communication-secret
labels:
app: botkube
type: Opaque
stringData:
comm_config.yaml: |
# Communication settings
communications:
# Settings for Slack
slack:
Expand Down Expand Up @@ -214,17 +235,6 @@ data:
webhook:
enabled: false
url: 'WEBHOOK_URL' # e.g https://example.com:80

# Setting to support multiple clusters
settings:
# Cluster name to differentiate incoming messages
clustername: not-configured
# Set true to enable kubectl commands execution
allowkubectl: false
# Set true to enable config watcher
configwatcher: true
# Set false to disable upgrade notification
upgradeNotifier: true
---
# serviceaccount
apiVersion: v1
Expand Down Expand Up @@ -301,8 +311,12 @@ spec:
value: v0.9.1
volumes:
- name: config-volume
configMap:
name: botkube-configmap
projected:
sources:
- configMap:
name: botkube-configmap
- secret:
name: botkube-communication-secret
# run as non privilaged user
securityContext:
runAsUser: 101
Expand Down
16 changes: 16 additions & 0 deletions helm/botkube/templates/communicationsecret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "botkube.fullname" . }}-communication-secret
labels:
app.kubernetes.io/name: {{ include "botkube.name" . }}
helm.sh/chart: {{ include "botkube.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
stringData:
comm_config.yaml: |
# Communication settings
communications:
{{- with .Values.communications }}
{{- toYaml . | nindent 6 }}
{{- end }}
2 changes: 1 addition & 1 deletion helm/botkube/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metadata:
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
data:
config.yaml: |
resource_config.yaml: |
{{- with .Values.config }}
{{- toYaml . | nindent 4 }}
{{- end }}
Expand Down
10 changes: 7 additions & 3 deletions helm/botkube/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,16 @@ spec:
{{- end }}
volumes:
- name: config-volume
configMap:
name: {{ include "botkube.fullname" . }}-configmap
projected:
sources:
- configMap:
name: {{ include "botkube.fullname" . }}-configmap
- secret:
name: {{ include "botkube.fullname" . }}-communication-secret
{{- if .Values.config.ssl.enabled }}
- name: certs
secret:
secretName: {{ include "botkube.fullname" . }}-secret
secretName: {{ include "botkube.fullname" . }}-certificate-secret
{{ end }}
{{- if .Values.securityContext }}
securityContext:
Expand Down
2 changes: 1 addition & 1 deletion helm/botkube/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "botkube.fullname" . }}-secret
name: {{ include "botkube.fullname" . }}-certificate-secret
labels:
app.kubernetes.io/name: {{ include "botkube.name" . }}
helm.sh/chart: {{ include "botkube.chart" . }}
Expand Down
73 changes: 36 additions & 37 deletions helm/botkube/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,43 +202,6 @@ config:
enabled: false # Set to true and specify cert path in the next line after uncommenting
#cert: # SSL Certificate file e.g certs/my-cert.crt

# Channels configuration
communications:
# Settings for Slack
slack:
enabled: false
channel: 'SLACK_CHANNEL' # Slack channel name without '#' prefix where you have added BotKube and want to receive notifications in
token: 'SLACK_API_TOKEN'
notiftype: short # Change notification type short/long you want to receive. notiftype is optional and Default notification type is short (if not specified)

# Settings for Mattermost
mattermost:
enabled: false
url: 'MATTERMOST_SERVER_URL' # URL where Mattermost is running. e.g https://example.com:9243
token: 'MATTERMOST_TOKEN' # Personal Access token generated by BotKube user
team: 'MATTERMOST_TEAM' # Mattermost Team to configure with BotKube
channel: 'MATTERMOST_CHANNEL' # Mattermost Channel for receiving BotKube alerts
notiftype: short # Change notification type short/long you want to receive. notiftype is optional and Default notification type is short (if not specified)

# Settings for ELS
elasticsearch:
enabled: false
server: 'ELASTICSEARCH_ADDRESS' # e.g https://example.com:9243
username: 'ELASTICSEARCH_USERNAME'
password: 'ELASTICSEARCH_PASSWORD'
# ELS index settings
index:
name: botkube
type: botkube-event
shards: 1
replicas: 0

# Settings for Webhook
webhook:
enabled: false
url: 'WEBHOOK_URL' # e.g https://example.com:80


# Setting to support multiple clusters
settings:
# Cluster name to differentiate incoming messages
Expand All @@ -250,6 +213,42 @@ config:
# Set false to disable upgrade notification
upgradeNotifier: true

# Communication settings
communications:
# Settings for Slack
slack:
enabled: false
channel: 'SLACK_CHANNEL' # Slack channel name without '#' prefix where you have added BotKube and want to receive notifications in
token: 'SLACK_API_TOKEN'
notiftype: short # Change notification type short/long you want to receive. notiftype is optional and Default notification type is short (if not specified)

# Settings for Mattermost
mattermost:
enabled: false
url: 'MATTERMOST_SERVER_URL' # URL where Mattermost is running. e.g https://example.com:9243
token: 'MATTERMOST_TOKEN' # Personal Access token generated by BotKube user
team: 'MATTERMOST_TEAM' # Mattermost Team to configure with BotKube
channel: 'MATTERMOST_CHANNEL' # Mattermost Channel for receiving BotKube alerts
notiftype: short # Change notification type short/long you want to receive. notiftype is optional and Default notification type is short (if not specified)

# Settings for ELS
elasticsearch:
enabled: false
server: 'ELASTICSEARCH_ADDRESS' # e.g https://example.com:9243
username: 'ELASTICSEARCH_USERNAME'
password: 'ELASTICSEARCH_PASSWORD'
# ELS index settings
index:
name: botkube
type: botkube-event
shards: 1
replicas: 0

# Settings for Webhook
webhook:
enabled: false
url: 'WEBHOOK_URL' # e.g https://example.com:80

service:
name: metrics
port: 2112
Expand Down
31 changes: 25 additions & 6 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ const (
// EventType to watch
type EventType string

// ConfigFileName is a name of botkube configuration file
var ConfigFileName = "config.yaml"
// ResourceConfigFileName is a name of botkube resource configuration file
var ResourceConfigFileName = "resource_config.yaml"

// CommunicationConfigFileName is a name of botkube communication configuration file
var CommunicationConfigFileName = "comm_config.yaml"

// Notify flag to toggle event notification
var Notify = true
Expand Down Expand Up @@ -134,14 +137,30 @@ func (eventType EventType) String() string {
func New() (*Config, error) {
c := &Config{}
configPath := os.Getenv("CONFIG_PATH")
configFile := filepath.Join(configPath, ConfigFileName)
file, err := os.Open(configFile)
defer file.Close()
resourceConfigFilePath := filepath.Join(configPath, ResourceConfigFileName)
resourceConfigFile, err := os.Open(resourceConfigFilePath)
defer resourceConfigFile.Close()
if err != nil {
return c, err
}

b, err := ioutil.ReadAll(resourceConfigFile)
if err != nil {
return c, err
}

if len(b) != 0 {
yaml.Unmarshal(b, c)
}

communicationConfigFilePath := filepath.Join(configPath, CommunicationConfigFileName)
communicationConfigFile, err := os.Open(communicationConfigFilePath)
defer communicationConfigFile.Close()
if err != nil {
return c, err
}

b, err := ioutil.ReadAll(file)
b, err = ioutil.ReadAll(communicationConfigFile)
if err != nil {
return c, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func sendMessage(c *config.Config, notifiers []notify.Notifier, msg string) {

func configWatcher(c *config.Config, notifiers []notify.Notifier) {
configPath := os.Getenv("CONFIG_PATH")
configFile := filepath.Join(configPath, config.ConfigFileName)
configFile := filepath.Join(configPath, config.ResourceConfigFileName)

watcher, err := fsnotify.NewWatcher()
if err != nil {
Expand Down
Loading