mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 09:02:53 +00:00
Change network to a boolean
This commit is contained in:
@@ -154,13 +154,17 @@ func (c *Filter) setupExec() {
|
||||
|
||||
// getArgs returns the command + args to run to spawn the container
|
||||
func (c *Filter) getCommand() (string, []string) {
|
||||
network := runtimeutil.NetworkNameNone
|
||||
if c.ContainerSpec.Network {
|
||||
network = runtimeutil.NetworkNameHost
|
||||
}
|
||||
// run the container using docker. this is simpler than using the docker
|
||||
// libraries, and ensures things like auth work the same as if the container
|
||||
// was run from the cli.
|
||||
args := []string{"run",
|
||||
"--rm", // delete the container afterward
|
||||
"-i", "-a", "STDIN", "-a", "STDOUT", "-a", "STDERR", // attach stdin, stdout, stderr
|
||||
"--network", string(c.ContainerSpec.Network.Name),
|
||||
"--network", string(network),
|
||||
|
||||
// added security options
|
||||
"--user", c.User.String(),
|
||||
@@ -186,10 +190,5 @@ func NewContainer(spec runtimeutil.ContainerSpec) Filter {
|
||||
f.ContainerSpec.User = runtimeutil.UserNobody
|
||||
}
|
||||
|
||||
// default network name is none
|
||||
if f.ContainerSpec.Network.Name == "" {
|
||||
f.ContainerSpec.Network.Name = runtimeutil.NetworkNameNone
|
||||
}
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
@@ -55,17 +55,15 @@ metadata:
|
||||
"run",
|
||||
"--rm",
|
||||
"-i", "-a", "STDIN", "-a", "STDOUT", "-a", "STDERR",
|
||||
"--network", "test-1",
|
||||
"--network", "host",
|
||||
"--user", "nobody",
|
||||
"--security-opt=no-new-privileges",
|
||||
},
|
||||
instance: NewContainer(
|
||||
runtimeutil.ContainerSpec{
|
||||
Image: "example.com:version",
|
||||
Network: runtimeutil.ContainerNetwork{
|
||||
Name: "test-1",
|
||||
},
|
||||
User: "nobody",
|
||||
Image: "example.com:version",
|
||||
Network: true,
|
||||
User: "nobody",
|
||||
},
|
||||
),
|
||||
},
|
||||
|
||||
@@ -38,8 +38,8 @@ const (
|
||||
type ContainerNetworkName string
|
||||
|
||||
const (
|
||||
NetworkNameNone ContainerNetworkName = "none"
|
||||
NetworkNameEmpty ContainerNetworkName = ""
|
||||
NetworkNameNone ContainerNetworkName = "none"
|
||||
NetworkNameHost ContainerNetworkName = "host"
|
||||
)
|
||||
const defaultEnvValue string = "true"
|
||||
|
||||
@@ -166,7 +166,7 @@ type ContainerSpec struct {
|
||||
Image string `json:"image,omitempty" yaml:"image,omitempty"`
|
||||
|
||||
// Network defines network specific configuration
|
||||
Network ContainerNetwork `json:"network,omitempty" yaml:"network,omitempty"`
|
||||
Network bool `json:"network,omitempty" yaml:"network,omitempty"`
|
||||
|
||||
// Mounts are the storage or directories to mount into the container
|
||||
StorageMounts []StorageMount `json:"mounts,omitempty" yaml:"mounts,omitempty"`
|
||||
@@ -178,15 +178,6 @@ type ContainerSpec struct {
|
||||
Env []string `json:"envs,omitempty" yaml:"envs,omitempty"`
|
||||
}
|
||||
|
||||
// ContainerNetwork
|
||||
type ContainerNetwork struct {
|
||||
// Required specifies that function requires a network
|
||||
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
|
||||
|
||||
// Name is the name of the network to use from a container
|
||||
Name ContainerNetworkName `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
}
|
||||
|
||||
// StarlarkSpec defines how to run a function as a starlark program
|
||||
type StarlarkSpec struct {
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
@@ -237,7 +228,6 @@ func GetFunctionSpec(n *yaml.RNode) *FunctionSpec {
|
||||
}
|
||||
|
||||
if fn := getFunctionSpecFromAnnotation(n, meta); fn != nil {
|
||||
fn.Container.Network.Name = NetworkNameEmpty
|
||||
fn.StorageMounts = []StorageMount{}
|
||||
return fn
|
||||
}
|
||||
|
||||
@@ -1208,14 +1208,12 @@ metadata:
|
||||
config.kubernetes.io/function: |-
|
||||
container:
|
||||
image: foo:v1.0.0
|
||||
network:
|
||||
required: true
|
||||
network: true
|
||||
`,
|
||||
expectedFn: `
|
||||
container:
|
||||
image: foo:v1.0.0
|
||||
network:
|
||||
required: true
|
||||
network: true
|
||||
`,
|
||||
},
|
||||
|
||||
@@ -1324,8 +1322,7 @@ metadata:
|
||||
configFn:
|
||||
container:
|
||||
image: gcr.io/kustomize-functions/example-tshirt:v0.1.0
|
||||
network:
|
||||
required: true
|
||||
network: true
|
||||
`,
|
||||
required: true,
|
||||
},
|
||||
@@ -1337,8 +1334,7 @@ metadata:
|
||||
configFn:
|
||||
container:
|
||||
image: gcr.io/kustomize-functions/example-tshirt:v0.1.0
|
||||
network:
|
||||
required: false
|
||||
network: false
|
||||
`,
|
||||
required: false,
|
||||
},
|
||||
@@ -1363,8 +1359,7 @@ metadata:
|
||||
config.kubernetes.io/function: |
|
||||
container:
|
||||
image: gcr.io/kustomize-functions/example-tshirt:v0.1.0
|
||||
network:
|
||||
required: true
|
||||
network: true
|
||||
`,
|
||||
required: true,
|
||||
},
|
||||
@@ -1376,7 +1371,7 @@ metadata:
|
||||
return
|
||||
}
|
||||
fn := GetFunctionSpec(cfg)
|
||||
assert.Equal(t, tc.required, fn.Container.Network.Required)
|
||||
assert.Equal(t, tc.required, fn.Container.Network)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user