From a4448f621f77723e8d74c3630d08398ea70c3e8b Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Mon, 4 Nov 2024 15:02:56 +0100 Subject: [PATCH] feat(clustertool): extract IPs without talhelper --- clustertool/pkg/talassist/ips.go | 37 +++++++++++++++++++++++++++++++ clustertool/pkg/talassist/vars.go | 5 +++++ 2 files changed, 42 insertions(+) create mode 100644 clustertool/pkg/talassist/ips.go create mode 100644 clustertool/pkg/talassist/vars.go diff --git a/clustertool/pkg/talassist/ips.go b/clustertool/pkg/talassist/ips.go new file mode 100644 index 00000000000..019dfd531d8 --- /dev/null +++ b/clustertool/pkg/talassist/ips.go @@ -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 +} diff --git a/clustertool/pkg/talassist/vars.go b/clustertool/pkg/talassist/vars.go new file mode 100644 index 00000000000..f277e3fd3fb --- /dev/null +++ b/clustertool/pkg/talassist/vars.go @@ -0,0 +1,5 @@ +package talassist + +var ( + ipAddresses = []string{} +)