-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): add nodeadm wasm targets to call from docs
- Loading branch information
Showing
8 changed files
with
125 additions
and
6 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 |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
.DS_Store | ||
site/ | ||
.git-commit | ||
*.wasm |
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,57 @@ | ||
# Playground | ||
|
||
This an interactive playground for `nodeadm`'s config parser packaged in the | ||
browser via WebAssembly! | ||
|
||
You can test out the validity of your EC2 Userdata and see any of the potential | ||
errors that might happen at runtime. | ||
|
||
<div> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.36.5/ace.min.js" integrity="sha512-NIDAOLuPuewIzUrGoK5fXxowwGDm0DFJhI5TJPyTP6MeY2hUcCSKJr54fecQTEZ8kxxEO2NBrILQSUl4qZ37FA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> | ||
<script src="/amazon-eks-ami/assets/javascripts/wasm_exec.js"></script> | ||
<body> | ||
<div style="display: grid; margin: auto;"> | ||
<div id="editor" style="height:50vh"></div> | ||
<textarea readonly style="height:15vh" id="response"></textarea> | ||
</div> | ||
</body> | ||
<script> | ||
const go = new Go(); | ||
WebAssembly.instantiateStreaming(fetch("/amazon-eks-ami/assets/wasm/nodeadm.wasm"), go.importObject).then((result) => { | ||
go.run(result.instance); | ||
}); | ||
const editor = ace.edit("editor", { | ||
useWorker: false | ||
}); | ||
editor.setTheme("ace/theme/monokai"); | ||
editor.session.setValue(` | ||
MIME-Version: 1.0 | ||
Content-Type: multipart/mixed; boundary="BOUNDARY" | ||
|
||
--BOUNDARY | ||
Content-Type: application/node.eks.aws | ||
|
||
--- | ||
apiVersion: node.eks.aws/v1alpha1 | ||
kind: NodeConfig | ||
spec: | ||
cluster: | ||
name: my-cluster | ||
apiServerEndpoint: https://example.com | ||
certificateAuthority: Y2VydGlmaWNhdGVBdXRob3JpdHk= | ||
cidr: 10.100.0.0/16 | ||
kubelet: | ||
config: | ||
shutdownGracePeriod: 30s | ||
featureGates: | ||
DisableKubeletCloudCredentialProviders: true | ||
|
||
--BOUNDARY--`.trim()); | ||
editor.session.setMode("ace/mode/yaml"); | ||
editor.setShowPrintMargin(false); | ||
// editor is exposed via a global created by the monaco webcomponent | ||
const validate = () => document.getElementById("response").textContent = nodeadmCheck(editor.session.getValue()) | ||
editor.session.on('change', function(_) { validate() }); | ||
validate() | ||
</script> | ||
</div> |
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,52 @@ | ||
//go:build wasm | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"syscall/js" | ||
|
||
"github.com/awslabs/amazon-eks-ami/nodeadm/internal/api" | ||
"github.com/awslabs/amazon-eks-ami/nodeadm/internal/configprovider" | ||
) | ||
|
||
type jsWrapperFunc = func(this js.Value, args []js.Value) any | ||
|
||
func main() { | ||
for jsFuncName, jsFunc := range map[string]jsWrapperFunc{ | ||
"nodeadmCheck": nodeadmCheckFunc, | ||
} { | ||
fmt.Printf("loading %q from Go WASM module\n", jsFuncName) | ||
js.Global().Set(jsFuncName, js.FuncOf(func(this js.Value, args []js.Value) any { | ||
defer func() { | ||
// Since we cannot return errors in proper convention back to | ||
// javascript through the WebAssembly Goroutine, we'll wrap the | ||
// panic handler instead and print the information to keep the | ||
// execution Go-like. | ||
if r := recover(); r != nil { | ||
errString := fmt.Sprintf("%s", r) | ||
fmt.Printf("encountered error: %s\n", errString) | ||
js.Global().Call("alert", errString) | ||
} | ||
}() | ||
return jsFunc(this, args) | ||
})) | ||
} | ||
// block function completion to keep the Go routines loaded in memory | ||
<-make(chan struct{}) | ||
} | ||
|
||
var nodeadmCheckFunc = func(this js.Value, args []js.Value) any { | ||
if len(args) != 1 { | ||
panic("incorrect number of arguments.") | ||
} | ||
document := args[0].String() | ||
nodeConfig, err := configprovider.ParseMaybeMultipart([]byte(document)) | ||
if err != nil { | ||
return js.ValueOf(err.Error()) | ||
} | ||
if err := api.ValidateNodeConfig(nodeConfig); err != nil { | ||
return js.ValueOf(fmt.Errorf("validating NodeConfig: %w", err).Error()) | ||
} | ||
return js.ValueOf("Looks Good! 👍") | ||
} |
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