1
0
mirror of https://github.com/rancher/types.git synced 2025-09-18 16:10:58 +00:00

Remove capAdd/capDrop if empty

This commit is contained in:
Alena Prokharchyk
2018-05-25 16:15:20 -07:00
parent 3482812846
commit 01dd042b75
2 changed files with 52 additions and 0 deletions

View File

@@ -448,6 +448,7 @@ func podTypes(schemas *types.Schemas) *types.Schemas {
m.Move{From: "command", To: "entrypoint"},
m.Move{From: "args", To: "command"},
mapper.EnvironmentMapper{},
mapper.ContainerSecurityContext{},
&m.Embed{Field: "securityContext"},
&m.Embed{Field: "lifecycle"},
).

View File

@@ -0,0 +1,51 @@
package mapper
import (
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/norman/types/values"
)
type ContainerSecurityContext struct {
}
func (n ContainerSecurityContext) FromInternal(data map[string]interface{}) {
}
func (n ContainerSecurityContext) ToInternal(data map[string]interface{}) {
if v, ok := values.GetValue(data, "securityContext"); ok && v != nil {
sc, err := convert.EncodeToMap(v)
if err != nil {
return
}
if len(sc) > 2 {
return
}
found := false
if v, ok := values.GetValue(sc, "capAdd"); ok && v != nil {
capAdd := convert.ToStringSlice(v)
if len(capAdd) == 0 {
found = true
}
}
if found {
found = false
} else {
return
}
if v, ok := values.GetValue(sc, "capDrop"); ok && v != nil {
capAdd := convert.ToStringSlice(v)
if len(capAdd) == 0 {
found = true
}
}
if found {
values.RemoveValue(data, "securityContext")
}
}
}
func (n ContainerSecurityContext) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
return nil
}