@@ -25,6 +25,7 @@ import (
25
25
26
26
"k8s.io/klog/v2"
27
27
api "k8s.io/kops/pkg/apis/kops/v1alpha2"
28
+ "k8s.io/kops/pkg/cloudinstances"
28
29
"sigs.k8s.io/kubetest2/pkg/exec"
29
30
)
30
31
@@ -61,6 +62,28 @@ func GetCluster(kopsBinary, clusterName string, env []string) (*api.Cluster, err
61
62
return cluster , nil
62
63
}
63
64
65
+ // GetCluster will retrieve the specified Cluster from the state store.
66
+ func GetInstances (kopsBinary , clusterName string , env []string ) ([]* cloudinstances.CloudInstance , error ) {
67
+ args := []string {
68
+ kopsBinary , "get" , "instances" , "--name" , clusterName , "-ojson" ,
69
+ }
70
+ c := exec .Command (args [0 ], args [1 :]... )
71
+ c .SetEnv (env ... )
72
+ var stdout bytes.Buffer
73
+ c .SetStdout (& stdout )
74
+ var stderr bytes.Buffer
75
+ c .SetStderr (& stderr )
76
+ if err := c .Run (); err != nil {
77
+ klog .Warningf ("failed to run %s; stderr=%s" , strings .Join (args , " " ), stderr .String ())
78
+ return nil , fmt .Errorf ("error querying instances from %s: %w" , strings .Join (args , " " ), err )
79
+ }
80
+ var instances []* cloudinstances.CloudInstance
81
+ if err := json .Unmarshal (stdout .Bytes (), & instances ); err != nil {
82
+ return nil , fmt .Errorf ("error parsing instance groups json: %w" , err )
83
+ }
84
+ return instances , nil
85
+ }
86
+
64
87
// GetInstanceGroups will retrieve the instance groups for the specified Cluster from the state store.
65
88
func GetInstanceGroups (kopsBinary , clusterName string , env []string ) ([]* api.InstanceGroup , error ) {
66
89
args := []string {
0 commit comments