@@ -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
@@ -64,6 +65,28 @@ func GetCluster(kopsBinary, clusterName string, env []string, full bool) (*api.C
64
65
return cluster , nil
65
66
}
66
67
68
+ // GetCluster will retrieve the specified Cluster from the state store.
69
+ func GetInstances (kopsBinary , clusterName string , env []string ) ([]* cloudinstances.CloudInstance , error ) {
70
+ args := []string {
71
+ kopsBinary , "get" , "instances" , "--name" , clusterName , "-ojson" ,
72
+ }
73
+ c := exec .Command (args [0 ], args [1 :]... )
74
+ c .SetEnv (env ... )
75
+ var stdout bytes.Buffer
76
+ c .SetStdout (& stdout )
77
+ var stderr bytes.Buffer
78
+ c .SetStderr (& stderr )
79
+ if err := c .Run (); err != nil {
80
+ klog .Warningf ("failed to run %s; stderr=%s" , strings .Join (args , " " ), stderr .String ())
81
+ return nil , fmt .Errorf ("error querying instances from %s: %w" , strings .Join (args , " " ), err )
82
+ }
83
+ var instances []* cloudinstances.CloudInstance
84
+ if err := json .Unmarshal (stdout .Bytes (), & instances ); err != nil {
85
+ return nil , fmt .Errorf ("error parsing instance groups json: %w" , err )
86
+ }
87
+ return instances , nil
88
+ }
89
+
67
90
// GetInstanceGroups will retrieve the instance groups for the specified Cluster from the state store.
68
91
func GetInstanceGroups (kopsBinary , clusterName string , env []string ) ([]* api.InstanceGroup , error ) {
69
92
args := []string {
0 commit comments