@@ -22,6 +22,7 @@ import (
2222 "net"
2323 "reflect"
2424 "regexp"
25+ "strings"
2526
2627 corev1 "k8s.io/api/core/v1"
2728 discoveryv1 "k8s.io/api/discovery/v1"
@@ -889,13 +890,9 @@ func getComputeNodesConnectionInfo(
889890 continue
890891 }
891892 for name , item := range nodeSetGroup .Hosts {
892- namespacedName := & types.NamespacedName {
893- Name : name ,
894- Namespace : instance .GetNamespace (),
895- }
896893 if len (ipSetList .Items ) > 0 {
897894 // if we have IPSets, lets go to search for the IPs there
898- address , _ = getAddressFromIPSet (instance , & item , namespacedName , helper )
895+ address , _ = getAddressFromIPSet (instance , & item , helper )
899896 } else if _ , ok := item .Vars ["ansible_host" ]; ok {
900897 address , _ = getAddressFromAnsibleHost (& item )
901898 } else {
@@ -955,21 +952,44 @@ func getInventorySecretList(instance *telemetryv1.MetricStorage, helper *helper.
955952func getAddressFromIPSet (
956953 instance * telemetryv1.MetricStorage ,
957954 item * ansible.Host ,
958- namespacedName * types.NamespacedName ,
959955 helper * helper.Helper ,
960956) (string , discoveryv1.AddressType ) {
961957 ansibleHost := item .Vars ["ansible_host" ].(string )
958+ canonicalHostname , _ := getCanonicalHostname (item )
959+ ctlplaneDNSDomain := ""
960+
961+ domains , ok := item .Vars ["dns_search_domains" ].([]interface {})
962+ if ok {
963+ for _ , domain := range domains {
964+ domainString , ok := domain .(string )
965+ if ok && domainString [0 :8 ] == "ctlplane" {
966+ ctlplaneDNSDomain = domainString
967+ }
968+ }
969+ }
962970 // we go search for an IPSet
971+ namespacedName := & types.NamespacedName {
972+ Name : canonicalHostname ,
973+ Namespace : instance .GetNamespace (),
974+ }
963975 ipset := & infranetworkv1.IPSet {}
964976 err := helper .GetClient ().Get (context .Background (), * namespacedName , ipset )
965977 if err != nil {
966- // No IPsets found, lets try to get the HostName as last resource
967- if isValidDomain (ansibleHost ) {
968- return ansibleHost , discoveryv1 .AddressTypeFQDN
978+ // No IPsets found, lets try the shorter version of the IPSet name
979+ namespacedName := & types.NamespacedName {
980+ Name : strings .TrimSuffix (canonicalHostname , "." + ctlplaneDNSDomain ),
981+ Namespace : instance .GetNamespace (),
982+ }
983+ err = helper .GetClient ().Get (context .Background (), * namespacedName , ipset )
984+ if err != nil {
985+ // No IPsets found, lets try to get the HostName as last resource
986+ if isValidDomain (ansibleHost ) {
987+ return ansibleHost , discoveryv1 .AddressTypeFQDN
988+ }
989+ // No IP address or valid hostname found anywhere
990+ helper .GetLogger ().Info ("Did not found a valid hostname or IP address" )
991+ return "" , ""
969992 }
970- // No IP address or valid hostname found anywhere
971- helper .GetLogger ().Info ("Did not found a valid hostname or IP address" )
972- return "" , ""
973993 }
974994 // check that the reservations list is not empty
975995 if len (ipset .Status .Reservation ) > 0 {
@@ -1001,9 +1021,9 @@ func getAddressFromAnsibleHost(item *ansible.Host) (string, discoveryv1.AddressT
10011021}
10021022
10031023func getCanonicalHostname (item * ansible.Host ) (string , discoveryv1.AddressType ) {
1004- canonicalHostname := item .Vars ["canonical_hostname" ].(string )
1024+ canonicalHostname , ok := item .Vars ["canonical_hostname" ].(string )
10051025 // is it a valid hostname?
1006- if isValidDomain (canonicalHostname ) {
1026+ if ok && isValidDomain (canonicalHostname ) {
10071027 // it is an valid domain name
10081028 return canonicalHostname , discoveryv1 .AddressTypeFQDN
10091029 }
0 commit comments