github.com/rancher/types@v0.0.0-20220328215343-4370ff10ecd5/mapper/init_container.go (about) 1 package mapper 2 3 import ( 4 "github.com/rancher/norman/types" 5 "github.com/rancher/norman/types/convert" 6 ) 7 8 type InitContainerMapper struct { 9 } 10 11 func (e InitContainerMapper) FromInternal(data map[string]interface{}) { 12 containers, _ := data["containers"].([]interface{}) 13 14 for _, initContainer := range convert.ToMapSlice(data["initContainers"]) { 15 if initContainer == nil { 16 continue 17 } 18 initContainer["initContainer"] = true 19 containers = append(containers, initContainer) 20 } 21 22 if data != nil { 23 data["containers"] = containers 24 } 25 } 26 27 func (e InitContainerMapper) ToInternal(data map[string]interface{}) error { 28 var newContainers []interface{} 29 var newInitContainers []interface{} 30 31 for _, container := range convert.ToMapSlice(data["containers"]) { 32 if convert.ToBool(container["initContainer"]) { 33 newInitContainers = append(newInitContainers, container) 34 } else { 35 newContainers = append(newContainers, container) 36 } 37 delete(container, "initContainer") 38 } 39 40 if data != nil { 41 data["containers"] = newContainers 42 data["initContainers"] = newInitContainers 43 } 44 45 return nil 46 } 47 48 func (e InitContainerMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error { 49 delete(schema.ResourceFields, "initContainers") 50 return nil 51 }