refactor network name in kyaml container

This commit is contained in:
Donny Xia
2020-08-24 11:40:57 -07:00
parent a2e080bf6c
commit fa15242719
5 changed files with 63 additions and 35 deletions

View File

@@ -33,6 +33,26 @@ const (
UserNobody ContainerUser = "nobody"
)
// ContainerNetworkName is a type for network name used in container
type ContainerNetworkName string
func (n *ContainerNetworkName) String() string {
return string(*n)
}
func (n *ContainerNetworkName) IsEmpty() bool {
return string(*n) == ""
}
func (n *ContainerNetworkName) Set(s string) {
*n = ContainerNetworkName(s)
}
const (
NetworkNameNone ContainerNetworkName = "none"
NetworkNameEmpty ContainerNetworkName = ""
)
// FunctionSpec defines a spec for running a function
type FunctionSpec struct {
DeferFailure bool `json:"deferFailure,omitempty" yaml:"deferFailure,omitempty"`
@@ -75,7 +95,7 @@ type ContainerNetwork struct {
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
// Name is the name of the network to use from a container
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Name ContainerNetworkName `json:"name,omitempty" yaml:"name,omitempty"`
}
// StarlarkSpec defines how to run a function as a starlark program
@@ -128,7 +148,7 @@ func GetFunctionSpec(n *yaml.RNode) *FunctionSpec {
}
if fn := getFunctionSpecFromAnnotation(n, meta); fn != nil {
fn.Container.Network.Name = ""
fn.Container.Network.Name = NetworkNameEmpty
fn.StorageMounts = []StorageMount{}
return fn
}