Skip to content

Commit

Permalink
Merge pull request #130 from OneideLuizSchneider/feature/new-ami-rele…
Browse files Browse the repository at this point in the history
…ase-10-06-24-5c1c8746e6aa9859929685b012e33404baf164c4

New AMI version for EKS - Auto-PR
  • Loading branch information
OneideLuizSchneider authored Oct 6, 2024
2 parents 5c1c874 + bd71fc3 commit d36e9ec
Show file tree
Hide file tree
Showing 48 changed files with 1,673 additions and 300 deletions.
1,164 changes: 1,164 additions & 0 deletions amazon-eks-ami/CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amazon-eks-ami/nodeadm/doc/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
certificateAuthority: Y2VydGlmaWNhdGVBdXRob3JpdHk=
cidr: 10.100.0.0/16
--BOUNDARY--
--BOUNDARY
Content-Type: application/node.eks.aws
---
Expand Down

This file was deleted.

14 changes: 7 additions & 7 deletions amazon-eks-ami/nodeadm/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module github.com/awslabs/amazon-eks-ami/nodeadm
go 1.22.5

require (
github.com/aws/aws-sdk-go-v2/config v1.27.36
github.com/aws/aws-sdk-go-v2/config v1.27.39
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.14
github.com/aws/aws-sdk-go-v2/service/ec2 v1.178.0
github.com/aws/aws-sdk-go-v2/service/ecr v1.35.0
github.com/aws/aws-sdk-go-v2/service/ec2 v1.179.2
github.com/aws/aws-sdk-go-v2/service/ecr v1.35.3
github.com/aws/smithy-go v1.21.0
github.com/containerd/containerd v1.7.22
github.com/coreos/go-systemd/v22 v22.5.0
Expand Down Expand Up @@ -37,15 +37,15 @@ require dario.cat/mergo v1.0.1 // direct

require (
github.com/aws/aws-sdk-go-v2 v1.31.0
github.com/aws/aws-sdk-go-v2/credentials v1.17.34 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.37 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.5 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.20 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.23.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.27.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.31.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.23.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.27.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.31.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand Down
28 changes: 14 additions & 14 deletions amazon-eks-ami/nodeadm/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/aws/aws-sdk-go-v2 v1.31.0 h1:3V05LbxTSItI5kUqNwhJrrrY1BAXxXt0sN0l72QmG5U=
github.com/aws/aws-sdk-go-v2 v1.31.0/go.mod h1:ztolYtaEUtdpf9Wftr31CJfLVjOnD/CVRkKOOYgF8hA=
github.com/aws/aws-sdk-go-v2/config v1.27.36 h1:4IlvHh6Olc7+61O1ktesh0jOcqmq/4WG6C2Aj5SKXy0=
github.com/aws/aws-sdk-go-v2/config v1.27.36/go.mod h1:IiBpC0HPAGq9Le0Xxb1wpAKzEfAQ3XlYgJLYKEVYcfw=
github.com/aws/aws-sdk-go-v2/credentials v1.17.34 h1:gmkk1l/cDGSowPRzkdxYi8edw+gN4HmVK151D/pqGNc=
github.com/aws/aws-sdk-go-v2/credentials v1.17.34/go.mod h1:4R9OEV3tgFMsok4ZeFpExn7zQaZRa9MRGFYnI/xC/vs=
github.com/aws/aws-sdk-go-v2/config v1.27.39 h1:FCylu78eTGzW1ynHcongXK9YHtoXD5AiiUqq3YfJYjU=
github.com/aws/aws-sdk-go-v2/config v1.27.39/go.mod h1:wczj2hbyskP4LjMKBEZwPRO1shXY+GsQleab+ZXT2ik=
github.com/aws/aws-sdk-go-v2/credentials v1.17.37 h1:G2aOH01yW8X373JK419THj5QVqu9vKEwxSEsGxihoW0=
github.com/aws/aws-sdk-go-v2/credentials v1.17.37/go.mod h1:0ecCjlb7htYCptRD45lXJ6aJDQac6D2NlKGpZqyTG6A=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.14 h1:C/d03NAmh8C4BZXhuRNboF/DqhBkBCeDiJDcaqIT5pA=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.14/go.mod h1:7I0Ju7p9mCIdlrfS+JCgqcYD0VXz/N4yozsox+0o078=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18 h1:kYQ3H1u0ANr9KEKlGs/jTLrBFPo8P8NaH/w7A01NeeM=
Expand All @@ -16,20 +16,20 @@ github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18 h1:Z7IdFUONvTcvS7Yuht
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18/go.mod h1:DkKMmksZVVyat+Y+r1dEOgJEfUeA7UngIHWeKsi0yNc=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.178.0 h1:yCVmlqH1bWVmdS/oFyyM+hbe2c+tKGPo6r0BHhTpn1U=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.178.0/go.mod h1:W6sNzs5T4VpZn1Vy+FMKw8s24vt5k6zPJXcNOK0asBo=
github.com/aws/aws-sdk-go-v2/service/ecr v1.35.0 h1:92Ck3zrJpZB6kae8ixF2zKkAFtURWg+KfLE1UiB9QHc=
github.com/aws/aws-sdk-go-v2/service/ecr v1.35.0/go.mod h1:oRaGEExKI6Pqcow+Tt7wpJf73/Srcj/CUJv5Eb9QFhg=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.179.2 h1:rGBv2N0zWvNTKnxOfbBH4mNM8WMdDNkaxdqtz152G40=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.179.2/go.mod h1:W6sNzs5T4VpZn1Vy+FMKw8s24vt5k6zPJXcNOK0asBo=
github.com/aws/aws-sdk-go-v2/service/ecr v1.35.3 h1:8/vARxqd0Pn2Gqhp+8PxxTm3HttUMR1i1vBBj7MNFfc=
github.com/aws/aws-sdk-go-v2/service/ecr v1.35.3/go.mod h1:oRaGEExKI6Pqcow+Tt7wpJf73/Srcj/CUJv5Eb9QFhg=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.5 h1:QFASJGfT8wMXtuP3D5CRmMjARHv9ZmzFUMJznHDOY3w=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.5/go.mod h1:QdZ3OmoIjSX+8D1OPAzPxDfjXASbBMDsz9qvtyIhtik=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.20 h1:Xbwbmk44URTiHNx6PNo0ujDE6ERlsCKJD3u1zfnzAPg=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.20/go.mod h1:oAfOFzUB14ltPZj1rWwRc3d/6OgD76R8KlvU3EqM9Fg=
github.com/aws/aws-sdk-go-v2/service/sso v1.23.0 h1:fHySkG0IGj2nepgGJPmmhZYL9ndnsq1Tvc6MeuVQCaQ=
github.com/aws/aws-sdk-go-v2/service/sso v1.23.0/go.mod h1:XRlMvmad0ZNL+75C5FYdMvbbLkd6qiqz6foR1nA1PXY=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.27.0 h1:cU/OeQPNReyMj1JEBgjE29aclYZYtXcsPMXbTkVGMFk=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.27.0/go.mod h1:FnvDM4sfa+isJ3kDXIzAB9GAwVSzFzSy97uZ3IsHo4E=
github.com/aws/aws-sdk-go-v2/service/sts v1.31.0 h1:GNVxIHBTi2EgwCxpNiozhNasMOK+ROUA2Z3X+cSBX58=
github.com/aws/aws-sdk-go-v2/service/sts v1.31.0/go.mod h1:yMWe0F+XG0DkRZK5ODZhG7BEFYhLXi2dqGsv6tX0cgI=
github.com/aws/aws-sdk-go-v2/service/sso v1.23.3 h1:rs4JCczF805+FDv2tRhZ1NU0RB2H6ryAvsWPanAr72Y=
github.com/aws/aws-sdk-go-v2/service/sso v1.23.3/go.mod h1:XRlMvmad0ZNL+75C5FYdMvbbLkd6qiqz6foR1nA1PXY=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.27.3 h1:S7EPdMVZod8BGKQQPTBK+FcX9g7bKR7c4+HxWqHP7Vg=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.27.3/go.mod h1:FnvDM4sfa+isJ3kDXIzAB9GAwVSzFzSy97uZ3IsHo4E=
github.com/aws/aws-sdk-go-v2/service/sts v1.31.3 h1:VzudTFrDCIDakXtemR7l6Qzt2+JYsVqo2MxBPt5k8T8=
github.com/aws/aws-sdk-go-v2/service/sts v1.31.3/go.mod h1:yMWe0F+XG0DkRZK5ODZhG7BEFYhLXi2dqGsv6tX0cgI=
github.com/aws/smithy-go v1.21.0 h1:H7L8dtDRk0P1Qm6y0ji7MCYMQObJ5R9CRpyPhRUkLYA=
github.com/aws/smithy-go v1.21.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down
6 changes: 6 additions & 0 deletions amazon-eks-ami/nodeadm/internal/api/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ func TestMerge(t *testing.T) {
"verbosity": 5,
},
"podsPerCore": 20,
"systemReserved": map[string]interface{}{
"cpu": "150m",
},
}),
Flags: []string{
"--node-labels=nodegroup=example",
Expand Down Expand Up @@ -167,6 +170,9 @@ discard_unpacked_layers = false`),
},
"maxPods": 150,
"podsPerCore": 20,
"systemReserved": map[string]interface{}{
"cpu": "150m",
},
}),
Flags: []string{
"--node-labels=nodegroup=example",
Expand Down
42 changes: 42 additions & 0 deletions amazon-eks-ami/nodeadm/internal/configprovider/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package configprovider

import (
"bytes"
"compress/gzip"
"encoding/base64"
"fmt"
"io"
)

func decodeIfBase64(data []byte) ([]byte, error) {
e := base64.StdEncoding
maxDecodedLen := e.DecodedLen(len(data))
decodedData := make([]byte, maxDecodedLen)
decodedLen, err := e.Decode(decodedData, data)
if err != nil {
return data, nil
}
return decodedData[:decodedLen], nil
}

// https://en.wikipedia.org/wiki/Gzip
const gzipMagicNumber = uint16(0x1f8b)

func decompressIfGZIP(data []byte) ([]byte, error) {
if len(data) < 2 {
return data, nil
}
preamble := uint16(data[0])<<8 | uint16(data[1])
if preamble == gzipMagicNumber {
reader, err := gzip.NewReader(bytes.NewReader(data))
if err != nil {
return nil, fmt.Errorf("failed to create GZIP reader: %v", err)
}
if decompressed, err := io.ReadAll(reader); err != nil {
return nil, fmt.Errorf("failed to read from GZIP reader: %v", err)
} else {
return decompressed, nil
}
}
return data, nil
}
7 changes: 1 addition & 6 deletions amazon-eks-ami/nodeadm/internal/configprovider/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"

internalapi "github.com/awslabs/amazon-eks-ami/nodeadm/internal/api"
apibridge "github.com/awslabs/amazon-eks-ami/nodeadm/internal/api/bridge"
)

type fileConfigProvider struct {
Expand Down Expand Up @@ -36,9 +35,5 @@ func (fcs *fileConfigProvider) Provide() (*internalapi.NodeConfig, error) {
if err != nil {
return nil, err
}
config, err := apibridge.DecodeNodeConfig(data)
if err != nil {
return nil, err
}
return config, nil
return parseMaybeMultipart(data)
}
96 changes: 96 additions & 0 deletions amazon-eks-ami/nodeadm/internal/configprovider/mime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package configprovider

import (
"bytes"
"fmt"
"io"
"mime"
"mime/multipart"
"net/mail"
"strings"

internalapi "github.com/awslabs/amazon-eks-ami/nodeadm/internal/api"
apibridge "github.com/awslabs/amazon-eks-ami/nodeadm/internal/api/bridge"
)

func parseMaybeMultipart(data []byte) (*internalapi.NodeConfig, error) {
// if the MIME data fails to parse as a multipart document, then fall back
// to parsing the entire userdata as the node config.
if multipartReader, err := getMultipartReader(data); err == nil {
config, err := parseMultipart(multipartReader)
if err != nil {
return nil, err
}
return config, nil
} else {
config, err := apibridge.DecodeNodeConfig(data)
if err != nil {
return nil, err
}
return config, nil
}
}

func parseMultipart(userDataReader *multipart.Reader) (*internalapi.NodeConfig, error) {
var nodeConfigs []*internalapi.NodeConfig
for {
part, err := userDataReader.NextPart()
if err == io.EOF {
break
}
if err != nil {
return nil, err
}
if partHeader := part.Header.Get(contentTypeHeader); len(partHeader) > 0 {
mediaType, _, err := mime.ParseMediaType(partHeader)
if err != nil {
return nil, err
}
if mediaType == nodeConfigMediaType {
nodeConfigPart, err := io.ReadAll(part)
if err != nil {
return nil, err
}
nodeConfigPart, err = decodeIfBase64(nodeConfigPart)
if err != nil {
return nil, err
}
nodeConfigPart, err = decompressIfGZIP(nodeConfigPart)
if err != nil {
return nil, err
}
decodedConfig, err := apibridge.DecodeNodeConfig(nodeConfigPart)
if err != nil {
return nil, err
}
nodeConfigs = append(nodeConfigs, decodedConfig)
}
}
}
if len(nodeConfigs) > 0 {
var config = nodeConfigs[0]
for _, nodeConfig := range nodeConfigs[1:] {
if err := config.Merge(nodeConfig); err != nil {
return nil, err
}
}
return config, nil
} else {
return nil, fmt.Errorf("could not find NodeConfig within UserData")
}
}

func getMultipartReader(data []byte) (*multipart.Reader, error) {
msg, err := mail.ReadMessage(bytes.NewReader(data))
if err != nil {
return nil, err
}
mediaType, params, err := mime.ParseMediaType(msg.Header.Get(contentTypeHeader))
if err != nil {
return nil, err
}
if !strings.HasPrefix(mediaType, multipartContentTypePrefix) {
return nil, fmt.Errorf("MIME type is not multipart")
}
return multipart.NewReader(msg.Body, params[mimeBoundaryParam]), nil
}
Loading

0 comments on commit d36e9ec

Please sign in to comment.