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:
@@ -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"},
|
||||
).
|
||||
|
51
mapper/container_security_context.go
Normal file
51
mapper/container_security_context.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user