aws / aws-node-termination-handler

Gracefully handle EC2 instance shutdown within Kubernetes
https://aws.amazon.com/ec2
Apache License 2.0
1.63k stars 268 forks source link

Improve InterruptionEvent with more details #183

Closed mmiranda closed 4 years ago

mmiranda commented 4 years ago

When an InterruptionEvent occurs (used to post on webhook), it would be nice to have information such as:

This way we can adapt the WEBHOOK_TEMPLATE to also send that information.

bwagner5 commented 4 years ago

Hi @mmiranda The following are the structs that are available to use in the webhook template:

type NodeMetadata struct {
    InstanceID     string
    InstanceType   string
    PublicHostname string
    PublicIP       string
    LocalHostname  string
    LocalIP        string
}
type InterruptionEvent struct {
    EventID      string
    Kind         string
    Description  string
    State        string
    StartTime    time.Time
    EndTime      time.Time
    Drained      bool
}

The data is merged into a convenient struct on the webhook for template usage:

type combinedDrainData struct {
    ec2metadata.NodeMetadata
    interruptionevent.InterruptionEvent
}

Currently, instance-id and instance-type are available to be included in the webhook template. LocalHostname is pretty close to node name, so that may work for you. Here's an example of specifying the webhook template w/ CLI args: https://github.com/aws/aws-node-termination-handler/blob/87fe242d4aef3c742826f952e61b121216570416/test/e2e/webhook-test#L30

We don't have AZ, but that could be easily added.

Would just need to update the following to capture AZ data:

  1. https://github.com/aws/aws-node-termination-handler/blob/master/pkg/ec2metadata/ec2metadata.go#L93
  2. https://github.com/aws/aws-node-termination-handler/blob/master/pkg/ec2metadata/ec2metadata.go#L273
DP19 commented 4 years ago

I'd like to take stab at this!

bwagner5 commented 4 years ago

@DP19 Go for it! 🚀

Also, since this issue was opened, documentation was added about which metadata paths NTH uses for kiam configurations. If you add additional paths, don't forget to update the readme:

https://github.com/aws/aws-node-termination-handler#use-with-kiam https://github.com/aws/aws-node-termination-handler#metadata-endpoints

DP19 commented 4 years ago

@bwagner5 Thanks! PR #210 adds this info

bwagner5 commented 4 years ago

released! https://github.com/aws/aws-node-termination-handler/releases/tag/v1.7.0