Skip to content

Commit

Permalink
Remove unused client and function getRunningInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
enxebre committed Feb 5, 2020
1 parent 6398c56 commit 4cd29b5
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 289 deletions.
150 changes: 0 additions & 150 deletions pkg/actuators/machine/awsclient.go

This file was deleted.

88 changes: 0 additions & 88 deletions pkg/actuators/machine/awsclient_test.go

This file was deleted.

29 changes: 0 additions & 29 deletions pkg/actuators/machine/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,35 +221,6 @@ func TestRemoveStoppedMachine(t *testing.T) {
}
}

func TestRunningInstance(t *testing.T) {
machine, err := stubMachine()
if err != nil {
t.Fatalf("Unable to build test machine manifest: %v", err)
}

mockCtrl := gomock.NewController(t)
mockAWSClient := mockaws.NewMockClient(mockCtrl)

// Error describing instances
mockAWSClient.EXPECT().DescribeInstances(gomock.Any()).Return(&ec2.DescribeInstancesOutput{
Reservations: []*ec2.Reservation{
{
Instances: []*ec2.Instance{
{
ImageId: aws.String("ami-a9acbbd6"),
InstanceId: aws.String("i-02fcb933c5da7085c"),
State: &ec2.InstanceState{
Name: aws.String(ec2.InstanceStateNameRunning),
},
LaunchTime: aws.Time(time.Now()),
},
},
},
},
}, nil).AnyTimes()
getRunningInstance(machine, mockAWSClient)
}

func TestLaunchInstance(t *testing.T) {
machine, err := stubMachine()
if err != nil {
Expand Down
22 changes: 0 additions & 22 deletions pkg/actuators/machine/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,6 @@ func existingInstanceStates() []*string {
}
}

// getRunningInstance returns the AWS instance for a given machine. If multiple instances match our machine,
// the most recently launched will be returned. If no instance exists, an error will be returned.
func getRunningInstance(machine *machinev1.Machine, client awsclient.Client) (*ec2.Instance, error) {
instances, err := getRunningInstances(machine, client)
if err != nil {
return nil, err
}
if len(instances) == 0 {
return nil, fmt.Errorf("no instance found for machine: %s", machine.Name)
}

sortInstances(instances)
return instances[0], nil
}

// getRunningInstances returns all running instances that have a tag matching our machine name,
// and cluster ID.
func getRunningInstances(machine *machinev1.Machine, client awsclient.Client) ([]*ec2.Instance, error) {
runningInstanceStateFilter := []*string{aws.String(ec2.InstanceStateNameRunning)}
return getInstances(machine, client, runningInstanceStateFilter)
}

// getRunningFromInstances returns all running instances from a list of instances.
func getRunningFromInstances(instances []*ec2.Instance) []*ec2.Instance {
var runningInstances []*ec2.Instance
Expand Down

0 comments on commit 4cd29b5

Please sign in to comment.