1
0
mirror of https://github.com/rancher/types.git synced 2025-06-27 05:56:50 +00:00
types/mapper/namespaces.go

49 lines
1.0 KiB
Go
Raw Normal View History

2017-11-12 04:14:05 +00:00
package mapper
import (
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
)
var namespaceMapping = map[string]string{
"hostNetwork": "net",
"hostIPC": "ipc",
"hostPID": "pid",
}
type NamespaceMapper struct {
}
func (e NamespaceMapper) FromInternal(data map[string]interface{}) {
for name, friendlyName := range namespaceMapping {
value := convert.ToBool(data[name])
if value {
data[friendlyName] = "host"
}
delete(data, name)
}
}
func (e NamespaceMapper) ToInternal(data map[string]interface{}) {
for name, friendlyName := range namespaceMapping {
obj, ok := data[friendlyName]
if !ok {
continue
}
value := convert.ToString(obj)
2017-11-12 04:14:05 +00:00
if value == "host" {
data[name] = true
} else {
data[name] = false
}
delete(data, friendlyName)
}
}
func (e NamespaceMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
delete(schema.ResourceFields, "hostNetwork")
delete(schema.ResourceFields, "hostPID")
delete(schema.ResourceFields, "hostIPC")
return nil
}