Skip to content

Commit

Permalink
Update ToInternal
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Jul 19, 2018
1 parent 7c20e28 commit 986f420
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 32 deletions.
6 changes: 4 additions & 2 deletions apis/project.cattle.io/v3/schema/registry_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions apis/project.cattle.io/v3/schema/service_spec_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]) {
Expand All @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions mapper/container_ports.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion mapper/container_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions mapper/container_security_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion mapper/container_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions mapper/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions mapper/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion mapper/init_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand All @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions mapper/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion mapper/namespace_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions mapper/node_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion mapper/os_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion mapper/persistvolumeclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions mapper/scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}()
Expand All @@ -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{}
Expand Down Expand Up @@ -253,6 +253,8 @@ func (s SchedulingMapper) ToInternal(data map[string]interface{}) {
}

data["affinity"] = affinity

return nil
}

func AggregateTerms(terms []v1.NodeSelectorTerm) v1.NodeSelectorTerm {
Expand Down
3 changes: 2 additions & 1 deletion mapper/statefulset_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion mapper/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion mapper/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type status struct {
}

type condition struct {
Reason string
Type string
Status string
Message string
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 986f420

Please sign in to comment.