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

Allow users to configure webhook message content with a template file #253

Merged
merged 5 commits into from
Sep 17, 2020

Conversation

supasteev0
Copy link
Contributor

Description of changes:

When the destination of the webhook requires a more complex message content, it can be easier to provide a json template file which will be mounted into the pod, rather than having the webhook message content set in an inline variable.

This will allow users to set a WEBHOOK_TEMPLATE_FILE environment variable (--webhook-template-file argument) to set the template file path which will be used to send the webhook message. This takes precedence over the --webhook-template argument.

Template file will have to exist (be mounted into the pod as volume by users) otherwise it will throw an error.

Example:

---
apiVersion: v1
data:
  webhook-alert-template.json: |-
    {
      "status": "firing",
      "alerts": [
          {
            "status": "firing",
            "labels": {
              "alertname": "myalert",
              "region": "eu-west-1",
              "severity": "high"
            }
          }
       ]
    }
kind: ConfigMap
metadata:
  name: webhook-template
  namespace: monitoring
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  labels:
    app: aws-node-termination-handler
  name: aws-node-termination-handler
  namespace: monitoring
spec:
  selector:
    matchLabels:
      app: aws-node-termination-handler
  template:
    metadata:
      labels:
        app: aws-node-termination-handler
    spec:
      containers:
      - env:
        ...
        - name: WEBHOOK_TEMPLATE_FILE
          value: /config/webhook-alert-template.json
        ...
        volumeMounts:
        - mountPath: /config/
          name: template
      volumes:
      - configMap:
          name: webhook-template
        name: template

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

codecov-commenter commented Sep 14, 2020

Codecov Report

Merging #253 into master will decrease coverage by 1.03%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #253      +/-   ##
==========================================
- Coverage   81.60%   80.56%   -1.04%     
==========================================
  Files          10       10              
  Lines         799      818      +19     
==========================================
+ Hits          652      659       +7     
- Misses        131      141      +10     
- Partials       16       18       +2     
Impacted Files Coverage Δ
pkg/webhook/webhook.go 77.46% <48.00%> (-14.99%) ⬇️
pkg/config/config.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae0676e...dcc6e60. Read the comment docs.

@bwagner5 bwagner5 added the Type: Enhancement New feature or request label Sep 14, 2020
Copy link
Contributor

@bwagner5 bwagner5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than making the user mount the file, can you instead use a ConfigMap similar to the way the webhookURLSecretName works.

@bwagner5 bwagner5 self-assigned this Sep 14, 2020
@supasteev0
Copy link
Contributor Author

@bwagner5 I have update the Helm chart by adding 2 new variables in order to set the configmap name and the template file name that will be mounted into the pod.

Copy link
Contributor

@bwagner5 bwagner5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! I missed one thing during my first pass review.

Can you update the ValidateWebhookConfig() function as well? The validate function is called on startup so you know if your template is invalid upfront rather than waiting for a termination event for the error to be thrown.

https://github.com/aws/aws-node-termination-handler/blob/master/pkg/webhook/webhook.go#L103

pkg/webhook/webhook.go Outdated Show resolved Hide resolved
…emplate content message as debug + typo nthConfig
@supasteev0
Copy link
Contributor Author

I updated the ValidateWebhookConfig function as requested. I also fixed a typo on the nthConfig variable which was written in 2 different ways. Looks like the travis test has failed because of an issue with ec2Mock not responding, but I don't know how to re trigger the job.

Copy link
Contributor

@bwagner5 bwagner5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀 thanks for the contribution!

@bwagner5 bwagner5 merged commit dad7670 into aws:master Sep 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants