mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Add FakeEC2 Instances support for matching by instance id
This commit is contained in:
parent
a3e8e80572
commit
5efd1e717f
@ -164,12 +164,25 @@ type FakeEC2 struct {
|
|||||||
instances []ec2.Instance
|
instances []ec2.Instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func contains(haystack []string, needle string) bool {
|
||||||
|
for _, s := range haystack {
|
||||||
|
if needle == s {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (self *FakeEC2) Instances(instanceIds []string, filter *ec2InstanceFilter) (resp *ec2.InstancesResp, err error) {
|
func (self *FakeEC2) Instances(instanceIds []string, filter *ec2InstanceFilter) (resp *ec2.InstancesResp, err error) {
|
||||||
matches := []ec2.Instance{}
|
matches := []ec2.Instance{}
|
||||||
for _, instance := range self.instances {
|
for _, instance := range self.instances {
|
||||||
if filter == nil || filter.Matches(instance) {
|
if filter != nil && !filter.Matches(instance) {
|
||||||
matches = append(matches, instance)
|
continue
|
||||||
}
|
}
|
||||||
|
if instanceIds != nil && !contains(instanceIds, instance.InstanceId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
matches = append(matches, instance)
|
||||||
}
|
}
|
||||||
return &ec2.InstancesResp{"",
|
return &ec2.InstancesResp{"",
|
||||||
[]ec2.Reservation{
|
[]ec2.Reservation{
|
||||||
|
Loading…
Reference in New Issue
Block a user