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:
commit
a2147fd936
@ -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"
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user