diff --git a/apis/management.cattle.io/v3/schema/schema.go b/apis/management.cattle.io/v3/schema/schema.go index b7802bb8..cc541069 100644 --- a/apis/management.cattle.io/v3/schema/schema.go +++ b/apis/management.cattle.io/v3/schema/schema.go @@ -95,6 +95,8 @@ func nativeNodeTypes(schemas *types.Schemas) *types.Schemas { "taints": "ru", "unschedulable": "ru", }}). + AddMapperForType(&Version, v1.Node{}, + &mapper.NodeAddressAnnotationMapper{}). MustImportAndCustomize(&Version, v1.NodeSpec{}, func(schema *types.Schema) { schema.CodeName = "InternalNodeSpec" schema.CodeNamePlural = "InternalNodeSpecs" diff --git a/mapper/node_address.go b/mapper/node_address.go index 81f92102..62fa4b96 100644 --- a/mapper/node_address.go +++ b/mapper/node_address.go @@ -5,6 +5,10 @@ import ( "github.com/rancher/norman/types/values" ) +const ( + extIPField = "externalIpAddress" +) + type NodeAddressMapper struct { } @@ -16,7 +20,7 @@ func (n NodeAddressMapper) FromInternal(data map[string]interface{}) { if t == "InternalIP" { data["ipAddress"] = a } else if t == "ExternalIP" { - data["externalIpAddress"] = a + data[extIPField] = a } else if t == "Hostname" { data["hostname"] = a } @@ -29,3 +33,20 @@ func (n NodeAddressMapper) ToInternal(data map[string]interface{}) { func (n NodeAddressMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error { return nil } + +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 +}