-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --user-data-format option, nodeadm support
- Loading branch information
1 parent
0a57f0e
commit 742a5cd
Showing
10 changed files
with
181 additions
and
62 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
7 changes: 7 additions & 0 deletions
7
kubetest2/internal/deployers/eksapi/templates/userdata_bootstrap.sh.mimepart.template
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,7 @@ | ||
Content-Type: text/x-shellscript; charset="us-ascii" | ||
MIME-Version: 1.0 | ||
|
||
#!/usr/bin/env bash | ||
/etc/eks/bootstrap.sh {{.Name}} \ | ||
--b64-cluster-ca {{.CertificateAuthority}} \ | ||
--apiserver-endpoint {{.APIServerEndpoint}} |
11 changes: 11 additions & 0 deletions
11
kubetest2/internal/deployers/eksapi/templates/userdata_nodeadm.yaml.mimepart.template
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,11 @@ | ||
Content-Type: application/node.eks.aws | ||
MIME-Version: 1.0 | ||
|
||
--- | ||
apiVersion: node.eks.aws/v1alpha1 | ||
kind: NodeConfig | ||
spec: | ||
cluster: | ||
name: {{.Name}} | ||
apiServerEndpoint: {{.APIServerEndpoint}} | ||
certificateAuthority: {{.CertificateAuthority}} |
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,30 @@ | ||
package eksapi | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"text/template" | ||
|
||
"github.com/aws/aws-k8s-tester/kubetest2/internal/deployers/eksapi/templates" | ||
) | ||
|
||
func generateUserData(format string, cluster *Cluster) (string, error) { | ||
var t *template.Template | ||
switch format { | ||
case "bootstrap.sh": | ||
t = templates.UserDataBootstrapSh | ||
case "nodeadm": | ||
t = templates.UserDataNodeadm | ||
default: | ||
return "", fmt.Errorf("uknown user data format: '%s'", format) | ||
} | ||
buf := bytes.Buffer{} | ||
if err := t.Execute(&buf, templates.UserDataTemplateData{ | ||
Name: cluster.name, | ||
CertificateAuthority: cluster.certificateAuthorityData, | ||
APIServerEndpoint: cluster.endpoint, | ||
}); err != nil { | ||
return "", err | ||
} | ||
return buf.String(), 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,61 @@ | ||
package eksapi | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var cluster = Cluster{ | ||
name: "cluster", | ||
endpoint: "https://example.com", | ||
certificateAuthorityData: "certificateAuthority", | ||
} | ||
|
||
const bootstrapShUserData = `Content-Type: text/x-shellscript; charset="us-ascii" | ||
MIME-Version: 1.0 | ||
#!/usr/bin/env bash | ||
/etc/eks/bootstrap.sh cluster \ | ||
--b64-cluster-ca certificateAuthority \ | ||
--apiserver-endpoint https://example.com | ||
` | ||
|
||
const nodeadmUserData = `Content-Type: application/node.eks.aws | ||
MIME-Version: 1.0 | ||
--- | ||
apiVersion: node.eks.aws/v1alpha1 | ||
kind: NodeConfig | ||
spec: | ||
cluster: | ||
name: cluster | ||
apiServerEndpoint: https://example.com | ||
certificateAuthority: certificateAuthority | ||
` | ||
|
||
func Test_generateUserData(t *testing.T) { | ||
cases := []struct { | ||
format string | ||
expected string | ||
}{ | ||
{ | ||
format: "bootstrap.sh", | ||
expected: bootstrapShUserData, | ||
}, | ||
{ | ||
format: "nodeadm", | ||
expected: nodeadmUserData, | ||
}, | ||
} | ||
for _, c := range cases { | ||
t.Run(c.format, func(t *testing.T) { | ||
actual, err := generateUserData(c.format, &cluster) | ||
if err != nil { | ||
t.Log(err) | ||
t.Error(err) | ||
} | ||
assert.Equal(t, c.expected, actual) | ||
}) | ||
} | ||
} |