Change network to a boolean

This commit is contained in:
Donny Xia
2020-09-16 16:20:50 -07:00
parent 76bae738a0
commit f6c06b58ef
6 changed files with 129 additions and 43 deletions

View File

@@ -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
}

View File

@@ -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)
}
}