1
0
mirror of https://github.com/rancher/types.git synced 2025-04-30 11:23:19 +00:00
types/mapper/init_container.go

52 lines
1.2 KiB
Go
Raw Permalink 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"
)
type InitContainerMapper struct {
}
func (e InitContainerMapper) FromInternal(data map[string]interface{}) {
containers, _ := data["containers"].([]interface{})
for _, initContainer := range convert.ToMapSlice(data["initContainers"]) {
if initContainer == nil {
continue
}
initContainer["initContainer"] = true
containers = append(containers, initContainer)
}
2017-11-28 21:32:17 +00:00
if data != nil {
data["containers"] = containers
}
2017-11-12 04:14:05 +00:00
}
2018-06-05 04:44:54 +00:00
func (e InitContainerMapper) ToInternal(data map[string]interface{}) error {
var newContainers []interface{}
var newInitContainers []interface{}
2017-11-12 04:14:05 +00:00
2017-11-28 21:32:17 +00:00
for _, container := range convert.ToMapSlice(data["containers"]) {
2017-11-12 04:14:05 +00:00
if convert.ToBool(container["initContainer"]) {
newInitContainers = append(newInitContainers, container)
} else {
newContainers = append(newContainers, container)
}
delete(container, "initContainer")
}
2017-11-28 21:32:17 +00:00
if data != nil {
data["containers"] = newContainers
data["initContainers"] = newInitContainers
}
2018-06-05 04:44:54 +00:00
return nil
2017-11-12 04:14:05 +00:00
}
func (e InitContainerMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
delete(schema.ResourceFields, "initContainers")
return nil
}