diff options
author | Pawel Wieczorek <p.wieczorek2@samsung.com> | 2019-08-06 16:04:53 +0200 |
---|---|---|
committer | Pawel Wieczorek <p.wieczorek2@samsung.com> | 2019-08-07 13:54:39 +0200 |
commit | 2b5b2e0ff77608cfdfc8a949076860672b38b93f (patch) | |
tree | ca634f3efdf603b772332fc71f23e492c2a04796 /test/security/k8s/src/check/config | |
parent | 57fae769fca12e55b0890316112fa3da19803cdc (diff) |
k8s: Add support for RKE-deployed clusters
RKE is used as a Kubernetes cluster deployment method from ONAP Dublin
release. RKE cluster definition is used to get access to necessary
information.
Issue-ID: SECCOM-235
Change-Id: I588598011ea746b5f7ba327a48f1cea605e56d31
Signed-off-by: Pawel Wieczorek <p.wieczorek2@samsung.com>
Diffstat (limited to 'test/security/k8s/src/check/config')
-rw-r--r-- | test/security/k8s/src/check/config/config.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/security/k8s/src/check/config/config.go b/test/security/k8s/src/check/config/config.go new file mode 100644 index 000000000..dade6a67a --- /dev/null +++ b/test/security/k8s/src/check/config/config.go @@ -0,0 +1,59 @@ +// Package config reads relevant SSH access information from cluster config declaration. +package config + +import ( + "io/ioutil" + + v3 "github.com/rancher/types/apis/management.cattle.io/v3" + "gopkg.in/yaml.v2" +) + +const ( + defaultConfigFile = "cluster.yml" +) + +// NodeInfo contains role and SSH access information for a single cluster node. +type NodeInfo struct { + Role []string + User string + Address string + Port string + SSHKeyPath string +} + +// GetNodesInfo returns nodes' roles and SSH access information for a whole cluster. +func GetNodesInfo() ([]NodeInfo, error) { + config, err := readConfig(defaultConfigFile) + if err != nil { + return []NodeInfo{}, err + } + + cluster, err := parseConfig(config) + if err != nil { + return []NodeInfo{}, err + } + + var nodes []NodeInfo + for _, node := range cluster.Nodes { + nodes = append(nodes, NodeInfo{ + node.Role, node.User, node.Address, node.Port, node.SSHKeyPath, + }) + } + return nodes, nil +} + +func readConfig(configFile string) (string, error) { + config, err := ioutil.ReadFile(configFile) + if err != nil { + return "", err + } + return string(config), nil +} + +func parseConfig(config string) (*v3.RancherKubernetesEngineConfig, error) { + var rkeConfig v3.RancherKubernetesEngineConfig + if err := yaml.Unmarshal([]byte(config), &rkeConfig); err != nil { + return nil, err + } + return &rkeConfig, nil +} |