From c99fa586563285d35534ebfa86df1f1930d378ed Mon Sep 17 00:00:00 2001 From: Fiona Waters Date: Tue, 12 Dec 2023 12:31:45 +0000 Subject: [PATCH] Adding node pool functions --- support/environment.go | 6 +++--- support/ocm.go | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/support/environment.go b/support/environment.go index 10418f8..e39d397 100644 --- a/support/environment.go +++ b/support/environment.go @@ -37,7 +37,7 @@ const ( InstaScaleOcmSecret = "INSTASCALE_OCM_SECRET" // Cluster ID for OSD cluster used in tests, used for testing InstaScale - OsdClusterID = "CLUSTERID" + ClusterID = "CLUSTERID" // Type of cluster test is run on ClusterTypeEnvVar = "CLUSTER_TYPE" @@ -77,8 +77,8 @@ func GetInstascaleOcmSecret() (string, string) { return res[0], res[1] } -func GetOsdClusterId() (string, bool) { - return os.LookupEnv(OsdClusterID) +func GetClusterId() (string, bool) { + return os.LookupEnv(ClusterID) } func GetClusterType(t Test) ClusterType { diff --git a/support/ocm.go b/support/ocm.go index 0618fa1..2e05b8f 100644 --- a/support/ocm.go +++ b/support/ocm.go @@ -54,7 +54,7 @@ func buildOCMConnection(secret string) (*ocmsdk.Connection, error) { } func MachinePools(t Test, connection *ocmsdk.Connection) func(g gomega.Gomega) []*cmv1.MachinePool { - osdClusterId, found := GetOsdClusterId() + osdClusterId, found := GetClusterId() t.Expect(found).To(gomega.BeTrue(), "OSD cluster id not found, please configure environment properly") return func(g gomega.Gomega) []*cmv1.MachinePool { @@ -76,3 +76,23 @@ func MachinePoolId(machinePool *cmv1.MachinePool) string { func MachinePoolLabels(machinePool *cmv1.MachinePool) map[string]string { return machinePool.Labels() } + +func NodePools(t Test, connection *ocmsdk.Connection) func(g gomega.Gomega) []*cmv1.NodePool { + clusterId, found := GetClusterId() + t.Expect(found).To(gomega.BeTrue(), "Cluster id not found, please configure environment properly") + + return func(g gomega.Gomega) []*cmv1.NodePool { + nodePoolsListResponse, err := connection.ClustersMgmt().V1().Clusters().Cluster(clusterId).NodePools().List().Send() + g.Expect(err).NotTo(gomega.HaveOccurred()) + return nodePoolsListResponse.Items().Slice() + } +} + +func GetNodePools(t Test, connection *ocmsdk.Connection) []*cmv1.NodePool { + t.T().Helper() + return NodePools(t, connection)(t) +} + +func NodePoolLabels(nodePool *cmv1.NodePool) map[string]string { + return nodePool.Labels() +}