mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Nit fixes and proper RunFns integration
This commit is contained in:
@@ -32,7 +32,7 @@ type ContainerFilter struct {
|
|||||||
// Network is the container network to use.
|
// Network is the container network to use.
|
||||||
Network string `yaml:"network,omitempty"`
|
Network string `yaml:"network,omitempty"`
|
||||||
|
|
||||||
// List of storage options that container will have mounted.
|
// StorageMounts is a list of storage options that the container will have mounted.
|
||||||
StorageMounts []StorageMount
|
StorageMounts []StorageMount
|
||||||
|
|
||||||
// Config is the API configuration for the container and passed through the
|
// Config is the API configuration for the container and passed through the
|
||||||
@@ -49,22 +49,20 @@ type ContainerFilter struct {
|
|||||||
// StorageMount represents a container's mounted storage option(s)
|
// StorageMount represents a container's mounted storage option(s)
|
||||||
type StorageMount struct {
|
type StorageMount struct {
|
||||||
// Type of mount e.g. bind mount, local volume, etc.
|
// Type of mount e.g. bind mount, local volume, etc.
|
||||||
mountType string
|
MountType string
|
||||||
|
|
||||||
// Source for the storage to be mounted.
|
// Source for the storage to be mounted.
|
||||||
// For named volumes, this is the name of the volume.
|
// For named volumes, this is the name of the volume.
|
||||||
// For anonymous volumes, this field is omitted (empty string).
|
// For anonymous volumes, this field is omitted (empty string).
|
||||||
// For bind mounts, this is the path to the file or directory on the host.
|
// For bind mounts, this is the path to the file or directory on the host.
|
||||||
src string
|
Src string
|
||||||
|
|
||||||
// The path where the file or directory is mounted in the container.
|
// The path where the file or directory is mounted in the container.
|
||||||
dstPath string
|
DstPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddStorageMount adds a mounted storage option to the Container
|
func (s *StorageMount) String() string {
|
||||||
func (c *ContainerFilter) AddStorageMount(mountType, src, dstPath string) {
|
return fmt.Sprintf("type=%s,src=%s,dst=%s:ro", s.MountType, s.Src, s.DstPath)
|
||||||
storageMount := StorageMount{mountType, src, dstPath}
|
|
||||||
c.StorageMounts = append(c.StorageMounts, storageMount)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GrepFilter implements kio.GrepFilter
|
// GrepFilter implements kio.GrepFilter
|
||||||
@@ -127,11 +125,7 @@ func (c *ContainerFilter) getArgs() []string {
|
|||||||
|
|
||||||
// TODO(joncwong): Allow StorageMount fields to have default values.
|
// TODO(joncwong): Allow StorageMount fields to have default values.
|
||||||
for _, storageMount := range c.StorageMounts {
|
for _, storageMount := range c.StorageMounts {
|
||||||
mountType := storageMount.mountType
|
args = append(args, "--mount", storageMount.String())
|
||||||
src := storageMount.src
|
|
||||||
dstPath := storageMount.dstPath
|
|
||||||
|
|
||||||
args = append(args, "--mount", fmt.Sprintf("'type=%s,src=%s,dst=%s:ro'", mountType, src, dstPath))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// export the local environment vars to the container
|
// export the local environment vars to the container
|
||||||
|
|||||||
@@ -90,9 +90,9 @@ metadata:
|
|||||||
"--network", "none",
|
"--network", "none",
|
||||||
"--user", "nobody",
|
"--user", "nobody",
|
||||||
"--security-opt=no-new-privileges",
|
"--security-opt=no-new-privileges",
|
||||||
"--mount", fmt.Sprintf("'type=%s,src=%s,dst=%s:ro'", "bind", "/mount/path", "/local/"),
|
"--mount", fmt.Sprintf("type=%s,src=%s,dst=%s:ro", "bind", "/mount/path", "/local/"),
|
||||||
"--mount", fmt.Sprintf("'type=%s,src=%s,dst=%s:ro'", "volume", "myvol", "/local/"),
|
"--mount", fmt.Sprintf("type=%s,src=%s,dst=%s:ro", "volume", "myvol", "/local/"),
|
||||||
"--mount", fmt.Sprintf("'type=%s,src=%s,dst=%s:ro'", "tmpfs", "", "/local/"),
|
"--mount", fmt.Sprintf("type=%s,src=%s,dst=%s:ro", "tmpfs", "", "/local/"),
|
||||||
}
|
}
|
||||||
for _, e := range os.Environ() {
|
for _, e := range os.Environ() {
|
||||||
// the process env
|
// the process env
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import (
|
|||||||
// RunFns runs the set of configuration functions in a local directory against
|
// RunFns runs the set of configuration functions in a local directory against
|
||||||
// the Resources in that directory
|
// the Resources in that directory
|
||||||
type RunFns struct {
|
type RunFns struct {
|
||||||
|
StorageMounts []filters.StorageMount
|
||||||
|
|
||||||
// Path is the path to the directory containing functions
|
// Path is the path to the directory containing functions
|
||||||
Path string
|
Path string
|
||||||
|
|
||||||
@@ -90,7 +92,9 @@ func (r *RunFns) init() {
|
|||||||
// if containerFilterProvider hasn't been set, use the default
|
// if containerFilterProvider hasn't been set, use the default
|
||||||
if r.containerFilterProvider == nil {
|
if r.containerFilterProvider == nil {
|
||||||
r.containerFilterProvider = func(image, path string, api *yaml.RNode) kio.Filter {
|
r.containerFilterProvider = func(image, path string, api *yaml.RNode) kio.Filter {
|
||||||
cf := &filters.ContainerFilter{Image: image, Config: api}
|
defaultMount := filters.StorageMount{}
|
||||||
|
r.StorageMounts = append(r.StorageMounts, defaultMount)
|
||||||
|
cf := &filters.ContainerFilter{Image: image, Config: api, StorageMounts: r.StorageMounts}
|
||||||
return cf
|
return cf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,10 @@ kind:
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
filter := instance.containerFilterProvider("example.com:version", "", api)
|
filter := instance.containerFilterProvider("example.com:version", "", api)
|
||||||
assert.Equal(t, &filters.ContainerFilter{Image: "example.com:version", Config: api}, filter)
|
defaultMount:= filters.StorageMount{}
|
||||||
|
mounts := []filters.StorageMount{}
|
||||||
|
mounts = append(mounts, defaultMount)
|
||||||
|
assert.Equal(t, &filters.ContainerFilter{Image: "example.com:version", Config: api, StorageMounts: mounts}, filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCmd_Execute(t *testing.T) {
|
func TestCmd_Execute(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user