@@ -17,7 +17,6 @@ limitations under the License.
1717package  controller
1818
1919import  (
20- 	"context" 
2120	"errors" 
2221	"fmt" 
2322	"strings" 
@@ -39,7 +38,7 @@ const (
3938	awsInternetGatewayIDAnnotation  =  "docker-machine-operator/aws-gateway" 
4039	awsVpcCIDR                      =  "10.1.0.0/16" 
4140	allowAllIPs                     =  "0.0.0.0/0" 
42- 	defaultZone                     =  "a"  //same as rancher amazonec2 driver default zone 
41+ 	defaultZone                     =  "a"  //  same as rancher amazonec2 driver default zone 
4342	regionParameter                 =  "amazonec2-region" 
4443)
4544
@@ -62,16 +61,16 @@ func (r *MachineReconciler) getAnnotationsArgsForAWS() []string {
6261	return  annotationArgs 
6362}
6463
65- func  (r  * MachineReconciler ) cleanupAWSResources (ctx  context. Context ) error  {
66- 	c , err  :=  r .awsEC2Client (ctx )
64+ func  (r  * MachineReconciler ) cleanupAWSResources () error  {
65+ 	c , err  :=  r .awsEC2Client ()
6766	if  err  !=  nil  {
6867		return  err 
6968	}
7069	return  r .deleteAwsVpc (c , r .machineObj .Annotations [awsVPCIDAnnotation ])
7170}
7271
73- func  (r  * MachineReconciler ) getAWSCredentials (ctx  context. Context ) (* awsAuthCredential , error ) {
74- 	authSecret , err  :=  r .getSecret (ctx ,  r .machineObj .Spec .AuthSecret )
72+ func  (r  * MachineReconciler ) getAWSCredentials () (* awsAuthCredential , error ) {
73+ 	authSecret , err  :=  r .getSecret (r .machineObj .Spec .AuthSecret )
7574	if  err  !=  nil  {
7675		return  nil , err 
7776	}
@@ -91,8 +90,8 @@ func (r *MachineReconciler) getAWSCredentials(ctx context.Context) (*awsAuthCred
9190	return  & awsCreds , nil 
9291}
9392
94- func  (r  * MachineReconciler ) newAWSClientSession (ctx  context. Context ) (* session.Session , error ) {
95- 	cred , err  :=  r .getAWSCredentials (ctx )
93+ func  (r  * MachineReconciler ) newAWSClientSession () (* session.Session , error ) {
94+ 	cred , err  :=  r .getAWSCredentials ()
9695	if  err  !=  nil  {
9796		return  nil , err 
9897	}
@@ -109,8 +108,8 @@ func (r *MachineReconciler) newAWSClientSession(ctx context.Context) (*session.S
109108	return  session , nil 
110109}
111110
112- func  (r  * MachineReconciler ) awsEC2Client (ctx  context. Context ) (* ec2.EC2 , error ) {
113- 	sess , err  :=  r .newAWSClientSession (ctx )
111+ func  (r  * MachineReconciler ) awsEC2Client () (* ec2.EC2 , error ) {
112+ 	sess , err  :=  r .newAWSClientSession ()
114113	if  err  !=  nil  {
115114		return  nil , err 
116115	}
@@ -144,6 +143,7 @@ func createAwsRoute(c *ec2.EC2, vpcId, internetGatewayID string) error {
144143	klog .Infof ("route table updated" )
145144	return  nil 
146145}
146+ 
147147func  deleteAwsRoute (c  * ec2.EC2 , vpcId  string ) error  {
148148	out , err  :=  c .DescribeRouteTables (& ec2.DescribeRouteTablesInput {})
149149	if  err  !=  nil  {
@@ -177,6 +177,7 @@ func attachInternetGatewayToVPC(c *ec2.EC2, internetGatewayId, vpcID string) err
177177	})
178178	return  err 
179179}
180+ 
180181func  detachInternetGatewayToVPC (c  * ec2.EC2 , internetGatewayID , vpcID  string ) error  {
181182	_ , err  :=  c .DetachInternetGateway (& ec2.DetachInternetGatewayInput {
182183		InternetGatewayId : & internetGatewayID ,
@@ -215,6 +216,7 @@ func (r *MachineReconciler) createAwsInternetGateway(c *ec2.EC2, vpcId string) e
215216	klog .Infof ("internet gateway is created with id: %s" , * out .InternetGateway .InternetGatewayId )
216217	return  nil 
217218}
219+ 
218220func  deleteAwsInternetGateway (c  * ec2.EC2 , gatewayId , vpcId  string ) error  {
219221	if  err  :=  deleteAwsRoute (c , vpcId ); err  !=  nil  {
220222		klog .Warningf ("failed to delete route, %s" , err .Error ())
@@ -263,9 +265,10 @@ func (r *MachineReconciler) createAwsSubnet(c *ec2.EC2, vpcID string) error {
263265		return  err 
264266	}
265267
266- 	r .log .Info ("aws subnet created" , "subnet id " , * out .Subnet .SubnetId )
268+ 	r .Log .Info ("aws subnet created" , "subnet id " , * out .Subnet .SubnetId )
267269	return  nil 
268270}
271+ 
269272func  (r  * MachineReconciler ) deleteAwsSubnet (c  * ec2.EC2 , subnetId  string ) error  {
270273	if  r .machineObj .Annotations [awsInternetGatewayIDAnnotation ] !=  ""  {
271274		if  err  :=  deleteAwsInternetGateway (c , r .machineObj .Annotations [awsInternetGatewayIDAnnotation ], r .machineObj .Annotations [awsVPCIDAnnotation ]); err  !=  nil  {
@@ -283,7 +286,7 @@ func (r *MachineReconciler) deleteAwsSubnet(c *ec2.EC2, subnetId string) error {
283286		return  err 
284287	}
285288
286- 	r .log .Info ("subnet successfully deleted" )
289+ 	r .Log .Info ("subnet successfully deleted" )
287290	return  nil 
288291}
289292
@@ -302,6 +305,7 @@ func getVPC(c *ec2.EC2, vpcId *string) (*ec2.Vpc, error) {
302305	}
303306	return  nil , fmt .Errorf ("no vpc found with id %s" , * vpcId )
304307}
308+ 
305309func  (r  * MachineReconciler ) createAwsVpc (c  * ec2.EC2 ) error  {
306310	var  vpc  * ec2.Vpc 
307311	var  err  error 
@@ -356,6 +360,7 @@ func (r *MachineReconciler) createAwsVpc(c *ec2.EC2) error {
356360	klog .Infof ("aws vpc created with id %s" , * vpc .VpcId )
357361	return  nil 
358362}
363+ 
359364func  (r  * MachineReconciler ) deleteAwsVpc (c  * ec2.EC2 , vpcID  string ) error  {
360365	if  r .machineObj .Annotations [awsVPCIDAnnotation ] ==  ""  {
361366		return  nil 
@@ -410,12 +415,12 @@ func deleteSecurityGroup(c *ec2.EC2, vpcId string) error {
410415	return  nil 
411416}
412417
413- func  (r  * MachineReconciler ) createAWSEnvironment (ctx  context. Context ) error  {
418+ func  (r  * MachineReconciler ) createAWSEnvironment () error  {
414419	if  r .machineObj .Annotations [awsVPCIDAnnotation ] !=  ""  &&  r .machineObj .Annotations [awsSubnetIDAnnotation ] !=  ""  &&  r .machineObj .Annotations [awsInternetGatewayIDAnnotation ] !=  ""  {
415420		return  nil 
416421	}
417422
418- 	c , err  :=  r .awsEC2Client (ctx )
423+ 	c , err  :=  r .awsEC2Client ()
419424	if  err  !=  nil  {
420425		return  err 
421426	}
0 commit comments