1
0
mirror of https://github.com/rancher/types.git synced 2025-06-29 06:56:50 +00:00

Merge pull request #361 from alena1108/apr10

Read external ip from annotation
This commit is contained in:
Alena Prokharchyk 2018-04-12 09:42:15 -07:00 committed by GitHub
commit a2147fd936
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -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"

View File

@ -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
}