diff --git a/data/example/init/templates/envoy.access_loggers/default/README.md b/data/example/init/templates/envoy.access_loggers/default/README.md index 3e4c47c0..e768d408 100644 --- a/data/example/init/templates/envoy.access_loggers/default/README.md +++ b/data/example/init/templates/envoy.access_loggers/default/README.md @@ -6,7 +6,7 @@ | ----------------- | ------------------------ | ----------------------------------------------------------------------- | | `example.yaml` | `Example` descriptor | Describes runtime requirements, e.g. a specific version of `Envoy` | | `envoy.tmpl.yaml` | `Envoy` bootstrap config | Provides `Envoy` config that demoes extension in action | -| `extension.json` | `Extension` config | Provides configuration for extension itself | +| `${EXTENSION_CONFIG_FILE_NAME}` | `Extension` config | Provides configuration for extension itself | ## Components diff --git a/data/example/init/templates/envoy.filters.http/default/README.md b/data/example/init/templates/envoy.filters.http/default/README.md index 225da5bd..6bbc5ae5 100644 --- a/data/example/init/templates/envoy.filters.http/default/README.md +++ b/data/example/init/templates/envoy.filters.http/default/README.md @@ -6,7 +6,7 @@ | ----------------- | ------------------------ | ----------------------------------------------------------------------- | | `example.yaml` | `Example` descriptor | Describes runtime requirements, e.g. a specific version of `Envoy` | | `envoy.tmpl.yaml` | `Envoy` bootstrap config | Provides `Envoy` config that demoes extension in action | -| `extension.json` | `Extension` config | Provides configuration for extension itself | +| `${EXTENSION_CONFIG_FILE_NAME}` | `Extension` config | Provides configuration for extension itself | ## Components diff --git a/data/example/init/templates/envoy.filters.http/default/extension.json b/data/example/init/templates/envoy.filters.http/default/extension.json deleted file mode 100644 index e69de29b..00000000 diff --git a/data/example/init/templates/envoy.filters.network/default/README.md b/data/example/init/templates/envoy.filters.network/default/README.md index 5f3667a5..8bc46c0f 100644 --- a/data/example/init/templates/envoy.filters.network/default/README.md +++ b/data/example/init/templates/envoy.filters.network/default/README.md @@ -6,7 +6,7 @@ | ----------------- | ------------------------ | ----------------------------------------------------------------------- | | `example.yaml` | `Example` descriptor | Describes runtime requirements, e.g. a specific version of `Envoy` | | `envoy.tmpl.yaml` | `Envoy` bootstrap config | Provides `Envoy` config that demoes extension in action | -| `extension.json` | `Extension` config | Provides configuration for extension itself | +| `${EXTENSION_CONFIG_FILE_NAME}` | `Extension` config | Provides configuration for extension itself | ## Components diff --git a/data/example/init/templates/envoy.filters.network/default/extension.json b/data/example/init/templates/envoy.filters.network/default/extension.json deleted file mode 100644 index e69de29b..00000000 diff --git a/data/example/init/templates/envoy.access_loggers/default/extension.json b/data/example/init/templates/language-specific/rust/extension.json similarity index 100% rename from data/example/init/templates/envoy.access_loggers/default/extension.json rename to data/example/init/templates/language-specific/rust/extension.json diff --git a/data/example/init/templates/language-specific/tinygo/extension.txt b/data/example/init/templates/language-specific/tinygo/extension.txt new file mode 100644 index 00000000..939f37cb --- /dev/null +++ b/data/example/init/templates/language-specific/tinygo/extension.txt @@ -0,0 +1,3 @@ +# We recommend to use json as the configuration format, +# however, some languages (e.g. TinyGo) does not support ready-to-use json library as of now. +# As a temporary alternative, we use ".txt" format. diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod index 02297849..9d693227 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0 + github.com/tetratelabs/proxy-wasm-go-sdk v0.1.1 ) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum index 4a33c4c1..9f3e6c68 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum @@ -5,8 +5,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0 h1:9CUaOB8CZInfG/VRCjOEOkzS4JLkri/weqogwmrl2a0= -github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.1.1 h1:m8O4nWCyb+8VlAxVxppobGNnC1N9CoAQBmMfRjTq/hU= +github.com/tetratelabs/proxy-wasm-go-sdk v0.1.1/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go index f00b6f5d..8164ced1 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go @@ -1,6 +1,10 @@ package main import ( + "bufio" + "bytes" + "strings" + "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm" "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" ) @@ -28,7 +32,20 @@ func (l *accessLogger) OnPluginStart(configurationSize int) types.OnPluginStartS proxywasm.LogCriticalf("failed to load config: %v", err) return types.OnPluginStartStatusFailed } - l.logMessage = string(data) + + // Ignore comment lines starting with "#" in the configuration. + // Note that we recommend to use json as the configuration format, + // however, some languages (e.g. TinyGo) does not support ready-to-use json library as of now. + // As a temporary alternative, we use ".txt" format for the plugin configuration. + var lines []string + scanner := bufio.NewScanner(bytes.NewReader(data)) + for scanner.Scan() { + line := scanner.Text() + if !strings.HasPrefix(line, "#") { + lines = append(lines, line) + } + } + l.logMessage = strings.Join(lines, "\n") return types.OnPluginStartStatusOK } diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go index 71928db6..3fadd353 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go @@ -10,7 +10,8 @@ import ( ) func TestAccessLogger_OnLog(t *testing.T) { - configuration := `this is my log message` + configuration := `# this is comment line, and should be ignored. +this is my log message` opt := proxytest.NewEmulatorOption(). WithNewRootContext(newAccessLogger). WithPluginConfiguration([]byte(configuration)) diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod index 02297849..9d693227 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0 + github.com/tetratelabs/proxy-wasm-go-sdk v0.1.1 ) diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum index 4a33c4c1..9f3e6c68 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum @@ -5,8 +5,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0 h1:9CUaOB8CZInfG/VRCjOEOkzS4JLkri/weqogwmrl2a0= -github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.1.1 h1:m8O4nWCyb+8VlAxVxppobGNnC1N9CoAQBmMfRjTq/hU= +github.com/tetratelabs/proxy-wasm-go-sdk v0.1.1/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go index 18f4dc3a..6c9277ce 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go @@ -42,11 +42,21 @@ func (ctx *rootContext) OnPluginStart(configurationSize int) types.OnPluginStart return types.OnPluginStartStatusFailed } - // Each line in the configuration is in the "KEY=VALUE" format. + // Read the configuration. + // Note that we recommend to use json as the configuration format, + // however, some languages (e.g. TinyGo) does not support ready-to-use json library as of now. + // As a temporary alternative, we use ".txt" format for the plugin configuration. scanner := bufio.NewScanner(bytes.NewReader(data)) for scanner.Scan() { - tokens := strings.Split(scanner.Text(), "=") - ctx.additionalHeaders[tokens[0]] = tokens[1] + // Ignore comment lines starting with "#". + line := scanner.Text() + if strings.HasPrefix(line, "#") { + continue + } + // Each line in the configuration is in the "KEY=VALUE" format. + if tokens := strings.Split(scanner.Text(), "="); len(tokens) == 2 { + ctx.additionalHeaders[tokens[0]] = tokens[1] + } } return types.OnPluginStartStatusOK } diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go index 0e0efff2..e9cf3181 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go @@ -10,7 +10,8 @@ import ( ) func TestHttpFilter_OnHttpRequestHeaders(t *testing.T) { - configuration := `HELLO=WORLD + configuration := `# this is comment line, and should be ignored. +HELLO=WORLD ENVOY=ISTIO` opt := proxytest.NewEmulatorOption(). WithNewRootContext(newRootContext). diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod index 02297849..9d693227 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0 + github.com/tetratelabs/proxy-wasm-go-sdk v0.1.1 ) diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum index 4a33c4c1..9f3e6c68 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum @@ -5,8 +5,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0 h1:9CUaOB8CZInfG/VRCjOEOkzS4JLkri/weqogwmrl2a0= -github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.1.1 h1:m8O4nWCyb+8VlAxVxppobGNnC1N9CoAQBmMfRjTq/hU= +github.com/tetratelabs/proxy-wasm-go-sdk v0.1.1/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go index 2d41b560..daea8cb4 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go @@ -1,6 +1,10 @@ package main import ( + "bufio" + "bytes" + "strings" + "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm" "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" ) @@ -34,7 +38,20 @@ func (ctx *rootContext) OnPluginStart(configurationSize int) types.OnPluginStart proxywasm.LogCriticalf("failed to load config: %v", err) return types.OnPluginStartStatusFailed } - ctx.config = string(data) + + // Ignore comment lines starting with "#" in the extension.txt. + // Note that we recommend to use json as the configuration format, + // however, some languages (e.g. TinyGo) does not support ready-to-use json library as of now. + // As a temporary alternative, we use ".txt" format for the plugin configuration. + var lines []string + scanner := bufio.NewScanner(bytes.NewReader(data)) + for scanner.Scan() { + line := scanner.Text() + if !strings.HasPrefix(line, "#") { + lines = append(lines, line) + } + } + ctx.config = strings.Join(lines, "\n") return types.OnPluginStartStatusOK } diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go index 06a95431..fa390cd1 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go @@ -9,7 +9,8 @@ import ( ) func TestNetworkFilter_OnNewConnection(t *testing.T) { - configuration := `message: this is new connection!` + configuration := `# this is comment line, and should be ignored. +message: this is new connection!` opt := proxytest.NewEmulatorOption(). WithPluginConfiguration([]byte(configuration)). WithNewRootContext(newRootContext) @@ -28,7 +29,7 @@ func TestNetworkFilter_OnNewConnection(t *testing.T) { // Retrieve logs emitted to Envoy. logs := host.GetLogs(types.LogLevelInfo) - require.Contains(t, logs, configuration) + require.Contains(t, logs, "message: this is new connection!") } func TestNetworkFilter_counter(t *testing.T) { diff --git a/pkg/cmd/extension/example/cmd_add_test.go b/pkg/cmd/extension/example/cmd_add_test.go index e8f581ca..02fd70b6 100644 --- a/pkg/cmd/extension/example/cmd_add_test.go +++ b/pkg/cmd/extension/example/cmd_add_test.go @@ -131,10 +131,17 @@ Run 'getenvoy extension examples add --help' for usage. Done! `)) By("verifying file system") - Expect(filepath.Join(tempDir, ".getenvoy/extension/examples/default/README.md")).To(BeAnExistingFile()) + readmePath := filepath.Join(tempDir, ".getenvoy/extension/examples/default/README.md") + Expect(readmePath).To(BeAnExistingFile()) Expect(filepath.Join(tempDir, ".getenvoy/extension/examples/default/envoy.tmpl.yaml")).To(BeAnExistingFile()) Expect(filepath.Join(tempDir, ".getenvoy/extension/examples/default/example.yaml")).To(BeAnExistingFile()) Expect(filepath.Join(tempDir, ".getenvoy/extension/examples/default/extension.json")).To(BeAnExistingFile()) + // Check README substitution: ${EXTENSION_CONFIG_FILE_NAME} must be replaced with "extension.json". + data, err := ioutil.ReadFile(readmePath) + Expect(err).ToNot(HaveOccurred()) + readme := string(data) + Expect(readme).To(ContainSubstring("extension.json")) + Expect(readme).NotTo(ContainSubstring("EXTENSION_CONFIG_FILE_NAME")) }) It("should create example setup with a given --name", func() { @@ -160,10 +167,17 @@ Done! Done! `)) By("verifying file system") - Expect(filepath.Join(tempDir, ".getenvoy/extension/examples/advanced/README.md")).To(BeAnExistingFile()) + readmePath := filepath.Join(tempDir, ".getenvoy/extension/examples/advanced/README.md") + Expect(readmePath).To(BeAnExistingFile()) Expect(filepath.Join(tempDir, ".getenvoy/extension/examples/advanced/envoy.tmpl.yaml")).To(BeAnExistingFile()) Expect(filepath.Join(tempDir, ".getenvoy/extension/examples/advanced/example.yaml")).To(BeAnExistingFile()) Expect(filepath.Join(tempDir, ".getenvoy/extension/examples/advanced/extension.json")).To(BeAnExistingFile()) + // Check README substitution: ${EXTENSION_CONFIG_FILE_NAME} must be replaced with "extension.json". + data, err := ioutil.ReadFile(readmePath) + Expect(err).ToNot(HaveOccurred()) + readme := string(data) + Expect(readme).To(ContainSubstring("extension.json")) + Expect(readme).NotTo(ContainSubstring("${EXTENSION_CONFIG_FILE_NAME}")) }) It("should fail if such example already exists", func() { @@ -186,6 +200,42 @@ Done! Run 'getenvoy extension examples add --help' for usage. `)) }) + + It("should create 'default' example setup when no --name is omitted for TinyGo", func() { + By("simulating a workspace without any examples") + err := copy.Copy("testdata/workspace4", tempDir) + Expect(err).NotTo(HaveOccurred()) + + By("changing to a workspace dir") + chdir(tempDir) + + By("running command") + c.SetArgs([]string{"extension", "examples", "add"}) + err = cmdutil.Execute(c) + Expect(err).ToNot(HaveOccurred()) + + By("verifying command output") + Expect(stdout.String()).To(BeEmpty()) + Expect(stderr.String()).To(Equal(`Scaffolding a new example setup: +* .getenvoy/extension/examples/default/README.md +* .getenvoy/extension/examples/default/envoy.tmpl.yaml +* .getenvoy/extension/examples/default/example.yaml +* .getenvoy/extension/examples/default/extension.txt +Done! +`)) + By("verifying file system") + readmePath := filepath.Join(tempDir, ".getenvoy/extension/examples/default/README.md") + Expect(readmePath).To(BeAnExistingFile()) + Expect(filepath.Join(tempDir, ".getenvoy/extension/examples/default/envoy.tmpl.yaml")).To(BeAnExistingFile()) + Expect(filepath.Join(tempDir, ".getenvoy/extension/examples/default/example.yaml")).To(BeAnExistingFile()) + Expect(filepath.Join(tempDir, ".getenvoy/extension/examples/default/extension.txt")).To(BeAnExistingFile()) + // Check README substitution: ${EXTENSION_CONFIG_FILE_NAME} must be replaced with "extension.txt". + data, err := ioutil.ReadFile(readmePath) + Expect(err).ToNot(HaveOccurred()) + readme := string(data) + Expect(readme).To(ContainSubstring("extension.txt")) + Expect(readme).NotTo(ContainSubstring("${EXTENSION_CONFIG_FILE_NAME}")) + }) }) Context("outside of a workspace directory", func() { diff --git a/pkg/cmd/extension/example/testdata/workspace4/.getenvoy/extension/extension.yaml b/pkg/cmd/extension/example/testdata/workspace4/.getenvoy/extension/extension.yaml new file mode 100644 index 00000000..839b9aee --- /dev/null +++ b/pkg/cmd/extension/example/testdata/workspace4/.getenvoy/extension/extension.yaml @@ -0,0 +1,14 @@ +# +# Envoy Wasm extension created with getenvoy toolkit. +# +kind: Extension + +name: me.filters.http.my_http_filter + +category: envoy.filters.http +language: tinygo + +# Runtime the extension is being developed against. +runtime: + envoy: + version: standard:1.17.0 diff --git a/pkg/cmd/extension/run/cmd_test.go b/pkg/cmd/extension/run/cmd_test.go index 8f9e5812..62906a17 100644 --- a/pkg/cmd/extension/run/cmd_test.go +++ b/pkg/cmd/extension/run/cmd_test.go @@ -700,6 +700,43 @@ Run 'getenvoy extension run --help' for usage. Done! docker stderr envoy stderr +`)) + + By("verifying Envoy config") + bootstrap := envoyCaptured.readFileToJSON("envoy.tmpl.yaml") + Expect(bootstrap).NotTo(BeEmpty()) + }) + + It("should create default example if missing for TinyGo", func() { + By("simulating a workspace without 'default' example") + tempDir, err := ioutil.TempDir("", "") + Expect(err).NotTo(HaveOccurred()) + defer func() { + Expect(os.RemoveAll(tempDir)).To(Succeed()) + }() + err = copy.Copy("testdata/workspace_tinygo", tempDir) + Expect(err).NotTo(HaveOccurred()) + + By("changing to a workspace dir") + workspaceDir := chdir(tempDir) + + By("running command") + c.SetArgs([]string{"extension", "run"}) + err = cmdutil.Execute(c) + Expect(err).ToNot(HaveOccurred()) + + By("verifying command output") + Expect(stdout.String()).To(Equal(fmt.Sprintf(`%s/docker run -u 1001:1002 --rm -t -v %s:/source -w /source --init getenvoy/extension-tinygo-builder:latest build --output-file build/extension.wasm +%s/builds/standard/1.17.0/%s/bin/envoy -c %s/envoy.tmpl.yaml +`, dockerDir, workspaceDir, getenvoyHomeDir, platform, envoyCaptured.cwd()))) + Expect(stderr.String()).To(Equal(`Scaffolding a new example setup: +* .getenvoy/extension/examples/default/README.md +* .getenvoy/extension/examples/default/envoy.tmpl.yaml +* .getenvoy/extension/examples/default/example.yaml +* .getenvoy/extension/examples/default/extension.txt +Done! +docker stderr +envoy stderr `)) By("verifying Envoy config") diff --git a/pkg/cmd/extension/run/testdata/workspace_tinygo/.getenvoy/extension/extension.yaml b/pkg/cmd/extension/run/testdata/workspace_tinygo/.getenvoy/extension/extension.yaml new file mode 100644 index 00000000..cddb5528 --- /dev/null +++ b/pkg/cmd/extension/run/testdata/workspace_tinygo/.getenvoy/extension/extension.yaml @@ -0,0 +1,14 @@ +# +# Envoy Wasm extension created with getenvoy toolkit. +# +kind: Extension + +name: mycompany.filters.http.mytest + +category: envoy.filters.http +language: tinygo + +# Runtime the extension is being developed against. +runtime: + envoy: + version: standard:1.17.0 diff --git a/pkg/extension/example/init/registry/global.go b/pkg/extension/example/init/registry/global.go index a51f6ed6..912f15ae 100644 --- a/pkg/extension/example/init/registry/global.go +++ b/pkg/extension/example/init/registry/global.go @@ -35,7 +35,7 @@ func globalRegistry() registry { } // Get returns an example template registered in a global registry for a given -// extension category and name. -func Get(category extension.Category, name string) (*Entry, error) { - return globalRegistry().Get(category, name) +// extension category, name and language. +func Get(descriptor *extension.Descriptor, name string) (*Entry, error) { + return globalRegistry().Get(descriptor, name) } diff --git a/pkg/extension/example/init/registry/types.go b/pkg/extension/example/init/registry/types.go index 2282ddc2..45ba1880 100644 --- a/pkg/extension/example/init/registry/types.go +++ b/pkg/extension/example/init/registry/types.go @@ -18,7 +18,9 @@ import ( "io/ioutil" "net/http" "os" + "path" "path/filepath" + "strings" "github.com/pkg/errors" "github.com/shurcooL/httpfs/vfsutil" @@ -30,7 +32,7 @@ import ( // registry represents a registry of example templates. type registry interface { // Get returns a registry entry. - Get(category extension.Category, example string) (*Entry, error) + Get(descriptor *extension.Descriptor, example string) (*Entry, error) } // fsRegistry represents a registry of example templates backed by @@ -40,8 +42,8 @@ type fsRegistry struct { namingScheme func(category extension.Category, example string) string } -func (r *fsRegistry) Get(category extension.Category, example string) (*Entry, error) { - dirName := r.namingScheme(category, example) +func (r *fsRegistry) Get(descriptor *extension.Descriptor, example string) (*Entry, error) { + dirName := r.namingScheme(descriptor.Category, example) dir, err := r.fs.Open(dirName) if err != nil { return nil, errors.Wrapf(err, "failed to open: %s", dirName) @@ -54,36 +56,75 @@ func (r *fsRegistry) Get(category extension.Category, example string) (*Entry, e if !info.IsDir() { return nil, errors.Errorf("%q is not a directory", dirName) } + return &Entry{ - Category: category, + Category: descriptor.Category, Name: example, NewExample: func(*extension.Descriptor) (model.Example, error) { + fileSet := model.NewFileSet() + + // Add language independent files fileNames, err := listFiles(r.fs, dirName) if err != nil { return nil, errors.Wrapf(err, "failed to list files in a directory: %s", dirName) } - fileSet := model.NewFileSet() for _, fileName := range fileNames { - file, err := r.fs.Open(fileName) + err = r.addFile(fileSet, dirName, fileName, descriptor.Language) if err != nil { - return nil, errors.Wrapf(err, "failed to open: %s", fileName) - } - defer file.Close() //nolint:errcheck - data, err := ioutil.ReadAll(file) - if err != nil { - return nil, errors.Wrapf(err, "failed to read: %s", fileName) + return nil, err } - relPath, err := filepath.Rel(dirName, fileName) + } + + // Add language specific files + languageDir := path.Join("/language-specific", descriptor.Language.String()) + fileNames, err = listFiles(r.fs, languageDir) + if err != nil { + return nil, errors.Wrapf(err, "failed to list files in a directory: %s", dirName) + } + for _, fileName := range fileNames { + err = r.addFile(fileSet, languageDir, fileName, descriptor.Language) if err != nil { return nil, err } - fileSet.Add(relPath, &model.File{Source: fileName, Content: data}) } return model.NewExample(fileSet) }, }, nil } +func (r *fsRegistry) addFile(fileSet model.FileSet, dirName, fileName string, language extension.Language) error { + file, err := r.fs.Open(fileName) + if err != nil { + return errors.Wrapf(err, "failed to open: %s", fileName) + } + defer file.Close() //nolint:errcheck + data, err := ioutil.ReadAll(file) + if err != nil { + return errors.Wrapf(err, "failed to read: %s", fileName) + } + relPath, err := filepath.Rel(dirName, fileName) + if err != nil { + return err + } + + // Need to adjust README.md according to the extension config file name. + // See https://github.com/tetratelabs/getenvoy/issues/124 + if relPath == "README.md" { + var extensionConfigFileName string + switch language { + case extension.LanguageTinyGo: + extensionConfigFileName = "extension.txt" + default: + extensionConfigFileName = "extension.json" + } + data = []byte(strings.ReplaceAll(string(data), + "${EXTENSION_CONFIG_FILE_NAME}", extensionConfigFileName)) + } + + fileSet.Add(relPath, &model.File{Source: fileName, Content: data}) + return nil +} + func listFiles(fs http.FileSystem, root string) ([]string, error) { fileNames := make([]string, 0) err := vfsutil.Walk(fs, root, func(path string, info os.FileInfo, err error) error { diff --git a/pkg/extension/workspace/example/runtime/configdir/configdir.go b/pkg/extension/workspace/example/runtime/configdir/configdir.go index c414c372..3101eb15 100644 --- a/pkg/extension/workspace/example/runtime/configdir/configdir.go +++ b/pkg/extension/workspace/example/runtime/configdir/configdir.go @@ -20,18 +20,16 @@ import ( "os" "path/filepath" - "github.com/pkg/errors" - envoybootstrap "github.com/envoyproxy/go-control-plane/envoy/config/bootstrap/v3" + "github.com/pkg/errors" "github.com/tetratelabs/getenvoy/pkg/extension/manager" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/example/envoy/template" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/example/envoy/util" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/example/runtime" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/model" - "github.com/tetratelabs/multierror" - osutil "github.com/tetratelabs/getenvoy/pkg/util/os" + "github.com/tetratelabs/multierror" ) // NewConfigDir creates a config directory for a single example run. @@ -106,7 +104,7 @@ func (d *configDir) init() error { return nil } -// process resolves placehoders in the Envoy bootstrap config, including +// process resolves placeholders in the Envoy bootstrap config, including // 1) placeholders in the bootstrap file (envoy.tmpl.yaml or envoy.tmpl.json) // 2) (optional) placeholders in a LDS file (value of `bootstrap.dynamic_resources.lds_config.path`) // 3) (optional) placeholders in a CDS file (value of `bootstrap.dynamic_resources.cds_config.path`) @@ -116,7 +114,7 @@ func (d *configDir) process() error { return err } - // resolve placehoders in the bootstrap file + // resolve placeholders in the bootstrap file bootstrapFileName, bootstrapFile := d.ctx.Opts.Example.GetEnvoyConfig() bootstrapContent, err := d.processEnvoyTemplate(bootstrapFile, expandContext) if err != nil { @@ -138,14 +136,14 @@ func (d *configDir) process() error { } d.bootstrap = &bootstrap - // resolve placehoders in the LDS file + // resolve placeholders in the LDS file if fileName := d.bootstrap.GetDynamicResources().GetLdsConfig().GetPath(); fileName != "" { if err := d.processEnvoyXdsFile(fileName, expandContext); err != nil { return err } } - // resolve placehoders in the CDS file + // resolve placeholders in the CDS file if fileName := d.bootstrap.GetDynamicResources().GetCdsConfig().GetPath(); fileName != "" { if err := d.processEnvoyXdsFile(fileName, expandContext); err != nil { return err diff --git a/pkg/extension/workspace/example/runtime/configdir/configdir_test.go b/pkg/extension/workspace/example/runtime/configdir/configdir_test.go index 8c85d15a..e6d49df3 100644 --- a/pkg/extension/workspace/example/runtime/configdir/configdir_test.go +++ b/pkg/extension/workspace/example/runtime/configdir/configdir_test.go @@ -20,22 +20,21 @@ import ( "os" "path/filepath" + envoybootstrap "github.com/envoyproxy/go-control-plane/envoy/config/bootstrap/v3" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" - . "github.com/tetratelabs/getenvoy/pkg/extension/workspace/example/runtime/configdir" - - envoybootstrap "github.com/envoyproxy/go-control-plane/envoy/config/bootstrap/v3" - workspaces "github.com/tetratelabs/getenvoy/pkg/extension/workspace" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/example/runtime" + . "github.com/tetratelabs/getenvoy/pkg/extension/workspace/example/runtime/configdir" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/model" ) var _ = Describe("NewConfigDir()", func() { runContext := func(workspace model.Workspace, example model.Example) *runtime.RunContext { + _, f := example.GetExtensionConfig() return &runtime.RunContext{ Opts: runtime.RunOpts{ Workspace: workspace, @@ -45,10 +44,7 @@ var _ = Describe("NewConfigDir()", func() { }, Extension: runtime.ExtensionOpts{ WasmFile: `/path/to/extension.wasm`, - Config: model.File{ - Source: "/path/to/config", - Content: []byte(`{"key2":"value2"}`), - }, + Config: *f, }, }, } @@ -105,7 +101,7 @@ var _ = Describe("NewConfigDir()", func() { actual, err := ioutil.ReadFile(filepath.Join(configDir.GetDir(), fileName)) Expect(err).ToNot(HaveOccurred()) if given.isEnvoyTemplate(fileName) { - Expect(actual).To(MatchYAML(expected)) + Expect(string(actual)).Should(MatchYAML(string(expected))) } else { Expect(string(actual)).To(Equal(string(expected))) } @@ -139,6 +135,13 @@ var _ = Describe("NewConfigDir()", func() { }, expectBootstrap: expectValidBootstrap, }), + Entry("envoy.tmpl.yaml: .txt configuration", testCase{ + workspaceDir: "testdata/workspace8", + isEnvoyTemplate: func(name string) bool { + return name == "envoy.tmpl.yaml" + }, + expectBootstrap: expectValidBootstrap, + }), ) }) diff --git a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace1/expected/getenvoy_extension_run/envoy.tmpl.yaml b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace1/expected/getenvoy_extension_run/envoy.tmpl.yaml index 8f799b06..5ad3c038 100644 --- a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace1/expected/getenvoy_extension_run/envoy.tmpl.yaml +++ b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace1/expected/getenvoy_extension_run/envoy.tmpl.yaml @@ -18,7 +18,8 @@ static_resources: config: configuration: '@type': type.googleapis.com/google.protobuf.StringValue - value: '{"key2":"value2"}' + value: | + {"key":"value"} name: mycompany.filters.http.custom_metrics root_id: mycompany.filters.http.custom_metrics vm_config: diff --git a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace2/expected/getenvoy_extension_run/envoy.tmpl.yaml b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace2/expected/getenvoy_extension_run/envoy.tmpl.yaml index 687c40fa..42b8c4a7 100644 --- a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace2/expected/getenvoy_extension_run/envoy.tmpl.yaml +++ b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace2/expected/getenvoy_extension_run/envoy.tmpl.yaml @@ -24,7 +24,8 @@ static_resources: config: configuration: '@type': type.googleapis.com/google.protobuf.StringValue - value: '{"key2":"value2"}' + value: | + {"key":"value"} name: mycompany.filters.http.custom_metrics root_id: mycompany.filters.http.custom_metrics vm_config: diff --git a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace2/expected/getenvoy_extension_run/lds.tmpl.yaml b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace2/expected/getenvoy_extension_run/lds.tmpl.yaml index eeb88978..9ab6bce4 100644 --- a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace2/expected/getenvoy_extension_run/lds.tmpl.yaml +++ b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace2/expected/getenvoy_extension_run/lds.tmpl.yaml @@ -15,7 +15,8 @@ resources: config: configuration: '@type': type.googleapis.com/google.protobuf.StringValue - value: '{"key2":"value2"}' + value: | + {"key":"value"} name: mycompany.filters.http.custom_metrics root_id: mycompany.filters.http.custom_metrics vm_config: diff --git a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace3/expected/getenvoy_extension_run/envoy.tmpl.yaml b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace3/expected/getenvoy_extension_run/envoy.tmpl.yaml index d0fb1af7..634a0fbd 100644 --- a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace3/expected/getenvoy_extension_run/envoy.tmpl.yaml +++ b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace3/expected/getenvoy_extension_run/envoy.tmpl.yaml @@ -18,7 +18,7 @@ static_resources: typed_config: "@type": type.googleapis.com/envoy.extensions.filters.network.wasm.v3.Wasm config: - configuration: {"@type":"type.googleapis.com/google.protobuf.StringValue","value":"{\"key2\":\"value2\"}"} + configuration: {"@type":"type.googleapis.com/google.protobuf.StringValue","value":"{\"key\":\"value\"}\n"} name: "mycompany.filters.http.custom_metrics" root_id: "mycompany.filters.http.custom_metrics" vm_config: diff --git a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace4/expected/getenvoy_extension_run/envoy.tmpl.yaml b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace4/expected/getenvoy_extension_run/envoy.tmpl.yaml index c6b15d0f..a3b532e0 100644 --- a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace4/expected/getenvoy_extension_run/envoy.tmpl.yaml +++ b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace4/expected/getenvoy_extension_run/envoy.tmpl.yaml @@ -24,7 +24,8 @@ static_resources: config: configuration: '@type': type.googleapis.com/google.protobuf.StringValue - value: '{"key2":"value2"}' + value: | + {"key":"value"} name: mycompany.filters.http.custom_metrics root_id: mycompany.filters.http.custom_metrics vm_config: diff --git a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/.getenvoy/extension/examples/default/envoy.tmpl.yaml b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/.getenvoy/extension/examples/default/envoy.tmpl.yaml new file mode 100644 index 00000000..e7f5445c --- /dev/null +++ b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/.getenvoy/extension/examples/default/envoy.tmpl.yaml @@ -0,0 +1,84 @@ +# +# Example Envoy configuration. +# +admin: {{ .GetEnvoy.DefaultValue "admin" }} + +static_resources: + listeners: + - name: ingress + address: + socket_address: + address: 0.0.0.0 + port_value: 10000 + filter_chains: + - filters: + - name: envoy.filters.network.http_connection_manager + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager + stat_prefix: ingress_http + route_config: + name: local_route + virtual_hosts: + - name: local_service + domains: + - "*" + routes: + - match: + prefix: "/" + route: + cluster: mock_service + http_filters: + - name: envoy.filters.http.wasm + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm + config: + configuration: {{ .GetEnvoy.Extension.Config }} + name: {{ .GetEnvoy.Extension.Name }} + root_id: {{ .GetEnvoy.Extension.Name }} + vm_config: + vm_id: {{ .GetEnvoy.Extension.Name }} + runtime: envoy.wasm.runtime.v8 + code: {{ .GetEnvoy.Extension.Code }} + - name: envoy.filters.http.router + + - name: mock + address: + socket_address: + address: 127.0.0.1 + port_value: 10001 + filter_chains: + - filters: + - name: envoy.filters.network.http_connection_manager + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager + stat_prefix: mock + route_config: + name: local_route + virtual_hosts: + - name: mock + domains: + - "*" + routes: + - match: + prefix: "/" + direct_response: + status: 200 + body: + inline_string: "Hi from mock service!\n" + http_filters: + - name: envoy.filters.http.router + + clusters: + - name: mock_service + connect_timeout: 0.25s + type: STATIC + lb_policy: ROUND_ROBIN + load_assignment: + cluster_name: mock_service + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 10001 diff --git a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/.getenvoy/extension/examples/default/example.yaml b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/.getenvoy/extension/examples/default/example.yaml new file mode 100644 index 00000000..c45b1262 --- /dev/null +++ b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/.getenvoy/extension/examples/default/example.yaml @@ -0,0 +1,4 @@ +# +# Example of a Wasm Http Filter. +# +kind: Example diff --git a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/.getenvoy/extension/examples/default/extension.txt b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/.getenvoy/extension/examples/default/extension.txt new file mode 100644 index 00000000..0ce4dc8b --- /dev/null +++ b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/.getenvoy/extension/examples/default/extension.txt @@ -0,0 +1,2 @@ +KEY=VALUE +ANOTHER=CONFIG \ No newline at end of file diff --git a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/.getenvoy/extension/extension.yaml b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/.getenvoy/extension/extension.yaml new file mode 100644 index 00000000..70564158 --- /dev/null +++ b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/.getenvoy/extension/extension.yaml @@ -0,0 +1,14 @@ +# +# Envoy Wasm extension created with getenvoy toolkit. +# +kind: Extension + +name: mycompany.filters.http.my_http_filter + +category: envoy.filters.http +language: tinygo + +# Runtime the extension is being developed against. +runtime: + envoy: + version: standard:1.17.0 diff --git a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/expected/getenvoy_extension_run/envoy.tmpl.yaml b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/expected/getenvoy_extension_run/envoy.tmpl.yaml new file mode 100644 index 00000000..d372ac79 --- /dev/null +++ b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/expected/getenvoy_extension_run/envoy.tmpl.yaml @@ -0,0 +1,86 @@ +# +# Example Envoy configuration. +# +admin: {"accessLogPath":"/dev/null","address":{"socketAddress":{"address":"127.0.0.1","portValue":9901}}} + +static_resources: + listeners: + - name: ingress + address: + socket_address: + address: 0.0.0.0 + port_value: 10000 + filter_chains: + - filters: + - name: envoy.filters.network.http_connection_manager + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager + stat_prefix: ingress_http + route_config: + name: local_route + virtual_hosts: + - name: local_service + domains: + - "*" + routes: + - match: + prefix: "/" + route: + cluster: mock_service + http_filters: + - name: envoy.filters.http.wasm + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm + config: + configuration: + '@type': type.googleapis.com/google.protobuf.StringValue + value: "KEY=VALUE\nANOTHER=CONFIG" + name: "mycompany.filters.http.my_http_filter" + root_id: "mycompany.filters.http.my_http_filter" + vm_config: + vm_id: "mycompany.filters.http.my_http_filter" + runtime: envoy.wasm.runtime.v8 + code: {"local":{"filename":"/path/to/extension.wasm"}} + - name: envoy.filters.http.router + + - name: mock + address: + socket_address: + address: 127.0.0.1 + port_value: 10001 + filter_chains: + - filters: + - name: envoy.filters.network.http_connection_manager + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager + stat_prefix: mock + route_config: + name: local_route + virtual_hosts: + - name: mock + domains: + - "*" + routes: + - match: + prefix: "/" + direct_response: + status: 200 + body: + inline_string: "Hi from mock service!\n" + http_filters: + - name: envoy.filters.http.router + + clusters: + - name: mock_service + connect_timeout: 0.25s + type: STATIC + lb_policy: ROUND_ROBIN + load_assignment: + cluster_name: mock_service + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 10001 diff --git a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/expected/getenvoy_extension_run/example.yaml b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/expected/getenvoy_extension_run/example.yaml new file mode 100644 index 00000000..c45b1262 --- /dev/null +++ b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/expected/getenvoy_extension_run/example.yaml @@ -0,0 +1,4 @@ +# +# Example of a Wasm Http Filter. +# +kind: Example diff --git a/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/expected/getenvoy_extension_run/extension.txt b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/expected/getenvoy_extension_run/extension.txt new file mode 100644 index 00000000..0ce4dc8b --- /dev/null +++ b/pkg/extension/workspace/example/runtime/configdir/testdata/workspace8/expected/getenvoy_extension_run/extension.txt @@ -0,0 +1,2 @@ +KEY=VALUE +ANOTHER=CONFIG \ No newline at end of file diff --git a/pkg/extension/workspace/example/scaffold.go b/pkg/extension/workspace/example/scaffold.go index e23061f3..d1cd583e 100644 --- a/pkg/extension/workspace/example/scaffold.go +++ b/pkg/extension/workspace/example/scaffold.go @@ -48,7 +48,7 @@ func ScaffoldIfDefault(opts *ScaffoldOpts) error { // Scaffold generates a new example setup. func Scaffold(opts *ScaffoldOpts) error { descriptor := opts.Workspace.GetExtensionDescriptor() - factory, err := registry.Get(descriptor.Category, registry.DefaultExample) + factory, err := registry.Get(descriptor, registry.DefaultExample) if err != nil { // must be caught by unit tests panic(errors.Errorf("there is no %q example for extension category %q", registry.DefaultExample, descriptor.Category)) diff --git a/pkg/extension/workspace/model/example.go b/pkg/extension/workspace/model/example.go index 00af72f4..47698263 100644 --- a/pkg/extension/workspace/model/example.go +++ b/pkg/extension/workspace/model/example.go @@ -25,7 +25,7 @@ var ( // notice that the file is named `envoy.tmpl.yaml` rather than `envoy.tmpl.yaml` // in order to meet constraints of Envoy. exampleEnvoyBootstrapFileAltNames = []string{"envoy.tmpl.yaml", "envoy.tmpl.json"} - exampleExtensionConfigFileAltNames = []string{"extension.yaml", "extension.json", "extension"} + exampleExtensionConfigFileAltNames = []string{"extension.yaml", "extension.json", "extension.txt", "extension"} ) // NewExample returns a new Example that consists of a given set of files. diff --git a/test/e2e/getenvoy_extension_examples_test.go b/test/e2e/getenvoy_extension_examples_test.go index 56b14069..e32a9f5b 100644 --- a/test/e2e/getenvoy_extension_examples_test.go +++ b/test/e2e/getenvoy_extension_examples_test.go @@ -15,6 +15,7 @@ package e2e_test import ( + "fmt" "os" "path/filepath" @@ -22,6 +23,7 @@ import ( . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" + "github.com/tetratelabs/getenvoy/pkg/extension/workspace/config/extension" e2e "github.com/tetratelabs/getenvoy/test/e2e/util" ) @@ -74,19 +76,28 @@ Use "getenvoy extension examples add --help" for more information on how to add Expect(err).NotTo(HaveOccurred()) By("verifying stdout/stderr") + var extensionConfigFileName string + switch given.Language { + case extension.LanguageTinyGo: + extensionConfigFileName = "extension.txt" + default: + extensionConfigFileName = "extension.json" + } Expect(stdout).To(Equal(``)) Expect(stderr).To(MatchRegexp(`^\QScaffolding a new example setup:\E\n`)) Expect(stderr).To(MatchRegexp(`\Q* .getenvoy/extension/examples/default/README.md\E\n`)) Expect(stderr).To(MatchRegexp(`\Q* .getenvoy/extension/examples/default/envoy.tmpl.yaml\E\n`)) Expect(stderr).To(MatchRegexp(`\Q* .getenvoy/extension/examples/default/example.yaml\E\n`)) - Expect(stderr).To(MatchRegexp(`\Q* .getenvoy/extension/examples/default/extension.json\E\n`)) + Expect(stderr).To(MatchRegexp( + fmt.Sprintf(`\Q* .getenvoy/extension/examples/default/%s\E\n`, extensionConfigFileName))) Expect(stderr).To(MatchRegexp(`\QDone!\E\n$`)) By("verifying output directory") Expect(filepath.Join(outputDir, ".getenvoy/extension/examples/default/README.md")).To(BeAnExistingFile()) Expect(filepath.Join(outputDir, ".getenvoy/extension/examples/default/envoy.tmpl.yaml")).To(BeAnExistingFile()) Expect(filepath.Join(outputDir, ".getenvoy/extension/examples/default/example.yaml")).To(BeAnExistingFile()) - Expect(filepath.Join(outputDir, ".getenvoy/extension/examples/default/extension.json")).To(BeAnExistingFile()) + Expect(filepath.Join(outputDir, + fmt.Sprintf(".getenvoy/extension/examples/default/%s", extensionConfigFileName))).To(BeAnExistingFile()) By("running `extension examples list` command") stdout, stderr, err = GetEnvoy("extension examples list").Exec() @@ -108,7 +119,8 @@ default Expect(stderr).To(MatchRegexp(`\Q* .getenvoy/extension/examples/default/README.md\E\n`)) Expect(stderr).To(MatchRegexp(`\Q* .getenvoy/extension/examples/default/envoy.tmpl.yaml\E\n`)) Expect(stderr).To(MatchRegexp(`\Q* .getenvoy/extension/examples/default/example.yaml\E\n`)) - Expect(stderr).To(MatchRegexp(`\Q* .getenvoy/extension/examples/default/extension.json\E\n`)) + Expect(stderr).To(MatchRegexp(fmt.Sprintf( + `\Q* .getenvoy/extension/examples/default/%s\E\n`, extensionConfigFileName))) Expect(stderr).To(MatchRegexp(`\QDone!\E\n$`)) By("running `extension examples list` command")