-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from OneideLuizSchneider/feature/new-ami-rele…
…ase-10-06-24-5c1c8746e6aa9859929685b012e33404baf164c4 New AMI version for EKS - Auto-PR
- Loading branch information
Showing
48 changed files
with
1,673 additions
and
300 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
amazon-eks-ami/nodeadm/example/node.eks.aws_v1alpha1_nodeconfig.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
amazon-eks-ami/nodeadm/internal/configprovider/encoding.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.