mirror of https://github.com/helm/helm
Merge cb98e56498 into f05c21b6b6
commit
8f554707df
@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright The Helm Authors.
|
||||
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 plugin
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type RawPlugin struct {
|
||||
Metadata Metadata
|
||||
Dir string
|
||||
}
|
||||
|
||||
func BuildLoadExtismPlugin(t *testing.T, dir string) RawPlugin {
|
||||
t.Helper()
|
||||
|
||||
pluginFile := filepath.Join(dir, PluginFileName)
|
||||
|
||||
metadataData, err := os.ReadFile(pluginFile)
|
||||
require.NoError(t, err)
|
||||
|
||||
m, err := loadMetadata(metadataData)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "extism/v1", m.Runtime, "expected plugin runtime to be extism/v1")
|
||||
|
||||
cmd := exec.Command("make", "-C", dir)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
require.NoError(t, cmd.Run(), "failed to build plugin in %q", dir)
|
||||
|
||||
return RawPlugin{
|
||||
Metadata: *m,
|
||||
Dir: dir,
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
plugin.wasm
|
||||
@ -0,0 +1,11 @@
|
||||
.DEFAULT: build
|
||||
.PHONY: build test vet
|
||||
|
||||
.PHONY: plugin.wasm
|
||||
plugin.wasm:
|
||||
GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o plugin.wasm .
|
||||
|
||||
build: plugin.wasm
|
||||
|
||||
vet:
|
||||
GOOS=wasip1 GOARCH=wasm go vet ./...
|
||||
@ -0,0 +1,10 @@
|
||||
module helm.sh/helm/v4/pkg/postrenderer/testdata/plugins/postrenderer-v1-extism
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
github.com/extism/go-pdk v1.1.3
|
||||
helm.sh/helm/v4 v4.0.0
|
||||
)
|
||||
|
||||
replace helm.sh/helm/v4 => ../../../../..
|
||||
@ -0,0 +1,2 @@
|
||||
github.com/extism/go-pdk v1.1.3 h1:hfViMPWrqjN6u67cIYRALZTZLk/enSPpNKa+rZ9X2SQ=
|
||||
github.com/extism/go-pdk v1.1.3/go.mod h1:Gz+LIU/YCKnKXhgge8yo5Yu1F/lbv7KtKFkiCSzW/P4=
|
||||
@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
pdk "github.com/extism/go-pdk"
|
||||
|
||||
"helm.sh/helm/v4/internal/plugin/schema"
|
||||
)
|
||||
|
||||
func RunPlugin() error {
|
||||
var input schema.InputMessagePostRendererV1
|
||||
|
||||
if err := pdk.InputJSON(&input); err != nil {
|
||||
return fmt.Errorf("failed to parse input json: %w", err)
|
||||
}
|
||||
|
||||
replacement := "BARTEST"
|
||||
|
||||
if len(input.ExtraArgs) > 0 {
|
||||
replacement = strings.Join(input.ExtraArgs, " ")
|
||||
}
|
||||
|
||||
updatedManifests := strings.ReplaceAll(input.Manifests, "FOOTEST", replacement)
|
||||
|
||||
result := schema.OutputMessagePostRendererV1{
|
||||
Manifests: updatedManifests,
|
||||
}
|
||||
|
||||
if err := pdk.OutputJSON(&result); err != nil {
|
||||
return fmt.Errorf("failed to write output json: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
//go:wasmexport helm_plugin_main
|
||||
func HelmChartRenderer() uint64 {
|
||||
pdk.Log(pdk.LogDebug, "running postrenderer-v1-extism plugin")
|
||||
|
||||
if err := RunPlugin(); err != nil {
|
||||
pdk.Log(pdk.LogError, err.Error())
|
||||
pdk.SetError(err)
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func main() {}
|
||||
@ -0,0 +1,5 @@
|
||||
name: extismv1-str-replace
|
||||
version: 1.2.3
|
||||
type: postrenderer/v1
|
||||
apiVersion: v1
|
||||
runtime: extism/v1
|
||||
Loading…
Reference in new issue