mirror of
https://github.com/rancher/types.git
synced 2025-06-26 21:51:33 +00:00
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
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)
|
|
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
|
|
}
|