-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: AL2023 AMI family support (#5604)
Co-authored-by: Jonathan Innis <[email protected]>
- Loading branch information
1 parent
1a8359c
commit eb53e9b
Showing
34 changed files
with
1,137 additions
and
11 deletions.
There are no files selected for viewing
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
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
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
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,79 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package amifamily | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/samber/lo" | ||
v1 "k8s.io/api/core/v1" | ||
corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1" | ||
"sigs.k8s.io/karpenter/pkg/cloudprovider" | ||
"sigs.k8s.io/karpenter/pkg/scheduling" | ||
|
||
"github.com/aws/karpenter-provider-aws/pkg/apis/v1beta1" | ||
"github.com/aws/karpenter-provider-aws/pkg/providers/amifamily/bootstrap" | ||
) | ||
|
||
type AL2023 struct { | ||
DefaultFamily | ||
*Options | ||
} | ||
|
||
func (a AL2023) DefaultAMIs(version string) []DefaultAMIOutput { | ||
return []DefaultAMIOutput{ | ||
{ | ||
Query: fmt.Sprintf("/aws/service/eks/optimized-ami/%s/amazon-linux-2023/x86_64/standard/recommended/image_id", version), | ||
Requirements: scheduling.NewRequirements( | ||
scheduling.NewRequirement(v1.LabelArchStable, v1.NodeSelectorOpIn, corev1beta1.ArchitectureAmd64), | ||
), | ||
}, | ||
{ | ||
Query: fmt.Sprintf("/aws/service/eks/optimized-ami/%s/amazon-linux-2023/arm64/standard/recommended/image_id", version), | ||
Requirements: scheduling.NewRequirements( | ||
scheduling.NewRequirement(v1.LabelArchStable, v1.NodeSelectorOpIn, corev1beta1.ArchitectureArm64), | ||
), | ||
}, | ||
} | ||
} | ||
|
||
func (a AL2023) UserData(kubeletConfig *corev1beta1.KubeletConfiguration, taints []v1.Taint, labels map[string]string, caBundle *string, _ []*cloudprovider.InstanceType, customUserData *string, instanceStorePolicy *v1beta1.InstanceStorePolicy) bootstrap.Bootstrapper { | ||
return bootstrap.Nodeadm{ | ||
Options: bootstrap.Options{ | ||
ClusterName: a.Options.ClusterName, | ||
ClusterEndpoint: a.Options.ClusterEndpoint, | ||
ClusterCIDR: a.Options.ClusterCIDR, | ||
KubeletConfig: kubeletConfig, | ||
Taints: taints, | ||
Labels: labels, | ||
CABundle: caBundle, | ||
AWSENILimitedPodDensity: false, | ||
CustomUserData: customUserData, | ||
InstanceStorePolicy: instanceStorePolicy, | ||
}, | ||
} | ||
} | ||
|
||
// DefaultBlockDeviceMappings returns the default block device mappings for the AMI Family | ||
func (a AL2023) DefaultBlockDeviceMappings() []*v1beta1.BlockDeviceMapping { | ||
return []*v1beta1.BlockDeviceMapping{{ | ||
DeviceName: a.EphemeralBlockDevice(), | ||
EBS: &DefaultEBS, | ||
}} | ||
} | ||
|
||
func (a AL2023) EphemeralBlockDevice() *string { | ||
return lo.ToPtr("/dev/xvda") | ||
} |
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,121 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package mime | ||
|
||
import ( | ||
"bytes" | ||
"encoding/base64" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"mime" | ||
"mime/multipart" | ||
"net/mail" | ||
"net/textproto" | ||
"strings" | ||
|
||
admapi "github.com/awslabs/amazon-eks-ami/nodeadm/api" | ||
) | ||
|
||
type ContentType string | ||
|
||
const ( | ||
boundary = "//" | ||
versionHeader = "MIME-Version: 1.0" | ||
|
||
ContentTypeShellScript ContentType = `text/x-shellscript; charset="us-ascii"` | ||
ContentTypeNodeConfig ContentType = "application/" + admapi.GroupName | ||
ContentTypeMultipart ContentType = `multipart/mixed; boundary="` + boundary + `"` | ||
) | ||
|
||
type Entry struct { | ||
ContentType ContentType | ||
Content string | ||
} | ||
|
||
type Archive []Entry | ||
|
||
func NewArchive(content string) (Archive, error) { | ||
archive := Archive{} | ||
if content == "" { | ||
return archive, nil | ||
} | ||
reader, err := archive.getReader(content) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for { | ||
p, err := reader.NextPart() | ||
if err != nil { | ||
if errors.Is(err, io.EOF) { | ||
break | ||
} | ||
return nil, fmt.Errorf("parsing content, %w", err) | ||
} | ||
slurp, err := io.ReadAll(p) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing content, %s, %w", string(slurp), err) | ||
} | ||
archive = append(archive, Entry{ | ||
ContentType: ContentType(p.Header.Get("Content-Type")), | ||
Content: string(slurp), | ||
}) | ||
} | ||
return archive, nil | ||
} | ||
|
||
// Serialize returns a base64 encoded serialized MIME multi-part archive | ||
func (ma Archive) Serialize() (string, error) { | ||
buffer := bytes.Buffer{} | ||
writer := multipart.NewWriter(&buffer) | ||
if err := writer.SetBoundary(boundary); err != nil { | ||
return "", err | ||
} | ||
buffer.WriteString(versionHeader + "\n") | ||
buffer.WriteString(fmt.Sprintf("Content-Type: %s\n\n", ContentTypeMultipart)) | ||
for _, entry := range ma { | ||
partWriter, err := writer.CreatePart(textproto.MIMEHeader{ | ||
"Content-Type": []string{string(entry.ContentType)}, | ||
}) | ||
if err != nil { | ||
return "", fmt.Errorf("creating multi-part section for entry, %w", err) | ||
} | ||
_, err = partWriter.Write([]byte(entry.Content)) | ||
if err != nil { | ||
return "", fmt.Errorf("writing entry, %w", err) | ||
} | ||
} | ||
if err := writer.Close(); err != nil { | ||
return "", fmt.Errorf("terminating multi-part archive, %w", err) | ||
} | ||
// The mime/multipart package adds carriage returns, while the rest of our logic does not. Remove all | ||
// carriage returns for consistency. | ||
return base64.StdEncoding.EncodeToString([]byte(strings.ReplaceAll(buffer.String(), "\r", ""))), nil | ||
} | ||
|
||
func (Archive) getReader(content string) (*multipart.Reader, error) { | ||
mailMsg, err := mail.ReadMessage(strings.NewReader(content)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
mediaType, params, err := mime.ParseMediaType(mailMsg.Header.Get("Content-Type")) | ||
if err != nil { | ||
return nil, fmt.Errorf("archive doesn't have Content-Type header, %w", err) | ||
} | ||
if !strings.HasPrefix(mediaType, "multipart/") { | ||
return nil, fmt.Errorf("archive is not in multipart format, %w", err) | ||
} | ||
return multipart.NewReader(mailMsg.Body, params["boundary"]), nil | ||
} |
Oops, something went wrong.