-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Support for Pre bootstrap commands in Windows Node Groups (#2004)
Allows the specification of preBootstrapCommands in the node group spec for windows. Users can run custom Powershell commands on instance start before the instance is bootstrapped for EKS. Issue #2003
- Loading branch information
1 parent
aaeab00
commit df2b4d5
Showing
5 changed files
with
149 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package nodebootstrap | ||
|
||
import ( | ||
"encoding/base64" | ||
"strings" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5" | ||
) | ||
|
||
var _ = Describe("Windows", func() { | ||
var ( | ||
clusterConfig *api.ClusterConfig | ||
ng *api.NodeGroup | ||
) | ||
|
||
BeforeEach(func() { | ||
clusterConfig = api.NewClusterConfig() | ||
clusterConfig.Status = &api.ClusterStatus{ | ||
Endpoint: "unit-test.example.com", | ||
CertificateAuthorityData: []byte(`CertificateAuthorityData`), | ||
} | ||
clusterConfig.Metadata = &api.ClusterMeta{ | ||
Name: "unit-test", | ||
} | ||
ng = &api.NodeGroup{ | ||
AMIFamily: api.NodeImageFamilyWindowsServer2019CoreContainer, | ||
} | ||
}) | ||
|
||
Describe("with single pre bootstrap script", func() { | ||
It("produces correct userdata", func() { | ||
ng.PreBootstrapCommands = []string{ | ||
"wget -UseBasicParsing -O amazon-cloudwatch-agent.msi https://s3.amazonaws.com/amazoncloudwatch-agent/windows/amd64/latest/amazon-cloudwatch-agent.msi", | ||
} | ||
userdata, err := NewUserDataForWindows(clusterConfig, ng) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
decodedBytes, err := base64.StdEncoding.DecodeString(userdata) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
decodedString := string(decodedBytes) | ||
|
||
Expect(decodedString).ToNot(Equal("")) | ||
Expect(decodedString).To(Equal(strings.TrimSpace(` | ||
<powershell> | ||
[string]$EKSBootstrapScriptFile = "$env:ProgramFiles\Amazon\EKS\Start-EKSBootstrap.ps1" | ||
wget -UseBasicParsing -O amazon-cloudwatch-agent.msi https://s3.amazonaws.com/amazoncloudwatch-agent/windows/amd64/latest/amazon-cloudwatch-agent.msi | ||
& $EKSBootstrapScriptFile -EKSClusterName "unit-test" -KubeletExtraArgs "--node-labels= --register-with-taints=" 3>&1 4>&1 5>&1 6>&1 | ||
</powershell> | ||
`))) | ||
}) | ||
}) | ||
|
||
Describe("with multiple pre bootstrap script", func() { | ||
It("produces correct userdata", func() { | ||
ng.PreBootstrapCommands = []string{ | ||
"wget -UseBasicParsing -O amazon-cloudwatch-agent.msi https://s3.amazonaws.com/amazoncloudwatch-agent/windows/amd64/latest/amazon-cloudwatch-agent.msi", | ||
"start /wait msiexec.exe /qb /i \"amazon-cloudwatch-agent.msi\"", | ||
} | ||
userdata, err := NewUserDataForWindows(clusterConfig, ng) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
decodedBytes, err := base64.StdEncoding.DecodeString(userdata) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
decodedString := string(decodedBytes) | ||
|
||
Expect(decodedString).ToNot(Equal("")) | ||
Expect(decodedString).To(Equal(strings.TrimSpace(` | ||
<powershell> | ||
[string]$EKSBootstrapScriptFile = "$env:ProgramFiles\Amazon\EKS\Start-EKSBootstrap.ps1" | ||
wget -UseBasicParsing -O amazon-cloudwatch-agent.msi https://s3.amazonaws.com/amazoncloudwatch-agent/windows/amd64/latest/amazon-cloudwatch-agent.msi | ||
start /wait msiexec.exe /qb /i "amazon-cloudwatch-agent.msi" | ||
& $EKSBootstrapScriptFile -EKSClusterName "unit-test" -KubeletExtraArgs "--node-labels= --register-with-taints=" 3>&1 4>&1 5>&1 6>&1 | ||
</powershell> | ||
`))) | ||
}) | ||
}) | ||
|
||
Describe("without pre bootstrap scripts", func() { | ||
It("produces correct userdata", func() { | ||
ng.PreBootstrapCommands = nil | ||
userdata, err := NewUserDataForWindows(clusterConfig, ng) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
decodedBytes, err := base64.StdEncoding.DecodeString(userdata) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
decodedString := string(decodedBytes) | ||
|
||
Expect(decodedString).ToNot(Equal("")) | ||
Expect(decodedString).To(Equal(strings.TrimSpace(` | ||
<powershell> | ||
[string]$EKSBootstrapScriptFile = "$env:ProgramFiles\Amazon\EKS\Start-EKSBootstrap.ps1" | ||
& $EKSBootstrapScriptFile -EKSClusterName "unit-test" -KubeletExtraArgs "--node-labels= --register-with-taints=" 3>&1 4>&1 5>&1 6>&1 | ||
</powershell> | ||
`))) | ||
}) | ||
}) | ||
}) |