mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Add local volume support to container filters
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func GetDocsRunner() *DocsRunner {
|
||||
r := &DocsRunner{}
|
||||
c := &cobra.Command{
|
||||
Use: "docs [API_TYPE]",
|
||||
Short: "Print out documentation for API resource",
|
||||
Long: `Print out documentation for API resource
|
||||
|
||||
The Docs command reads a JSON schema from the Kustomize API and outputs a pretiffied version of the documentation.
|
||||
|
||||
TODO:
|
||||
<INSERT MORE DOCUMENTATION HERE>
|
||||
|
||||
For information on merge rules, run:
|
||||
|
||||
kyaml help docs
|
||||
`,
|
||||
Example: `kyaml docs kustomization`,
|
||||
PreRunE: r.preRunE,
|
||||
RunE: r.runE,
|
||||
}
|
||||
r.Command = c
|
||||
r.Command.Flags().StringVar(&r.apiType, "api-type", "",
|
||||
"API type to print out")
|
||||
return r
|
||||
}
|
||||
|
||||
// DocsCommand ...
|
||||
func DocsCommand() *cobra.Command {
|
||||
return GetDocsRunner().Command
|
||||
}
|
||||
|
||||
// DocsRunner contains the run function
|
||||
type DocsRunner struct {
|
||||
Command *cobra.Command
|
||||
apiType string
|
||||
}
|
||||
|
||||
func (r *DocsRunner) preRunE(c *cobra.Command, args []string) error {
|
||||
fmt.Println("Docs pre run. :)")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *DocsRunner) runE(c *cobra.Command, args []string) error {
|
||||
fmt.Println("Docs actual run. :-)")
|
||||
fmt.Println(args[0])
|
||||
return nil
|
||||
}
|
||||
@@ -33,6 +33,9 @@ type ContainerFilter struct {
|
||||
// Network is the container network to use.
|
||||
Network string `yaml:"network,omitempty"`
|
||||
|
||||
// LocalVolume is the volume the container uses.
|
||||
LocalVolume string `yaml:"localVolume,omitempty"`
|
||||
|
||||
// Config is the API configuration for the container and passed through the
|
||||
// API_CONFIG env var to the container.
|
||||
// Typically a Kubernetes style Resource Config.
|
||||
@@ -110,6 +113,10 @@ func (c *ContainerFilter) getArgs() []string {
|
||||
args = append(args, "-v", fmt.Sprintf("%s:/local/:ro", c.mountPath))
|
||||
}
|
||||
|
||||
if c.LocalVolume != "" {
|
||||
args = append(args, "--mount", fmt.Sprintf("'type=volume,src=%s,dst=/local/'", c.LocalVolume))
|
||||
}
|
||||
|
||||
// export the local environment vars to the container
|
||||
for _, pair := range os.Environ() {
|
||||
args = append(args, "-e", strings.Split(pair, "=")[0])
|
||||
|
||||
@@ -99,6 +99,42 @@ metadata:
|
||||
assert.Equal(t, expected, cmd.Args)
|
||||
}
|
||||
|
||||
func TestFilter_command_LocalVolume(t *testing.T) {
|
||||
cfg, err := yaml.Parse(`apiversion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: foo
|
||||
`)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
instance := &ContainerFilter{
|
||||
Image: "example.com:version",
|
||||
Config: cfg,
|
||||
LocalVolume: "myvol",
|
||||
}
|
||||
cmd, err := instance.getCommand()
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
expected := []string{
|
||||
"docker", "run",
|
||||
"--rm",
|
||||
"-i", "-a", "STDIN", "-a", "STDOUT", "-a", "STDERR",
|
||||
"--network", "none",
|
||||
"--user", "nobody",
|
||||
"--security-opt=no-new-privileges",
|
||||
"--mount", fmt.Sprintf("'type=volume,src=%s,dst=/local/'", "myvol"),
|
||||
}
|
||||
for _, e := range os.Environ() {
|
||||
// the process env
|
||||
expected = append(expected, "-e", strings.Split(e, "=")[0])
|
||||
}
|
||||
expected = append(expected, "example.com:version")
|
||||
assert.Equal(t, expected, cmd.Args)
|
||||
}
|
||||
|
||||
func TestFilter_command_network(t *testing.T) {
|
||||
cfg, err := yaml.Parse(`apiversion: apps/v1
|
||||
kind: Deployment
|
||||
|
||||
Reference in New Issue
Block a user