2017-11-14 21:45:08 -07:00
|
|
|
package mapper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/rancher/norman/types"
|
2017-11-29 14:38:39 -07:00
|
|
|
"github.com/rancher/norman/types/values"
|
2017-11-14 21:45:08 -07:00
|
|
|
)
|
|
|
|
|
2018-04-10 16:11:27 -07:00
|
|
|
const (
|
|
|
|
extIPField = "externalIpAddress"
|
|
|
|
)
|
|
|
|
|
2017-11-14 21:45:08 -07:00
|
|
|
type NodeAddressMapper struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n NodeAddressMapper) FromInternal(data map[string]interface{}) {
|
2017-11-29 14:38:39 -07:00
|
|
|
addresses, _ := values.GetSlice(data, "addresses")
|
2017-11-14 21:45:08 -07:00
|
|
|
for _, address := range addresses {
|
|
|
|
t := address["type"]
|
|
|
|
a := address["address"]
|
|
|
|
if t == "InternalIP" {
|
2017-12-29 15:20:33 -07:00
|
|
|
data["ipAddress"] = a
|
2018-04-03 14:00:43 -07:00
|
|
|
} else if t == "ExternalIP" {
|
2018-04-10 16:11:27 -07:00
|
|
|
data[extIPField] = a
|
2017-11-14 21:45:08 -07:00
|
|
|
} else if t == "Hostname" {
|
|
|
|
data["hostname"] = a
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n NodeAddressMapper) ToInternal(data map[string]interface{}) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n NodeAddressMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
|
|
|
return nil
|
|
|
|
}
|
2018-04-10 16:11:27 -07:00
|
|
|
|
|
|
|
type NodeAddressAnnotationMapper struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n NodeAddressAnnotationMapper) FromInternal(data map[string]interface{}) {
|
|
|
|
externalIP, ok := values.GetValue(data, "status", "nodeAnnotations", "rke.cattle.io/external-ip")
|
|
|
|
if ok {
|
|
|
|
data[extIPField] = externalIP
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n NodeAddressAnnotationMapper) ToInternal(data map[string]interface{}) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n NodeAddressAnnotationMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
|
|
|
return nil
|
|
|
|
}
|