diff --git a/apis/project.cattle.io/v3/schema/registry_credential.go b/apis/project.cattle.io/v3/schema/registry_credential.go index 809a2d33..fa683bc7 100644 --- a/apis/project.cattle.io/v3/schema/registry_credential.go +++ b/apis/project.cattle.io/v3/schema/registry_credential.go @@ -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 { diff --git a/apis/project.cattle.io/v3/schema/service_spec_mapper.go b/apis/project.cattle.io/v3/schema/service_spec_mapper.go index 4486c4fd..e1429bad 100644 --- a/apis/project.cattle.io/v3/schema/service_spec_mapper.go +++ b/apis/project.cattle.io/v3/schema/service_spec_mapper.go @@ -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 { diff --git a/mapper/container_ports.go b/mapper/container_ports.go index f003b848..464eef41 100644 --- a/mapper/container_ports.go +++ b/mapper/container_ports.go @@ -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 { diff --git a/mapper/container_probe.go b/mapper/container_probe.go index bfe6c899..b1ae83a2 100644 --- a/mapper/container_probe.go +++ b/mapper/container_probe.go @@ -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 { diff --git a/mapper/container_security_context.go b/mapper/container_security_context.go index f24037a3..1f5d6400 100644 --- a/mapper/container_security_context.go +++ b/mapper/container_security_context.go @@ -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 { diff --git a/mapper/container_status.go b/mapper/container_status.go index 5f827024..5459674c 100644 --- a/mapper/container_status.go +++ b/mapper/container_status.go @@ -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 { diff --git a/mapper/creator.go b/mapper/creator.go index bc8fc033..e70fc4bf 100644 --- a/mapper/creator.go +++ b/mapper/creator.go @@ -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 { diff --git a/mapper/env.go b/mapper/env.go index 2db7fe5c..e6c0d3e3 100644 --- a/mapper/env.go +++ b/mapper/env.go @@ -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 { diff --git a/mapper/init_container.go b/mapper/init_container.go index bc1881eb..ac78868e 100644 --- a/mapper/init_container.go +++ b/mapper/init_container.go @@ -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 { diff --git a/mapper/namespace.go b/mapper/namespace.go index 3b73039e..883b3485 100644 --- a/mapper/namespace.go +++ b/mapper/namespace.go @@ -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 { diff --git a/mapper/namespace_reference.go b/mapper/namespace_reference.go index 6c643f7f..f36be7bb 100644 --- a/mapper/namespace_reference.go +++ b/mapper/namespace_reference.go @@ -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 { diff --git a/mapper/node_address.go b/mapper/node_address.go index 62fa4b96..4f1794ad 100644 --- a/mapper/node_address.go +++ b/mapper/node_address.go @@ -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 { diff --git a/mapper/os_info.go b/mapper/os_info.go index 3f73e315..7e53c633 100644 --- a/mapper/os_info.go +++ b/mapper/os_info.go @@ -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 { diff --git a/mapper/persistvolumeclaim.go b/mapper/persistvolumeclaim.go index 1e4f2d15..58f28e6d 100644 --- a/mapper/persistvolumeclaim.go +++ b/mapper/persistvolumeclaim.go @@ -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 { diff --git a/mapper/scheduling.go b/mapper/scheduling.go index b0f71730..657d284b 100644 --- a/mapper/scheduling.go +++ b/mapper/scheduling.go @@ -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 { diff --git a/mapper/statefulset_spec.go b/mapper/statefulset_spec.go index 9d7f92b1..245758ec 100644 --- a/mapper/statefulset_spec.go +++ b/mapper/statefulset_spec.go @@ -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 { diff --git a/mapper/status.go b/mapper/status.go index 651ab767..c0f9fa45 100644 --- a/mapper/status.go +++ b/mapper/status.go @@ -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 { diff --git a/mapper/workload.go b/mapper/workload.go index 09605fd6..b2706443 100644 --- a/mapper/workload.go +++ b/mapper/workload.go @@ -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 { diff --git a/status/status.go b/status/status.go index fd8e4d6c..b0070a09 100644 --- a/status/status.go +++ b/status/status.go @@ -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