mirror of https://github.com/helm/helm
Signed-off-by: George Jenkins <gvjenkins@gmail.com>pull/31080/head
parent
98d6d9c1ef
commit
ac0fcef641
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
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 pluginloader // import "helm.sh/helm/v4/internal/plugins/loader"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"helm.sh/helm/v4/internal/plugins"
|
||||||
|
"helm.sh/helm/v4/internal/plugins/runtimes/subprocess"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FindPlugins returns a list of YAML files that describe plugins
|
||||||
|
func FindPlugins(pluginsDirs []string, descriptor plugins.PluginDescriptor) ([]plugins.Plugin, error) {
|
||||||
|
return findPlugins(pluginsDirs, subprocessFindPlugins, makeDescriptorFilter(descriptor))
|
||||||
|
}
|
||||||
|
|
||||||
|
type findFunc func(pluginsDirs string) ([]plugins.Plugin, error)
|
||||||
|
|
||||||
|
type filterFunc func(plugins.Plugin) bool
|
||||||
|
|
||||||
|
func findPlugins(pluginsDirs []string, findFunc findFunc, filterFunc filterFunc) ([]plugins.Plugin, error) {
|
||||||
|
|
||||||
|
found := []plugins.Plugin{}
|
||||||
|
for _, pluginsDir := range pluginsDirs {
|
||||||
|
ps, err := findFunc(pluginsDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range ps {
|
||||||
|
if filterFunc(p) {
|
||||||
|
found = append(found, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return found, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertSubprocess(subs []*subprocess.Plugin) []plugins.Plugin {
|
||||||
|
ps := make([]plugins.Plugin, len(subs))
|
||||||
|
for i, r := range subs {
|
||||||
|
ps[i] = r
|
||||||
|
}
|
||||||
|
return ps
|
||||||
|
}
|
||||||
|
|
||||||
|
func subprocessFindPlugins(pluginsDir string) ([]plugins.Plugin, error) {
|
||||||
|
|
||||||
|
ps, err := subprocess.FindPlugins(pluginsDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return convertSubprocess(ps), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeDescriptorFilter(descriptor plugins.PluginDescriptor) filterFunc {
|
||||||
|
|
||||||
|
return func(p plugins.Plugin) bool {
|
||||||
|
manifest := p.Manifest()
|
||||||
|
return manifest.TypeVersion == descriptor.TypeVersion
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
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 pluginloader // import "helm.sh/helm/v4/internal/plugins/loader"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"helm.sh/helm/v4/internal/plugins"
|
||||||
|
"helm.sh/helm/v4/internal/plugins/runtimes/subprocess"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestConvertSubprocess(t *testing.T) {
|
||||||
|
sps := []*subprocess.Plugin{
|
||||||
|
{
|
||||||
|
Metadata: &subprocess.Metadata{Name: "test-plugin"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ps := convertSubprocess(sps)
|
||||||
|
|
||||||
|
require.Equal(t, len(sps), len(ps))
|
||||||
|
for index := range sps {
|
||||||
|
assert.Equal(t, sps[index], ps[index].(*subprocess.Plugin))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFindPlugins(t *testing.T) {
|
||||||
|
pluginsDirs := []string{"testdata/plugins"}
|
||||||
|
|
||||||
|
findFunc := func(pluginsDir string) ([]plugins.Plugin, error) {
|
||||||
|
return []plugins.Plugin{
|
||||||
|
&subprocess.Plugin{
|
||||||
|
Dir: filepath.Join(pluginsDir, "test-plugin"),
|
||||||
|
Metadata: &subprocess.Metadata{
|
||||||
|
Name: "test-plugin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
filterFunc := func(p plugins.Plugin) bool {
|
||||||
|
assert.Equal(t, "test-plugin", p.Manifest().Name)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
ps, err := findPlugins(pluginsDirs, findFunc, filterFunc)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
require.Len(t, ps, 1)
|
||||||
|
assert.Equal(t, "test-plugin", ps[0].Manifest().Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMakeDescriptorFilter(t *testing.T) {
|
||||||
|
descriptor := plugins.PluginDescriptor{
|
||||||
|
TypeVersion: "getter/v1",
|
||||||
|
}
|
||||||
|
|
||||||
|
filterFunc := makeDescriptorFilter(descriptor)
|
||||||
|
|
||||||
|
ps := []plugins.Plugin{
|
||||||
|
&subprocess.Plugin{
|
||||||
|
Metadata: &subprocess.Metadata{
|
||||||
|
Name: "test-plugin",
|
||||||
|
// subprocess plugins classify themselves as "cli" or "downloader" based on presence of Downloaders field
|
||||||
|
Downloaders: []subprocess.Downloaders{
|
||||||
|
{
|
||||||
|
Protocols: []string{"http"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&subprocess.Plugin{
|
||||||
|
Metadata: &subprocess.Metadata{
|
||||||
|
Name: "other-plugin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
filtered := []plugins.Plugin{}
|
||||||
|
for _, p := range ps {
|
||||||
|
if filterFunc(p) {
|
||||||
|
filtered = append(filtered, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
require.Len(t, filtered, 1)
|
||||||
|
assert.Equal(t, "test-plugin", filtered[0].Manifest().Name)
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
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 plugins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
const PluginFileName = "plugin.yaml"
|
||||||
|
|
||||||
|
type PluginDescriptor struct {
|
||||||
|
TypeVersion string
|
||||||
|
}
|
||||||
|
|
||||||
|
// plugin.yaml definition
|
||||||
|
type Manifest struct {
|
||||||
|
// APIVersion of the plugin manifest document
|
||||||
|
// Currently: 'plugins.helm.sh/v1alpha1'
|
||||||
|
APIVersion string `json:"apiVersion"`
|
||||||
|
|
||||||
|
// Author defined name, version and description of the plugin
|
||||||
|
Name string `json:"name"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
|
||||||
|
// Type/version of the plugin: 'getter/v1', 'postrenderer/v1', 'cli/v1', etc
|
||||||
|
// Describing the situation the plugin is expected to be invoked, and the correspondng message type/version used to invoke
|
||||||
|
TypeVersion string `json:"typeVersion"`
|
||||||
|
|
||||||
|
// Runtime used to execute the plugin
|
||||||
|
// subprocess, extism/v1, etc
|
||||||
|
RuntimeClass string `json:"runtimeClass"`
|
||||||
|
|
||||||
|
// Additional config associated with the plugin kind: e.g. downloader URI schemes
|
||||||
|
// (Config is intepreted by the plugin invoker)
|
||||||
|
Config map[string]any `json:"config,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Input defined the input message and parameters to be passed to the plugin
|
||||||
|
type Input struct {
|
||||||
|
// Message represents the type-elided value to be passed to the plugin
|
||||||
|
// The plugin is expected to interpret the message according to its type/version
|
||||||
|
// The message object must be JSON-serializable
|
||||||
|
Message any
|
||||||
|
}
|
||||||
|
|
||||||
|
// Input defined the output message and parameters the passed from the plugin
|
||||||
|
type Output struct {
|
||||||
|
// Message represents the type-elided value passed from the plugin
|
||||||
|
// The invoker is expected to interpret the message according to the plugins type/version
|
||||||
|
Message any
|
||||||
|
}
|
||||||
|
|
||||||
|
// Plugin defines the "invokable" interface for a plugin, as well a getter for the plugin's describing manifest
|
||||||
|
// The invoke method can be thought of request/response message passing between the plugin invoker and the plugin itself
|
||||||
|
type Plugin interface {
|
||||||
|
Manifest() Manifest
|
||||||
|
Invoke(ctx context.Context, input *Input) (*Output, error)
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
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 subprocess // import "helm.sh/helm/v4/internal/plugins/runtimes/subprocess"
|
||||||
|
|
||||||
|
func IsDownloader(p *Plugin) bool {
|
||||||
|
if p.Metadata == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(p.Metadata.Downloaders) > 0
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
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 subprocess // import "helm.sh/helm/v4/internal/plugins/runtimes/subprocess"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIsDownloader(t *testing.T) {
|
||||||
|
|
||||||
|
testCases := map[string]struct {
|
||||||
|
Plugin Plugin
|
||||||
|
Want bool
|
||||||
|
}{
|
||||||
|
"nil metadata": {
|
||||||
|
Plugin: Plugin{
|
||||||
|
Metadata: nil,
|
||||||
|
},
|
||||||
|
Want: false,
|
||||||
|
},
|
||||||
|
"no downloaders": {
|
||||||
|
Plugin: Plugin{
|
||||||
|
Metadata: &Metadata{
|
||||||
|
Downloaders: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Want: false,
|
||||||
|
},
|
||||||
|
"downloader": {
|
||||||
|
Plugin: Plugin{
|
||||||
|
Metadata: &Metadata{
|
||||||
|
Downloaders: []Downloaders{
|
||||||
|
{
|
||||||
|
Protocols: []string{"test"},
|
||||||
|
Command: "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Want: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for name, tc := range testCases {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
got := IsDownloader(&tc.Plugin)
|
||||||
|
assert.Equal(t, got, tc.Want)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
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 schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO: can we generate these plugin input/outputs?
|
||||||
|
|
||||||
|
type GetterOptionsV1 struct {
|
||||||
|
URL string
|
||||||
|
Cert []byte
|
||||||
|
Key []byte
|
||||||
|
CA []byte
|
||||||
|
UNTar bool
|
||||||
|
InsecureSkipVerifyTLS bool
|
||||||
|
PlainHTTP bool
|
||||||
|
AcceptHeader string
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
|
PassCredentialsAll bool
|
||||||
|
UserAgent string
|
||||||
|
Version string
|
||||||
|
Timeout time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetterInputV1 struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
Options GetterOptionsV1 `json:"options"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetterOutputV1 struct {
|
||||||
|
Data *bytes.Buffer `json:"data"`
|
||||||
|
}
|
Loading…
Reference in new issue