From 732de7aaf46e2f3acf28d1f5a7f8385de72e33cb Mon Sep 17 00:00:00 2001 From: Sumit Lalwani Date: Mon, 2 Dec 2019 23:10:07 +0530 Subject: [PATCH 01/12] Pass communication settings as a k8s secret Signed-off-by: Sumit Lalwani --- deploy-all-in-one.yaml | 32 ++++++++++++++++++++------------ pkg/config/config.go | 27 +++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/deploy-all-in-one.yaml b/deploy-all-in-one.yaml index 483172ef6..55af8e40d 100644 --- a/deploy-all-in-one.yaml +++ b/deploy-all-in-one.yaml @@ -179,7 +179,26 @@ 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-secret +type: Opaque +stringData: + communication.yaml: | + # Communication settings communications: # Settings for Slack slack: @@ -214,17 +233,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 diff --git a/pkg/config/config.go b/pkg/config/config.go index 12327a562..d845f7048 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -37,6 +37,9 @@ type EventType string // ConfigFileName is a name of botkube configuration file var ConfigFileName = "config.yaml" +// CommunicationFileName is a name of botkube communication file +var CommunicationFileName = "communication.yaml" + // Notify flag to toggle event notification var Notify = true @@ -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() + configFilePath := filepath.Join(configPath, ConfigFileName) + configFile, err := os.Open(configFilePath) + defer configFile.Close() + if err != nil { + return c, err + } + + b, err := ioutil.ReadAll(configFile) + if err != nil { + return c, err + } + + if len(b) != 0 { + yaml.Unmarshal(b, c) + } + + communicationFilePath := filepath.Join(configPath, CommunicationFileName) + communicationFile, err := os.Open(communicationFilePath) + defer communicationFile.Close() if err != nil { return c, err } - b, err := ioutil.ReadAll(file) + b, err = ioutil.ReadAll(communicationFile) if err != nil { return c, err } From 862c927157619d8e09c8dbfc3c85477ae1d252a2 Mon Sep 17 00:00:00 2001 From: Sumit Lalwani Date: Mon, 2 Dec 2019 23:49:02 +0530 Subject: [PATCH 02/12] Update botkube deployment Signed-off-by: Sumit Lalwani --- deploy-all-in-one.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/deploy-all-in-one.yaml b/deploy-all-in-one.yaml index 55af8e40d..121146cf7 100644 --- a/deploy-all-in-one.yaml +++ b/deploy-all-in-one.yaml @@ -309,8 +309,12 @@ spec: value: v0.9.1 volumes: - name: config-volume - configMap: - name: botkube-configmap + projected: + sources: + - configMap: + name: botkube-configmap + - secret: + name: botkube-secret # run as non privilaged user securityContext: runAsUser: 101 From 70c065a1f80472a3bd0886ea5d484977cf4af762 Mon Sep 17 00:00:00 2001 From: Sumit Lalwani Date: Tue, 3 Dec 2019 19:57:48 +0530 Subject: [PATCH 03/12] update tls deployment, helm and e2e tests Signed-off-by: Sumit Lalwani --- deploy-all-in-one-tls.yaml | 45 ++++++++++++------- deploy-all-in-one.yaml | 4 +- .../templates/communicationsecret.yaml | 14 ++++++ helm/botkube/templates/deployment.yaml | 10 +++-- helm/botkube/templates/secret.yaml | 2 +- helm/botkube/values.yaml | 26 +++++------ test/communication.yaml | 35 +++++++++++++++ test/config.yaml | 36 --------------- 8 files changed, 100 insertions(+), 72 deletions(-) create mode 100644 helm/botkube/templates/communicationsecret.yaml create mode 100644 test/communication.yaml diff --git a/deploy-all-in-one-tls.yaml b/deploy-all-in-one-tls.yaml index 57fb96b48..774da562b 100644 --- a/deploy-all-in-one-tls.yaml +++ b/deploy-all-in-one-tls.yaml @@ -178,7 +178,26 @@ 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 +type: Opaque +stringData: + communication.yaml: | + # Communication settings communications: # Settings for Slack slack: @@ -213,18 +232,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 @@ -266,7 +273,7 @@ subjects: apiVersion: v1 kind: Secret metadata: - name: botkube-secret + name: botkube-certificate-secret labels: app: botkube data: @@ -313,11 +320,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 diff --git a/deploy-all-in-one.yaml b/deploy-all-in-one.yaml index 121146cf7..77d058690 100644 --- a/deploy-all-in-one.yaml +++ b/deploy-all-in-one.yaml @@ -194,7 +194,7 @@ data: apiVersion: v1 kind: Secret metadata: - name: botkube-secret + name: botkube-communication-secret type: Opaque stringData: communication.yaml: | @@ -314,7 +314,7 @@ spec: - configMap: name: botkube-configmap - secret: - name: botkube-secret + name: botkube-communication-secret # run as non privilaged user securityContext: runAsUser: 101 diff --git a/helm/botkube/templates/communicationsecret.yaml b/helm/botkube/templates/communicationsecret.yaml new file mode 100644 index 000000000..eb4e95f0b --- /dev/null +++ b/helm/botkube/templates/communicationsecret.yaml @@ -0,0 +1,14 @@ +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: + communication.yaml: | + {{- with .Values.communication }} + {{- toYaml . | nindent 4 }} + {{- end }} diff --git a/helm/botkube/templates/deployment.yaml b/helm/botkube/templates/deployment.yaml index 098e63768..4e68cbbeb 100644 --- a/helm/botkube/templates/deployment.yaml +++ b/helm/botkube/templates/deployment.yaml @@ -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: diff --git a/helm/botkube/templates/secret.yaml b/helm/botkube/templates/secret.yaml index 9a4a560f1..855ab6f0b 100644 --- a/helm/botkube/templates/secret.yaml +++ b/helm/botkube/templates/secret.yaml @@ -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" . }} diff --git a/helm/botkube/values.yaml b/helm/botkube/values.yaml index 637f3f136..c64066c67 100644 --- a/helm/botkube/values.yaml +++ b/helm/botkube/values.yaml @@ -202,7 +202,19 @@ 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 + # 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 + +communication: + # Communication settings communications: # Settings for Slack slack: @@ -238,18 +250,6 @@ config: 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 - service: name: metrics port: 2112 diff --git a/test/communication.yaml b/test/communication.yaml new file mode 100644 index 000000000..836b61de0 --- /dev/null +++ b/test/communication.yaml @@ -0,0 +1,35 @@ +# Communication settings +communications: + # Settings for Slack + slack: + enabled: true + channel: 'cloud-alerts' + token: 'ABCDEFG' + 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: true + url: 'WEBHOOK_URL' # e.g https://example.com:80 \ No newline at end of file diff --git a/test/config.yaml b/test/config.yaml index 6bece951f..b2819082b 100644 --- a/test/config.yaml +++ b/test/config.yaml @@ -180,42 +180,6 @@ resources: # about the best practices for the created resource recommendations: true -# Channels configuration -communications: - # Settings for Slack - slack: - enabled: true - channel: 'cloud-alerts' - token: 'ABCDEFG' - 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: true - url: 'WEBHOOK_URL' # e.g https://example.com:80 - # Setting to support multiple clusters settings: # Cluster name to differentiate incoming messages From 84d6040147f3d307e4abf2c7520d6fc83c5bec01 Mon Sep 17 00:00:00 2001 From: Sumit Lalwani Date: Tue, 3 Dec 2019 20:08:50 +0530 Subject: [PATCH 04/12] Add app label in secret Signed-off-by: Sumit Lalwani --- deploy-all-in-one-tls.yaml | 2 ++ deploy-all-in-one.yaml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/deploy-all-in-one-tls.yaml b/deploy-all-in-one-tls.yaml index 774da562b..3373fb462 100644 --- a/deploy-all-in-one-tls.yaml +++ b/deploy-all-in-one-tls.yaml @@ -194,6 +194,8 @@ apiVersion: v1 kind: Secret metadata: name: botkube-communication-secret + labels: + app: botkube type: Opaque stringData: communication.yaml: | diff --git a/deploy-all-in-one.yaml b/deploy-all-in-one.yaml index 77d058690..c4e548a08 100644 --- a/deploy-all-in-one.yaml +++ b/deploy-all-in-one.yaml @@ -195,6 +195,8 @@ apiVersion: v1 kind: Secret metadata: name: botkube-communication-secret + labels: + app: botkube type: Opaque stringData: communication.yaml: | From 1ce12443e2abe4fd9eacbc0996cc7001de72838d Mon Sep 17 00:00:00 2001 From: Sumit Lalwani Date: Mon, 9 Dec 2019 23:21:09 +0530 Subject: [PATCH 05/12] Update yaml files name Signed-off-by: Sumit Lalwani --- deploy-all-in-one-tls.yaml | 2 +- deploy-all-in-one.yaml | 2 +- .../templates/communicationsecret.yaml | 4 ++-- helm/botkube/templates/configmap.yaml | 4 ++-- helm/botkube/values.yaml | 4 ++-- pkg/config/config.go | 24 +++++++++---------- test/{communication.yaml => comm_config.yaml} | 0 test/{config.yaml => resource_config.yaml} | 0 8 files changed, 20 insertions(+), 20 deletions(-) rename test/{communication.yaml => comm_config.yaml} (100%) rename test/{config.yaml => resource_config.yaml} (100%) diff --git a/deploy-all-in-one-tls.yaml b/deploy-all-in-one-tls.yaml index 3373fb462..da8a38e81 100644 --- a/deploy-all-in-one-tls.yaml +++ b/deploy-all-in-one-tls.yaml @@ -198,7 +198,7 @@ metadata: app: botkube type: Opaque stringData: - communication.yaml: | + comm_config.yaml: | # Communication settings communications: # Settings for Slack diff --git a/deploy-all-in-one.yaml b/deploy-all-in-one.yaml index c4e548a08..a1f22b8bc 100644 --- a/deploy-all-in-one.yaml +++ b/deploy-all-in-one.yaml @@ -199,7 +199,7 @@ metadata: app: botkube type: Opaque stringData: - communication.yaml: | + comm_config.yaml: | # Communication settings communications: # Settings for Slack diff --git a/helm/botkube/templates/communicationsecret.yaml b/helm/botkube/templates/communicationsecret.yaml index eb4e95f0b..fc576c08e 100644 --- a/helm/botkube/templates/communicationsecret.yaml +++ b/helm/botkube/templates/communicationsecret.yaml @@ -8,7 +8,7 @@ metadata: app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/managed-by: {{ .Release.Service }} stringData: - communication.yaml: | - {{- with .Values.communication }} + comm_config.yaml: | + {{- with .Values.communicationConfig }} {{- toYaml . | nindent 4 }} {{- end }} diff --git a/helm/botkube/templates/configmap.yaml b/helm/botkube/templates/configmap.yaml index e1d00efff..ddb4588d2 100644 --- a/helm/botkube/templates/configmap.yaml +++ b/helm/botkube/templates/configmap.yaml @@ -8,8 +8,8 @@ metadata: app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/managed-by: {{ .Release.Service }} data: - config.yaml: | - {{- with .Values.config }} + resource_config.yaml: | + {{- with .Values.resourceConfig }} {{- toYaml . | nindent 4 }} {{- end }} diff --git a/helm/botkube/values.yaml b/helm/botkube/values.yaml index c64066c67..0ca8e4b3e 100644 --- a/helm/botkube/values.yaml +++ b/helm/botkube/values.yaml @@ -27,7 +27,7 @@ securityContext: # set one of the log levels- info, warn, debug, error, fatal, panic logLevel: info -config: +resourceConfig: ## Resources you want to watch resources: - name: pod # Name of the resources e.g pod, deployment, ingress, etc. (Resource name must be in singular form) @@ -213,7 +213,7 @@ config: # Set false to disable upgrade notification upgradeNotifier: true -communication: +communicationConfig: # Communication settings communications: # Settings for Slack diff --git a/pkg/config/config.go b/pkg/config/config.go index d845f7048..1e4182628 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -34,11 +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" -// CommunicationFileName is a name of botkube communication file -var CommunicationFileName = "communication.yaml" +// CommunicationConfigFileName is a name of botkube communication configuration file +var CommunicationConfigFileName = "comm_config.yaml" // Notify flag to toggle event notification var Notify = true @@ -137,14 +137,14 @@ func (eventType EventType) String() string { func New() (*Config, error) { c := &Config{} configPath := os.Getenv("CONFIG_PATH") - configFilePath := filepath.Join(configPath, ConfigFileName) - configFile, err := os.Open(configFilePath) - defer configFile.Close() + resourceConfigFilePath := filepath.Join(configPath, ResourceConfigFileName) + resourceConfigFile, err := os.Open(resourceConfigFilePath) + defer resourceConfigFile.Close() if err != nil { return c, err } - b, err := ioutil.ReadAll(configFile) + b, err := ioutil.ReadAll(resourceConfigFile) if err != nil { return c, err } @@ -153,14 +153,14 @@ func New() (*Config, error) { yaml.Unmarshal(b, c) } - communicationFilePath := filepath.Join(configPath, CommunicationFileName) - communicationFile, err := os.Open(communicationFilePath) - defer communicationFile.Close() + communicationConfigFilePath := filepath.Join(configPath, CommunicationConfigFileName) + communicationConfigFile, err := os.Open(communicationConfigFilePath) + defer communicationConfigFile.Close() if err != nil { return c, err } - b, err = ioutil.ReadAll(communicationFile) + b, err = ioutil.ReadAll(communicationConfigFile) if err != nil { return c, err } diff --git a/test/communication.yaml b/test/comm_config.yaml similarity index 100% rename from test/communication.yaml rename to test/comm_config.yaml diff --git a/test/config.yaml b/test/resource_config.yaml similarity index 100% rename from test/config.yaml rename to test/resource_config.yaml From 6de65943b2781ad1f05baaa54a4e8a3daa37da2b Mon Sep 17 00:00:00 2001 From: Sumit Lalwani Date: Mon, 9 Dec 2019 23:48:16 +0530 Subject: [PATCH 06/12] Fix travis failure Signed-off-by: Sumit Lalwani --- pkg/controller/controller.go | 2 +- pkg/execute/executor.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 83de26aa4..5ea5fab79 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -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 { diff --git a/pkg/execute/executor.go b/pkg/execute/executor.go index 4e24e240f..5adfe9251 100644 --- a/pkg/execute/executor.go +++ b/pkg/execute/executor.go @@ -361,7 +361,7 @@ func runVersionCommand(args []string, clusterName string) string { func showControllerConfig() (configYaml string, err error) { configPath := os.Getenv("CONFIG_PATH") - configFile := filepath.Join(configPath, config.ConfigFileName) + configFile := filepath.Join(configPath, config.ResourceConfigFileName) file, err := os.Open(configFile) defer file.Close() if err != nil { From a838c26054f96f74b712eb03d8787f31eb108cb6 Mon Sep 17 00:00:00 2001 From: Sumit Lalwani Date: Tue, 10 Dec 2019 00:02:28 +0530 Subject: [PATCH 07/12] Update config -> resourceConfig name and fix travis failure Signed-off-by: Sumit Lalwani --- helm/botkube/templates/deployment.yaml | 4 ++-- helm/botkube/templates/secret.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/helm/botkube/templates/deployment.yaml b/helm/botkube/templates/deployment.yaml index 4e68cbbeb..85b1fcd8a 100644 --- a/helm/botkube/templates/deployment.yaml +++ b/helm/botkube/templates/deployment.yaml @@ -31,7 +31,7 @@ spec: volumeMounts: - name: config-volume mountPath: "/config" - {{- if .Values.config.ssl.enabled }} + {{- if .Values.resourceConfig.ssl.enabled }} - name: certs mountPath: "/etc/ssl/certs" {{ end }} @@ -58,7 +58,7 @@ spec: name: {{ include "botkube.fullname" . }}-configmap - secret: name: {{ include "botkube.fullname" . }}-communication-secret - {{- if .Values.config.ssl.enabled }} + {{- if .Values.resourceConfig.ssl.enabled }} - name: certs secret: secretName: {{ include "botkube.fullname" . }}-certificate-secret diff --git a/helm/botkube/templates/secret.yaml b/helm/botkube/templates/secret.yaml index 855ab6f0b..6fcb67371 100644 --- a/helm/botkube/templates/secret.yaml +++ b/helm/botkube/templates/secret.yaml @@ -1,4 +1,4 @@ -{{- if .Values.config.ssl.enabled }} +{{- if .Values.resourceConfig.ssl.enabled }} apiVersion: v1 kind: Secret @@ -10,6 +10,6 @@ metadata: app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/managed-by: {{ .Release.Service }} data: - ca-certificates.crt: {{ .Files.Get (printf "%s" .Values.config.ssl.cert) | b64enc }} + ca-certificates.crt: {{ .Files.Get (printf "%s" .Values.resourceConfig.ssl.cert) | b64enc }} {{ end }} From 3b19a1fdb0fdb5f5d98a794ea0d697d24f7a25db Mon Sep 17 00:00:00 2001 From: Sumit Lalwani Date: Mon, 16 Dec 2019 20:49:08 +0530 Subject: [PATCH 08/12] move communications to root in helm Signed-off-by: Sumit Lalwani --- .../templates/communicationsecret.yaml | 38 +++++++++- helm/botkube/templates/configmap.yaml | 2 +- helm/botkube/templates/deployment.yaml | 4 +- helm/botkube/templates/secret.yaml | 4 +- helm/botkube/values.yaml | 69 +++++++++---------- test/comm_config.yaml | 2 +- 6 files changed, 75 insertions(+), 44 deletions(-) diff --git a/helm/botkube/templates/communicationsecret.yaml b/helm/botkube/templates/communicationsecret.yaml index fc576c08e..4bdca230a 100644 --- a/helm/botkube/templates/communicationsecret.yaml +++ b/helm/botkube/templates/communicationsecret.yaml @@ -9,6 +9,38 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} stringData: comm_config.yaml: | - {{- with .Values.communicationConfig }} - {{- toYaml . | nindent 4 }} - {{- end }} + # Communication settings + communications: + # Settings for Slack + slack: + enabled: {{ .Values.communications.slack.enabled }} + channel: {{ .Values.communications.slack.channel }} # Slack channel name without '#' prefix where you have added BotKube and want to receive notifications in + token: {{ .Values.communications.slack.token }} + notiftype: {{ .Values.communications.slack.notiftype }} # 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: {{ .Values.communications.mattermost.enabled }} + url: {{ .Values.communications.mattermost.url }} # URL where Mattermost is running. e.g https://example.com:9243 + token: {{ .Values.communications.mattermost.token }} # Personal Access token generated by BotKube user + team: {{ .Values.communications.mattermost.team }} # Mattermost Team to configure with BotKube + channel: {{ .Values.communications.mattermost.channel }} # Mattermost Channel for receiving BotKube alerts + notiftype: {{ .Values.communications.mattermost.notiftype }} # 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: {{ .Values.communications.elasticsearch.enabled }} + server: {{ .Values.communications.elasticsearch.server }} # e.g https://example.com:9243 + username: {{ .Values.communications.elasticsearch.username }} + password: {{ .Values.communications.elasticsearch.password }} + # ELS index settings + index: + name: {{ .Values.communications.elasticsearch.index.name }} + type: {{ .Values.communications.elasticsearch.index.type }} + shards: {{ .Values.communications.elasticsearch.index.shards }} + replicas: {{ .Values.communications.elasticsearch.index.replicas }} + + # Settings for Webhook + webhook: + enabled: {{ .Values.communications.webhook.enabled }} + url: {{ .Values.communications.webhook.url }} # e.g https://example.com:80 diff --git a/helm/botkube/templates/configmap.yaml b/helm/botkube/templates/configmap.yaml index ddb4588d2..c95157c16 100644 --- a/helm/botkube/templates/configmap.yaml +++ b/helm/botkube/templates/configmap.yaml @@ -9,7 +9,7 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} data: resource_config.yaml: | - {{- with .Values.resourceConfig }} + {{- with .Values.config }} {{- toYaml . | nindent 4 }} {{- end }} diff --git a/helm/botkube/templates/deployment.yaml b/helm/botkube/templates/deployment.yaml index 85b1fcd8a..4e68cbbeb 100644 --- a/helm/botkube/templates/deployment.yaml +++ b/helm/botkube/templates/deployment.yaml @@ -31,7 +31,7 @@ spec: volumeMounts: - name: config-volume mountPath: "/config" - {{- if .Values.resourceConfig.ssl.enabled }} + {{- if .Values.config.ssl.enabled }} - name: certs mountPath: "/etc/ssl/certs" {{ end }} @@ -58,7 +58,7 @@ spec: name: {{ include "botkube.fullname" . }}-configmap - secret: name: {{ include "botkube.fullname" . }}-communication-secret - {{- if .Values.resourceConfig.ssl.enabled }} + {{- if .Values.config.ssl.enabled }} - name: certs secret: secretName: {{ include "botkube.fullname" . }}-certificate-secret diff --git a/helm/botkube/templates/secret.yaml b/helm/botkube/templates/secret.yaml index 6fcb67371..855ab6f0b 100644 --- a/helm/botkube/templates/secret.yaml +++ b/helm/botkube/templates/secret.yaml @@ -1,4 +1,4 @@ -{{- if .Values.resourceConfig.ssl.enabled }} +{{- if .Values.config.ssl.enabled }} apiVersion: v1 kind: Secret @@ -10,6 +10,6 @@ metadata: app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/managed-by: {{ .Release.Service }} data: - ca-certificates.crt: {{ .Files.Get (printf "%s" .Values.resourceConfig.ssl.cert) | b64enc }} + ca-certificates.crt: {{ .Files.Get (printf "%s" .Values.config.ssl.cert) | b64enc }} {{ end }} diff --git a/helm/botkube/values.yaml b/helm/botkube/values.yaml index 0ca8e4b3e..7360b6555 100644 --- a/helm/botkube/values.yaml +++ b/helm/botkube/values.yaml @@ -27,7 +27,7 @@ securityContext: # set one of the log levels- info, warn, debug, error, fatal, panic logLevel: info -resourceConfig: +config: ## Resources you want to watch resources: - name: pod # Name of the resources e.g pod, deployment, ingress, etc. (Resource name must be in singular form) @@ -213,42 +213,41 @@ resourceConfig: # Set false to disable upgrade notification upgradeNotifier: true -communicationConfig: - # 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) +# 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 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 + # 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 diff --git a/test/comm_config.yaml b/test/comm_config.yaml index 836b61de0..a0b459d04 100644 --- a/test/comm_config.yaml +++ b/test/comm_config.yaml @@ -32,4 +32,4 @@ communications: # Settings for Webhook webhook: enabled: true - url: 'WEBHOOK_URL' # e.g https://example.com:80 \ No newline at end of file + url: 'WEBHOOK_URL' # e.g https://example.com:80 From d7bc591ce4cb4fc4d28c6bd728dc5bb29658c290 Mon Sep 17 00:00:00 2001 From: Sumit Lalwani Date: Tue, 17 Dec 2019 09:18:40 +0530 Subject: [PATCH 09/12] Update communication secret Signed-off-by: Sumit Lalwani --- .../templates/communicationsecret.yaml | 36 ++----------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/helm/botkube/templates/communicationsecret.yaml b/helm/botkube/templates/communicationsecret.yaml index 4bdca230a..e7c8d02d7 100644 --- a/helm/botkube/templates/communicationsecret.yaml +++ b/helm/botkube/templates/communicationsecret.yaml @@ -11,36 +11,6 @@ stringData: comm_config.yaml: | # Communication settings communications: - # Settings for Slack - slack: - enabled: {{ .Values.communications.slack.enabled }} - channel: {{ .Values.communications.slack.channel }} # Slack channel name without '#' prefix where you have added BotKube and want to receive notifications in - token: {{ .Values.communications.slack.token }} - notiftype: {{ .Values.communications.slack.notiftype }} # 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: {{ .Values.communications.mattermost.enabled }} - url: {{ .Values.communications.mattermost.url }} # URL where Mattermost is running. e.g https://example.com:9243 - token: {{ .Values.communications.mattermost.token }} # Personal Access token generated by BotKube user - team: {{ .Values.communications.mattermost.team }} # Mattermost Team to configure with BotKube - channel: {{ .Values.communications.mattermost.channel }} # Mattermost Channel for receiving BotKube alerts - notiftype: {{ .Values.communications.mattermost.notiftype }} # 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: {{ .Values.communications.elasticsearch.enabled }} - server: {{ .Values.communications.elasticsearch.server }} # e.g https://example.com:9243 - username: {{ .Values.communications.elasticsearch.username }} - password: {{ .Values.communications.elasticsearch.password }} - # ELS index settings - index: - name: {{ .Values.communications.elasticsearch.index.name }} - type: {{ .Values.communications.elasticsearch.index.type }} - shards: {{ .Values.communications.elasticsearch.index.shards }} - replicas: {{ .Values.communications.elasticsearch.index.replicas }} - - # Settings for Webhook - webhook: - enabled: {{ .Values.communications.webhook.enabled }} - url: {{ .Values.communications.webhook.url }} # e.g https://example.com:80 + {{- with .Values.communications }} + {{- toYaml . | nindent 4 }} + {{- end }} \ No newline at end of file From d0ab324154c44e73f3ba5601f9943bd168cedfd6 Mon Sep 17 00:00:00 2001 From: Sumit Lalwani Date: Tue, 17 Dec 2019 14:44:46 +0530 Subject: [PATCH 10/12] Add new line Signed-off-by: Sumit Lalwani --- helm/botkube/templates/communicationsecret.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/botkube/templates/communicationsecret.yaml b/helm/botkube/templates/communicationsecret.yaml index e7c8d02d7..79c3ff7fb 100644 --- a/helm/botkube/templates/communicationsecret.yaml +++ b/helm/botkube/templates/communicationsecret.yaml @@ -13,4 +13,4 @@ stringData: communications: {{- with .Values.communications }} {{- toYaml . | nindent 4 }} - {{- end }} \ No newline at end of file + {{- end }} From cbc27dd23e1059a826ea58c14c1453623bf817ea Mon Sep 17 00:00:00 2001 From: Sumit Lalwani Date: Thu, 19 Dec 2019 17:08:01 +0530 Subject: [PATCH 11/12] fix indentation Signed-off-by: Sumit Lalwani --- .../templates/communicationsecret.yaml | 2 +- pkg/execute/executor.go | 25 +++---------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/helm/botkube/templates/communicationsecret.yaml b/helm/botkube/templates/communicationsecret.yaml index 79c3ff7fb..2ef5a2e13 100644 --- a/helm/botkube/templates/communicationsecret.yaml +++ b/helm/botkube/templates/communicationsecret.yaml @@ -12,5 +12,5 @@ stringData: # Communication settings communications: {{- with .Values.communications }} - {{- toYaml . | nindent 4 }} + {{- toYaml . | nindent 6 }} {{- end }} diff --git a/pkg/execute/executor.go b/pkg/execute/executor.go index 5adfe9251..a2e4660b0 100644 --- a/pkg/execute/executor.go +++ b/pkg/execute/executor.go @@ -3,9 +3,7 @@ package execute import ( "bytes" "fmt" - "io/ioutil" "os" - "path/filepath" "reflect" "strings" "text/tabwriter" @@ -15,6 +13,7 @@ import ( "github.com/infracloudio/botkube/pkg/config" filterengine "github.com/infracloudio/botkube/pkg/filterengine" + "github.com/infracloudio/botkube/pkg/logging" log "github.com/infracloudio/botkube/pkg/logging" "github.com/infracloudio/botkube/pkg/utils" ) @@ -360,32 +359,16 @@ func runVersionCommand(args []string, clusterName string) string { } func showControllerConfig() (configYaml string, err error) { - configPath := os.Getenv("CONFIG_PATH") - configFile := filepath.Join(configPath, config.ResourceConfigFileName) - file, err := os.Open(configFile) - defer file.Close() + c, err := config.New() if err != nil { - return configYaml, err - } - - b, err := ioutil.ReadAll(file) - if err != nil { - return configYaml, err - } - - c := &config.Config{} - if len(b) != 0 { - err = yaml.Unmarshal(b, c) - if err != nil { - return configYaml, err - } + logging.Logger.Fatal(fmt.Sprintf("Error in loading configuration. Error:%s", err.Error())) } // hide sensitive info c.Communications.Slack.Token = "" c.Communications.ElasticSearch.Password = "" - b, err = yaml.Marshal(c) + b, err := yaml.Marshal(c) if err != nil { return configYaml, err } From b3f7bd1db8f7aa1fc74e14bc001d137203785281 Mon Sep 17 00:00:00 2001 From: Sumit Lalwani Date: Thu, 19 Dec 2019 17:37:22 +0530 Subject: [PATCH 12/12] split config.yaml into resource and communication Signed-off-by: Sumit Lalwani --- comm_config.yaml | 35 ++++++++++++++++++++++++++++ config.yaml => resource_config.yaml | 36 ----------------------------- 2 files changed, 35 insertions(+), 36 deletions(-) create mode 100644 comm_config.yaml rename config.yaml => resource_config.yaml (71%) diff --git a/comm_config.yaml b/comm_config.yaml new file mode 100644 index 000000000..bc0a619f9 --- /dev/null +++ b/comm_config.yaml @@ -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 diff --git a/config.yaml b/resource_config.yaml similarity index 71% rename from config.yaml rename to resource_config.yaml index 16a619d32..9c56fdf6f 100644 --- a/config.yaml +++ b/resource_config.yaml @@ -179,42 +179,6 @@ resources: # about the best practices for the created resource recommendations: true -# 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 - # Setting to support multiple clusters settings: # Cluster name to differentiate incoming messages