feat(clustertool): extract IPs without talhelper

This commit is contained in:
Kjeld Schouten
2024-11-04 15:34:07 +01:00
parent 842d27e186
commit a4448f621f
2 changed files with 42 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
package talassist
import (
"io/ioutil"
"github.com/truecharts/public/clustertool/pkg/helper"
"gopkg.in/yaml.v3"
)
// NodeIPConfig represents a simplified YAML structure to only parse node IP addresses
type NodeIPConfig struct {
Nodes []struct {
IPAddress string `yaml:"ipAddress"`
} `yaml:"nodes"`
}
// LoadNodeIPs loads the list of IP addresses in nodes[].ipAddress from talconfig.yaml
func LoadNodeIPs() error {
// Read the YAML file
data, err := ioutil.ReadFile(helper.TalConfigFile)
if err != nil {
return err
}
// Unmarshal only the IP addresses from the YAML
var config NodeIPConfig
if err := yaml.Unmarshal(data, &config); err != nil {
return err
}
// Extract the IP addresses into a list
for _, node := range config.Nodes {
ipAddresses = append(ipAddresses, node.IPAddress)
}
return nil
}
+5
View File
@@ -0,0 +1,5 @@
package talassist
var (
ipAddresses = []string{}
)