forked from aws/karpenter-provider-aws
-
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.
Fixes aws#1131 This change try to integrate with the latest EKS window support. Add two new Windows AMI Family, Windows2019 and Windows2022. Only Core are supported OOTB. Windows relevant code, "kubernetes.io/os" and "vpc.amazonaws.com/PrivateIPv4Address" is only active when Windows AMI Family defined in the AwsNodeTemplate Users can use amiSelector to choose other AMIs. Test on a Linux and Windows mixed system for provision and de-provision. Test on a live system with mixed Windows and Linux workload. Both provision and de-provision are tested
- Loading branch information
1 parent
adce368
commit 3b3fd5e
Showing
6 changed files
with
257 additions
and
17 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
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 bootstrap | ||
|
||
import ( | ||
"bytes" | ||
"encoding/base64" | ||
"fmt" | ||
"sort" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/aws/karpenter-core/pkg/apis/v1alpha5" | ||
|
||
"github.com/samber/lo" | ||
) | ||
|
||
type Windows struct { | ||
Options | ||
} | ||
|
||
// nolint:gocyclo | ||
func (w Windows) Script() (string, error) { | ||
var userData bytes.Buffer | ||
userData.WriteString("<powershell>\n") | ||
userData.WriteString("[string]$EKSBootstrapScriptFile = \"$env:ProgramFiles\\Amazon\\EKS\\Start-EKSBootstrap.ps1\"\n") | ||
userData.WriteString(fmt.Sprintf(`& $EKSBootstrapScriptFile -EKSClusterName "%s" -APIServerEndpoint "%s"`, w.ClusterName, w.ClusterEndpoint)) | ||
if w.CABundle != nil { | ||
userData.WriteString(fmt.Sprintf(" -Base64ClusterCA \"%s\"", *w.CABundle)) | ||
} | ||
kubeletExtraArgs := strings.Join([]string{w.nodeLabelArg(), w.nodeTaintArg()}, " ") | ||
if kubeletExtraArgs = strings.Trim(kubeletExtraArgs, " "); len(kubeletExtraArgs) > 0 { | ||
userData.WriteString(fmt.Sprintf(` -KubeletExtraArgs "%s"`, kubeletExtraArgs)) | ||
} | ||
if w.KubeletConfig != nil && len(w.KubeletConfig.ClusterDNS) > 0 { | ||
userData.WriteString(fmt.Sprintf(` -DNSClusterIP "%s"`, w.KubeletConfig.ClusterDNS[0])) | ||
} | ||
userData.WriteString("\n</powershell>") | ||
return base64.StdEncoding.EncodeToString(userData.Bytes()), nil | ||
} | ||
|
||
func (w Windows) nodeTaintArg() string { | ||
nodeTaintsArg := "" | ||
var taintStrings []string | ||
var once sync.Once | ||
for _, taint := range w.Taints { | ||
once.Do(func() { nodeTaintsArg = "--register-with-taints=" }) | ||
taintStrings = append(taintStrings, fmt.Sprintf("%s=%s:%s", taint.Key, taint.Value, taint.Effect)) | ||
} | ||
return fmt.Sprintf("%s%s", nodeTaintsArg, strings.Join(taintStrings, ",")) | ||
} | ||
|
||
func (w Windows) nodeLabelArg() string { | ||
nodeLabelArg := "" | ||
var labelStrings []string | ||
var once sync.Once | ||
keys := lo.Keys(w.Labels) | ||
sort.Strings(keys) // ensures this list is deterministic, for easy testing. | ||
for _, key := range keys { | ||
if v1alpha5.LabelDomainExceptions.Has(key) { | ||
continue | ||
} | ||
once.Do(func() { nodeLabelArg = "--node-labels=" }) | ||
labelStrings = append(labelStrings, fmt.Sprintf("%s=%v", key, w.Labels[key])) | ||
} | ||
return fmt.Sprintf("%s%s", nodeLabelArg, strings.Join(labelStrings, ",")) | ||
} |
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,85 @@ | ||
/* | ||
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/karpenter-core/pkg/scheduling" | ||
|
||
"github.com/samber/lo" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
|
||
"github.com/aws/karpenter/pkg/providers/amifamily/bootstrap" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
|
||
"github.com/aws/karpenter-core/pkg/apis/v1alpha5" | ||
"github.com/aws/karpenter-core/pkg/cloudprovider" | ||
|
||
"github.com/aws/karpenter/pkg/apis/v1alpha1" | ||
) | ||
|
||
type Windows struct { | ||
DefaultFamily | ||
*Options | ||
Version string | ||
Build string | ||
Variant string | ||
} | ||
|
||
func (w Windows) DefaultAMIs(version string) []DefaultAMIOutput { | ||
return []DefaultAMIOutput{ | ||
{ | ||
Query: fmt.Sprintf("/aws/service/ami-windows-latest/Windows_Server-%s-English-%s-EKS_Optimized-%s/image_id", w.Version, w.Variant, version), | ||
Requirements: scheduling.NewRequirements( | ||
scheduling.NewRequirement(v1.LabelArchStable, v1.NodeSelectorOpIn, v1alpha5.ArchitectureAmd64), | ||
scheduling.NewRequirement(v1.LabelOSStable, v1.NodeSelectorOpIn, string(v1.Windows)), | ||
scheduling.NewRequirement(v1.LabelWindowsBuild, v1.NodeSelectorOpIn, w.Build), | ||
), | ||
}, | ||
} | ||
} | ||
|
||
// UserData returns the default userdata script for the AMI Family | ||
func (w Windows) UserData(kubeletConfig *v1alpha5.KubeletConfiguration, taints []v1.Taint, labels map[string]string, caBundle *string, _ []*cloudprovider.InstanceType, customUserData *string) bootstrap.Bootstrapper { | ||
return bootstrap.Windows{ | ||
Options: bootstrap.Options{ | ||
ClusterName: w.Options.ClusterName, | ||
ClusterEndpoint: w.Options.ClusterEndpoint, | ||
KubeletConfig: kubeletConfig, | ||
Taints: taints, | ||
Labels: labels, | ||
CABundle: caBundle, | ||
CustomUserData: customUserData, | ||
}, | ||
} | ||
} | ||
|
||
// DefaultBlockDeviceMappings returns the default block device mappings for the AMI Family | ||
func (w Windows) DefaultBlockDeviceMappings() []*v1alpha1.BlockDeviceMapping { | ||
sda1EBS := DefaultEBS | ||
sda1EBS.VolumeSize = lo.ToPtr(resource.MustParse("50Gi")) | ||
return []*v1alpha1.BlockDeviceMapping{{ | ||
DeviceName: w.EphemeralBlockDevice(), | ||
EBS: &sda1EBS, | ||
}} | ||
} | ||
|
||
func (w Windows) EphemeralBlockDevice() *string { | ||
return aws.String("/dev/sda1") | ||
} |
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
Oops, something went wrong.