github.com/rancher/types@v0.0.0-20220328215343-4370ff10ecd5/mapper/node_address.go (about) 1 package mapper 2 3 import ( 4 "github.com/rancher/norman/types" 5 "github.com/rancher/norman/types/values" 6 ) 7 8 const ( 9 extIPField = "externalIpAddress" 10 ) 11 12 type NodeAddressMapper struct { 13 } 14 15 func (n NodeAddressMapper) FromInternal(data map[string]interface{}) { 16 addresses, _ := values.GetSlice(data, "addresses") 17 for _, address := range addresses { 18 t := address["type"] 19 a := address["address"] 20 if t == "InternalIP" { 21 data["ipAddress"] = a 22 } else if t == "ExternalIP" { 23 data[extIPField] = a 24 } else if t == "Hostname" { 25 data["hostname"] = a 26 } 27 } 28 } 29 30 func (n NodeAddressMapper) ToInternal(data map[string]interface{}) error { 31 return nil 32 } 33 34 func (n NodeAddressMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error { 35 return nil 36 } 37 38 type NodeAddressAnnotationMapper struct { 39 } 40 41 func (n NodeAddressAnnotationMapper) FromInternal(data map[string]interface{}) { 42 externalIP, ok := values.GetValue(data, "status", "nodeAnnotations", "rke.cattle.io/external-ip") 43 if ok { 44 data[extIPField] = externalIP 45 } 46 } 47 48 func (n NodeAddressAnnotationMapper) ToInternal(data map[string]interface{}) error { 49 return nil 50 } 51 52 func (n NodeAddressAnnotationMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error { 53 return nil 54 }