-
Notifications
You must be signed in to change notification settings - Fork 983
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BlockDeviceMappings to the AWS cloudprovider (#1420)
* Add support for specifying blockDeviceMappings in the provisioner * cleanup * a few fixes * rename pkg ltresolver to amifamily * naming changes
- Loading branch information
Showing
27 changed files
with
1,200 additions
and
503 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
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/aws/aws-sdk-go/aws" | ||
core "k8s.io/api/core/v1" | ||
|
||
"github.com/aws/karpenter/pkg/apis/provisioning/v1alpha5" | ||
"github.com/aws/karpenter/pkg/cloudprovider" | ||
"github.com/aws/karpenter/pkg/cloudprovider/aws/amifamily/bootstrap" | ||
"github.com/aws/karpenter/pkg/cloudprovider/aws/apis/v1alpha1" | ||
) | ||
|
||
type AL2 struct { | ||
*Options | ||
} | ||
|
||
// SSMAlias returns the AMI Alias to query SSM | ||
func (a AL2) SSMAlias(version string, instanceType cloudprovider.InstanceType) string { | ||
amiSuffix := "" | ||
if !instanceType.NvidiaGPUs().IsZero() || !instanceType.AWSNeurons().IsZero() { | ||
amiSuffix = "-gpu" | ||
} else if instanceType.Architecture() == v1alpha5.ArchitectureArm64 { | ||
amiSuffix = fmt.Sprintf("-%s", instanceType.Architecture()) | ||
} | ||
return fmt.Sprintf("/aws/service/eks/optimized-ami/%s/amazon-linux-2%s/recommended/image_id", version, amiSuffix) | ||
} | ||
|
||
// UserData returns the exact same string for equivalent input, | ||
// even if elements of those inputs are in differing orders, | ||
// guaranteeing it won't cause spurious hash differences. | ||
// AL2 userdata also works on Ubuntu | ||
func (a AL2) UserData(kubeletConfig v1alpha5.KubeletConfiguration, taints []core.Taint, labels map[string]string, caBundle *string) bootstrap.Bootstrapper { | ||
return bootstrap.EKS{ | ||
Options: bootstrap.Options{ | ||
ClusterName: a.Options.ClusterName, | ||
ClusterEndpoint: a.Options.ClusterEndpoint, | ||
AWSENILimitedPodDensity: a.Options.AWSENILimitedPodDensity, | ||
KubeletConfig: kubeletConfig, | ||
Taints: taints, | ||
Labels: labels, | ||
CABundle: caBundle, | ||
}, | ||
} | ||
} | ||
|
||
// DefaultBlockDeviceMappings returns the default block device mappings for the AMI Family | ||
func (a AL2) DefaultBlockDeviceMappings() []*v1alpha1.BlockDeviceMapping { | ||
return []*v1alpha1.BlockDeviceMapping{{ | ||
DeviceName: aws.String("/dev/xvda"), | ||
EBS: &defaultEBS, | ||
}} | ||
} |
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,48 @@ | ||
/* | ||
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 ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ssm" | ||
"github.com/aws/aws-sdk-go/service/ssm/ssmiface" | ||
"github.com/patrickmn/go-cache" | ||
"knative.dev/pkg/logging" | ||
|
||
"github.com/aws/karpenter/pkg/cloudprovider" | ||
) | ||
|
||
type AMIProvider struct { | ||
cache *cache.Cache | ||
ssm ssmiface.SSMAPI | ||
} | ||
|
||
// Get returns a set of AMIIDs and corresponding instance types. AMI may vary due to architecture, accelerator, etc | ||
func (p *AMIProvider) Get(ctx context.Context, instanceType cloudprovider.InstanceType, ssmQuery string) (string, error) { | ||
if id, ok := p.cache.Get(ssmQuery); ok { | ||
return id.(string), nil | ||
} | ||
output, err := p.ssm.GetParameterWithContext(ctx, &ssm.GetParameterInput{Name: aws.String(ssmQuery)}) | ||
if err != nil { | ||
return "", fmt.Errorf("getting ssm parameter, %w", err) | ||
} | ||
ami := aws.StringValue(output.Parameter.Value) | ||
p.cache.SetDefault(ssmQuery, ami) | ||
logging.FromContext(ctx).Debugf("Discovered %s for query %s", ami, ssmQuery) | ||
return ami, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
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 bootstrap | ||
|
||
import ( | ||
core "k8s.io/api/core/v1" | ||
|
||
"github.com/aws/karpenter/pkg/apis/provisioning/v1alpha5" | ||
) | ||
|
||
// Options is the node bootstrapping parameters passed from Karpenter to the provisioning node | ||
type Options struct { | ||
ClusterName string | ||
ClusterEndpoint string | ||
KubeletConfig v1alpha5.KubeletConfiguration | ||
Taints []core.Taint `hash:"set"` | ||
Labels map[string]string `hash:"set"` | ||
CABundle *string | ||
AWSENILimitedPodDensity bool | ||
} | ||
|
||
// Bootstrapper can be implemented to generate a bootstrap script | ||
// that uses the params from the Bootstrap type for a specific | ||
// bootstrapping method. | ||
// Examples are the Bottlerocket config and the eks-bootstrap script | ||
type Bootstrapper interface { | ||
Script() string | ||
} |
Oops, something went wrong.