mirror of
https://github.com/rancher/types.git
synced 2025-04-27 18:25:05 +00:00
Update ToInternal
This commit is contained in:
parent
7c20e28b3c
commit
986f420630
@ -13,9 +13,9 @@ type RegistryCredentialMapper struct {
|
||||
func (e RegistryCredentialMapper) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
|
||||
func (e RegistryCredentialMapper) ToInternal(data map[string]interface{}) {
|
||||
func (e RegistryCredentialMapper) ToInternal(data map[string]interface{}) error {
|
||||
if data == nil {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
auth := convert.ToString(data["auth"])
|
||||
@ -25,6 +25,8 @@ func (e RegistryCredentialMapper) ToInternal(data map[string]interface{}) {
|
||||
if auth == "" && username != "" && password != "" {
|
||||
data["auth"] = base64.StdEncoding.EncodeToString([]byte(username + ":" + password))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e RegistryCredentialMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -11,9 +11,9 @@ type ServiceSpecMapper struct {
|
||||
func (e ServiceSpecMapper) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
|
||||
func (e ServiceSpecMapper) ToInternal(data map[string]interface{}) {
|
||||
func (e ServiceSpecMapper) ToInternal(data map[string]interface{}) error {
|
||||
if data == nil {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
if convert.IsEmpty(data["hostname"]) {
|
||||
@ -23,6 +23,8 @@ func (e ServiceSpecMapper) ToInternal(data map[string]interface{}) {
|
||||
data["type"] = "ExternalName"
|
||||
data["clusterIP"] = ""
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e ServiceSpecMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -1,11 +1,12 @@
|
||||
package mapper
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/rancher/norman/types"
|
||||
"github.com/rancher/norman/types/convert"
|
||||
"github.com/rancher/norman/types/mapper"
|
||||
"github.com/sirupsen/logrus"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ContainerPorts struct {
|
||||
@ -41,7 +42,7 @@ func (n ContainerPorts) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (n ContainerPorts) ToInternal(data map[string]interface{}) {
|
||||
func (n ContainerPorts) ToInternal(data map[string]interface{}) error {
|
||||
field := mapper.AnnotationField{
|
||||
Field: "ports",
|
||||
List: true,
|
||||
@ -70,8 +71,10 @@ func (n ContainerPorts) ToInternal(data map[string]interface{}) {
|
||||
|
||||
if len(ports) != 0 {
|
||||
data["ports"] = ports
|
||||
field.ToInternal(data)
|
||||
return field.ToInternal(data)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n ContainerPorts) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -16,7 +16,8 @@ func (n ContainerProbeHandler) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (n ContainerProbeHandler) ToInternal(data map[string]interface{}) {
|
||||
func (n ContainerProbeHandler) ToInternal(data map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n ContainerProbeHandler) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -12,12 +12,13 @@ type ContainerSecurityContext struct {
|
||||
func (n ContainerSecurityContext) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
|
||||
func (n ContainerSecurityContext) ToInternal(data map[string]interface{}) {
|
||||
func (n ContainerSecurityContext) ToInternal(data map[string]interface{}) error {
|
||||
if v, ok := values.GetValue(data, "securityContext"); ok && v != nil {
|
||||
sc, err := convert.EncodeToMap(v)
|
||||
if err != nil {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
if v, ok := values.GetValue(sc, "capAdd"); ok && v != nil {
|
||||
capAdd := convert.ToStringSlice(v)
|
||||
if len(capAdd) == 0 {
|
||||
@ -32,6 +33,8 @@ func (n ContainerSecurityContext) ToInternal(data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n ContainerSecurityContext) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -89,7 +89,8 @@ func (n ContainerStatus) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (n ContainerStatus) ToInternal(data map[string]interface{}) {
|
||||
func (n ContainerStatus) ToInternal(data map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n ContainerStatus) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -15,10 +15,11 @@ func (c *Creator) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Creator) ToInternal(data map[string]interface{}) {
|
||||
func (c *Creator) ToInternal(data map[string]interface{}) error {
|
||||
if c.m != nil {
|
||||
c.m.ToInternal(data)
|
||||
return c.m.ToInternal(data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Creator) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -94,9 +94,9 @@ func (e EnvironmentMapper) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (e EnvironmentMapper) ToInternal(data map[string]interface{}) {
|
||||
envVar := []map[string]interface{}{}
|
||||
envVarFrom := []map[string]interface{}{}
|
||||
func (e EnvironmentMapper) ToInternal(data map[string]interface{}) error {
|
||||
var envVar []map[string]interface{}
|
||||
var envVarFrom []map[string]interface{}
|
||||
|
||||
for key, value := range convert.ToMapInterface(data["environment"]) {
|
||||
envVar = append(envVar, map[string]interface{}{
|
||||
@ -187,6 +187,8 @@ func (e EnvironmentMapper) ToInternal(data map[string]interface{}) {
|
||||
delete(data, "environmentFrom")
|
||||
data["env"] = envVar
|
||||
data["envFrom"] = envVarFrom
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e EnvironmentMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -24,7 +24,7 @@ func (e InitContainerMapper) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (e InitContainerMapper) ToInternal(data map[string]interface{}) {
|
||||
func (e InitContainerMapper) ToInternal(data map[string]interface{}) error {
|
||||
var newContainers []interface{}
|
||||
var newInitContainers []interface{}
|
||||
|
||||
@ -41,6 +41,8 @@ func (e InitContainerMapper) ToInternal(data map[string]interface{}) {
|
||||
data["containers"] = newContainers
|
||||
data["initContainers"] = newInitContainers
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e InitContainerMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -15,10 +15,11 @@ func (n *NamespaceIDMapper) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (n *NamespaceIDMapper) ToInternal(data map[string]interface{}) {
|
||||
func (n *NamespaceIDMapper) ToInternal(data map[string]interface{}) error {
|
||||
if n.Move != nil {
|
||||
n.Move.ToInternal(data)
|
||||
return n.Move.ToInternal(data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *NamespaceIDMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -26,7 +26,7 @@ func (n *NamespaceReference) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (n *NamespaceReference) ToInternal(data map[string]interface{}) {
|
||||
func (n *NamespaceReference) ToInternal(data map[string]interface{}) error {
|
||||
for _, path := range n.fields {
|
||||
convert.Transform(data, path, func(input interface{}) interface{} {
|
||||
parts := strings.SplitN(convert.ToString(input), ":", 2)
|
||||
@ -36,6 +36,8 @@ func (n *NamespaceReference) ToInternal(data map[string]interface{}) {
|
||||
return parts[0]
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *NamespaceReference) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -27,7 +27,8 @@ func (n NodeAddressMapper) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (n NodeAddressMapper) ToInternal(data map[string]interface{}) {
|
||||
func (n NodeAddressMapper) ToInternal(data map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n NodeAddressMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
@ -44,7 +45,8 @@ func (n NodeAddressAnnotationMapper) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (n NodeAddressAnnotationMapper) ToInternal(data map[string]interface{}) {
|
||||
func (n NodeAddressAnnotationMapper) ToInternal(data map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n NodeAddressAnnotationMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -41,7 +41,8 @@ func (o OSInfo) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (o OSInfo) ToInternal(data map[string]interface{}) {
|
||||
func (o OSInfo) ToInternal(data map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o OSInfo) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -11,10 +11,11 @@ type PersistVolumeClaim struct {
|
||||
func (p PersistVolumeClaim) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
|
||||
func (p PersistVolumeClaim) ToInternal(data map[string]interface{}) {
|
||||
func (p PersistVolumeClaim) ToInternal(data map[string]interface{}) error {
|
||||
if v, ok := values.GetValue(data, "storageClassId"); ok && v == nil {
|
||||
values.PutValue(data, "", "storageClassId")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p PersistVolumeClaim) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -192,7 +192,7 @@ func StringsToNodeSelectorTerm(exprs []string) []v1.NodeSelectorTerm {
|
||||
return result
|
||||
}
|
||||
|
||||
func (s SchedulingMapper) ToInternal(data map[string]interface{}) {
|
||||
func (s SchedulingMapper) ToInternal(data map[string]interface{}) error {
|
||||
defer func() {
|
||||
delete(data, "scheduling")
|
||||
}()
|
||||
@ -208,7 +208,7 @@ func (s SchedulingMapper) ToInternal(data map[string]interface{}) {
|
||||
|
||||
if len(requireAll) == 0 && len(requireAny) == 0 && len(preferred) == 0 {
|
||||
values.PutValue(data, nil, "affinity", "nodeAffinity")
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
nodeAffinity := v1.NodeAffinity{}
|
||||
@ -253,6 +253,8 @@ func (s SchedulingMapper) ToInternal(data map[string]interface{}) {
|
||||
}
|
||||
|
||||
data["affinity"] = affinity
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func AggregateTerms(terms []v1.NodeSelectorTerm) v1.NodeSelectorTerm {
|
||||
|
@ -10,7 +10,8 @@ type StatefulSetSpecMapper struct {
|
||||
func (s StatefulSetSpecMapper) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
|
||||
func (s StatefulSetSpecMapper) ToInternal(data map[string]interface{}) {
|
||||
func (s StatefulSetSpecMapper) ToInternal(data map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s StatefulSetSpecMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -12,7 +12,8 @@ func (s Status) FromInternal(data map[string]interface{}) {
|
||||
status.Set(data)
|
||||
}
|
||||
|
||||
func (s Status) ToInternal(data map[string]interface{}) {
|
||||
func (s Status) ToInternal(data map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s Status) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -20,7 +20,8 @@ func (n WorkloadAnnotations) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (n WorkloadAnnotations) ToInternal(data map[string]interface{}) {
|
||||
func (n WorkloadAnnotations) ToInternal(data map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n WorkloadAnnotations) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
|
@ -17,6 +17,7 @@ type status struct {
|
||||
}
|
||||
|
||||
type condition struct {
|
||||
Reason string
|
||||
Type string
|
||||
Status string
|
||||
Message string
|
||||
@ -105,10 +106,10 @@ func concat(str, next string) string {
|
||||
|
||||
func Set(data map[string]interface{}) {
|
||||
genericStatus(data)
|
||||
loadBalancerSetatus(data)
|
||||
loadBalancerStatus(data)
|
||||
}
|
||||
|
||||
func loadBalancerSetatus(data map[string]interface{}) {
|
||||
func loadBalancerStatus(data map[string]interface{}) {
|
||||
if data["state"] == "active" && data["kind"] == "Service" && values.GetValueN(data, "spec", "serviceKind") == "LoadBalancer" {
|
||||
addresses, ok := values.GetSlice(data, "status", "loadBalancer", "ingress")
|
||||
if !ok || len(addresses) == 0 {
|
||||
@ -149,7 +150,7 @@ func genericStatus(data map[string]interface{}) {
|
||||
message := ""
|
||||
|
||||
for _, c := range conditions {
|
||||
if errorMapping[c.Type] && c.Status == "False" {
|
||||
if (errorMapping[c.Type] && c.Status == "False") || c.Reason == "Error" {
|
||||
error = true
|
||||
message = c.Message
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user